func (s *networkSuite) TestNetworkNames(c *gc.C) { for i, test := range networkNameTests { c.Logf("test %d: %q", i, test.pattern) c.Check(names.IsNetwork(test.pattern), gc.Equals, test.valid) if test.valid { expectTag := fmt.Sprintf("%s-%s", names.NetworkTagKind, test.pattern) c.Check(names.NetworkTag(test.pattern), gc.Equals, expectTag) } else { expectErr := fmt.Sprintf("%q is not a valid network name", test.pattern) testNetworkTag := func() { names.NetworkTag(test.pattern) } c.Check(testNetworkTag, gc.PanicMatches, regexp.QuoteMeta(expectErr)) } } }
func (task *provisionerTask) prepareNetworkAndInterfaces(networkInfo []network.Info) ( networks []params.Network, ifaces []params.NetworkInterface) { if len(networkInfo) == 0 { return nil, nil } visitedNetworks := set.NewStrings() for _, info := range networkInfo { networkTag := names.NetworkTag(info.NetworkName) if !visitedNetworks.Contains(networkTag) { networks = append(networks, params.Network{ Tag: networkTag, ProviderId: info.ProviderId, CIDR: info.CIDR, VLANTag: info.VLANTag, }) visitedNetworks.Add(networkTag) } ifaces = append(ifaces, params.NetworkInterface{ InterfaceName: info.InterfaceName, MACAddress: info.MACAddress, NetworkTag: networkTag, IsVirtual: info.IsVirtual, }) } return networks, ifaces }
// parseNetworks returns a list of network tags by parsing the // comma-delimited string value of --networks or --exclude-networks // arguments. func parseNetworks(networksValue string) (networks []string) { parts := strings.Split(networksValue, ",") for _, part := range parts { network := strings.TrimSpace(part) if network != "" { networks = append(networks, names.NetworkTag(network)) } } return networks }
// Tag returns the network tag. func (n *Network) Tag() string { return names.NetworkTag(n.doc.Name) }
// NetworkTag returns the network tag of the interface. func (ni *NetworkInterface) NetworkTag() string { return names.NetworkTag(ni.doc.NetworkName) }