• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang ip.NewResolvingInterfaceAddress函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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
}
开发者ID:jianqiu,项目名称:bosh-agent,代码行数:12,代码来源:ubuntu_net_manager.go


示例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
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:52,代码来源:ubuntu_net_manager.go


示例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
		}
	}()
}
开发者ID:viovanov,项目名称:bosh-agent,代码行数:16,代码来源:centos_net_manager.go


示例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
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:39,代码来源:centos_net_manager.go


示例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() {
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:30,代码来源:ubuntu_net_manager_test.go


示例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{
开发者ID:nimbus-cloud,项目名称:bosh-agent,代码行数:67,代码来源:centos_net_manager_test.go


示例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() {
开发者ID:ardnaxelarak,项目名称:bosh-agent,代码行数:67,代码来源:ubuntu_net_manager_test.go



注:本文中的github.com/cloudfoundry/bosh-agent/platform/net/ip.NewResolvingInterfaceAddress函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ip.NewSimpleInterfaceAddress函数代码示例发布时间:2022-05-23
下一篇:
Golang fakes.FakePlatform类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap