// determineContainerSpaces tries to use the direct information about a
// container to find what spaces it should be in, and then falls back to what
// we know about the host machine.
331886
func (p *BridgePolicy) determineContainerSpaces(m Machine, containerMachine Container, defaultSpaceName string) (set.Strings, error) {
	containerSpaces, err := containerMachine.DesiredSpaces()
	if err != nil {
		return nil, errors.Trace(err)
	}
	logger.Debugf("for container %q, found desired spaces: %s",
		containerMachine.Id(), network.QuoteSpaceSet(containerSpaces))
	if len(containerSpaces) == 0 {
		// We have determined that the container doesn't have any useful
		// constraints set on it. So lets see if we can come up with
		// something useful.
		containerSpaces, err = p.inferContainerSpaces(m, containerMachine.Id(), defaultSpaceName)
		if err != nil {
			return nil, errors.Trace(err)
		}
	}
	return containerSpaces, nil
}
170188
func SupportsSpaces(backing environs.EnvironConfigGetter, ctx context.ProviderCallContext) error {
	env, err := environs.GetEnviron(backing, environs.New)
	if err != nil {
		return errors.Annotate(err, "getting environ")
	}
	if !environs.SupportsSpaces(ctx, env) {
		return errors.NotSupportedf("spaces")
	}
	return nil
}
1074527
func (e Environ) SupportsSpaces(ctx context.ProviderCallContext) (bool, error) {
	logger.Infof("checking for spaces support")
	access, err := e.canAccessNetworkAPI()
	if err != nil {
		return false, errors.Trace(err)
	}
	if access {
		return true, nil
	}
	return false, nil
}
663022
func (k *kubernetesClient) Namespaces() ([]string, error) {
	namespaces := k.client().CoreV1().Namespaces()
	ns, err := namespaces.List(v1.ListOptions{IncludeUninitialized: true})
	if err != nil {
		return nil, errors.Annotate(err, "listing namespaces")
	}
	result := make([]string, len(ns.Items))
	for i, n := range ns.Items {
		if err := checkNamespaceOwnedByJuju(&n, k.annotations); err != nil {
			continue
		}
		result[i] = n.Name
	}
	return result, nil
}
1177388
func (s *PresetSettings) SetContainerSettings(v *ContainerSettings) *PresetSettings {
	s.ContainerSettings = v
	return s
}
847794
func (actor Actor) GetSpaceStagingSecurityGroupsBySpace(spaceGUID string) ([]SecurityGroup, Warnings, error) {
	ccv2SecurityGroups, warnings, err := actor.CloudControllerClient.GetSpaceStagingSecurityGroups(spaceGUID)
	return processSecurityGroups(spaceGUID, ccv2SecurityGroups, Warnings(warnings), err)
}
198506
func layoutContainerCells(containers []api.Container) (names string, images string) {
	var namesBuffer bytes.Buffer
	var imagesBuffer bytes.Buffer

	for i, container := range containers {
		namesBuffer.WriteString(container.Name)
		imagesBuffer.WriteString(container.Image)
		if i != len(containers)-1 {
			namesBuffer.WriteString(",")
			imagesBuffer.WriteString(",")
		}
	}
	return namesBuffer.String(), imagesBuffer.String()
}
1297619
func (r *Docker) StopContainers(ids []string) error {
	if len(ids) == 0 {
		return nil
	}
	glog.Infof("Stopping containers: %s", ids)
	return r.Runner.Run(fmt.Sprintf("docker stop %s", strings.Join(ids, " ")))
}
248346
func (runtime *DockerRuntime) RemoveContainers(containers []string) error {
	errs := []error{}
	for _, container := range containers {
		out, err := runtime.exec.Command("docker", "rm", "--force", "--volumes", container).CombinedOutput()
		if err != nil {
			// don't stop on errors, try to remove as many containers as possible
			errs = append(errs, errors.Wrapf(err, "failed to remove running container %s: output: %s, error", container, string(out)))
		}
	}
	return errorsutil.NewAggregate(errs)
}
485963
func (p *Project) Containers(c *check.C, service string) []types.ContainerJSON {
	containers, err := p.project.Containers(service)
	c.Assert(err, check.IsNil,
		check.Commentf("error while getting the containers for service '%s'", service))
	return containers
}
161143
func (e *environ) Spaces(ctx context.ProviderCallContext) ([]network.SpaceInfo, error) {
	return nil, errors.NotSupportedf("Spaces")
}
145341
func (s *RegisterJobDefinitionInput) SetContainerProperties(v *ContainerProperties) *RegisterJobDefinitionInput {
	s.ContainerProperties = v
	return s
}
58608
func convertSpacesFromConstraints(spaces *[]string) ([]string, []string) {
	if spaces == nil || len(*spaces) == 0 {
		return nil, nil
	}
	return parseDelimitedValues(*spaces)
}
777696
func (ts *Server) GetKeyspaces(ctx context.Context) ([]string, error) {
	children, err := ts.globalCell.ListDir(ctx, KeyspacesPath, false /*full*/)
	switch {
	case err == nil:
		return DirEntriesToStringArray(children), nil
	case IsErrType(err, NoNode):
		return nil, nil
	default:
		return nil, err
	}
}
1269592
func (c *ContainerServer) GetStorageContainer(container string) (*cstorage.Container, error) {
	ociCtr, err := c.LookupContainer(container)
	if err != nil {
		return nil, err
	}
	return c.store.Container(ociCtr.ID())
}
72129
func (s *Server) FilterContainers(prefix string, statuses ...string) ([]Container, error) {
	containers, err := s.GetContainers()
	if err != nil {
		return nil, errors.Trace(err)
	}

	var results []Container
	for _, c := range containers {
		if prefix != "" && !strings.HasPrefix(c.Name, prefix) {
			continue
		}
		if len(statuses) > 0 && !containerHasStatus(c, statuses) {
			continue
		}
		results = append(results, Container{c})
	}
	return results, nil
}
819843
func (client *Client) ShareServiceInstanceToSpaces(serviceInstanceGUID string, spaceGUIDs []string) (RelationshipList, Warnings, error) {
	body, err := json.Marshal(RelationshipList{GUIDs: spaceGUIDs})
	if err != nil {
		return RelationshipList{}, nil, err
	}

	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.PostServiceInstanceRelationshipsSharedSpacesRequest,
		URIParams:   internal.Params{"service_instance_guid": serviceInstanceGUID},
		Body:        bytes.NewReader(body),
	})

	if err != nil {
		return RelationshipList{}, nil, err
	}

	var relationships RelationshipList
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &relationships,
	}

	err = client.connection.Make(request, &response)
	return relationships, response.Warnings, err
}