本文整理汇总了Golang中github.com/juju/names.ParseNetworkTag函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseNetworkTag函数的具体用法?Golang ParseNetworkTag怎么用?Golang ParseNetworkTag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseNetworkTag函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ActiveNetworks
// ActiveNetworks returns a list of network tags for which the machine
// has opened ports.
func (m *Machine) ActiveNetworks() ([]names.NetworkTag, error) {
var results params.StringsResults
args := params.Entities{
Entities: []params.Entity{{Tag: m.tag.String()}},
}
err := m.st.facade.FacadeCall("GetMachineActiveNetworks", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
// Convert string tags to names.NetworkTag before returning.
tags := make([]names.NetworkTag, len(result.Result))
for i, tag := range result.Result {
networkTag, err := names.ParseNetworkTag(tag)
if err != nil {
return nil, err
}
tags[i] = networkTag
}
return tags, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:29,代码来源:machine.go
示例2: networkTagsToNames
func networkTagsToNames(tags []string) ([]string, error) {
netNames := make([]string, len(tags))
for i, tag := range tags {
t, err := names.ParseNetworkTag(tag)
if err != nil {
return nil, err
}
netNames[i] = t.Id()
}
return netNames, nil
}
开发者ID:exekias,项目名称:juju,代码行数:11,代码来源:service.go
示例3: TestParseNetworkTag
func (s *networkSuite) TestParseNetworkTag(c *gc.C) {
for i, t := range parseNetworkTagTests {
c.Logf("test %d: %s", i, t.tag)
got, err := names.ParseNetworkTag(t.tag)
if err != nil || t.err != nil {
c.Check(err, gc.DeepEquals, t.err)
continue
}
c.Check(got, gc.FitsTypeOf, t.expected)
c.Check(got, gc.Equals, t.expected)
}
}
开发者ID:rogpeppe,项目名称:juju-names,代码行数:12,代码来源:network_test.go
示例4: GetMachinePorts
// GetMachinePorts returns the port ranges opened on a machine for the
// specified network as a map mapping port ranges to the tags of the
// units that opened them.
func (f *FirewallerAPI) GetMachinePorts(args params.MachinePortsParams) (params.MachinePortsResults, error) {
result := params.MachinePortsResults{
Results: make([]params.MachinePortsResult, len(args.Params)),
}
canAccess, err := f.accessMachine()
if err != nil {
return params.MachinePortsResults{}, err
}
for i, param := range args.Params {
machineTag, err := names.ParseMachineTag(param.MachineTag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
networkTag, err := names.ParseNetworkTag(param.NetworkTag)
if err != nil {
result.Results[i].Error = common.ServerError(common.ErrPerm)
continue
}
machine, err := f.getMachine(canAccess, machineTag)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
ports, err := machine.OpenedPorts(networkTag.Id())
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
if ports != nil {
portRangeMap := ports.AllPortRanges()
var portRanges []network.PortRange
for portRange := range portRangeMap {
portRanges = append(portRanges, portRange)
}
network.SortPortRanges(portRanges)
for _, portRange := range portRanges {
unitTag := names.NewUnitTag(portRangeMap[portRange]).String()
result.Results[i].Ports = append(result.Results[i].Ports,
params.MachinePortRange{
UnitTag: unitTag,
PortRange: params.FromNetworkPortRange(portRange),
})
}
}
}
return result, nil
}
开发者ID:exekias,项目名称:juju,代码行数:52,代码来源:firewaller.go
示例5: TestSetInstanceInfo
//.........这里部分代码省略.........
VLANTag: 0,
}, {
Tag: "network-vlan42",
ProviderId: "vlan42",
CIDR: "0.2.2.0/24",
VLANTag: 42,
}, {
Tag: "network-vlan69",
ProviderId: "vlan69",
CIDR: "0.3.2.0/24",
VLANTag: 69,
}, {
Tag: "network-vlan42", // duplicated; ignored
ProviderId: "vlan42",
CIDR: "0.2.2.0/24",
VLANTag: 42,
}}
ifaces := []params.NetworkInterface{{
MACAddress: "aa:bb:cc:dd:ee:f0",
NetworkTag: "network-net1",
InterfaceName: "eth0",
IsVirtual: false,
}, {
MACAddress: "aa:bb:cc:dd:ee:f1",
NetworkTag: "network-net1",
InterfaceName: "eth1",
IsVirtual: false,
}, {
MACAddress: "aa:bb:cc:dd:ee:f1",
NetworkTag: "network-vlan42",
InterfaceName: "eth1.42",
IsVirtual: true,
}, {
MACAddress: "aa:bb:cc:dd:ee:f1",
NetworkTag: "network-vlan69",
InterfaceName: "eth1.69",
IsVirtual: true,
}, {
MACAddress: "aa:bb:cc:dd:ee:f1", // duplicated mac+net; ignored
NetworkTag: "network-vlan42",
InterfaceName: "eth2",
IsVirtual: true,
}, {
MACAddress: "aa:bb:cc:dd:ee:f4",
NetworkTag: "network-net1",
InterfaceName: "eth1", // duplicated name+machine id; ignored
IsVirtual: false,
}}
err = apiMachine.SetInstanceInfo("i-will", "fake_nonce", &hwChars, networks, ifaces)
c.Assert(err, gc.IsNil)
instanceId, err = apiMachine.InstanceId()
c.Assert(err, gc.IsNil)
c.Assert(instanceId, gc.Equals, instance.Id("i-will"))
// Try it again - should fail.
err = apiMachine.SetInstanceInfo("i-wont", "fake", nil, nil, nil)
c.Assert(err, gc.ErrorMatches, `aborted instance "i-wont": cannot set instance data for machine "1": already set`)
// Now try to get machine 0's instance id.
apiMachine, err = s.provisioner.Machine(s.machine.Tag().(names.MachineTag))
c.Assert(err, gc.IsNil)
instanceId, err = apiMachine.InstanceId()
c.Assert(err, gc.IsNil)
c.Assert(instanceId, gc.Equals, instance.Id("i-manager"))
// Check the networks are created.
for i, _ := range networks {
if i == 3 {
// Last one was ignored, so skip it.
break
}
tag, err := names.ParseNetworkTag(networks[i].Tag)
c.Assert(err, gc.IsNil)
networkName := tag.Id()
network, err := s.State.Network(networkName)
c.Assert(err, gc.IsNil)
c.Check(network.Name(), gc.Equals, networkName)
c.Check(network.ProviderId(), gc.Equals, networks[i].ProviderId)
c.Check(network.Tag().String(), gc.Equals, networks[i].Tag)
c.Check(network.VLANTag(), gc.Equals, networks[i].VLANTag)
c.Check(network.CIDR(), gc.Equals, networks[i].CIDR)
}
// And the network interfaces as well.
ifacesMachine, err = notProvisionedMachine.NetworkInterfaces()
c.Assert(err, gc.IsNil)
c.Assert(ifacesMachine, gc.HasLen, 4)
actual := make([]params.NetworkInterface, len(ifacesMachine))
for i, iface := range ifacesMachine {
actual[i].InterfaceName = iface.InterfaceName()
actual[i].NetworkTag = iface.NetworkTag().String()
actual[i].MACAddress = iface.MACAddress()
actual[i].IsVirtual = iface.IsVirtual()
c.Check(iface.MachineTag(), gc.Equals, notProvisionedMachine.Tag())
c.Check(iface.MachineId(), gc.Equals, notProvisionedMachine.Id())
}
c.Assert(actual, jc.SameContents, ifaces[:4]) // skip the rest as they are ignored.
}
开发者ID:zhouqt,项目名称:juju,代码行数:101,代码来源:provisioner_test.go
示例6: TestSetInstanceInfo
//.........这里部分代码省略.........
MACAddress: "aa:bb:cc:dd:ee:f1",
NetworkTag: "network-vlan69",
InterfaceName: "eth1.69",
IsVirtual: true,
}, {
MACAddress: "aa:bb:cc:dd:ee:f1", // duplicated mac+net; ignored
NetworkTag: "network-vlan42",
InterfaceName: "eth2",
IsVirtual: true,
}, {
MACAddress: "aa:bb:cc:dd:ee:f4",
NetworkTag: "network-net1",
InterfaceName: "eth1", // duplicated name+machine id; ignored
IsVirtual: false,
}}
volumes := []params.Volume{{
VolumeTag: "volume-1-0",
Info: params.VolumeInfo{
VolumeId: "vol-123",
Size: 124,
},
}}
volumeAttachments := map[string]params.VolumeAttachmentInfo{
"volume-1-0": {
DeviceName: "xvdf1",
},
}
err = apiMachine.SetInstanceInfo(
"i-will", "fake_nonce", &hwChars, networks, ifaces, volumes, volumeAttachments,
)
c.Assert(err, jc.ErrorIsNil)
instanceId, err = apiMachine.InstanceId()
c.Assert(err, jc.ErrorIsNil)
c.Assert(instanceId, gc.Equals, instance.Id("i-will"))
// Try it again - should fail.
err = apiMachine.SetInstanceInfo("i-wont", "fake", nil, nil, nil, nil, nil)
c.Assert(err, gc.ErrorMatches, `cannot record provisioning info for "i-wont": cannot set instance data for machine "1": already set`)
// Now try to get machine 0's instance id.
apiMachine, err = s.provisioner.Machine(s.machine.Tag().(names.MachineTag))
c.Assert(err, jc.ErrorIsNil)
instanceId, err = apiMachine.InstanceId()
c.Assert(err, jc.ErrorIsNil)
c.Assert(instanceId, gc.Equals, instance.Id("i-manager"))
// Check the networks are created.
for i := range networks {
if i == 3 {
// Last one was ignored, so skip it.
break
}
tag, err := names.ParseNetworkTag(networks[i].Tag)
c.Assert(err, jc.ErrorIsNil)
networkName := tag.Id()
nw, err := s.State.Network(networkName)
c.Assert(err, jc.ErrorIsNil)
c.Check(nw.Name(), gc.Equals, networkName)
c.Check(nw.ProviderId(), gc.Equals, network.Id(networks[i].ProviderId))
c.Check(nw.Tag().String(), gc.Equals, networks[i].Tag)
c.Check(nw.VLANTag(), gc.Equals, networks[i].VLANTag)
c.Check(nw.CIDR(), gc.Equals, networks[i].CIDR)
}
// And the network interfaces as well.
ifacesMachine, err = notProvisionedMachine.NetworkInterfaces()
c.Assert(err, jc.ErrorIsNil)
c.Assert(ifacesMachine, gc.HasLen, 4)
actual := make([]params.NetworkInterface, len(ifacesMachine))
for i, iface := range ifacesMachine {
actual[i].InterfaceName = iface.InterfaceName()
actual[i].NetworkTag = iface.NetworkTag().String()
actual[i].MACAddress = iface.MACAddress()
actual[i].IsVirtual = iface.IsVirtual()
c.Check(iface.MachineTag(), gc.Equals, notProvisionedMachine.Tag())
c.Check(iface.MachineId(), gc.Equals, notProvisionedMachine.Id())
}
c.Assert(actual, jc.SameContents, ifaces[:4]) // skip the rest as they are ignored.
// Now check volumes and volume attachments.
volume, err := s.State.Volume(names.NewVolumeTag("1/0"))
c.Assert(err, jc.ErrorIsNil)
volumeInfo, err := volume.Info()
c.Assert(err, jc.ErrorIsNil)
c.Assert(volumeInfo, gc.Equals, state.VolumeInfo{
VolumeId: "vol-123",
Pool: "loop-pool",
Size: 124,
})
stateVolumeAttachments, err := s.State.MachineVolumeAttachments(names.NewMachineTag("1"))
c.Assert(err, jc.ErrorIsNil)
c.Assert(stateVolumeAttachments, gc.HasLen, 1)
volumeAttachmentInfo, err := stateVolumeAttachments[0].Info()
c.Assert(err, jc.ErrorIsNil)
c.Assert(volumeAttachmentInfo, gc.Equals, state.VolumeAttachmentInfo{
DeviceName: "xvdf1",
})
}
开发者ID:ktsakalozos,项目名称:juju,代码行数:101,代码来源:provisioner_test.go
示例7: TestSetInstanceInfo
//.........这里部分代码省略.........
NetworkTag: "network-vlan42",
InterfaceName: "eth2",
IsVirtual: true,
}, {
MACAddress: "aa:bb:cc:dd:ee:f2",
NetworkTag: "network-net1",
InterfaceName: "eth1", // duplicated name+machine id; ignored for machine 1.
IsVirtual: false,
}}
args := params.InstancesInfo{Machines: []params.InstanceInfo{{
Tag: s.machines[0].Tag().String(),
InstanceId: "i-was",
Nonce: "fake_nonce",
}, {
Tag: s.machines[1].Tag().String(),
InstanceId: "i-will",
Nonce: "fake_nonce",
Characteristics: &hwChars,
Networks: networks,
Interfaces: ifaces,
}, {
Tag: s.machines[2].Tag().String(),
InstanceId: "i-am-too",
Nonce: "fake",
Characteristics: nil,
Networks: networks,
Interfaces: ifaces,
},
{Tag: "machine-42"},
{Tag: "unit-foo-0"},
{Tag: "service-bar"},
}}
result, err := s.provisioner.SetInstanceInfo(args)
c.Assert(err, gc.IsNil)
c.Assert(result, jc.DeepEquals, params.ErrorResults{
Results: []params.ErrorResult{
{¶ms.Error{
Message: `aborted instance "i-was": cannot set instance data for machine "0": already set`,
}},
{nil},
{nil},
{apiservertesting.NotFoundError("machine 42")},
{apiservertesting.ErrUnauthorized},
{apiservertesting.ErrUnauthorized},
},
})
// Verify machine 1 and 2 were provisioned.
c.Assert(s.machines[1].Refresh(), gc.IsNil)
c.Assert(s.machines[2].Refresh(), gc.IsNil)
instanceId, err := s.machines[1].InstanceId()
c.Assert(err, gc.IsNil)
c.Check(instanceId, gc.Equals, instance.Id("i-will"))
instanceId, err = s.machines[2].InstanceId()
c.Assert(err, gc.IsNil)
c.Check(instanceId, gc.Equals, instance.Id("i-am-too"))
c.Check(s.machines[1].CheckProvisioned("fake_nonce"), jc.IsTrue)
c.Check(s.machines[2].CheckProvisioned("fake"), jc.IsTrue)
gotHardware, err := s.machines[1].HardwareCharacteristics()
c.Assert(err, gc.IsNil)
c.Check(gotHardware, gc.DeepEquals, &hwChars)
ifacesMachine1, err := s.machines[1].NetworkInterfaces()
c.Assert(err, gc.IsNil)
c.Assert(ifacesMachine1, gc.HasLen, 4)
actual := make([]params.NetworkInterface, len(ifacesMachine1))
for i, iface := range ifacesMachine1 {
actual[i].InterfaceName = iface.InterfaceName()
actual[i].NetworkTag = iface.NetworkTag()
actual[i].MACAddress = iface.MACAddress()
actual[i].IsVirtual = iface.IsVirtual()
actual[i].Disabled = iface.IsDisabled()
c.Check(iface.MachineId(), gc.Equals, s.machines[1].Id())
c.Check(iface.MachineTag(), gc.Equals, s.machines[1].Tag().String())
}
c.Assert(actual, jc.SameContents, ifaces[:4])
ifacesMachine2, err := s.machines[2].NetworkInterfaces()
c.Assert(err, gc.IsNil)
c.Assert(ifacesMachine2, gc.HasLen, 1)
c.Assert(ifacesMachine2[0].InterfaceName(), gc.Equals, ifaces[5].InterfaceName)
c.Assert(ifacesMachine2[0].MACAddress(), gc.Equals, ifaces[5].MACAddress)
c.Assert(ifacesMachine2[0].NetworkTag(), gc.Equals, ifaces[5].NetworkTag)
c.Assert(ifacesMachine2[0].MachineId(), gc.Equals, s.machines[2].Id())
for i, _ := range networks {
if i == 3 {
// Last one was ignored, so don't check.
break
}
tag, err := names.ParseNetworkTag(networks[i].Tag)
c.Assert(err, gc.IsNil)
networkName := tag.Id()
network, err := s.State.Network(networkName)
c.Assert(err, gc.IsNil)
c.Check(network.Name(), gc.Equals, networkName)
c.Check(network.ProviderId(), gc.Equals, networks[i].ProviderId)
c.Check(network.Tag().String(), gc.Equals, networks[i].Tag)
c.Check(network.VLANTag(), gc.Equals, networks[i].VLANTag)
c.Check(network.CIDR(), gc.Equals, networks[i].CIDR)
}
}
开发者ID:klyachin,项目名称:juju,代码行数:101,代码来源:provisioner_test.go
示例8: TestSetInstanceInfo
//.........这里部分代码省略.........
}},
VolumeAttachments: map[string]params.VolumeAttachmentInfo{
"volume-0": {
DeviceName: "sda",
},
},
},
{Tag: "machine-42"},
{Tag: "unit-foo-0"},
{Tag: "service-bar"},
}}
result, err := s.provisioner.SetInstanceInfo(args)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, jc.DeepEquals, params.ErrorResults{
Results: []params.ErrorResult{
{¶ms.Error{
Message: `cannot record provisioning info for "i-was": cannot set instance data for machine "0": already set`,
}},
{nil},
{nil},
{nil},
{apiservertesting.NotFoundError("machine 42")},
{apiservertesting.ErrUnauthorized},
{apiservertesting.ErrUnauthorized},
},
})
// Verify machine 1 and 2 were provisioned.
c.Assert(s.machines[1].Refresh(), gc.IsNil)
c.Assert(s.machines[2].Refresh(), gc.IsNil)
instanceId, err := s.machines[1].InstanceId()
c.Assert(err, jc.ErrorIsNil)
c.Check(instanceId, gc.Equals, instance.Id("i-will"))
instanceId, err = s.machines[2].InstanceId()
c.Assert(err, jc.ErrorIsNil)
c.Check(instanceId, gc.Equals, instance.Id("i-am-too"))
c.Check(s.machines[1].CheckProvisioned("fake_nonce"), jc.IsTrue)
c.Check(s.machines[2].CheckProvisioned("fake"), jc.IsTrue)
gotHardware, err := s.machines[1].HardwareCharacteristics()
c.Assert(err, jc.ErrorIsNil)
c.Check(gotHardware, gc.DeepEquals, &hwChars)
ifacesMachine1, err := s.machines[1].NetworkInterfaces()
c.Assert(err, jc.ErrorIsNil)
c.Assert(ifacesMachine1, gc.HasLen, 4)
actual := make([]params.NetworkInterface, len(ifacesMachine1))
for i, iface := range ifacesMachine1 {
actual[i].InterfaceName = iface.InterfaceName()
actual[i].NetworkTag = iface.NetworkTag().String()
actual[i].MACAddress = iface.MACAddress()
actual[i].IsVirtual = iface.IsVirtual()
actual[i].Disabled = iface.IsDisabled()
c.Check(iface.MachineId(), gc.Equals, s.machines[1].Id())
c.Check(iface.MachineTag(), gc.Equals, s.machines[1].Tag())
}
c.Assert(actual, jc.SameContents, ifaces[:4])
ifacesMachine2, err := s.machines[2].NetworkInterfaces()
c.Assert(err, jc.ErrorIsNil)
c.Assert(ifacesMachine2, gc.HasLen, 1)
c.Assert(ifacesMachine2[0].InterfaceName(), gc.Equals, ifaces[5].InterfaceName)
c.Assert(ifacesMachine2[0].MACAddress(), gc.Equals, ifaces[5].MACAddress)
c.Assert(ifacesMachine2[0].NetworkTag().String(), gc.Equals, ifaces[5].NetworkTag)
c.Assert(ifacesMachine2[0].MachineId(), gc.Equals, s.machines[2].Id())
for i := range networks {
if i == 3 {
// Last one was ignored, so don't check.
break
}
tag, err := names.ParseNetworkTag(networks[i].Tag)
c.Assert(err, jc.ErrorIsNil)
networkName := tag.Id()
nw, err := s.State.Network(networkName)
c.Assert(err, jc.ErrorIsNil)
c.Check(nw.Name(), gc.Equals, networkName)
c.Check(nw.ProviderId(), gc.Equals, network.Id(networks[i].ProviderId))
c.Check(nw.Tag().String(), gc.Equals, networks[i].Tag)
c.Check(nw.VLANTag(), gc.Equals, networks[i].VLANTag)
c.Check(nw.CIDR(), gc.Equals, networks[i].CIDR)
}
// Verify the machine with requested volumes was provisioned, and the
// volume information recorded in state.
volumeAttachments, err := s.State.MachineVolumeAttachments(volumesMachine.MachineTag())
c.Assert(err, jc.ErrorIsNil)
c.Assert(volumeAttachments, gc.HasLen, 1)
volumeAttachmentInfo, err := volumeAttachments[0].Info()
c.Assert(err, jc.ErrorIsNil)
c.Assert(volumeAttachmentInfo, gc.Equals, state.VolumeAttachmentInfo{DeviceName: "sda"})
volume, err := s.State.Volume(volumeAttachments[0].Volume())
c.Assert(err, jc.ErrorIsNil)
volumeInfo, err := volume.Info()
c.Assert(err, jc.ErrorIsNil)
c.Assert(volumeInfo, gc.Equals, state.VolumeInfo{VolumeId: "vol-0", Pool: "static-pool", Size: 1234})
// Verify the machine without requested volumes still has no volume
// attachments recorded in state.
volumeAttachments, err = s.State.MachineVolumeAttachments(s.machines[1].MachineTag())
c.Assert(err, jc.ErrorIsNil)
c.Assert(volumeAttachments, gc.HasLen, 0)
}
开发者ID:OSBI,项目名称:juju,代码行数:101,代码来源:provisioner_test.go
注:本文中的github.com/juju/names.ParseNetworkTag函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论