func (s SubnetInfos) GetByCIDR(cidr string) (SubnetInfos, error) {
	if !IsValidCIDR(cidr) {
		return nil, errors.NotValidf("CIDR %q", cidr)
	}

	var matching SubnetInfos
	for _, sub := range s {
		if sub.CIDR == cidr {
			matching = append(matching, sub)
		}
	}

	if len(matching) != 0 {
		return matching, nil
	}

	// Some providers (e.g. equinix) carve subnets into smaller CIDRs and
	// assign addresses from the carved subnets to the machines. If we were
	// not able to find a direct CIDR match fallback to a CIDR is sub-CIDR
	// of check.
	firstIP, lastIP, err := IPRangeForCIDR(cidr)
	if err != nil {
		return nil, errors.Annotatef(err, "unable to extract first and last IP addresses from CIDR %q", cidr)
	}

	for _, sub := range s {
		subNet, err := sub.ParsedCIDRNetwork()
		if err != nil { // this should not happen; but let's be paranoid.
			logger.Warningf("unable to parse CIDR %q for subnet %q", sub.CIDR, sub.ID)
			continue
		}

		if subNet.Contains(firstIP) && subNet.Contains(lastIP) {
			matching = append(matching, sub)
		}
	}

	return matching, nil
}
// GetByCIDR returns all subnets in the collection
// with a CIDR matching the input.
GetByCIDR returns all subnets in the collection
with a CIDR matching the input.
// GetByCIDR returns all subnets in the collection // with a CIDR matching the input .
func (s SubnetInfos) GetByCIDR(cidr string) (SubnetInfos, error) {
	if !IsValidCIDR(cidr) {
		return nil, errors.NotValidf("CIDR %q", cidr)
	}
	var matching SubnetInfos
	for _, sub := range s {
		if sub.CIDR == cidr {
			matching = append(matching, sub)
		}
	}
	if len(matching) != 0 {
		return matching, nil
	}
	firstIP, lastIP, err := IPRangeForCIDR(cidr)
	if err != nil {
		return nil, errors.Annotatef(err, "unable to extract first and last IP addresses from CIDR %q", cidr)
	}
	for _, sub := range s {
		subNet, err := sub.ParsedCIDRNetwork()
		if err != nil { 
			logger.Warningf("unable to parse CIDR %q for subnet %q", sub.CIDR, sub.ID)
			continue
		}
		if subNet.Contains(firstIP) && subNet.Contains(lastIP) {
			matching = append(matching, sub)
		}
	}
	return matching, nil
}
func ( s SubnetInfos ) GetByCIDR ( cidr string ) ( SubnetInfos , error ) { if ! IsValidCIDR ( cidr ) { return nil , errors . NotValidf ( " " , cidr ) } var matching SubnetInfos for _ , sub := range s { if sub . CIDR == cidr { matching = append ( matching , sub ) } } if len ( matching ) != 0 { return matching , nil } firstIP , lastIP , err := IPRangeForCIDR ( cidr ) if err != nil { return nil , errors . Annotatef ( err , " " , cidr ) } for _ , sub := range s { subNet , err := sub . ParsedCIDRNetwork ( ) if err != nil { logger . Warningf ( " " , sub . CIDR , sub . ID ) continue } if subNet . Contains ( firstIP ) && subNet . Contains ( lastIP ) { matching = append ( matching , sub ) } } return matching , nil }
GetByCIDR returns all subnets in the collection
with a CIDR matching the input.
GetByCIDR returns all subnets in the collection with a CIDR matching the input .
// Some providers (e.g. equinix) carve subnets into smaller CIDRs and // assign addresses from the carved subnets to the machines. If we were // not able to find a direct CIDR match fallback to a CIDR is sub-CIDR // of check. // this should not happen; but let's be paranoid.