本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/platform/net/ip.NewResolvingInterfaceAddress函数的典型用法代码示例。如果您正苦于以下问题:Golang NewResolvingInterfaceAddress函数的具体用法?Golang NewResolvingInterfaceAddress怎么用?Golang NewResolvingInterfaceAddress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewResolvingInterfaceAddress函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ifaceAddresses
func (net UbuntuNetManager) ifaceAddresses(staticConfigs []StaticInterfaceConfiguration, dhcpConfigs []DHCPInterfaceConfiguration) ([]boship.InterfaceAddress, []boship.InterfaceAddress) {
staticAddresses := []boship.InterfaceAddress{}
for _, iface := range staticConfigs {
staticAddresses = append(staticAddresses, boship.NewSimpleInterfaceAddress(iface.Name, iface.Address))
}
dynamicAddresses := []boship.InterfaceAddress{}
for _, iface := range dhcpConfigs {
dynamicAddresses = append(dynamicAddresses, boship.NewResolvingInterfaceAddress(iface.Name, net.ipResolver))
}
return staticAddresses, dynamicAddresses
}
示例2: SetupDhcp
func (net ubuntuNetManager) SetupDhcp(networks boshsettings.Networks, errCh chan error) error {
net.logger.Debug(ubuntuNetManagerLogTag, "Configuring DHCP networking")
buffer := bytes.NewBuffer([]byte{})
t := template.Must(template.New("dhcp-config").Parse(ubuntuDHCPConfigTemplate))
// Keep DNS servers in the order specified by the network
// because they are added by a *single* DHCP's prepend command
dnsNetwork, _ := networks.DefaultNetworkFor("dns")
dnsServersList := strings.Join(dnsNetwork.DNS, ", ")
err := t.Execute(buffer, dnsServersList)
if err != nil {
return bosherr.WrapError(err, "Generating config from template")
}
dhclientConfigFile := net.dhclientConfigFile()
written, err := net.fs.ConvergeFileContents(dhclientConfigFile, buffer.Bytes())
if err != nil {
return bosherr.WrapError(err, "Writing to %s", dhclientConfigFile)
}
if written {
args := net.restartNetworkArguments()
net.logger.Debug(ubuntuNetManagerLogTag, "Restarting network interfaces")
_, _, _, err := net.cmdRunner.RunCommand("ifdown", args...)
if err != nil {
net.logger.Error(ubuntuNetManagerLogTag, "Ignoring ifdown failure: %s", err)
}
_, _, _, err = net.cmdRunner.RunCommand("ifup", args...)
if err != nil {
net.logger.Error(ubuntuNetManagerLogTag, "Ignoring ifup failure: %s", err)
}
}
addresses := []boship.InterfaceAddress{
// eth0 is hard coded in AWS and OpenStack stemcells.
// TODO: abstract hardcoded network interface name to the NetManager
boship.NewResolvingInterfaceAddress("eth0", net.ipResolver),
}
go func() {
net.addressBroadcaster.BroadcastMACAddresses(addresses)
if errCh != nil {
errCh <- nil
}
}()
return nil
}
示例3: broadcastIps
func (net centosNetManager) broadcastIps(staticInterfaceConfigurations []StaticInterfaceConfiguration, dhcpInterfaceConfigurations []DHCPInterfaceConfiguration, errCh chan error) {
addresses := []boship.InterfaceAddress{}
for _, iface := range staticInterfaceConfigurations {
addresses = append(addresses, boship.NewSimpleInterfaceAddress(iface.Name, iface.Address))
}
for _, iface := range dhcpInterfaceConfigurations {
addresses = append(addresses, boship.NewResolvingInterfaceAddress(iface.Name, net.ipResolver))
}
go func() {
net.addressBroadcaster.BroadcastMACAddresses(addresses)
if errCh != nil {
errCh <- nil
}
}()
}
示例4: SetupDhcp
func (net centosNetManager) SetupDhcp(networks boshsettings.Networks, errCh chan error) error {
net.logger.Debug(centosNetManagerLogTag, "Configuring DHCP networking")
buffer := bytes.NewBuffer([]byte{})
t := template.Must(template.New("dhcp-config").Parse(centosDHCPConfigTemplate))
// Keep DNS servers in the order specified by the network
// because they are added by a *single* DHCP's prepend command
dnsNetwork, _ := networks.DefaultNetworkFor("dns")
dnsServersList := strings.Join(dnsNetwork.DNS, ", ")
err := t.Execute(buffer, dnsServersList)
if err != nil {
return bosherr.WrapError(err, "Generating config from template")
}
written, err := net.fs.ConvergeFileContents("/etc/dhcp/dhclient.conf", buffer.Bytes())
if err != nil {
return bosherr.WrapError(err, "Writing to /etc/dhcp/dhclient.conf")
}
if written {
net.restartNetwork()
}
addresses := []boship.InterfaceAddress{
// eth0 is hard coded in AWS and OpenStack stemcells.
// TODO: abstract hardcoded network interface name to the NetManager
boship.NewResolvingInterfaceAddress("eth0", net.ipResolver),
}
go func() {
net.addressBroadcaster.BroadcastMACAddresses(addresses)
if errCh != nil {
errCh <- nil
}
}()
return err
}
示例5:
Expect(len(cmdRunner.RunCommands)).To(Equal(0))
})
}
ItBroadcastsMACAddresses := func() {
It("starts broadcasting the MAC addresses", func() {
errCh := make(chan error)
err := netManager.SetupDhcp(networks, errCh)
Expect(err).ToNot(HaveOccurred())
<-errCh // wait for all arpings
Expect(addressBroadcaster.BroadcastMACAddressesAddresses).To(Equal([]boship.InterfaceAddress{
boship.NewResolvingInterfaceAddress("eth0", ipResolver),
}))
})
}
Context("when dhclient3 is installed on the system", func() {
BeforeEach(func() { cmdRunner.CommandExistsValue = true })
Context("when dhcp was not previously configured", func() {
ItUpdatesDhcpConfig(dhcp3ConfPath)
ItRestartsDhcp()
ItBroadcastsMACAddresses()
})
Context("when dhcp was previously configured with different configuration", func() {
BeforeEach(func() {
示例6: describeCentosNetManager
//.........这里部分代码省略.........
Default: []string{"dns"},
DNS: []string{"8.8.8.8"},
Netmask: "255.255.255.0",
Gateway: "3.4.5.6",
Mac: "fake-static-mac-address",
}
stubInterfaces(map[string]boshsettings.Network{
"ethstatic": staticNetwork,
})
errCh := make(chan error)
err := netManager.SetupNetworking(boshsettings.Networks{"static-network": staticNetwork}, errCh)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Validating dns configuration"))
})
})
It("broadcasts MAC addresses for all interfaces", func() {
stubInterfaces(map[string]boshsettings.Network{
"ethdhcp": dhcpNetwork,
"ethstatic": staticNetwork,
})
errCh := make(chan error)
err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, errCh)
Expect(err).ToNot(HaveOccurred())
broadcastErr := <-errCh // wait for all arpings
Expect(broadcastErr).ToNot(HaveOccurred())
Expect(addressBroadcaster.BroadcastMACAddressesAddresses).To(Equal([]boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("ethstatic", "1.2.3.4"),
boship.NewResolvingInterfaceAddress("ethdhcp", ipResolver),
}))
})
It("skips vip networks", func() {
stubInterfaces(map[string]boshsettings.Network{
"ethdhcp": dhcpNetwork,
"ethstatic": staticNetwork,
})
vipNetwork := boshsettings.Network{
Type: "vip",
Default: []string{"dns"},
DNS: []string{"4.4.4.4", "5.5.5.5"},
Mac: "fake-vip-mac-address",
IP: "9.8.7.6",
}
err := netManager.SetupNetworking(boshsettings.Networks{
"dhcp-network": dhcpNetwork,
"static-network": staticNetwork,
"vip-network": vipNetwork,
}, nil)
Expect(err).ToNot(HaveOccurred())
networkConfig := fs.GetFileTestStat("/etc/sysconfig/network-scripts/ifcfg-ethstatic")
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(expectedNetworkConfigurationForStatic))
})
It("doesn't use vip networks dns", func() {
stubInterfaces(map[string]boshsettings.Network{
示例7: describeUbuntuNetManager
//.........这里部分代码省略.........
})
fs.WriteFileString("/etc/network/interfaces", expectedNetworkConfigurationForStaticAndDhcp)
err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, nil)
Expect(err).ToNot(HaveOccurred())
networkConfig := fs.GetFileTestStat("/etc/network/interfaces")
Expect(networkConfig.StringContents()).To(Equal(expectedNetworkConfigurationForStaticAndDhcp))
Expect(len(cmdRunner.RunCommands)).To(Equal(5))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"pkill", "dhclient"}))
Expect(cmdRunner.RunCommands[1:3]).To(ContainElement([]string{"resolvconf", "-d", "ethdhcp.dhclient"}))
Expect(cmdRunner.RunCommands[1:3]).To(ContainElement([]string{"resolvconf", "-d", "ethstatic.dhclient"}))
Expect(cmdRunner.RunCommands[3]).To(Equal([]string{"ifdown", "--force", "ethdhcp", "ethstatic"}))
Expect(cmdRunner.RunCommands[4]).To(Equal([]string{"ifup", "--force", "ethdhcp", "ethstatic"}))
})
It("broadcasts MAC addresses for all interfaces", func() {
stubInterfaces(map[string]boshsettings.Network{
"ethdhcp": dhcpNetwork,
"ethstatic": staticNetwork,
})
errCh := make(chan error)
err := netManager.SetupNetworking(boshsettings.Networks{"dhcp-network": dhcpNetwork, "static-network": staticNetwork}, errCh)
Expect(err).ToNot(HaveOccurred())
broadcastErr := <-errCh // wait for all arpings
Expect(broadcastErr).ToNot(HaveOccurred())
Expect(addressBroadcaster.BroadcastMACAddressesAddresses).To(Equal([]boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("ethstatic", "1.2.3.4"),
boship.NewResolvingInterfaceAddress("ethdhcp", ipResolver),
}))
})
It("skips vip networks", func() {
stubInterfaces(map[string]boshsettings.Network{
"ethdhcp": dhcpNetwork,
"ethstatic": staticNetwork,
})
vipNetwork := boshsettings.Network{
Type: "vip",
Default: []string{"dns"},
DNS: []string{"8.8.8.8", "9.9.9.9"},
Mac: "fake-vip-mac-address",
IP: "9.8.7.6",
}
err := netManager.SetupNetworking(boshsettings.Networks{
"dhcp-network": dhcpNetwork,
"static-network": staticNetwork,
"vip-network": vipNetwork,
}, nil)
Expect(err).ToNot(HaveOccurred())
networkConfig := fs.GetFileTestStat("/etc/network/interfaces")
Expect(networkConfig).ToNot(BeNil())
Expect(networkConfig.StringContents()).To(Equal(expectedNetworkConfigurationForStaticAndDhcp))
})
Context("when manual networks were not configured with proper IP addresses", func() {
BeforeEach(func() {