本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/platform/net/ip/fakes.FakeInterfaceAddressesProvider.GetInterfaceAddresses方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeInterfaceAddressesProvider.GetInterfaceAddresses方法的具体用法?Golang FakeInterfaceAddressesProvider.GetInterfaceAddresses怎么用?Golang FakeInterfaceAddressesProvider.GetInterfaceAddresses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/bosh-agent/platform/net/ip/fakes.FakeInterfaceAddressesProvider
的用法示例。
在下文中一共展示了FakeInterfaceAddressesProvider.GetInterfaceAddresses方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
//.........这里部分代码省略.........
"networks": {
"netA": {
"default": ["dns", "gateway"],
"ip": "2.2.2.2",
"dns": [
"8.8.8.8",
"4.4.4.4"
],
"netmask": "255.255.255.0",
"gateway": "2.2.2.0",
"mac": "aa:bb:cc"
}
}
}`
})
Context("and no physical network interfaces exist", func() {
Context("and a single virtual network interface exists", func() {
BeforeEach(func() {
stubInterfaces([][]string{[]string{"lo", "aa:bb:cc", "virtual"}})
})
It("raises an error", func() {
err := boot.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Number of network settings '1' is greater than the number of network devices '0"))
})
})
})
Context("and a single physical network interface exists", func() {
BeforeEach(func() {
stubInterfaces([][]string{[]string{"eth0", "aa:bb:cc", "physical"}})
interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("eth0", "2.2.2.2"),
}
})
It("succeeds", func() {
err := boot.Run()
Expect(err).NotTo(HaveOccurred())
})
})
Context("and extra physical network interfaces exist", func() {
BeforeEach(func() {
stubInterfaces([][]string{[]string{"eth0", "aa:bb:cc", "physical"}, []string{"eth1", "aa:bb:dd", "physical"}})
interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("eth0", "2.2.2.2"),
}
})
It("succeeds", func() {
err := boot.Run()
Expect(err).NotTo(HaveOccurred())
})
})
Context("and extra virtual network interfaces exist", func() {
BeforeEach(func() {
stubInterfaces([][]string{[]string{"eth0", "aa:bb:cc", "physical"}, []string{"lo", "aa:bb:ee", "virtual"}})
interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("eth0", "2.2.2.2"),
}
})
示例2: describeUbuntuNetManager
//.........这里部分代码省略.........
Broadcast: "10.10.0.255",
Mac: "aa::bb::cc",
Gateway: "10.10.0.1",
},
}))
Expect(dhcpInterfaceConfigurations).To(BeEmpty())
Expect(dnsServers).To(Equal([]string{"54.209.78.6", "127.0.0.5"}))
})
})
})
Describe("SetupNetworking", func() {
var (
dhcpNetwork boshsettings.Network
staticNetwork boshsettings.Network
expectedNetworkConfigurationForStaticAndDhcp string
)
BeforeEach(func() {
dhcpNetwork = boshsettings.Network{
Type: "dynamic",
Default: []string{"dns"},
DNS: []string{"8.8.8.8", "9.9.9.9"},
Mac: "fake-dhcp-mac-address",
}
staticNetwork = boshsettings.Network{
Type: "manual",
IP: "1.2.3.4",
Default: []string{"gateway"},
Netmask: "255.255.255.0",
Gateway: "3.4.5.6",
Mac: "fake-static-mac-address",
}
interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("ethstatic", "1.2.3.4"),
}
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`
})
It("writes interfaces in /etc/network/interfaces in alphabetic order", func() {
anotherDHCPNetwork := boshsettings.Network{
Type: "dynamic",
Default: []string{"dns"},
DNS: []string{"8.8.8.8", "9.9.9.9"},
Mac: "fake-another-mac-address",
}
示例3: describeCentosNetManager
func describeCentosNetManager() {
var (
fs *fakesys.FakeFileSystem
cmdRunner *fakesys.FakeCmdRunner
ipResolver *fakeip.FakeResolver
interfaceAddrsProvider *fakeip.FakeInterfaceAddressesProvider
addressBroadcaster *fakearp.FakeAddressBroadcaster
netManager Manager
interfaceConfigurationCreator InterfaceConfigurationCreator
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
ipResolver = &fakeip.FakeResolver{}
logger := boshlog.NewLogger(boshlog.LevelNone)
interfaceConfigurationCreator = NewInterfaceConfigurationCreator(logger)
interfaceAddrsProvider = &fakeip.FakeInterfaceAddressesProvider{}
interfaceAddrsValidator := boship.NewInterfaceAddressesValidator(interfaceAddrsProvider)
dnsValidator := NewDNSValidator(fs)
addressBroadcaster = &fakearp.FakeAddressBroadcaster{}
netManager = NewCentosNetManager(
fs,
cmdRunner,
ipResolver,
interfaceConfigurationCreator,
interfaceAddrsValidator,
dnsValidator,
addressBroadcaster,
logger,
)
})
writeNetworkDevice := func(iface string, macAddress string, isPhysical bool) string {
interfacePath := fmt.Sprintf("/sys/class/net/%s", iface)
fs.WriteFile(interfacePath, []byte{})
if isPhysical {
fs.WriteFile(fmt.Sprintf("/sys/class/net/%s/device", iface), []byte{})
}
fs.WriteFileString(fmt.Sprintf("/sys/class/net/%s/address", iface), fmt.Sprintf("%s\n", macAddress))
return interfacePath
}
Describe("SetupNetworking", func() {
var (
dhcpNetwork boshsettings.Network
staticNetwork boshsettings.Network
expectedNetworkConfigurationForStatic string
expectedNetworkConfigurationForDHCP string
expectedDhclientConfiguration string
)
BeforeEach(func() {
dhcpNetwork = boshsettings.Network{
Type: "dynamic",
Default: []string{"dns"},
DNS: []string{"8.8.8.8", "9.9.9.9"},
Mac: "fake-dhcp-mac-address",
}
staticNetwork = boshsettings.Network{
Type: "manual",
IP: "1.2.3.4",
Netmask: "255.255.255.0",
Gateway: "3.4.5.6",
Mac: "fake-static-mac-address",
}
interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("ethstatic", "1.2.3.4"),
}
fs.WriteFileString("/etc/resolv.conf", `
nameserver 8.8.8.8
nameserver 9.9.9.9
`)
expectedNetworkConfigurationForStatic = `DEVICE=ethstatic
BOOTPROTO=static
IPADDR=1.2.3.4
NETMASK=255.255.255.0
BROADCAST=1.2.3.255
GATEWAY=3.4.5.6
ONBOOT=yes
PEERDNS=no
DNS1=8.8.8.8
DNS2=9.9.9.9
`
expectedNetworkConfigurationForDHCP = `DEVICE=ethdhcp
BOOTPROTO=dhcp
ONBOOT=yes
PEERDNS=yes
`
expectedDhclientConfiguration = `# Generated by bosh-agent
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name "<hostname>";
request subnet-mask, broadcast-address, time-offset, routers,
//.........这里部分代码省略.........
示例4:
var _ = Describe("InterfaceAddressesValidator", func() {
var (
interfaceAddrsProvider *fakeip.FakeInterfaceAddressesProvider
interfaceAddrsValidator boship.InterfaceAddressesValidator
)
BeforeEach(func() {
interfaceAddrsProvider = &fakeip.FakeInterfaceAddressesProvider{}
interfaceAddrsValidator = boship.NewInterfaceAddressesValidator(interfaceAddrsProvider)
})
Context("when networks match", func() {
BeforeEach(func() {
interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("eth0", "1.2.3.4"),
boship.NewSimpleInterfaceAddress("eth1", "5.6.7.8"),
}
})
It("returns nil", func() {
err := interfaceAddrsValidator.Validate([]boship.InterfaceAddress{
boship.NewSimpleInterfaceAddress("eth0", "1.2.3.4"),
boship.NewSimpleInterfaceAddress("eth1", "5.6.7.8"),
})
Expect(err).ToNot(HaveOccurred())
})
})
Context("when desired networks do not match actual network IP address", func() {
BeforeEach(func() {
interfaceAddrsProvider.GetInterfaceAddresses = []boship.InterfaceAddress{