本文整理汇总了Golang中github.com/juju/juju/container.BridgeNetworkConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang BridgeNetworkConfig函数的具体用法?Golang BridgeNetworkConfig怎么用?Golang BridgeNetworkConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BridgeNetworkConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createContainer
func createContainer(c *gc.C, manager container.Manager, machineId string) instance.Instance {
machineNonce := "fake-nonce"
stateInfo := jujutesting.FakeStateInfo(machineId)
apiInfo := jujutesting.FakeAPIInfo(machineId)
instanceConfig, err := instancecfg.NewInstanceConfig(machineId, machineNonce, imagemetadata.ReleasedStream, "quantal", "", true, stateInfo, apiInfo)
c.Assert(err, jc.ErrorIsNil)
network := container.BridgeNetworkConfig("virbr0", 0, nil)
err = instanceConfig.SetTools(tools.List{
&tools.Tools{
Version: version.MustParseBinary("2.3.4-foo-bar"),
URL: "http://tools.testing.invalid/2.3.4-foo-bar.tgz",
},
})
c.Assert(err, jc.ErrorIsNil)
environConfig := dummyConfig(c)
err = instancecfg.FinishInstanceConfig(instanceConfig, environConfig)
c.Assert(err, jc.ErrorIsNil)
callback := func(settableStatus status.Status, info string, data map[string]interface{}) error { return nil }
inst, hardware, err := manager.CreateContainer(instanceConfig, "precise", network, nil, callback)
c.Assert(err, jc.ErrorIsNil)
c.Assert(hardware, gc.NotNil)
expected := fmt.Sprintf("arch=%s cpu-cores=1 mem=512M root-disk=8192M", arch.HostArch())
c.Assert(hardware.String(), gc.Equals, expected)
return inst
}
示例2: TestGenerateNetworkConfig
func (*NetworkSuite) TestGenerateNetworkConfig(c *gc.C) {
for _, test := range []struct {
config *container.NetworkConfig
net string
link string
}{{
config: nil,
net: "veth",
link: "lxcbr0",
}, {
config: lxc.DefaultNetworkConfig(),
net: "veth",
link: "lxcbr0",
}, {
config: container.BridgeNetworkConfig("foo"),
net: "veth",
link: "foo",
}, {
config: container.PhysicalNetworkConfig("foo"),
net: "phys",
link: "foo",
}} {
config := lxc.GenerateNetworkConfig(test.config)
c.Assert(config, jc.Contains, fmt.Sprintf("lxc.network.type = %s\n", test.net))
c.Assert(config, jc.Contains, fmt.Sprintf("lxc.network.link = %s\n", test.link))
}
}
示例3: TestCloudInitUserDataFallbackConfigWithContainerHostname
func (s *UserDataSuite) TestCloudInitUserDataFallbackConfigWithContainerHostname(c *gc.C) {
instanceConfig, err := containertesting.MockMachineConfig("1/lxd/0")
instanceConfig.MachineContainerHostname = "lxdhostname"
c.Assert(err, jc.ErrorIsNil)
networkConfig := container.BridgeNetworkConfig("foo", 0, nil)
data, err := containerinit.CloudInitUserData(instanceConfig, networkConfig)
c.Assert(err, jc.ErrorIsNil)
c.Assert(data, gc.NotNil)
linesToMatch := CloudInitDataExcludingOutputSection(string(data))
expected := fmt.Sprintf(s.expectedFallbackUserData, s.networkInterfacesFile, s.systemNetworkInterfacesFile)
var expectedLinesToMatch []string
for _, line := range strings.Split(expected, "\n") {
if strings.HasPrefix(line, "runcmd:") {
break
}
expectedLinesToMatch = append(expectedLinesToMatch, line)
}
expectedLinesToMatch = append(expectedLinesToMatch, "hostname: lxdhostname")
expectedLinesToMatch = append(expectedLinesToMatch, "manage_etc_hosts: true")
c.Assert(strings.Join(linesToMatch, "\n")+"\n", gc.Equals, strings.Join(expectedLinesToMatch, "\n")+"\n")
}
示例4: CreateContainerTest
// CreateContainerTest tries to create a container and returns any errors encountered along the
// way
func CreateContainerTest(c *gc.C, manager container.Manager, machineId string) (instance.Instance, error) {
instanceConfig, err := MockMachineConfig(machineId)
if err != nil {
return nil, errors.Trace(err)
}
envConfig, err := config.New(config.NoDefaults, dummy.SampleConfig())
if err != nil {
return nil, errors.Trace(err)
}
instanceConfig.Config = envConfig
network := container.BridgeNetworkConfig("nic42", 0, nil)
storage := &container.StorageConfig{}
callback := func(settableStatus status.Status, info string, data map[string]interface{}) error { return nil }
inst, hardware, err := manager.CreateContainer(instanceConfig, "quantal", network, storage, callback)
if err != nil {
return nil, errors.Trace(err)
}
if hardware == nil {
return nil, errors.New("nil hardware characteristics")
}
if hardware.String() == "" {
return nil, errors.New("empty hardware characteristics")
}
return inst, nil
}
示例5: TestNewCloudInitConfigWithNetworksNoConfig
func (s *UserDataSuite) TestNewCloudInitConfigWithNetworksNoConfig(c *gc.C) {
netConfig := container.BridgeNetworkConfig("foo", 0, nil)
cloudConf, err := containerinit.NewCloudInitConfigWithNetworks("quantal", netConfig)
c.Assert(err, jc.ErrorIsNil)
expected := "#cloud-config\n{}\n"
assertUserData(c, cloudConf, expected)
}
示例6: TestCreateContainerWithBlockStorage
func (s *LxcSuite) TestCreateContainerWithBlockStorage(c *gc.C) {
err := os.Remove(s.RestartDir)
c.Assert(err, jc.ErrorIsNil)
manager := s.makeManager(c, "test")
machineConfig, err := containertesting.MockMachineConfig("1/lxc/0")
c.Assert(err, jc.ErrorIsNil)
storageConfig := &container.StorageConfig{AllowMount: true}
networkConfig := container.BridgeNetworkConfig("nic42", 4321, nil)
instance := containertesting.CreateContainerWithMachineAndNetworkAndStorageConfig(c, manager, machineConfig, networkConfig, storageConfig)
name := string(instance.Id())
autostartLink := lxc.RestartSymlink(name)
config, err := ioutil.ReadFile(lxc.ContainerConfigFilename(name))
c.Assert(err, jc.ErrorIsNil)
expected := fmt.Sprintf(`
# network config
# interface "eth0"
lxc.network.type = veth
lxc.network.link = nic42
lxc.network.flags = up
lxc.network.mtu = 4321
lxc.start.auto = 1
lxc.mount.entry = %s var/log/juju none defaults,bind 0 0
lxc.aa_profile = lxc-container-default-with-mounting
lxc.cgroup.devices.allow = b 7:* rwm
lxc.cgroup.devices.allow = c 10:237 rwm
`, s.logDir)
c.Assert(string(config), gc.Equals, expected)
c.Assert(autostartLink, jc.DoesNotExist)
}
示例7: TestGenerateNetworkConfig
func (s *UserDataSuite) TestGenerateNetworkConfig(c *gc.C) {
data, err := containerinit.GenerateNetworkConfig(nil)
c.Assert(err, gc.ErrorMatches, "missing container network config")
c.Assert(data, gc.Equals, "")
netConfig := container.BridgeNetworkConfig("foo", 0, nil)
data, err = containerinit.GenerateNetworkConfig(netConfig)
c.Assert(err, jc.ErrorIsNil)
c.Assert(data, gc.Equals, s.expectedFallbackConfig)
// Test with all interface types.
netConfig = container.BridgeNetworkConfig("foo", 0, s.fakeInterfaces)
data, err = containerinit.GenerateNetworkConfig(netConfig)
c.Assert(err, jc.ErrorIsNil)
c.Assert(data, gc.Equals, s.expectedSampleConfig)
}
示例8: TestGenerateNetworkConfig
func (s *UserDataSuite) TestGenerateNetworkConfig(c *gc.C) {
// No config or no interfaces - no error, but also noting to generate.
data, err := containerinit.GenerateNetworkConfig(nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(data, gc.HasLen, 0)
netConfig := container.BridgeNetworkConfig("foo", 0, nil)
data, err = containerinit.GenerateNetworkConfig(netConfig)
c.Assert(err, jc.ErrorIsNil)
c.Assert(data, gc.HasLen, 0)
// Test with all interface types.
netConfig = container.BridgeNetworkConfig("foo", 0, s.fakeInterfaces)
data, err = containerinit.GenerateNetworkConfig(netConfig)
c.Assert(err, jc.ErrorIsNil)
c.Assert(data, gc.Equals, s.expectedNetConfig)
}
示例9: TestNewCloudInitConfigWithNetworksFallbackConfig
func (s *UserDataSuite) TestNewCloudInitConfigWithNetworksFallbackConfig(c *gc.C) {
netConfig := container.BridgeNetworkConfig("foo", 0, nil)
cloudConf, err := containerinit.NewCloudInitConfigWithNetworks("quantal", netConfig)
c.Assert(err, jc.ErrorIsNil)
c.Assert(cloudConf, gc.NotNil)
expected := fmt.Sprintf(s.expectedFallbackUserData, s.networkInterfacesFile, s.systemNetworkInterfacesFile)
assertUserData(c, cloudConf, expected)
}
示例10: CreateContainerWithMachineConfig
func CreateContainerWithMachineConfig(
c *gc.C,
manager container.Manager,
instanceConfig *instancecfg.InstanceConfig,
) instance.Instance {
networkConfig := container.BridgeNetworkConfig("nic42", 0, nil)
storageConfig := &container.StorageConfig{}
return CreateContainerWithMachineAndNetworkAndStorageConfig(c, manager, instanceConfig, networkConfig, storageConfig)
}
示例11: TestCloudInitUserData
func (s *UserDataSuite) TestCloudInitUserData(c *gc.C) {
instanceConfig, err := containertesting.MockMachineConfig("1/lxc/0")
c.Assert(err, jc.ErrorIsNil)
networkConfig := container.BridgeNetworkConfig("foo", 0, nil)
data, err := containerinit.CloudInitUserData(instanceConfig, networkConfig)
c.Assert(err, jc.ErrorIsNil)
// No need to test the exact contents here, as they are already
// tested separately.
c.Assert(string(data), jc.HasPrefix, "#cloud-config\n")
}
示例12: createRunningContainer
func (s *KVMSuite) createRunningContainer(c *gc.C, name string) kvm.Container {
kvmContainer := s.ContainerFactory.New(name)
network := container.BridgeNetworkConfig("testbr0")
c.Assert(kvmContainer.Start(kvm.StartParams{
Series: "quantal",
Arch: version.Current.Arch,
UserDataFile: "userdata.txt",
Network: network}), gc.IsNil)
return kvmContainer
}
示例13: CreateContainerWithMachineConfig
func CreateContainerWithMachineConfig(
c *gc.C,
manager container.Manager,
machineConfig *cloudinit.MachineConfig,
) instance.Instance {
network := container.BridgeNetworkConfig("nic42")
inst, hardware, err := manager.CreateContainer(machineConfig, "quantal", network)
c.Assert(err, gc.IsNil)
c.Assert(hardware, gc.NotNil)
c.Assert(hardware.String(), gc.Not(gc.Equals), "")
return inst
}
示例14: TestCloudInitUserDataFallbackConfig
func (s *UserDataSuite) TestCloudInitUserDataFallbackConfig(c *gc.C) {
instanceConfig, err := containertesting.MockMachineConfig("1/lxd/0")
c.Assert(err, jc.ErrorIsNil)
networkConfig := container.BridgeNetworkConfig("foo", 0, nil)
data, err := containerinit.CloudInitUserData(instanceConfig, networkConfig)
c.Assert(err, jc.ErrorIsNil)
c.Assert(data, gc.NotNil)
// Extract the "#cloud-config" header and all lines between
// from the "bootcmd" section up to (but not including) the
// "output" sections to match against expected. But we cannot
// possibly handle all the /other/ output that may be added by
// CloudInitUserData() in the future, so we also truncate at
// the first runcmd which now happens to include the runcmd's
// added for raising the network interfaces captured in
// expectedFallbackUserData. However, the other tests above do
// check for that output.
var linesToMatch []string
seenBootcmd := false
for _, line := range strings.Split(string(data), "\n") {
if strings.HasPrefix(line, "#cloud-config") {
linesToMatch = append(linesToMatch, line)
continue
}
if strings.HasPrefix(line, "bootcmd:") {
seenBootcmd = true
}
if strings.HasPrefix(line, "output:") && seenBootcmd {
break
}
if seenBootcmd {
linesToMatch = append(linesToMatch, line)
}
}
expected := fmt.Sprintf(s.expectedFallbackUserData, s.networkInterfacesFile, s.systemNetworkInterfacesFile)
var expectedLinesToMatch []string
for _, line := range strings.Split(expected, "\n") {
if strings.HasPrefix(line, "runcmd:") {
break
}
expectedLinesToMatch = append(expectedLinesToMatch, line)
}
c.Assert(strings.Join(linesToMatch, "\n")+"\n", gc.Equals, strings.Join(expectedLinesToMatch, "\n")+"\n")
}
示例15: createTemplate
func (s *LxcSuite) createTemplate(c *gc.C) golxc.Container {
name := "juju-quantal-lxc-template"
ch := s.ensureTemplateStopped(name)
defer func() { <-ch }()
network := container.BridgeNetworkConfig("nic42", 4321, nil)
authorizedKeys := "authorized keys list"
aptProxy := proxy.Settings{}
aptMirror := "http://my.archive.ubuntu.com/ubuntu"
callback := func(containerStatus status.Status, info string, data map[string]interface{}) error { return nil }
template, err := lxc.EnsureCloneTemplate(
"ext4",
"quantal",
network,
authorizedKeys,
aptProxy,
aptMirror,
true,
true,
&containertesting.MockURLGetter{},
false,
callback,
)
c.Assert(err, jc.ErrorIsNil)
c.Assert(template.Name(), gc.Equals, name)
createEvent := <-s.events
c.Assert(createEvent.Action, gc.Equals, mock.Created)
c.Assert(createEvent.InstanceId, gc.Equals, name)
argsSet := set.NewStrings(createEvent.TemplateArgs...)
c.Assert(argsSet.Contains("imageURL"), jc.IsTrue)
s.AssertEvent(c, <-s.events, mock.Started, name)
s.AssertEvent(c, <-s.events, mock.Stopped, name)
autostartLink := lxc.RestartSymlink(name)
config, err := ioutil.ReadFile(lxc.ContainerConfigFilename(name))
c.Assert(err, jc.ErrorIsNil)
expected := `
# network config
# interface "eth0"
lxc.network.type = veth
lxc.network.link = nic42
lxc.network.flags = up
lxc.network.mtu = 4321
`
// NOTE: no autostart, no mounting the log dir
c.Assert(string(config), gc.Equals, expected)
c.Assert(autostartLink, jc.DoesNotExist)
return template
}