本文整理汇总了Golang中github.com/juju/juju/network.Id函数的典型用法代码示例。如果您正苦于以下问题:Golang Id函数的具体用法?Golang Id怎么用?Golang Id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetNetworkInterfaces
func (c *client) GetNetworkInterfaces(inst instance.Id, ecfg *environConfig) ([]network.InterfaceInfo, error) {
vm, err := c.getVm(string(inst))
if err != nil {
return nil, errors.Trace(err)
}
if vm.Guest == nil {
return nil, errors.Errorf("vm guest is not initialized")
}
res := make([]network.InterfaceInfo, 0)
for _, net := range vm.Guest.Net {
ipScope := network.ScopeCloudLocal
if net.Network == ecfg.externalNetwork() {
ipScope = network.ScopePublic
}
res = append(res, network.InterfaceInfo{
DeviceIndex: net.DeviceConfigId,
MACAddress: net.MacAddress,
NetworkName: net.Network,
Disabled: !net.Connected,
ProviderId: network.Id(fmt.Sprintf("net-device%d", net.DeviceConfigId)),
ProviderSubnetId: network.Id(net.Network),
InterfaceName: fmt.Sprintf("unsupported%d", net.DeviceConfigId),
ConfigType: network.ConfigDHCP,
Address: network.NewScopedAddress(net.IpAddress[0], ipScope),
})
}
return res, nil
}
示例2: createSubnetInfo
func createSubnetInfo(subnetID, spaceID, ipRange uint) network.SubnetInfo {
return network.SubnetInfo{
CIDR: fmt.Sprintf("192.168.%d.0/24", ipRange),
ProviderId: network.Id(strconv.Itoa(int(subnetID))),
SpaceProviderId: network.Id(fmt.Sprintf("%d", spaceID)),
}
}
示例3: subnetsForSpaceDiscovery
func (env *environ) subnetsForSpaceDiscovery(estate *environState) ([]network.SubnetInfo, error) {
result := []network.SubnetInfo{{
ProviderId: network.Id("1"),
AvailabilityZones: []string{"zone1"},
CIDR: "192.168.1.0/24",
}, {
ProviderId: network.Id("2"),
AvailabilityZones: []string{"zone1"},
CIDR: "192.168.2.0/24",
VLANTag: 1,
}, {
ProviderId: network.Id("3"),
AvailabilityZones: []string{"zone1"},
CIDR: "192.168.3.0/24",
}, {
ProviderId: network.Id("4"),
AvailabilityZones: []string{"zone1"},
CIDR: "192.168.4.0/24",
}, {
ProviderId: network.Id("5"),
AvailabilityZones: []string{"zone1"},
CIDR: "192.168.5.0/24",
}}
estate.ops <- OpSubnets{
Env: env.name,
InstanceId: instance.UnknownId,
SubnetIds: []network.Id{},
Info: result,
}
return result, nil
}
示例4: addTestingSubnets
// addTestingSubnets adds a testing default VPC with 3 subnets in the EC2 test
// server: 2 of the subnets are in the "test-available" AZ, the remaining - in
// "test-unavailable". Returns a slice with the IDs of the created subnets.
func (t *localServerSuite) addTestingSubnets(c *gc.C) []network.Id {
vpc := t.srv.ec2srv.AddVPC(amzec2.VPC{
CIDRBlock: "0.1.0.0/16",
IsDefault: true,
})
results := make([]network.Id, 3)
sub1, err := t.srv.ec2srv.AddSubnet(amzec2.Subnet{
VPCId: vpc.Id,
CIDRBlock: "0.1.2.0/24",
AvailZone: "test-available",
DefaultForAZ: true,
})
c.Assert(err, jc.ErrorIsNil)
results[0] = network.Id(sub1.Id)
sub2, err := t.srv.ec2srv.AddSubnet(amzec2.Subnet{
VPCId: vpc.Id,
CIDRBlock: "0.1.3.0/24",
AvailZone: "test-available",
})
c.Assert(err, jc.ErrorIsNil)
results[1] = network.Id(sub2.Id)
sub3, err := t.srv.ec2srv.AddSubnet(amzec2.Subnet{
VPCId: vpc.Id,
CIDRBlock: "0.1.4.0/24",
AvailZone: "test-unavailable",
DefaultForAZ: true,
})
c.Assert(err, jc.ErrorIsNil)
results[2] = network.Id(sub3.Id)
return results
}
示例5: TestSpaces
func (suite *maas2EnvironSuite) TestSpaces(c *gc.C) {
controller := &fakeController{
spaces: []gomaasapi.Space{
fakeSpace{
name: "pepper",
id: 1234,
},
fakeSpace{
name: "freckles",
id: 4567,
subnets: []gomaasapi.Subnet{
fakeSubnet{id: 99, vlan: fakeVLAN{vid: 66}, cidr: "192.168.10.0/24"},
fakeSubnet{id: 98, vlan: fakeVLAN{vid: 67}, cidr: "192.168.11.0/24"},
},
},
},
}
env := suite.makeEnviron(c, controller)
result, err := env.Spaces()
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.HasLen, 1)
c.Assert(result[0].Name, gc.Equals, "freckles")
c.Assert(result[0].ProviderId, gc.Equals, network.Id("4567"))
subnets := result[0].Subnets
c.Assert(subnets, gc.HasLen, 2)
c.Assert(subnets[0].ProviderId, gc.Equals, network.Id("99"))
c.Assert(subnets[0].VLANTag, gc.Equals, 66)
c.Assert(subnets[0].CIDR, gc.Equals, "192.168.10.0/24")
c.Assert(subnets[0].SpaceProviderId, gc.Equals, network.Id("4567"))
c.Assert(subnets[1].ProviderId, gc.Equals, network.Id("98"))
c.Assert(subnets[1].VLANTag, gc.Equals, 67)
c.Assert(subnets[1].CIDR, gc.Equals, "192.168.11.0/24")
c.Assert(subnets[1].SpaceProviderId, gc.Equals, network.Id("4567"))
}
示例6: deviceInterfaceInfo
func (env *maasEnviron) deviceInterfaceInfo(deviceID instance.Id, nameToParentName map[string]string) ([]network.InterfaceInfo, error) {
interfaces, err := env.deviceInterfaces(deviceID)
if err != nil {
return nil, errors.Trace(err)
}
interfaceInfo := make([]network.InterfaceInfo, 0, len(interfaces))
for _, nic := range interfaces {
nicInfo := network.InterfaceInfo{
InterfaceName: nic.Name,
InterfaceType: network.EthernetInterface,
MACAddress: nic.MACAddress,
MTU: nic.EffectveMTU,
VLANTag: nic.VLAN.VID,
ProviderId: network.Id(strconv.Itoa(nic.ID)),
ProviderVLANId: network.Id(strconv.Itoa(nic.VLAN.ID)),
Disabled: !nic.Enabled,
NoAutoStart: !nic.Enabled,
ParentInterfaceName: nameToParentName[nic.Name],
}
if len(nic.Links) == 0 {
logger.Debugf("device %q interface %q has no links", deviceID, nic.Name)
interfaceInfo = append(interfaceInfo, nicInfo)
continue
}
for _, link := range nic.Links {
nicInfo.ConfigType = maasLinkToInterfaceConfigType(string(link.Mode))
if link.IPAddress == "" {
logger.Debugf("device %q interface %q has no address", deviceID, nic.Name)
interfaceInfo = append(interfaceInfo, nicInfo)
continue
}
if link.Subnet == nil {
logger.Debugf("device %q interface %q link %d missing subnet", deviceID, nic.Name, link.ID)
interfaceInfo = append(interfaceInfo, nicInfo)
continue
}
nicInfo.CIDR = link.Subnet.CIDR
nicInfo.Address = network.NewAddressOnSpace(link.Subnet.Space, link.IPAddress)
nicInfo.ProviderSubnetId = network.Id(strconv.Itoa(link.Subnet.ID))
nicInfo.ProviderAddressId = network.Id(strconv.Itoa(link.ID))
if link.Subnet.GatewayIP != "" {
nicInfo.GatewayAddress = network.NewAddressOnSpace(link.Subnet.Space, link.Subnet.GatewayIP)
}
if len(link.Subnet.DNSServers) > 0 {
nicInfo.DNSServers = network.NewAddressesOnSpace(link.Subnet.Space, link.Subnet.DNSServers...)
}
interfaceInfo = append(interfaceInfo, nicInfo)
}
}
logger.Debugf("device %q has interface info: %+v", deviceID, interfaceInfo)
return interfaceInfo, nil
}
示例7: createSubnetInfo
func createSubnetInfo(subnetID, spaceID, ipRange uint) network.SubnetInfo {
return network.SubnetInfo{
CIDR: fmt.Sprintf("192.168.%d.0/24", ipRange),
ProviderId: network.Id(strconv.Itoa(int(subnetID))),
AllocatableIPLow: net.ParseIP(fmt.Sprintf("192.168.%d.139", ipRange)).To4(),
AllocatableIPHigh: net.ParseIP(fmt.Sprintf("192.168.%d.255", ipRange)).To4(),
SpaceProviderId: network.Id(fmt.Sprintf("Space %d", spaceID)),
}
}
示例8: Spaces
// Spaces is specified on environs.Networking.
func (env *environ) Spaces() ([]network.SpaceInfo, error) {
if err := env.checkBroken("Spaces"); err != nil {
return []network.SpaceInfo{}, err
}
return []network.SpaceInfo{{
ProviderId: network.Id("foo"),
Subnets: []network.SubnetInfo{{
ProviderId: network.Id("1"),
AvailabilityZones: []string{"zone1"},
}, {
ProviderId: network.Id("2"),
AvailabilityZones: []string{"zone1"},
}}}, {
ProviderId: network.Id("Another Foo 99!"),
Subnets: []network.SubnetInfo{{
ProviderId: network.Id("3"),
AvailabilityZones: []string{"zone1"},
}}}, {
ProviderId: network.Id("foo-"),
Subnets: []network.SubnetInfo{{
ProviderId: network.Id("4"),
AvailabilityZones: []string{"zone1"},
}}}, {
ProviderId: network.Id("---"),
Subnets: []network.SubnetInfo{{
ProviderId: network.Id("5"),
AvailabilityZones: []string{"zone1"},
}}}}, nil
}
示例9: TestProviderIDDoesNotIncludeModelUUIDWhenSet
func (s *ipAddressesInternalSuite) TestProviderIDDoesNotIncludeModelUUIDWhenSet(c *gc.C) {
const localProviderID = "foo"
globalProviderID := coretesting.ModelTag.Id() + ":" + localProviderID
result := s.newIPAddressWithDummyState(ipAddressDoc{ProviderID: localProviderID})
c.Assert(result.ProviderID(), gc.Equals, network.Id(localProviderID))
c.Assert(result.localProviderID(), gc.Equals, localProviderID)
result = s.newIPAddressWithDummyState(ipAddressDoc{ProviderID: globalProviderID})
c.Assert(result.ProviderID(), gc.Equals, network.Id(localProviderID))
c.Assert(result.localProviderID(), gc.Equals, localProviderID)
}
示例10: TestMAASObjectNetworkInterfaces
func (s *interfacesSuite) TestMAASObjectNetworkInterfaces(c *gc.C) {
nodeJSON := fmt.Sprintf(`{
"system_id": "foo",
"interface_set": %s
}`, exampleInterfaceSetJSON)
obj := s.testMAASObject.TestServer.NewNode(nodeJSON)
subnetsMap := make(map[string]network.Id)
subnetsMap["10.250.19.0/24"] = network.Id("3")
subnetsMap["192.168.1.0/24"] = network.Id("0")
infos, err := maasObjectNetworkInterfaces(&obj, subnetsMap)
c.Assert(err, jc.ErrorIsNil)
c.Check(infos, jc.DeepEquals, exampleParsedInterfaceSetJSON)
}
示例11: prepareOrGetContainerInterfaceInfo
// prepareOrGetContainerInterfaceInfo returns the necessary information to
// configure network interfaces of a container with allocated static
// IP addresses.
//
// TODO(dimitern): Before we start using this, we need to rename both
// the method and the network.InterfaceInfo type to be called
// InterfaceConfig.
func (st *State) prepareOrGetContainerInterfaceInfo(
containerTag names.MachineTag, allocateNewAddress bool) (
[]network.InterfaceInfo, error) {
var result params.MachineNetworkConfigResults
args := params.Entities{
Entities: []params.Entity{{Tag: containerTag.String()}},
}
facadeName := ""
if allocateNewAddress {
facadeName = "PrepareContainerInterfaceInfo"
} else {
facadeName = "GetContainerInterfaceInfo"
}
if err := st.facade.FacadeCall(facadeName, args, &result); err != nil {
return nil, err
}
if len(result.Results) != 1 {
return nil, errors.Errorf("expected 1 result, got %d", len(result.Results))
}
if err := result.Results[0].Error; err != nil {
return nil, err
}
ifaceInfo := make([]network.InterfaceInfo, len(result.Results[0].Config))
for i, cfg := range result.Results[0].Config {
ifaceInfo[i] = network.InterfaceInfo{
DeviceIndex: cfg.DeviceIndex,
MACAddress: cfg.MACAddress,
CIDR: cfg.CIDR,
MTU: cfg.MTU,
ProviderId: network.Id(cfg.ProviderId),
ProviderSubnetId: network.Id(cfg.ProviderSubnetId),
ProviderSpaceId: network.Id(cfg.ProviderSpaceId),
ProviderVLANId: network.Id(cfg.ProviderVLANId),
ProviderAddressId: network.Id(cfg.ProviderAddressId),
VLANTag: cfg.VLANTag,
InterfaceName: cfg.InterfaceName,
ParentInterfaceName: cfg.ParentInterfaceName,
InterfaceType: network.InterfaceType(cfg.InterfaceType),
Disabled: cfg.Disabled,
NoAutoStart: cfg.NoAutoStart,
ConfigType: network.InterfaceConfigType(cfg.ConfigType),
Address: network.NewAddress(cfg.Address),
DNSServers: network.NewAddresses(cfg.DNSServers...),
DNSSearchDomains: cfg.DNSSearchDomains,
GatewayAddress: network.NewAddress(cfg.GatewayAddress),
}
}
return ifaceInfo, nil
}
示例12: addLinkLayerDevice
func (i *importer) addLinkLayerDevice(device description.LinkLayerDevice) error {
providerID := device.ProviderID()
modelUUID := i.st.ModelUUID()
localID := linkLayerDeviceGlobalKey(device.MachineID(), device.Name())
linkLayerDeviceDocID := i.st.docID(localID)
newDoc := &linkLayerDeviceDoc{
ModelUUID: modelUUID,
DocID: linkLayerDeviceDocID,
MachineID: device.MachineID(),
ProviderID: providerID,
Name: device.Name(),
MTU: device.MTU(),
Type: LinkLayerDeviceType(device.Type()),
MACAddress: device.MACAddress(),
IsAutoStart: device.IsAutoStart(),
IsUp: device.IsUp(),
ParentName: device.ParentName(),
}
ops := []txn.Op{{
C: linkLayerDevicesC,
Id: newDoc.DocID,
Insert: newDoc,
},
insertLinkLayerDevicesRefsOp(modelUUID, linkLayerDeviceDocID),
}
if providerID != "" {
id := network.Id(providerID)
ops = append(ops, i.st.networkEntityGlobalKeyOp("linklayerdevice", id))
}
if err := i.st.runTransaction(ops); err != nil {
return errors.Trace(err)
}
return nil
}
示例13: Subnets
func (c *client) Subnets(inst instance.Id, ids []network.Id) ([]network.SubnetInfo, error) {
if len(ids) == 0 {
return nil, errors.Errorf("subnetIds must not be empty")
}
vm, err := c.getVm(string(inst))
if err != nil {
return nil, errors.Trace(err)
}
res := make([]network.SubnetInfo, 0)
for _, vmNet := range vm.Guest.Net {
existId := false
for _, id := range ids {
if string(id) == vmNet.Network {
existId = true
break
}
}
if !existId {
continue
}
res = append(res, network.SubnetInfo{
ProviderId: network.Id(vmNet.Network),
})
}
return res, nil
}
示例14: setupNetworks
// setupNetworks prepares a []network.InterfaceInfo for the given instance. Any
// disabled network interfaces (as discovered from the lshw output for the node)
// will stay disabled.
func (environ *maasEnviron) setupNetworks(inst instance.Instance) ([]network.InterfaceInfo, error) {
// Get the instance network interfaces first.
interfaces, err := environ.getInstanceNetworkInterfaces(inst)
if err != nil {
return nil, errors.Annotatef(err, "getInstanceNetworkInterfaces failed")
}
logger.Debugf("node %q has network interfaces %v", inst.Id(), interfaces)
networks, err := environ.getInstanceNetworks(inst)
if err != nil {
return nil, errors.Annotatef(err, "getInstanceNetworks failed")
}
logger.Debugf("node %q has networks %v", inst.Id(), networks)
var tempInterfaceInfo []network.InterfaceInfo
for _, netw := range networks {
netCIDR := &net.IPNet{
IP: net.ParseIP(netw.IP),
Mask: net.IPMask(net.ParseIP(netw.Mask)),
}
macs, err := environ.getNetworkMACs(netw.Name)
if err != nil {
return nil, errors.Annotatef(err, "getNetworkMACs failed")
}
logger.Debugf("network %q has MACs: %v", netw.Name, macs)
var defaultGateway network.Address
if netw.DefaultGateway != "" {
defaultGateway = network.NewAddress(netw.DefaultGateway)
}
for _, mac := range macs {
if ifinfo, ok := interfaces[mac]; ok {
tempInterfaceInfo = append(tempInterfaceInfo, network.InterfaceInfo{
MACAddress: mac,
InterfaceName: ifinfo.InterfaceName,
DeviceIndex: ifinfo.DeviceIndex,
CIDR: netCIDR.String(),
VLANTag: netw.VLANTag,
ProviderId: network.Id(netw.Name),
NetworkName: netw.Name,
Disabled: ifinfo.Disabled,
GatewayAddress: defaultGateway,
})
}
}
}
// Verify we filled-in everything for all networks/interfaces
// and drop incomplete records.
var interfaceInfo []network.InterfaceInfo
for _, info := range tempInterfaceInfo {
if info.ProviderId == "" || info.NetworkName == "" || info.CIDR == "" {
logger.Infof("ignoring interface %q: missing subnet info", info.InterfaceName)
continue
}
if info.MACAddress == "" || info.InterfaceName == "" {
logger.Infof("ignoring subnet %q: missing interface info", info.ProviderId)
continue
}
interfaceInfo = append(interfaceInfo, info)
}
logger.Debugf("node %q network information: %#v", inst.Id(), interfaceInfo)
return interfaceInfo, nil
}
示例15: networkParamsToStateParams
func networkParamsToStateParams(networks []params.Network, ifaces []params.NetworkInterface) (
[]state.NetworkInfo, []state.NetworkInterfaceInfo, error,
) {
stateNetworks := make([]state.NetworkInfo, len(networks))
for i, net := range networks {
tag, err := names.ParseNetworkTag(net.Tag)
if err != nil {
return nil, nil, err
}
stateNetworks[i] = state.NetworkInfo{
Name: tag.Id(),
ProviderId: network.Id(net.ProviderId),
CIDR: net.CIDR,
VLANTag: net.VLANTag,
}
}
stateInterfaces := make([]state.NetworkInterfaceInfo, len(ifaces))
for i, iface := range ifaces {
tag, err := names.ParseNetworkTag(iface.NetworkTag)
if err != nil {
return nil, nil, err
}
stateInterfaces[i] = state.NetworkInterfaceInfo{
MACAddress: iface.MACAddress,
NetworkName: tag.Id(),
InterfaceName: iface.InterfaceName,
IsVirtual: iface.IsVirtual,
Disabled: iface.Disabled,
}
}
return stateNetworks, stateInterfaces, nil
}