func (s SpaceInfos) MoveSubnets(subnetIDs IDSet, spaceName string) (SpaceInfos, error) {
	newSpace := s.GetByName(spaceName)
	if newSpace == nil {
		return nil, errors.NotFoundf("space with name %q", spaceName)
	}

	// We return a copy, not mutating the original.
	newSpaces := make(SpaceInfos, len(s))
	var movers SubnetInfos
	found := MakeIDSet()

	// First accrue the moving subnets and remove them from their old spaces.
	for i, space := range s {
		newSpaces[i] = space
		newSpaces[i].Subnets = nil

		for _, sub := range space.Subnets {
			if subnetIDs.Contains(sub.ID) {
				// Indicate that we found the subnet,
				// but don't do anything if it is already in the space.
				found.Add(sub.ID)
				if string(space.Name) != spaceName {
					sub.SpaceID = newSpace.ID
					sub.SpaceName = spaceName
					sub.ProviderSpaceId = newSpace.ProviderId
					movers = append(movers, sub)
				}
				continue
			}
			newSpaces[i].Subnets = append(newSpaces[i].Subnets, sub)
		}
	}

	// Ensure that the input did not include subnets not in this collection.
	if diff := subnetIDs.Difference(found); len(diff) != 0 {
		return nil, errors.NotFoundf("subnet IDs %v", diff.SortedValues())
	}

	// Then put them against the new one.
	// We have to find the space again in this collection,
	// because newSpace was returned from a copy.
	for i, space := range newSpaces {
		if string(space.Name) == spaceName {
			newSpaces[i].Subnets = append(space.Subnets, movers...)
			break
		}
	}

	return newSpaces, nil
}
// MoveSubnets returns a new topology representing
// the movement of subnets to a new network space.
MoveSubnets returns a new topology representing
the movement of subnets to a new network space.
// MoveSubnets returns a new topology representing // the movement of subnets to a new network space .
func (s SpaceInfos) MoveSubnets(subnetIDs IDSet, spaceName string) (SpaceInfos, error) {
	newSpace := s.GetByName(spaceName)
	if newSpace == nil {
		return nil, errors.NotFoundf("space with name %q", spaceName)
	}
	newSpaces := make(SpaceInfos, len(s))
	var movers SubnetInfos
	found := MakeIDSet()
	for i, space := range s {
		newSpaces[i] = space
		newSpaces[i].Subnets = nil
		for _, sub := range space.Subnets {
			if subnetIDs.Contains(sub.ID) {
				found.Add(sub.ID)
				if string(space.Name) != spaceName {
					sub.SpaceID = newSpace.ID
					sub.SpaceName = spaceName
					sub.ProviderSpaceId = newSpace.ProviderId
					movers = append(movers, sub)
				}
				continue
			}
			newSpaces[i].Subnets = append(newSpaces[i].Subnets, sub)
		}
	}
	if diff := subnetIDs.Difference(found); len(diff) != 0 {
		return nil, errors.NotFoundf("subnet IDs %v", diff.SortedValues())
	}
	for i, space := range newSpaces {
		if string(space.Name) == spaceName {
			newSpaces[i].Subnets = append(space.Subnets, movers...)
			break
		}
	}
	return newSpaces, nil
}
func ( s SpaceInfos ) MoveSubnets ( subnetIDs IDSet , spaceName string ) ( SpaceInfos , error ) { newSpace := s . GetByName ( spaceName ) if newSpace == nil { return nil , errors . NotFoundf ( " " , spaceName ) } newSpaces := make ( SpaceInfos , len ( s ) ) var movers SubnetInfos found := MakeIDSet ( ) for i , space := range s { newSpaces [ i ] = space newSpaces [ i ] . Subnets = nil for _ , sub := range space . Subnets { if subnetIDs . Contains ( sub . ID ) { found . Add ( sub . ID ) if string ( space . Name ) != spaceName { sub . SpaceID = newSpace . ID sub . SpaceName = spaceName sub . ProviderSpaceId = newSpace . ProviderId movers = append ( movers , sub ) } continue } newSpaces [ i ] . Subnets = append ( newSpaces [ i ] . Subnets , sub ) } } if diff := subnetIDs . Difference ( found ) ; len ( diff ) != 0 { return nil , errors . NotFoundf ( " " , diff . SortedValues ( ) ) } for i , space := range newSpaces { if string ( space . Name ) == spaceName { newSpaces [ i ] . Subnets = append ( space . Subnets , movers ... ) break } } return newSpaces , nil }
MoveSubnets returns a new topology representing
the movement of subnets to a new network space.
MoveSubnets returns a new topology representing the movement of subnets to a new network space .
// We return a copy, not mutating the original. // First accrue the moving subnets and remove them from their old spaces. // Indicate that we found the subnet, // but don't do anything if it is already in the space. // Ensure that the input did not include subnets not in this collection. // Then put them against the new one. // We have to find the space again in this collection, // because newSpace was returned from a copy.