本文整理汇总了Golang中github.com/docker/libnetwork.JoinOptionDomainname函数的典型用法代码示例。如果您正苦于以下问题:Golang JoinOptionDomainname函数的具体用法?Golang JoinOptionDomainname怎么用?Golang JoinOptionDomainname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JoinOptionDomainname函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestEndpointUpdateParent
func TestEndpointUpdateParent(t *testing.T) {
if !netutils.IsRunningInContainer() {
defer netutils.SetupTestNetNS(t)()
}
n, err := createTestNetwork("bridge", "testnetwork", options.Generic{}, options.Generic{})
if err != nil {
t.Fatal(err)
}
ep1, err := n.CreateEndpoint("ep1", nil)
if err != nil {
t.Fatal(err)
}
_, err = ep1.Join(containerID,
libnetwork.JoinOptionHostname("test1"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
if err != nil {
t.Fatal(err)
}
defer func() {
err = ep1.Leave(containerID)
if err != nil {
t.Fatal(err)
}
}()
ep2, err := n.CreateEndpoint("ep2", nil)
if err != nil {
t.Fatal(err)
}
_, err = ep2.Join("container2",
libnetwork.JoinOptionHostname("test2"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionHostsPath("/var/lib/docker/test_network/container2/hosts"),
libnetwork.JoinOptionParentUpdate(ep1.ID(), "web", "192.168.0.2"))
if err != nil {
t.Fatal(err)
}
defer func() {
err = ep2.Leave("container2")
if err != nil {
t.Fatal(err)
}
}()
}
开发者ID:choldrim,项目名称:docker,代码行数:53,代码来源:libnetwork_test.go
示例2: parseOptions
func (ej *endpointJoin) parseOptions() []libnetwork.EndpointOption {
var setFctList []libnetwork.EndpointOption
if ej.HostName != "" {
setFctList = append(setFctList, libnetwork.JoinOptionHostname(ej.HostName))
}
if ej.DomainName != "" {
setFctList = append(setFctList, libnetwork.JoinOptionDomainname(ej.DomainName))
}
if ej.HostsPath != "" {
setFctList = append(setFctList, libnetwork.JoinOptionHostsPath(ej.HostsPath))
}
if ej.ResolvConfPath != "" {
setFctList = append(setFctList, libnetwork.JoinOptionResolvConfPath(ej.ResolvConfPath))
}
if ej.UseDefaultSandbox {
setFctList = append(setFctList, libnetwork.JoinOptionUseDefaultSandbox())
}
if ej.DNS != nil {
for _, d := range ej.DNS {
setFctList = append(setFctList, libnetwork.JoinOptionDNS(d))
}
}
if ej.ExtraHosts != nil {
for _, e := range ej.ExtraHosts {
setFctList = append(setFctList, libnetwork.JoinOptionExtraHost(e.Name, e.Address))
}
}
if ej.ParentUpdates != nil {
for _, p := range ej.ParentUpdates {
setFctList = append(setFctList, libnetwork.JoinOptionParentUpdate(p.EndpointID, p.Name, p.Address))
}
}
return setFctList
}
开发者ID:ch3lo,项目名称:docker,代码行数:34,代码来源:api.go
示例3: TestEndpointInvalidLeave
func TestEndpointInvalidLeave(t *testing.T) {
if !netutils.IsRunningInContainer() {
defer netutils.SetupTestNetNS(t)()
}
n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{}, options.Generic{})
if err != nil {
t.Fatal(err)
}
ep, err := n.CreateEndpoint("ep1")
if err != nil {
t.Fatal(err)
}
err = ep.Leave(containerID)
if err == nil {
t.Fatal("Expected to fail leave from an endpoint which has no active join")
}
if _, ok := err.(libnetwork.InvalidContainerIDError); !ok {
if err != libnetwork.ErrNoContainer {
t.Fatalf("Failed for unexpected reason: %v", err)
}
}
_, err = ep.Join(containerID,
libnetwork.JoinOptionHostname("test"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
if err != nil {
t.Fatal(err)
}
defer func() {
err = ep.Leave(containerID)
if err != nil {
t.Fatal(err)
}
}()
err = ep.Leave("")
if err == nil {
t.Fatal("Expected to fail leave with empty container id")
}
if _, ok := err.(libnetwork.InvalidContainerIDError); !ok {
t.Fatalf("Failed for unexpected reason: %v", err)
}
err = ep.Leave("container2")
if err == nil {
t.Fatal("Expected to fail leave with wrong container id")
}
if _, ok := err.(libnetwork.InvalidContainerIDError); !ok {
t.Fatalf("Failed for unexpected reason: %v", err)
}
}
开发者ID:choldrim,项目名称:docker,代码行数:60,代码来源:libnetwork_test.go
示例4: TestNull
func TestNull(t *testing.T) {
network, err := createTestNetwork("null", "testnetwork", options.Generic{},
options.Generic{})
if err != nil {
t.Fatal(err)
}
ep, err := network.CreateEndpoint("testep")
if err != nil {
t.Fatal(err)
}
_, err = ep.Join("null_container",
libnetwork.JoinOptionHostname("test"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
if err != nil {
t.Fatal(err)
}
err = ep.Leave("null_container")
if err != nil {
t.Fatal(err)
}
if err := ep.Delete(); err != nil {
t.Fatal(err)
}
if err := network.Delete(); err != nil {
t.Fatal(err)
}
}
开发者ID:choldrim,项目名称:docker,代码行数:33,代码来源:libnetwork_test.go
示例5: TestEndpointJoin
func TestEndpointJoin(t *testing.T) {
if !netutils.IsRunningInContainer() {
defer netutils.SetupTestNetNS(t)()
}
n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{}, options.Generic{})
if err != nil {
t.Fatal(err)
}
ep, err := n.CreateEndpoint("ep1")
if err != nil {
t.Fatal(err)
}
// Validate if ep.Info() only gives me IP address info and not names and gateway during CreateEndpoint()
info := ep.Info()
for _, iface := range info.InterfaceList() {
if iface.Address().IP.To4() == nil {
t.Fatalf("Invalid IP address returned: %v", iface.Address())
}
}
if info.Gateway().To4() != nil {
t.Fatalf("Expected empty gateway for an empty endpoint. Instead found a gateway: %v", info.Gateway())
}
if info.SandboxKey() != "" {
t.Fatalf("Expected an empty sandbox key for an empty endpoint. Instead found a non-empty sandbox key: %s", info.SandboxKey())
}
_, err = ep.Join(containerID,
libnetwork.JoinOptionHostname("test"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
if err != nil {
t.Fatal(err)
}
defer func() {
err = ep.Leave(containerID)
if err != nil {
t.Fatal(err)
}
}()
// Validate if ep.Info() only gives valid gateway and sandbox key after has container has joined.
info = ep.Info()
if info.Gateway().To4() == nil {
t.Fatalf("Expected a valid gateway for a joined endpoint. Instead found an invalid gateway: %v", info.Gateway())
}
if info.SandboxKey() == "" {
t.Fatalf("Expected an non-empty sandbox key for a joined endpoint. Instead found a empty sandbox key")
}
checkSandbox(t, info)
}
开发者ID:fwalker,项目名称:dashboard,代码行数:59,代码来源:libnetwork_test.go
示例6: TestEndpointDeleteWithActiveContainer
func TestEndpointDeleteWithActiveContainer(t *testing.T) {
if !netutils.IsRunningInContainer() {
defer netutils.SetupTestNetNS(t)()
}
n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
netlabel.GenericData: options.Generic{
"BridgeName": "testnetwork",
"AllowNonDefaultBridge": true,
},
})
if err != nil {
t.Fatal(err)
}
defer func() {
if err := n.Delete(); err != nil {
t.Fatal(err)
}
}()
ep, err := n.CreateEndpoint("ep1")
if err != nil {
t.Fatal(err)
}
defer func() {
err = ep.Delete()
if err != nil {
t.Fatal(err)
}
}()
defer controller.LeaveAll(containerID)
err = ep.Join(containerID,
libnetwork.JoinOptionHostname("test"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
runtime.LockOSThread()
if err != nil {
t.Fatal(err)
}
defer func() {
err = ep.Leave(containerID)
runtime.LockOSThread()
if err != nil {
t.Fatal(err)
}
}()
err = ep.Delete()
if err == nil {
t.Fatal("Expected to fail. But instead succeeded")
}
if _, ok := err.(*libnetwork.ActiveContainerError); !ok {
t.Fatalf("Did not fail with expected error. Actual error: %v", err)
}
}
开发者ID:aduermael,项目名称:libnetwork,代码行数:58,代码来源:libnetwork_test.go
示例7: TestEndpointMultipleJoins
func TestEndpointMultipleJoins(t *testing.T) {
if !netutils.IsRunningInContainer() {
defer netutils.SetupTestNetNS(t)()
}
n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{
netlabel.GenericData: options.Generic{
"BridgeName": "testnetwork",
"AllowNonDefaultBridge": true,
},
})
if err != nil {
t.Fatal(err)
}
defer func() {
if err := n.Delete(); err != nil {
t.Fatal(err)
}
}()
ep, err := n.CreateEndpoint("ep1")
if err != nil {
t.Fatal(err)
}
defer func() {
if err := ep.Delete(); err != nil {
t.Fatal(err)
}
}()
defer controller.LeaveAll(containerID)
err = ep.Join(containerID,
libnetwork.JoinOptionHostname("test"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
runtime.LockOSThread()
if err != nil {
t.Fatal(err)
}
defer func() {
err = ep.Leave(containerID)
runtime.LockOSThread()
if err != nil {
t.Fatal(err)
}
}()
err = ep.Join("container2")
if err == nil {
t.Fatal("Expected to fail multiple joins for the same endpoint")
}
if _, ok := err.(libnetwork.ErrInvalidJoin); !ok {
t.Fatalf("Failed for unexpected reason: %v", err)
}
}
开发者ID:aduermael,项目名称:libnetwork,代码行数:57,代码来源:libnetwork_test.go
示例8: main
func main() {
// Create a new controller instance
controller, err := libnetwork.New()
if err != nil {
return
}
// Select and configure the network driver
networkType := "bridge"
driverOptions := options.Generic{}
genericOption := make(map[string]interface{})
genericOption[netlabel.GenericData] = driverOptions
err = controller.ConfigureNetworkDriver(networkType, genericOption)
if err != nil {
return
}
// Create a network for containers to join.
// NewNetwork accepts Variadic optional arguments that libnetwork and Drivers can make of
network, err := controller.NewNetwork(networkType, "network1")
if err != nil {
return
}
// For each new container: allocate IP and interfaces. The returned network
// settings will be used for container infos (inspect and such), as well as
// iptables rules for port publishing. This info is contained or accessible
// from the returned endpoint.
ep, err := network.CreateEndpoint("Endpoint1")
if err != nil {
return
}
// A container can join the endpoint by providing the container ID to the join
// api which returns the sandbox key which can be used to access the sandbox
// created for the container during join.
// Join acceps Variadic arguments which will be made use of by libnetwork and Drivers
_, err = ep.Join("container1",
libnetwork.JoinOptionHostname("test"),
libnetwork.JoinOptionDomainname("docker.io"))
if err != nil {
return
}
// libentwork client can check the endpoint's operational data via the Info() API
epInfo, err := ep.DriverInfo()
mapData, ok := epInfo[netlabel.PortMap]
if ok {
portMapping, ok := mapData.([]netutils.PortBinding)
if ok {
fmt.Printf("Current port mapping for endpoint %s: %v", ep.Name(), portMapping)
}
}
}
开发者ID:colebrumley,项目名称:docker,代码行数:55,代码来源:readme.go
示例9: TestEndpointDeleteWithActiveContainer
func TestEndpointDeleteWithActiveContainer(t *testing.T) {
if !netutils.IsRunningInContainer() {
defer netutils.SetupTestNetNS(t)()
}
n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{}, options.Generic{})
if err != nil {
t.Fatal(err)
}
ep, err := n.CreateEndpoint("ep1")
if err != nil {
t.Fatal(err)
}
_, err = ep.Join(containerID,
libnetwork.JoinOptionHostname("test"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
if err != nil {
t.Fatal(err)
}
defer func() {
err = ep.Leave(containerID)
if err != nil {
t.Fatal(err)
}
err = ep.Delete()
if err != nil {
t.Fatal(err)
}
}()
err = ep.Delete()
if err == nil {
t.Fatal("Expected to fail. But instead succeeded")
}
if _, ok := err.(*libnetwork.ActiveContainerError); !ok {
t.Fatalf("Did not fail with expected error. Actual error: %v", err)
}
}
开发者ID:choldrim,项目名称:docker,代码行数:43,代码来源:libnetwork_test.go
示例10: TestEndpointMultipleJoins
func TestEndpointMultipleJoins(t *testing.T) {
if !netutils.IsRunningInContainer() {
defer netutils.SetupTestNetNS(t)()
}
n, err := createTestNetwork(bridgeNetType, "testnetwork", options.Generic{}, options.Generic{})
if err != nil {
t.Fatal(err)
}
ep, err := n.CreateEndpoint("ep1")
if err != nil {
t.Fatal(err)
}
_, err = ep.Join(containerID,
libnetwork.JoinOptionHostname("test"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
if err != nil {
t.Fatal(err)
}
defer func() {
err = ep.Leave(containerID)
if err != nil {
t.Fatal(err)
}
}()
_, err = ep.Join("container2")
if err == nil {
t.Fatal("Expected to fail multiple joins for the same endpoint")
}
if err != libnetwork.ErrInvalidJoin {
t.Fatalf("Failed for unexpected reason: %v", err)
}
}
开发者ID:choldrim,项目名称:docker,代码行数:39,代码来源:libnetwork_test.go
示例11: TestNull
func TestNull(t *testing.T) {
network, err := createTestNetwork("null", "testnull", options.Generic{})
if err != nil {
t.Fatal(err)
}
ep, err := network.CreateEndpoint("testep")
if err != nil {
t.Fatal(err)
}
err = ep.Join("null_container",
libnetwork.JoinOptionHostname("test"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
if err != nil {
t.Fatal(err)
}
err = ep.Leave("null_container")
if err != nil {
t.Fatal(err)
}
if err := ep.Delete(); err != nil {
t.Fatal(err)
}
// host type is special network. Cannot be removed.
err = network.Delete()
if err == nil {
t.Fatal(err)
}
if _, ok := err.(types.ForbiddenError); !ok {
t.Fatalf("Unexpected error type")
}
}
开发者ID:aduermael,项目名称:libnetwork,代码行数:37,代码来源:libnetwork_test.go
示例12: buildJoinOptions
func (container *Container) buildJoinOptions() ([]libnetwork.EndpointOption, error) {
var (
joinOptions []libnetwork.EndpointOption
err error
dns []string
dnsSearch []string
)
joinOptions = append(joinOptions, libnetwork.JoinOptionHostname(container.Config.Hostname),
libnetwork.JoinOptionDomainname(container.Config.Domainname))
if container.hostConfig.NetworkMode.IsHost() {
joinOptions = append(joinOptions, libnetwork.JoinOptionUseDefaultSandbox())
}
container.HostsPath, err = container.GetRootResourcePath("hosts")
if err != nil {
return nil, err
}
joinOptions = append(joinOptions, libnetwork.JoinOptionHostsPath(container.HostsPath))
container.ResolvConfPath, err = container.GetRootResourcePath("resolv.conf")
if err != nil {
return nil, err
}
joinOptions = append(joinOptions, libnetwork.JoinOptionResolvConfPath(container.ResolvConfPath))
if len(container.hostConfig.DNS) > 0 {
dns = container.hostConfig.DNS
} else if len(container.daemon.config.Dns) > 0 {
dns = container.daemon.config.Dns
}
for _, d := range dns {
joinOptions = append(joinOptions, libnetwork.JoinOptionDNS(d))
}
if len(container.hostConfig.DNSSearch) > 0 {
dnsSearch = container.hostConfig.DNSSearch
} else if len(container.daemon.config.DnsSearch) > 0 {
dnsSearch = container.daemon.config.DnsSearch
}
for _, ds := range dnsSearch {
joinOptions = append(joinOptions, libnetwork.JoinOptionDNSSearch(ds))
}
if container.NetworkSettings.SecondaryIPAddresses != nil {
name := container.Config.Hostname
if container.Config.Domainname != "" {
name = name + "." + container.Config.Domainname
}
for _, a := range container.NetworkSettings.SecondaryIPAddresses {
joinOptions = append(joinOptions, libnetwork.JoinOptionExtraHost(name, a.Addr))
}
}
var childEndpoints, parentEndpoints []string
children, err := container.daemon.Children(container.Name)
if err != nil {
return nil, err
}
for linkAlias, child := range children {
_, alias := path.Split(linkAlias)
// allow access to the linked container via the alias, real name, and container hostname
aliasList := alias + " " + child.Config.Hostname
// only add the name if alias isn't equal to the name
if alias != child.Name[1:] {
aliasList = aliasList + " " + child.Name[1:]
}
joinOptions = append(joinOptions, libnetwork.JoinOptionExtraHost(aliasList, child.NetworkSettings.IPAddress))
if child.NetworkSettings.EndpointID != "" {
childEndpoints = append(childEndpoints, child.NetworkSettings.EndpointID)
}
}
for _, extraHost := range container.hostConfig.ExtraHosts {
// allow IPv6 addresses in extra hosts; only split on first ":"
parts := strings.SplitN(extraHost, ":", 2)
joinOptions = append(joinOptions, libnetwork.JoinOptionExtraHost(parts[0], parts[1]))
}
refs := container.daemon.ContainerGraph().RefPaths(container.ID)
for _, ref := range refs {
if ref.ParentID == "0" {
continue
}
c, err := container.daemon.Get(ref.ParentID)
if err != nil {
logrus.Error(err)
}
if c != nil && !container.daemon.config.DisableBridge && container.hostConfig.NetworkMode.IsPrivate() {
logrus.Debugf("Update /etc/hosts of %s for alias %s with ip %s", c.ID, ref.Name, container.NetworkSettings.IPAddress)
joinOptions = append(joinOptions, libnetwork.JoinOptionParentUpdate(c.NetworkSettings.EndpointID, ref.Name, container.NetworkSettings.IPAddress))
if c.NetworkSettings.EndpointID != "" {
//.........这里部分代码省略.........
开发者ID:paralin,项目名称:docker,代码行数:101,代码来源:container_unix.go
示例13: TestHost
func TestHost(t *testing.T) {
network, err := createTestNetwork("host", "testnetwork", options.Generic{}, options.Generic{})
if err != nil {
t.Fatal(err)
}
ep1, err := network.CreateEndpoint("testep1")
if err != nil {
t.Fatal(err)
}
_, err = ep1.Join("host_container1",
libnetwork.JoinOptionHostname("test1"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
libnetwork.JoinOptionUseDefaultSandbox())
if err != nil {
t.Fatal(err)
}
ep2, err := network.CreateEndpoint("testep2")
if err != nil {
t.Fatal(err)
}
_, err = ep2.Join("host_container2",
libnetwork.JoinOptionHostname("test2"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
libnetwork.JoinOptionUseDefaultSandbox())
if err != nil {
t.Fatal(err)
}
err = ep1.Leave("host_container1")
if err != nil {
t.Fatal(err)
}
err = ep2.Leave("host_container2")
if err != nil {
t.Fatal(err)
}
if err := ep1.Delete(); err != nil {
t.Fatal(err)
}
if err := ep2.Delete(); err != nil {
t.Fatal(err)
}
// Try to create another host endpoint and join/leave that.
ep3, err := network.CreateEndpoint("testep3")
if err != nil {
t.Fatal(err)
}
_, err = ep3.Join("host_container3",
libnetwork.JoinOptionHostname("test3"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
libnetwork.JoinOptionUseDefaultSandbox())
if err != nil {
t.Fatal(err)
}
err = ep3.Leave("host_container3")
if err != nil {
t.Fatal(err)
}
if err := ep3.Delete(); err != nil {
t.Fatal(err)
}
if err := network.Delete(); err != nil {
t.Fatal(err)
}
}
开发者ID:choldrim,项目名称:docker,代码行数:80,代码来源:libnetwork_test.go
示例14: TestEndpointJoin
func TestEndpointJoin(t *testing.T) {
if !netutils.IsRunningInContainer() {
defer netutils.SetupTestNetNS(t)()
}
// Create network 1 and add 2 endpoint: ep11, ep12
n1, err := createTestNetwork(bridgeNetType, "testnetwork1", options.Generic{
netlabel.GenericData: options.Generic{
"BridgeName": "testnetwork1",
"AllowNonDefaultBridge": true,
},
})
if err != nil {
t.Fatal(err)
}
defer func() {
if err := n1.Delete(); err != nil {
t.Fatal(err)
}
}()
ep1, err := n1.CreateEndpoint("ep1")
if err != nil {
t.Fatal(err)
}
defer func() {
if err := ep1.Delete(); err != nil {
t.Fatal(err)
}
}()
// Validate if ep.Info() only gives me IP address info and not names and gateway during CreateEndpoint()
info := ep1.Info()
for _, iface := range info.InterfaceList() {
if iface.Address().IP.To4() == nil {
t.Fatalf("Invalid IP address returned: %v", iface.Address())
}
}
if info.Gateway().To4() != nil {
t.Fatalf("Expected empty gateway for an empty endpoint. Instead found a gateway: %v", info.Gateway())
}
if info.SandboxKey() != "" {
t.Fatalf("Expected an empty sandbox key for an empty endpoint. Instead found a non-empty sandbox key: %s", info.SandboxKey())
}
defer controller.LeaveAll(containerID)
err = ep1.Join(containerID,
libnetwork.JoinOptionHostname("test"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
runtime.LockOSThread()
if err != nil {
t.Fatal(err)
}
defer func() {
err = ep1.Leave(containerID)
runtime.LockOSThread()
if err != nil {
t.Fatal(err)
}
}()
// Validate if ep.Info() only gives valid gateway and sandbox key after has container has joined.
info = ep1.Info()
if info.Gateway().To4() == nil {
t.Fatalf("Expected a valid gateway for a joined endpoint. Instead found an invalid gateway: %v", info.Gateway())
}
if info.SandboxKey() == "" {
t.Fatalf("Expected an non-empty sandbox key for a joined endpoint. Instead found a empty sandbox key")
}
// Check endpoint provided container information
if ep1.ContainerInfo().ID() != containerID {
t.Fatalf("Endpoint ContainerInfo returned unexpected id: %s", ep1.ContainerInfo().ID())
}
// Attempt retrieval of endpoint interfaces statistics
stats, err := ep1.Statistics()
if err != nil {
t.Fatal(err)
}
if _, ok := stats["eth0"]; !ok {
t.Fatalf("Did not find eth0 statistics")
}
// Now test the container joining another network
n2, err := createTestNetwork(bridgeNetType, "testnetwork2",
options.Generic{
netlabel.GenericData: options.Generic{
"BridgeName": "testnetwork2",
"AllowNonDefaultBridge": true,
},
})
if err != nil {
t.Fatal(err)
//.........这里部分代码省略.........
开发者ID:aduermael,项目名称:libnetwork,代码行数:101,代码来源:libnetwork_test.go
示例15: TestEndpointUpdateParent
func TestEndpointUpdateParent(t *testing.T) {
if !netutils.IsRunningInContainer() {
defer netutils.SetupTestNetNS(t)()
}
n, err := createTestNetwork("bridge", "testnetwork", options.Generic{
netlabel.GenericData: options.Generic{
"BridgeName": "testnetwork",
"AllowNonDefaultBridge": true,
},
})
if err != nil {
t.Fatal(err)
}
defer func() {
if err := n.Delete(); err != nil {
t.Fatal(err)
}
}()
ep1, err := n.CreateEndpoint("ep1")
if err != nil {
t.Fatal(err)
}
defer func() {
if err := ep1.Delete(); err != nil {
t.Fatal(err)
}
}()
defer controller.LeaveAll(containerID)
err = ep1.Join(containerID,
libnetwork.JoinOptionHostname("test1"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"))
runtime.LockOSThread()
if err != nil {
t.Fatal(err)
}
defer func() {
err = ep1.Leave(containerID)
runtime.LockOSThread()
if err != nil {
t.Fatal(err)
}
}()
ep2, err := n.CreateEndpoint("ep2")
if err != nil {
t.Fatal(err)
}
defer func() {
if err := ep2.Delete(); err != nil {
t.Fatal(err)
}
}()
defer controller.LeaveAll("container2")
err = ep2.Join("container2",
libnetwork.JoinOptionHostname("test2"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionHostsPath("/var/lib/docker/test_network/container2/hosts"),
libnetwork.JoinOptionParentUpdate(ep1.ID(), "web", "192.168.0.2"))
runtime.LockOSThread()
if err != nil {
t.Fatal(err)
}
err = ep2.Leave("container2")
runtime.LockOSThread()
if err != nil {
t.Fatal(err)
}
}
开发者ID:aduermael,项目名称:libnetwork,代码行数:75,代码来源:libnetwork_test.go
示例16: TestHost
func TestHost(t *testing.T) {
network, err := createTestNetwork("host", "testhost", options.Generic{})
if err != nil {
t.Fatal(err)
}
ep1, err := network.CreateEndpoint("testep1")
if err != nil {
t.Fatal(err)
}
err = ep1.Join("host_container1",
libnetwork.JoinOptionHostname("test1"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
libnetwork.JoinOptionUseDefaultSandbox())
if err != nil {
t.Fatal(err)
}
ep2, err := network.CreateEndpoint("testep2")
if err != nil {
t.Fatal(err)
}
err = ep2.Join("host_container2",
libnetwork.JoinOptionHostname("test2"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
libnetwork.JoinOptionUseDefaultSandbox())
if err != nil {
t.Fatal(err)
}
err = ep1.Leave("host_container1")
if err != nil {
t.Fatal(err)
}
err = ep2.Leave("host_container2")
if err != nil {
t.Fatal(err)
}
if err := ep1.Delete(); err != nil {
t.Fatal(err)
}
if err := ep2.Delete(); err != nil {
t.Fatal(err)
}
// Try to create another host endpoint and join/leave that.
ep3, err := network.CreateEndpoint("testep3")
if err != nil {
t.Fatal(err)
}
err = ep3.Join("host_container3",
libnetwork.JoinOptionHostname("test3"),
libnetwork.JoinOptionDomainname("docker.io"),
libnetwork.JoinOptionExtraHost("web", "192.168.0.1"),
libnetwork.JoinOptionUseDefaultSandbox())
if err != nil {
t.Fatal(err)
}
err = ep3.Leave("host_container3")
if err != nil {
t.Fatal(err)
}
if err := ep3.Delete(); err != nil {
t.Fatal(err)
}
// host type is special network. Cannot be removed.
err = network.Delete()
if err == nil {
t.Fatal(err)
}
if _, ok := err.(types.ForbiddenError); !ok {
t.Fatalf("Unexpected error type")
}
}
开发者ID:aduermael,项目名称:libnetwork,代码行数:85,代码来源:libnetwork_test.go
注:本文中的github.com/docker/libnetwork.JoinOptionDomainname函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论