// Join method is invoked when a Sandbox is attached to an endpoint. func (d *driver) Join(nid, eid types.UUID, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error { if err := jinfo.SetHostsPath("/etc/hosts"); err != nil { return err } return jinfo.SetResolvConfPath("/etc/resolv.conf") }
// Join method is invoked when a Sandbox is attached to an endpoint. func (d *driver) Join(nid, eid types.UUID, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error { join := &joinRequest{ NetworkID: string(nid), EndpointID: string(eid), SandboxKey: sboxKey, Options: options, } var ( res joinResponse err error ) if err = d.call("Join", join, &res); err != nil { return err } // Expect each interface ID given by CreateEndpoint to have an // entry at that index in the names supplied here. In other words, // if you supply 0..n interfaces with IDs 0..n above, you should // supply the names in the same order. ifaceNames := res.InterfaceNames for _, iface := range jinfo.InterfaceNames() { i := iface.ID() if i >= len(ifaceNames) || i < 0 { return fmt.Errorf("no correlating interface %d in supplied interface names", i) } supplied := ifaceNames[i] if err := iface.SetNames(supplied.SrcName, supplied.DstName); err != nil { return errorWithRollback(fmt.Sprintf("failed to set interface name: %s", err), d.Leave(nid, eid)) } } var addr net.IP if res.Gateway != "" { if addr = net.ParseIP(res.Gateway); addr == nil { return fmt.Errorf(`unable to parse Gateway "%s"`, res.Gateway) } if jinfo.SetGateway(addr) != nil { return errorWithRollback(fmt.Sprintf("failed to set gateway: %v", addr), d.Leave(nid, eid)) } } if res.GatewayIPv6 != "" { if addr = net.ParseIP(res.GatewayIPv6); addr == nil { return fmt.Errorf(`unable to parse GatewayIPv6 "%s"`, res.GatewayIPv6) } if jinfo.SetGatewayIPv6(addr) != nil { return errorWithRollback(fmt.Sprintf("failed to set gateway IPv6: %v", addr), d.Leave(nid, eid)) } } if jinfo.SetHostsPath(res.HostsPath) != nil { return errorWithRollback(fmt.Sprintf("failed to set hosts path: %s", res.HostsPath), d.Leave(nid, eid)) } if jinfo.SetResolvConfPath(res.ResolvConfPath) != nil { return errorWithRollback(fmt.Sprintf("failed to set resolv.conf path: %s", res.ResolvConfPath), d.Leave(nid, eid)) } return nil }