本文整理汇总了Golang中github.com/docker/libnetwork.Endpoint类的典型用法代码示例。如果您正苦于以下问题:Golang Endpoint类的具体用法?Golang Endpoint怎么用?Golang Endpoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Endpoint类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: disconnectFromNetwork
func (container *Container) disconnectFromNetwork(n libnetwork.Network) error {
var (
ep libnetwork.Endpoint
sbox libnetwork.Sandbox
)
s := func(current libnetwork.Endpoint) bool {
if sb := current.Info().Sandbox(); sb != nil {
if sb.ContainerID() == container.ID {
ep = current
sbox = sb
return true
}
}
return false
}
n.WalkEndpoints(s)
if ep == nil {
return fmt.Errorf("container %s is not connected to the network", container.ID)
}
if err := ep.Leave(sbox); err != nil {
return fmt.Errorf("container %s failed to leave network %s: %v", container.ID, n.Name(), err)
}
if err := ep.Delete(); err != nil {
return fmt.Errorf("endpoint delete failed for container %s on network %s: %v", container.ID, n.Name(), err)
}
delete(container.NetworkSettings.Networks, n.Name())
return nil
}
开发者ID:rszewczyk,项目名称:docker,代码行数:33,代码来源:container_unix.go
示例2: buildEndpointInfo
func (container *Container) buildEndpointInfo(ep libnetwork.Endpoint, networkSettings *network.Settings) (*network.Settings, error) {
if ep == nil {
return nil, fmt.Errorf("invalid endpoint while building port map info")
}
if networkSettings == nil {
return nil, fmt.Errorf("invalid networksettings while building port map info")
}
epInfo := ep.Info()
if epInfo == nil {
// It is not an error to get an empty endpoint info
return networkSettings, nil
}
iface := epInfo.Iface()
if iface == nil {
return networkSettings, nil
}
ones, _ := iface.Address().Mask.Size()
networkSettings.IPAddress = iface.Address().IP.String()
networkSettings.IPPrefixLen = ones
if iface.AddressIPv6().IP.To16() != nil {
onesv6, _ := iface.AddressIPv6().Mask.Size()
networkSettings.GlobalIPv6Address = iface.AddressIPv6().IP.String()
networkSettings.GlobalIPv6PrefixLen = onesv6
}
return networkSettings, nil
}
开发者ID:francisbouvier,项目名称:docker,代码行数:32,代码来源:container_unix.go
示例3: parallelLeave
func parallelLeave(t *testing.T, rc libnetwork.Sandbox, ep libnetwork.Endpoint, thrNumber int) {
debugf("L%d.", thrNumber)
var err error
cid := fmt.Sprintf("%drace", thrNumber)
sb := sboxes[thrNumber-1]
if thrNumber == first {
err = ep.Leave(sb)
} else {
err = sb.Delete()
// re add sandbox
defer func() {
if err == nil {
var e error
if sboxes[thrNumber-1], e = controller.NewSandbox(cid); e != nil {
t.Fatalf("Failed to recreate sandbox %s: %v", cid, e)
}
}
}()
}
runtime.LockOSThread()
if err != nil {
if _, ok := err.(types.ForbiddenError); !ok {
t.Fatalf("thread %d: %v", thrNumber, err)
}
debugf("LE%d(%v).", thrNumber, err)
}
debugf("LD%d.", thrNumber)
}
开发者ID:hurrygeek,项目名称:libnetwork,代码行数:31,代码来源:libnetwork_test.go
示例4: parallelLeave
func parallelLeave(t *testing.T, ep libnetwork.Endpoint, thrNumber int) {
debugf("L%d.", thrNumber)
err := ep.Leave("racing_container")
runtime.LockOSThread()
if err != nil {
if err != libnetwork.ErrNoContainer && err != libnetwork.ErrInvalidJoin {
t.Fatal(err)
}
debugf("LE%d(%v).", thrNumber, err)
}
debugf("LD%d.", thrNumber)
}
开发者ID:choldrim,项目名称:docker,代码行数:12,代码来源:libnetwork_test.go
示例5: buildEndpointInfo
func (container *Container) buildEndpointInfo(ep libnetwork.Endpoint, networkSettings *network.Settings) (*network.Settings, error) {
if ep == nil {
return nil, fmt.Errorf("invalid endpoint while building port map info")
}
if networkSettings == nil {
return nil, fmt.Errorf("invalid networksettings while building port map info")
}
epInfo := ep.Info()
if epInfo == nil {
// It is not an error to get an empty endpoint info
return networkSettings, nil
}
ifaceList := epInfo.InterfaceList()
if len(ifaceList) == 0 {
return networkSettings, nil
}
iface := ifaceList[0]
ones, _ := iface.Address().Mask.Size()
networkSettings.IPAddress = iface.Address().IP.String()
networkSettings.IPPrefixLen = ones
if iface.AddressIPv6().IP.To16() != nil {
onesv6, _ := iface.AddressIPv6().Mask.Size()
networkSettings.GlobalIPv6Address = iface.AddressIPv6().IP.String()
networkSettings.GlobalIPv6PrefixLen = onesv6
}
if len(ifaceList) == 1 {
return networkSettings, nil
}
networkSettings.SecondaryIPAddresses = make([]network.Address, 0, len(ifaceList)-1)
networkSettings.SecondaryIPv6Addresses = make([]network.Address, 0, len(ifaceList)-1)
for _, iface := range ifaceList[1:] {
ones, _ := iface.Address().Mask.Size()
addr := network.Address{Addr: iface.Address().IP.String(), PrefixLen: ones}
networkSettings.SecondaryIPAddresses = append(networkSettings.SecondaryIPAddresses, addr)
if iface.AddressIPv6().IP.To16() != nil {
onesv6, _ := iface.AddressIPv6().Mask.Size()
addrv6 := network.Address{Addr: iface.AddressIPv6().IP.String(), PrefixLen: onesv6}
networkSettings.SecondaryIPv6Addresses = append(networkSettings.SecondaryIPv6Addresses, addrv6)
}
}
return networkSettings, nil
}
开发者ID:renrujue,项目名称:docker,代码行数:52,代码来源:container_unix.go
示例6: updateJoinInfo
func (container *Container) updateJoinInfo(n libnetwork.Network, ep libnetwork.Endpoint) error {
epInfo := ep.Info()
if epInfo == nil {
// It is not an error to get an empty endpoint info
return nil
}
container.NetworkSettings.Networks[n.Name()].Gateway = epInfo.Gateway().String()
if epInfo.GatewayIPv6().To16() != nil {
container.NetworkSettings.Networks[n.Name()].IPv6Gateway = epInfo.GatewayIPv6().String()
}
return nil
}
开发者ID:maaquib,项目名称:docker,代码行数:13,代码来源:container_unix.go
示例7: parallelJoin
func parallelJoin(t *testing.T, ep libnetwork.Endpoint, thrNumber int) {
debugf("J%d.", thrNumber)
_, err := ep.Join("racing_container")
runtime.LockOSThread()
if err != nil {
if _, ok := err.(libnetwork.ErrNoContainer); !ok {
if _, ok := err.(libnetwork.ErrInvalidJoin); !ok {
t.Fatal(err)
}
}
debugf("JE%d(%v).", thrNumber, err)
}
debugf("JD%d.", thrNumber)
}
开发者ID:fwalker,项目名称:dashboard,代码行数:14,代码来源:libnetwork_test.go
示例8: buildPortMapInfo
func (container *Container) buildPortMapInfo(n libnetwork.Network, ep libnetwork.Endpoint, networkSettings *network.Settings) (*network.Settings, error) {
if ep == nil {
return nil, fmt.Errorf("invalid endpoint while building port map info")
}
if networkSettings == nil {
return nil, fmt.Errorf("invalid networksettings while building port map info")
}
driverInfo, err := ep.DriverInfo()
if err != nil {
return nil, err
}
if driverInfo == nil {
// It is not an error for epInfo to be nil
return networkSettings, nil
}
if mac, ok := driverInfo[netlabel.MacAddress]; ok {
networkSettings.MacAddress = mac.(net.HardwareAddr).String()
}
networkSettings.Ports = nat.PortMap{}
if expData, ok := driverInfo[netlabel.ExposedPorts]; ok {
if exposedPorts, ok := expData.([]types.TransportPort); ok {
for _, tp := range exposedPorts {
natPort := nat.NewPort(tp.Proto.String(), strconv.Itoa(int(tp.Port)))
networkSettings.Ports[natPort] = nil
}
}
}
mapData, ok := driverInfo[netlabel.PortMap]
if !ok {
return networkSettings, nil
}
if portMapping, ok := mapData.([]types.PortBinding); ok {
for _, pp := range portMapping {
natPort := nat.NewPort(pp.Proto.String(), strconv.Itoa(int(pp.Port)))
natBndg := nat.PortBinding{HostIp: pp.HostIP.String(), HostPort: strconv.Itoa(int(pp.HostPort))}
networkSettings.Ports[natPort] = append(networkSettings.Ports[natPort], natBndg)
}
}
return networkSettings, nil
}
开发者ID:circular-dark,项目名称:docker,代码行数:49,代码来源:container_linux.go
示例9: updateJoinInfo
func (container *Container) updateJoinInfo(ep libnetwork.Endpoint) error {
epInfo := ep.Info()
if epInfo == nil {
// It is not an error to get an empty endpoint info
return nil
}
container.NetworkSettings.Gateway = epInfo.Gateway().String()
if epInfo.GatewayIPv6().To16() != nil {
container.NetworkSettings.IPv6Gateway = epInfo.GatewayIPv6().String()
}
container.NetworkSettings.SandboxKey = epInfo.SandboxKey()
return nil
}
开发者ID:paralin,项目名称:docker,代码行数:16,代码来源:container_unix.go
示例10: parallelJoin
func parallelJoin(t *testing.T, rc libnetwork.Sandbox, ep libnetwork.Endpoint, thrNumber int) {
debugf("J%d.", thrNumber)
var err error
sb := sboxes[thrNumber-1]
err = ep.Join(sb)
runtime.LockOSThread()
if err != nil {
if _, ok := err.(types.ForbiddenError); !ok {
t.Fatalf("thread %d: %v", thrNumber, err)
}
debugf("JE%d(%v).", thrNumber, err)
}
debugf("JD%d.", thrNumber)
}
开发者ID:hurrygeek,项目名称:libnetwork,代码行数:16,代码来源:libnetwork_test.go
示例11: BuildEndpointInfo
// BuildEndpointInfo sets endpoint-related fields on container.NetworkSettings based on the provided network and endpoint.
func (container *Container) BuildEndpointInfo(n libnetwork.Network, ep libnetwork.Endpoint) error {
if ep == nil {
return errInvalidEndpoint
}
networkSettings := container.NetworkSettings
if networkSettings == nil {
return errInvalidNetwork
}
epInfo := ep.Info()
if epInfo == nil {
// It is not an error to get an empty endpoint info
return nil
}
if _, ok := networkSettings.Networks[n.Name()]; !ok {
networkSettings.Networks[n.Name()] = &network.EndpointSettings{
EndpointSettings: &networktypes.EndpointSettings{},
}
}
networkSettings.Networks[n.Name()].NetworkID = n.ID()
networkSettings.Networks[n.Name()].EndpointID = ep.ID()
iface := epInfo.Iface()
if iface == nil {
return nil
}
if iface.MacAddress() != nil {
networkSettings.Networks[n.Name()].MacAddress = iface.MacAddress().String()
}
if iface.Address() != nil {
ones, _ := iface.Address().Mask.Size()
networkSettings.Networks[n.Name()].IPAddress = iface.Address().IP.String()
networkSettings.Networks[n.Name()].IPPrefixLen = ones
}
if iface.AddressIPv6() != nil && iface.AddressIPv6().IP.To16() != nil {
onesv6, _ := iface.AddressIPv6().Mask.Size()
networkSettings.Networks[n.Name()].GlobalIPv6Address = iface.AddressIPv6().IP.String()
networkSettings.Networks[n.Name()].GlobalIPv6PrefixLen = onesv6
}
return nil
}
开发者ID:docker,项目名称:dockercraft,代码行数:48,代码来源:container.go
示例12: disconnectFromNetwork
func (container *Container) disconnectFromNetwork(n libnetwork.Network, updateSettings bool) error {
var (
ep libnetwork.Endpoint
sbox libnetwork.Sandbox
)
s := func(current libnetwork.Endpoint) bool {
if sb := current.Info().Sandbox(); sb != nil {
if sb.ContainerID() == container.ID {
ep = current
sbox = sb
return true
}
}
return false
}
n.WalkEndpoints(s)
if ep == nil {
return fmt.Errorf("could not locate network endpoint for container %s", container.ID)
}
if err := ep.Leave(sbox); err != nil {
return fmt.Errorf("container %s failed to leave network %s: %v", container.ID, n.Name(), err)
}
if err := ep.Delete(); err != nil {
return fmt.Errorf("endpoint delete failed for container %s on network %s: %v", container.ID, n.Name(), err)
}
if updateSettings {
networks := container.NetworkSettings.Networks
for i, s := range networks {
sn, err := container.daemon.FindNetwork(s)
if err != nil {
continue
}
if sn.Name() == n.Name() {
networks = append(networks[:i], networks[i+1:]...)
container.NetworkSettings.Networks = networks
break
}
}
}
return nil
}
开发者ID:ndeloof,项目名称:docker,代码行数:46,代码来源:container_unix.go
示例13: buildEndpointInfo
func (container *Container) buildEndpointInfo(n libnetwork.Network, ep libnetwork.Endpoint, networkSettings *network.Settings) (*network.Settings, error) {
if ep == nil {
return nil, derr.ErrorCodeEmptyEndpoint
}
if networkSettings == nil {
return nil, derr.ErrorCodeEmptyNetwork
}
epInfo := ep.Info()
if epInfo == nil {
// It is not an error to get an empty endpoint info
return networkSettings, nil
}
if _, ok := networkSettings.Networks[n.Name()]; !ok {
networkSettings.Networks[n.Name()] = new(network.EndpointSettings)
}
networkSettings.Networks[n.Name()].EndpointID = ep.ID()
iface := epInfo.Iface()
if iface == nil {
return networkSettings, nil
}
if iface.MacAddress() != nil {
networkSettings.Networks[n.Name()].MacAddress = iface.MacAddress().String()
}
if iface.Address() != nil {
ones, _ := iface.Address().Mask.Size()
networkSettings.Networks[n.Name()].IPAddress = iface.Address().IP.String()
networkSettings.Networks[n.Name()].IPPrefixLen = ones
}
if iface.AddressIPv6() != nil && iface.AddressIPv6().IP.To16() != nil {
onesv6, _ := iface.AddressIPv6().Mask.Size()
networkSettings.Networks[n.Name()].GlobalIPv6Address = iface.AddressIPv6().IP.String()
networkSettings.Networks[n.Name()].GlobalIPv6PrefixLen = onesv6
}
return networkSettings, nil
}
开发者ID:RockaLabs,项目名称:docker,代码行数:43,代码来源:container_unix.go
示例14: disconnectFromNetwork
func (daemon *Daemon) disconnectFromNetwork(container *container.Container, n libnetwork.Network, force bool) error {
var (
ep libnetwork.Endpoint
sbox libnetwork.Sandbox
)
s := func(current libnetwork.Endpoint) bool {
epInfo := current.Info()
if epInfo == nil {
return false
}
if sb := epInfo.Sandbox(); sb != nil {
if sb.ContainerID() == container.ID {
ep = current
sbox = sb
return true
}
}
return false
}
n.WalkEndpoints(s)
if ep == nil && force {
epName := strings.TrimPrefix(container.Name, "/")
ep, err := n.EndpointByName(epName)
if err != nil {
return err
}
return ep.Delete(force)
}
if ep == nil {
return fmt.Errorf("container %s is not connected to the network", container.ID)
}
if err := ep.Leave(sbox); err != nil {
return fmt.Errorf("container %s failed to leave network %s: %v", container.ID, n.Name(), err)
}
container.NetworkSettings.Ports = getPortMapInfo(sbox)
if err := ep.Delete(false); err != nil {
return fmt.Errorf("endpoint delete failed for container %s on network %s: %v", container.ID, n.Name(), err)
}
delete(container.NetworkSettings.Networks, n.Name())
if daemon.clusterProvider != nil && n.Info().Dynamic() && !container.Managed {
if err := daemon.clusterProvider.DetachNetwork(n.Name(), container.ID); err != nil {
logrus.Warnf("error detaching from network %s: %v", n.Name(), err)
if err := daemon.clusterProvider.DetachNetwork(n.ID(), container.ID); err != nil {
logrus.Warnf("error detaching from network %s: %v", n.ID(), err)
}
}
}
return nil
}
开发者ID:wowsoso,项目名称:docker,代码行数:58,代码来源:container_operations.go
示例15: getEndpointPortMapInfo
func getEndpointPortMapInfo(ep libnetwork.Endpoint) (nat.PortMap, error) {
pm := nat.PortMap{}
driverInfo, err := ep.DriverInfo()
if err != nil {
return pm, err
}
if driverInfo == nil {
// It is not an error for epInfo to be nil
return pm, nil
}
if expData, ok := driverInfo[netlabel.ExposedPorts]; ok {
if exposedPorts, ok := expData.([]types.TransportPort); ok {
for _, tp := range exposedPorts {
natPort, err := nat.NewPort(tp.Proto.String(), strconv.Itoa(int(tp.Port)))
if err != nil {
return pm, fmt.Errorf("Error parsing Port value(%v):%v", tp.Port, err)
}
pm[natPort] = nil
}
}
}
mapData, ok := driverInfo[netlabel.PortMap]
if !ok {
return pm, nil
}
if portMapping, ok := mapData.([]types.PortBinding); ok {
for _, pp := range portMapping {
natPort, err := nat.NewPort(pp.Proto.String(), strconv.Itoa(int(pp.Port)))
if err != nil {
return pm, err
}
natBndg := nat.PortBinding{HostIP: pp.HostIP.String(), HostPort: strconv.Itoa(int(pp.HostPort))}
pm[natPort] = append(pm[natPort], natBndg)
}
}
return pm, nil
}
开发者ID:docker,项目名称:dockercraft,代码行数:42,代码来源:container.go
示例16: parallelJoin
func parallelJoin(t *testing.T, ep libnetwork.Endpoint, thrNumber int) {
debugf("J%d.", thrNumber)
var err error
if thrNumber == first {
err = ep.Join(fmt.Sprintf("%drace", thrNumber), libnetwork.JoinOptionUseDefaultSandbox())
} else {
err = ep.Join(fmt.Sprintf("%drace", thrNumber))
}
runtime.LockOSThread()
if err != nil {
if _, ok := err.(libnetwork.ErrNoContainer); !ok {
if _, ok := err.(libnetwork.ErrInvalidJoin); !ok {
t.Fatalf("thread %d: %v", thrNumber, err)
}
}
debugf("JE%d(%v).", thrNumber, err)
}
debugf("JD%d.", thrNumber)
}
开发者ID:aduermael,项目名称:libnetwork,代码行数:20,代码来源:libnetwork_test.go
示例17: parallelLeave
func parallelLeave(t *testing.T, ep libnetwork.Endpoint, thrNumber int) {
debugf("L%d.", thrNumber)
var err error
if thrNumber == first {
err = ep.Leave(fmt.Sprintf("%drace", thrNumber))
} else {
err = controller.LeaveAll(fmt.Sprintf("%drace", thrNumber))
}
runtime.LockOSThread()
if err != nil {
if _, ok := err.(libnetwork.ErrNoContainer); !ok {
if _, ok := err.(libnetwork.ErrInvalidJoin); !ok {
t.Fatalf("thread %d: %v", thrNumber, err)
}
}
debugf("LE%d(%v).", thrNumber, err)
}
debugf("LD%d.", thrNumber)
}
开发者ID:aduermael,项目名称:libnetwork,代码行数:20,代码来源:libnetwork_test.go
示例18: getRunzAnet
func (daemon *Daemon) getRunzAnet(ep libnetwork.Endpoint) (specs.Anet, error) {
var (
linkName string
lowerLink string
defRouter string
)
epInfo := ep.Info()
if epInfo == nil {
return specs.Anet{}, fmt.Errorf("invalid endpoint")
}
nw, err := daemon.GetNetworkByName(ep.Network())
if err != nil {
return specs.Anet{}, fmt.Errorf("Failed to get network %s: %v", ep.Network(), err)
}
// Evaluate default router, linkname and lowerlink for interface endpoint
switch nw.Type() {
case "bridge":
defRouter = epInfo.Gateway().String()
linkName = "net0" // Should always be net0 for a container
// TODO We construct lowerlink here exactly as done for solaris bridge
// initialization. Need modular code to reuse.
options := nw.Info().DriverOptions()
nwName := options["com.docker.network.bridge.name"]
lastChar := nwName[len(nwName)-1:]
if _, err = strconv.Atoi(lastChar); err != nil {
lowerLink = nwName + "_0"
} else {
lowerLink = nwName
}
case "overlay":
defRouter = ""
linkName = "net1"
// TODO Follows generateVxlanName() in solaris overlay.
id := nw.ID()
if len(nw.ID()) > 12 {
id = nw.ID()[:12]
}
lowerLink = "vx_" + id + "_0"
}
runzanet := specs.Anet{
Linkname: linkName,
Lowerlink: lowerLink,
Allowedaddr: epInfo.Iface().Address().String(),
Configallowedaddr: "true",
Defrouter: defRouter,
Linkprotection: "mac-nospoof, ip-nospoof",
Macaddress: epInfo.Iface().MacAddress().String(),
}
return runzanet, nil
}
开发者ID:jfrazelle,项目名称:docker,代码行数:58,代码来源:oci_solaris.go
示例19: buildEndpointResource
func buildEndpointResource(ep libnetwork.Endpoint) *endpointResource {
r := &endpointResource{}
if ep != nil {
r.Name = ep.Name()
r.ID = ep.ID()
r.Network = ep.Network()
}
return r
}
开发者ID:noqcks,项目名称:docker,代码行数:9,代码来源:api.go
示例20: buildEndpointResource
func buildEndpointResource(ep libnetwork.Endpoint) *endpointResource {
r := &endpointResource{}
var iplist []string
if ep != nil {
r.Name = ep.Name()
r.ID = ep.ID()
r.Network = ep.Network()
// Build a list of ip addrs on this endpoint.
for _, iface := range ep.Info().InterfaceList() {
if iface.Address().IP != nil && len(iface.Address().IP) > 0 {
ip := iface.Address().IP.String()
iplist = append(iplist, ip)
}
}
r.InterfaceList = iplist
}
return r
}
开发者ID:vijayendrabvs,项目名称:libnetwork,代码行数:18,代码来源:api.go
注:本文中的github.com/docker/libnetwork.Endpoint类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论