本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/settings.Networks.IsPreconfigured方法的典型用法代码示例。如果您正苦于以下问题:Golang Networks.IsPreconfigured方法的具体用法?Golang Networks.IsPreconfigured怎么用?Golang Networks.IsPreconfigured使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/bosh-agent/settings.Networks
的用法示例。
在下文中一共展示了Networks.IsPreconfigured方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetupNetworking
func (net UbuntuNetManager) SetupNetworking(networks boshsettings.Networks, errCh chan error) error {
if networks.IsPreconfigured() {
// Note in this case IPs are not broadcasted
return net.writeResolvConf(networks)
}
staticConfigs, dhcpConfigs, dnsServers, err := net.ComputeNetworkConfig(networks)
if err != nil {
return bosherr.WrapError(err, "Computing network configuration")
}
interfacesChanged, err := net.writeNetworkInterfaces(dhcpConfigs, staticConfigs, dnsServers)
if err != nil {
return bosherr.WrapError(err, "Writing network configuration")
}
dhcpChanged := false
if len(dhcpConfigs) > 0 {
dhcpChanged, err = net.writeDHCPConfiguration(dnsServers)
if err != nil {
return err
}
}
if interfacesChanged || dhcpChanged {
err = net.removeDhcpDNSConfiguration()
if err != nil {
return err
}
net.restartNetworkingInterfaces(net.ifaceNames(dhcpConfigs, staticConfigs))
}
staticAddresses, dynamicAddresses := net.ifaceAddresses(staticConfigs, dhcpConfigs)
err = net.interfaceAddressesValidator.Validate(staticAddresses)
if err != nil {
return bosherr.WrapError(err, "Validating static network configuration")
}
err = net.dnsValidator.Validate(dnsServers)
if err != nil {
return bosherr.WrapError(err, "Validating dns configuration")
}
net.broadcastIps(append(staticAddresses, dynamicAddresses...), errCh)
return nil
}
示例2: describeUbuntuNetManager
//.........这里部分代码省略.........
}
fs.WriteFileString("/etc/resolv.conf", `
nameserver 8.8.8.8
nameserver 9.9.9.9
`)
expectedNetworkConfigurationForStaticAndDhcp = `# Generated by bosh-agent
auto lo
iface lo inet loopback
auto ethdhcp
iface ethdhcp inet dhcp
auto ethstatic
iface ethstatic inet static
address 1.2.3.4
network 1.2.3.0
netmask 255.255.255.0
broadcast 1.2.3.255
gateway 3.4.5.6
dns-nameservers 8.8.8.8 9.9.9.9`
})
Context("networks is preconfigured", func() {
var networks boshsettings.Networks
BeforeEach(func() {
dhcpNetwork.Preconfigured = true
staticNetwork.Preconfigured = true
networks = boshsettings.Networks{
"first": dhcpNetwork,
"second": staticNetwork,
}
Expect(networks.IsPreconfigured()).To(BeTrue())
})
Context("when there are configured DNS servers", func() {
BeforeEach(func() {
networks = boshsettings.Networks{
"first": dhcpNetwork,
}
})
It("writes DNS to /etc/resolvconf/resolv.conf.d/base", func() {
err := netManager.SetupNetworking(networks, nil)
Expect(err).ToNot(HaveOccurred())
resolvConfBase := fs.GetFileTestStat("/etc/resolvconf/resolv.conf.d/base")
Expect(resolvConfBase).ToNot(BeNil())
expectedResolvConfBase := `# Generated by bosh-agent
nameserver 8.8.8.8
nameserver 9.9.9.9
`
Expect(resolvConfBase.StringContents()).To(Equal(expectedResolvConfBase))
})
Context("when writing to ../resolv.conf.d/base fails", func() {
It("fails reporting the error", func() {
fs.WriteFileError = errors.New("fake-write-file-error")
err := netManager.SetupNetworking(networks, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Writing to /etc/resolvconf/resolv.conf.d/base"))
})
})