func ConvertToSpaceAddress(addr SpaceAddressCandidate, lookup SubnetLookup) (SpaceAddress, error) {
	subnets, err := lookup.AllSubnetInfos()
	if err != nil {
		return SpaceAddress{}, errors.Trace(err)
	}

	cidr := addr.SubnetCIDR()

	spaceAddr := SpaceAddress{
		MachineAddress: NewMachineAddress(
			addr.Value(),
			WithCIDR(cidr),
			WithConfigType(addr.ConfigMethod()),
			WithSecondary(addr.IsSecondary()),
		),
	}

	// If this is not a loopback device, attempt to
	// set the space ID based on the subnet.
	if addr.ConfigMethod() != ConfigLoopback && cidr != "" {
		allMatching, err := subnets.GetByCIDR(cidr)
		if err != nil {
			return SpaceAddress{}, errors.Trace(err)
		}

		// This only holds true while CIDRs uniquely identify subnets.
		if len(allMatching) != 0 {
			spaceAddr.SpaceID = allMatching[0].SpaceID
		}
	}

	return spaceAddr, nil
}
// ConvertToSpaceAddress returns a SpaceAddress representing the
// input candidate address, by using the input subnet lookup to
// associate the address with a space..
ConvertToSpaceAddress returns a SpaceAddress representing the
input candidate address, by using the input subnet lookup to
associate the address with a space
// ConvertToSpaceAddress returns a SpaceAddress representing the // input candidate address by using the input subnet lookup to // associate the address with a space ..
func ConvertToSpaceAddress(addr SpaceAddressCandidate, lookup SubnetLookup) (SpaceAddress, error) {
	subnets, err := lookup.AllSubnetInfos()
	if err != nil {
		return SpaceAddress{}, errors.Trace(err)
	}
	cidr := addr.SubnetCIDR()
	spaceAddr := SpaceAddress{
		MachineAddress: NewMachineAddress(
			addr.Value(),
			WithCIDR(cidr),
			WithConfigType(addr.ConfigMethod()),
			WithSecondary(addr.IsSecondary()),
		),
	}
	if addr.ConfigMethod() != ConfigLoopback && cidr != "" {
		allMatching, err := subnets.GetByCIDR(cidr)
		if err != nil {
			return SpaceAddress{}, errors.Trace(err)
		}
		if len(allMatching) != 0 {
			spaceAddr.SpaceID = allMatching[0].SpaceID
		}
	}
	return spaceAddr, nil
}
func ConvertToSpaceAddress ( addr SpaceAddressCandidate , lookup SubnetLookup ) ( SpaceAddress , error ) { subnets , err := lookup . AllSubnetInfos ( ) if err != nil { return SpaceAddress { } , errors . Trace ( err ) } cidr := addr . SubnetCIDR ( ) spaceAddr := SpaceAddress { MachineAddress : NewMachineAddress ( addr . Value ( ) , WithCIDR ( cidr ) , WithConfigType ( addr . ConfigMethod ( ) ) , WithSecondary ( addr . IsSecondary ( ) ) , ) , } if addr . ConfigMethod ( ) != ConfigLoopback && cidr != " " { allMatching , err := subnets . GetByCIDR ( cidr ) if err != nil { return SpaceAddress { } , errors . Trace ( err ) } if len ( allMatching ) != 0 { spaceAddr . SpaceID = allMatching [ 0 ] . SpaceID } } return spaceAddr , nil }
ConvertToSpaceAddress returns a SpaceAddress representing the
input candidate address, by using the input subnet lookup to
associate the address with a space
ConvertToSpaceAddress returns a SpaceAddress representing the input candidate address by using the input subnet lookup to associate the address with a space
// If this is not a loopback device, attempt to // set the space ID based on the subnet. // This only holds true while CIDRs uniquely identify subnets.