// Retrieve Associated subnets for a router object.
970995
func (r Hardware_Router) GetBoundSubnets() (resp []datatypes.Network_Subnet, err error) {
	err = r.Session.DoRequest("SoftLayer_Hardware_Router", "getBoundSubnets", nil, &r.Options, &resp)
	return
}
1236182
func (r Network_Subnet) GetNetworkId() (resp int, err error) {
	err = r.Session.DoRequest("SoftLayer_Network_Subnet", "getNetworkId", nil, &r.Options, &resp)
	return
}
406986
func (e Environ) getSubnetInfo() ([]network.SubnetInfo, error) {
	networks, err := e.client.AllIpNetworks(nil)
	if err != nil {
		return nil, errors.Trace(err)
	}
	subnets := make([]network.SubnetInfo, len(networks.Result))
	idx := 0
	for _, val := range networks.Result {
		var spaceId network.Id
		if val.IpNetworkExchange != nil {
			spaceId = network.Id(*val.IpNetworkExchange)
		}
		subnets[idx] = network.SubnetInfo{
			ProviderId:      network.Id(val.Name),
			CIDR:            val.IpAddressPrefix,
			SpaceProviderId: spaceId,
			AvailabilityZones: []string{
				"default",
			},
		}
		idx++
	}
	return subnets, nil
}
281163
func (api *ProjectsAPI) GetNetworks(projectID string, options *NetworkGetOptions) (result *Networks, err error) {
	uri := api.client.Endpoint + projectUrl + projectID + "/networks"
	if options != nil {
		uri += getQueryString(options)
	}
	res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
	if err != nil {
		return
	}

	result = &Networks{}
	err = json.Unmarshal(res, result)
	return
}
1018474
func (r Network_Subnet) GetSubnetForIpAddress(ipAddress *string) (resp datatypes.Network_Subnet, err error) {
	params := []interface{}{
		ipAddress,
	}
	err = r.Session.DoRequest("SoftLayer_Network_Subnet", "getSubnetForIpAddress", params, &r.Options, &resp)
	return
}
612936
func GetSubnetAddr(ipStr string, length uint) string {
	subnetStr := ipStr
	if isSubnetIPRange(ipStr) {
		subnetStr = strings.Split(ipStr, "-")[0]
	}

	subnet, _ := ipv4ToUint32(subnetStr)
	subnetMask := -1 << (32 - length)

	ipSubnet, _ := ipv4Uint32ToString(uint32(subnetMask) & subnet)
	return ipSubnet
}
101243
func (env *maasEnviron) subnetFromJson(subnet gomaasapi.JSONObject, spaceId network.Id) (network.SubnetInfo, error) {
	var subnetInfo network.SubnetInfo
	fields, err := subnet.GetMap()
	if err != nil {
		return subnetInfo, errors.Trace(err)
	}
	subnetIdFloat, err := fields["id"].GetFloat64()
	if err != nil {
		return subnetInfo, errors.Annotatef(err, "cannot get subnet Id")
	}
	subnetId := strconv.Itoa(int(subnetIdFloat))
	cidr, err := fields["cidr"].GetString()
	if err != nil {
		return subnetInfo, errors.Annotatef(err, "cannot get cidr")
	}
	vid := 0
	vidField, ok := fields["vid"]
	if ok && !vidField.IsNil() {
		// vid is optional, so assume it's 0 when missing or nil.
		vidFloat, err := vidField.GetFloat64()
		if err != nil {
			return subnetInfo, errors.Errorf("cannot get vlan tag: %v", err)
		}
		vid = int(vidFloat)
	}

	subnetInfo = network.SubnetInfo{
		ProviderId:      network.Id(subnetId),
		VLANTag:         vid,
		CIDR:            cidr,
		SpaceProviderId: spaceId,
	}
	return subnetInfo, nil
}
51294
func (r Network_Storage) GetAllowableIpAddresses(subnetId *int, filterIpAddress *string) (resp []datatypes.Network_Subnet_IpAddress, err error) {
	params := []interface{}{
		subnetId,
		filterIpAddress,
	}
	err = r.Session.DoRequest("SoftLayer_Network_Storage", "getAllowableIpAddresses", params, &r.Options, &resp)
	return
}
688438
func getNetworking(c *InstanceConfig) (string, string, error) {
	networkId := c.Network
	subnetworkId := c.Subnetwork

	// Apply network naming requirements per
	// https://cloud.google.com/compute/docs/reference/latest/instances#resource
	switch c.Network {
	// It is possible to omit the network property as long as a subnet is
	// specified. That will be validated later.
	case "":
		break
	// This special short name should be expanded.
	case "default":
		networkId = "global/networks/default"
	// A value other than "default" was provided for the network name.
	default:
		// If the value doesn't contain a slash, we assume it's not a full or
		// partial URL. We will expand it into a partial URL here and avoid
		// making an API call to discover the network as it's common for the
		// caller to not have permission against network discovery APIs.
		if !strings.Contains(c.Network, "/") {
			networkId = "projects/" + c.NetworkProjectId + "/global/networks/" + c.Network
		}
	}

	// Apply subnetwork naming requirements per
	// https://cloud.google.com/compute/docs/reference/latest/instances#resource
	switch c.Subnetwork {
	case "":
		// You can't omit both subnetwork and network
		if networkId == "" {
			return networkId, subnetworkId, fmt.Errorf("both network and subnetwork were empty.")
		}
		// An empty subnetwork is only valid for networks in legacy mode or
		// auto-subnet mode. We could make an API call to get that information
		// about the network, but it's common for the caller to not have
		// permission to that API. We'll proceed assuming they're correct in
		// omitting the subnetwork and let the compute.insert API surface an
		// error about an invalid network configuration if it exists.
		break
	default:
		// If the value doesn't contain a slash, we assume it's not a full or
		// partial URL. We will expand it into a partial URL here and avoid
		// making a call to discover the subnetwork.
		if !strings.Contains(c.Subnetwork, "/") {
			subnetworkId = "projects/" + c.NetworkProjectId + "/regions/" + c.Region + "/subnetworks/" + c.Subnetwork
		}
	}
	return networkId, subnetworkId, nil
}
1202544
func (c *Cluster) GetNetworks(filter filters.Args) ([]apitypes.NetworkResource, error) {
	var f *swarmapi.ListNetworksRequest_Filters

	if filter.Len() > 0 {
		f = &swarmapi.ListNetworksRequest_Filters{}

		if filter.Contains("name") {
			f.Names = filter.Get("name")
			f.NamePrefixes = filter.Get("name")
		}

		if filter.Contains("id") {
			f.IDPrefixes = filter.Get("id")
		}
	}

	list, err := c.getNetworks(f)
	if err != nil {
		return nil, err
	}
	filterPredefinedNetworks(&list)

	return internalnetwork.FilterNetworks(list, filter)
}
208939
func (api *API) ListSubnets(spaceTag *names.SpaceTag, zone string) ([]params.Subnet, error) {
	var response params.ListSubnetsResults
	var space string
	if spaceTag != nil {
		space = spaceTag.String()
	}
	args := params.SubnetsFilters{
		SpaceTag: space,
		Zone:     zone,
	}
	err := api.facade.FacadeCall("ListSubnets", args, &response)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return response.Results, nil
}
631192
func InSubnets(ip net.IP, subnets map[string]*net.IPNet) bool {
	for _, subnet := range subnets {
		if subnet.Contains(ip) {
			return true
		}
	}
	return false
}
848911
func FindSubnet(c *kops.Cluster, subnetName string) *kops.ClusterSubnetSpec {
	for i := range c.Spec.Subnets {
		if c.Spec.Subnets[i].Name == subnetName {
			return &c.Spec.Subnets[i]
		}
	}
	return nil
}
400267
func (n *Networking) GetForwardableNet() (*activeNet, error) {
	numberNets := len(n.nets)
	if numberNets == 0 {
		return nil, fmt.Errorf("no networks found")
	}
	for _, net := range n.nets {
		if net.IPMasq() {
			return &net, nil
		}
	}
	return &n.nets[numberNets-1], nil
}
99961
func listSubnetworksOfNetwork(svc *compute.Service, networkProjectID, networkID, region string) ([]*compute.Subnetwork, error) {
	var subnets []*compute.Subnetwork
	err := svc.Subnetworks.List(networkProjectID, region).Filter(fmt.Sprintf("network eq .*/%v$", networkID)).Pages(context.Background(), func(res *compute.SubnetworkList) error {
		subnets = append(subnets, res.Items...)
		return nil
	})
	return subnets, err
}
125239
func (api *SubnetsAPI) GetAll(options *SubnetGetOptions) (result *Subnets, err error) {
	uri := api.client.Endpoint + subnetUrl
	if options != nil {
		uri += getQueryString(options)
	}
	res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
	if err != nil {
		return
	}

	result = &Subnets{}
	err = json.Unmarshal(res, result)
	return
}
1274997
func (r Hardware_Router) GetAttachedNetworkStorages(nasType *string) (resp []datatypes.Network_Storage, err error) {
	params := []interface{}{
		nasType,
	}
	err = r.Session.DoRequest("SoftLayer_Hardware_Router", "getAttachedNetworkStorages", params, &r.Options, &resp)
	return
}