// ConvertSpaceToModel converts an `app.Space` to a `space.Space`
16425
func ConvertSpaceToModel(appSpace app.Space) space.Space {
	modelSpace := space.Space{}

	if appSpace.ID != nil {
		modelSpace.ID = *appSpace.ID
	}
	if appSpace.Attributes != nil {
		if appSpace.Attributes.CreatedAt != nil {
			modelSpace.CreatedAt = *appSpace.Attributes.CreatedAt
		}
		if appSpace.Attributes.UpdatedAt != nil {
			modelSpace.UpdatedAt = *appSpace.Attributes.UpdatedAt
		}
		if appSpace.Attributes.Version != nil {
			modelSpace.Version = *appSpace.Attributes.Version
		}
		if appSpace.Attributes.Name != nil {
			modelSpace.Name = *appSpace.Attributes.Name
		}
		if appSpace.Attributes.Description != nil {
			modelSpace.Description = *appSpace.Attributes.Description
		}
	}
	if appSpace.Relationships != nil && appSpace.Relationships.OwnedBy != nil &&
		appSpace.Relationships.OwnedBy.Data != nil && appSpace.Relationships.OwnedBy.Data.ID != nil {
		modelSpace.OwnerID = *appSpace.Relationships.OwnedBy.Data.ID
	}
	if appSpace.Relationships != nil && appSpace.Relationships.SpaceTemplate != nil &&
		appSpace.Relationships.SpaceTemplate.Data != nil {
		modelSpace.SpaceTemplateID = appSpace.Relationships.SpaceTemplate.Data.ID
	}
	return modelSpace
}
106533
func Convert_v1_DaemonSetList_To_apps_DaemonSetList(in *v1.DaemonSetList, out *apps.DaemonSetList, s conversion.Scope) error {
	return autoConvert_v1_DaemonSetList_To_apps_DaemonSetList(in, out, s)
}
37960
func (v Volumes) MarshalYAML() (interface{}, error) {
	vs := []string{}
	for _, volume := range v.Volumes {
		vs = append(vs, volume.String())
	}
	return vs, nil
}
504568
func (p *Plan) GetSpace() int {
	if p == nil || p.Space == nil {
		return 0
	}
	return *p.Space
}
598520
func convertLabels(newLabels []mesosAgent.KeyValue) map[string]string {
	result := map[string]string{}
	for _, l := range newLabels {
		// Remove blacklisted cosmos labels
		if _, inSlice := cosmosLabels[l.Key]; inSlice {
			continue
		}
		result[l.Key] = l.Value
	}

	return result
}
1274589
func (api *spacesAPI) CreateSpaces(args params.CreateSpacesParams) (results params.ErrorResults, err error) {
	isAdmin, err := api.authorizer.HasPermission(permission.AdminAccess, api.backing.ModelTag())
	if err != nil && !errors.IsNotFound(err) {
		return results, errors.Trace(err)
	}
	if !isAdmin {
		return results, common.ServerError(common.ErrPerm)
	}

	return networkingcommon.CreateSpaces(api.backing, api.context, args)
}
781206
func ConvertCodebase(request *http.Request, codebase codebase.Codebase, options ...CodebaseConvertFunc) *app.Codebase {
	relatedURL := rest.AbsoluteURL(request, app.CodebaseHref(codebase.ID))
	spaceRelatedURL := rest.AbsoluteURL(request, app.SpaceHref(codebase.SpaceID))
	workspacesRelatedURL := rest.AbsoluteURL(request, app.CodebaseHref(codebase.ID)+"/workspaces")

	result := &app.Codebase{
		Type: APIStringTypeCodebase,
		ID:   &codebase.ID,
		Attributes: &app.CodebaseAttributes{
			CreatedAt:         &codebase.CreatedAt,
			Type:              &codebase.Type,
			URL:               &codebase.URL,
			StackID:           codebase.StackID,
			LastUsedWorkspace: &codebase.LastUsedWorkspace,
			CveScan:           &codebase.CVEScan,
		},
		Relationships: &app.CodebaseRelations{
			Space: &app.RelationGeneric{
				Data: &app.GenericData{
					Type: ptr.String(APIStringTypeSpace),
					ID:   ptr.String(codebase.SpaceID.String()),
				},
				Links: &app.GenericLinks{
					Self:    &spaceRelatedURL,
					Related: &spaceRelatedURL,
				},
			},
			Workspaces: &app.RelationGeneric{
				Links: &app.GenericLinks{
					Self:    &workspacesRelatedURL,
					Related: &workspacesRelatedURL,
				},
			},
		},
		Links: &app.CodebaseLinks{
			Self:    &relatedURL,
			Related: &relatedURL,
			// Deprecated: use 'Workspaces' links instead
			Edit: ptr.String(rest.AbsoluteURL(request, app.CodebaseHref(codebase.ID)+"/edit")),
		},
	}
	for _, option := range options {
		option(request, codebase, result)
	}
	return result
}
852509
func CreateSpaces(backing NetworkBacking, ctx context.ProviderCallContext, args params.CreateSpacesParams) (results params.ErrorResults, err error) {
	err = SupportsSpaces(backing, ctx)
	if err != nil {
		return results, common.ServerError(errors.Trace(err))
	}

	results.Results = make([]params.ErrorResult, len(args.Spaces))

	for i, space := range args.Spaces {
		err := createOneSpace(backing, space)
		if err == nil {
			continue
		}
		results.Results[i].Error = common.ServerError(errors.Trace(err))
	}

	return results, nil
}
632941
func (s *RemoteApplication) Spaces() []RemoteSpace {
	var result []RemoteSpace
	for _, space := range s.doc.Spaces {
		result = append(result, remoteSpaceFromDoc(space))
	}
	return result
}
259449
func (env *maasEnviron) Spaces(ctx context.ProviderCallContext) ([]network.SpaceInfo, error) {
	if !env.usingMAAS2() {
		return env.spaces1(ctx)
	}
	return env.spaces2(ctx)
}
58608
func convertSpacesFromConstraints(spaces *[]string) ([]string, []string) {
	if spaces == nil || len(*spaces) == 0 {
		return nil, nil
	}
	return parseDelimitedValues(*spaces)
}
1081762
func ConvertGoLayoutToUnicode(layout string) string {
	// Year
	layout = strings.Replace(layout, "20", "yy", -1)
	layout = strings.Replace(layout, "06", "yy", -1)

	// Month
	layout = strings.Replace(layout, "January", "MMMM", -1)
	layout = strings.Replace(layout, "Jan", "MMM", -1)
	layout = strings.Replace(layout, "01", "MM", -1)
	layout = strings.Replace(layout, "1", "M", -1)

	// Day
	layout = strings.Replace(layout, "02", "dd", -1)
	layout = strings.Replace(layout, "_2", "d", -1)

	// Weekday
	layout = strings.Replace(layout, "Mon", "EEE", -1)
	layout = strings.Replace(layout, "Monday", "EEEE", -1)

	// Hour
	layout = strings.Replace(layout, "03", "hh", -1)
	layout = strings.Replace(layout, "3", "h", -1)
	layout = strings.Replace(layout, "15", "HH", -1)
	layout = strings.Replace(layout, "PM", "a", -1)

	// Minute
	layout = strings.Replace(layout, "04", "mm", -1)

	// Second
	layout = strings.Replace(layout, "05", "ss", -1)

	// Timezone
	layout = strings.Replace(layout, "MST", "zzz", -1)
	layout = strings.Replace(layout, "-0700", "ZZZ", -1)
	layout = strings.Replace(layout, "GMT-07:00", "ZZZZ", -1)

	return layout
}
925243
func (e *OracleEnviron) buildSpacesMap(ctx context.ProviderCallContext) (map[string]network.SpaceInfo, map[string]string, error) {
	empty := set.Strings{}
	providerIdMap := map[string]string{}
	// NOTE (gsamfira): This seems brittle to me, and I would much rather get this
	// from state, as that information should already be there from the discovered spaces
	// and that is the information that gets presented to the user when running:
	// juju spaces
	// However I have not found a clean way to access that info from the provider,
	// without creating a facade. Someone with more knowledge on this might be able to chip in.
	spaces, err := e.Spaces(ctx)
	if err != nil {
		return nil, providerIdMap, errors.Trace(err)
	}
	spaceMap := make(map[string]network.SpaceInfo)
	for _, space := range spaces {
		jujuName := network.ConvertSpaceName(space.Name, empty)
		spaceMap[jujuName] = space
		empty.Add(jujuName)
		providerIdMap[string(space.ProviderId)] = space.Name
	}
	return spaceMap, providerIdMap, nil

}
971882
func (api *spacesAPI) ReloadSpaces() error {
	canWrite, err := api.authorizer.HasPermission(permission.WriteAccess, api.backing.ModelTag())
	if err != nil && !errors.IsNotFound(err) {
		return errors.Trace(err)
	}
	if !canWrite {
		return common.ServerError(common.ErrPerm)
	}
	env, err := environs.GetEnviron(api.backing, environs.New)
	if err != nil {
		return errors.Trace(err)
	}
	return errors.Trace(api.backing.ReloadSpaces(env))
}
221657
func (api *API) ReloadSpaces() error {
	if api.facade.BestAPIVersion() < 3 {
		return errors.NewNotSupported(nil, "Controller does not support reloading spaces")
	}
	err := api.facade.FacadeCall("ReloadSpaces", nil, nil)
	if params.IsCodeNotSupported(err) {
		return errors.NewNotSupported(nil, err.Error())
	}
	return err
}
237118
func ConvertNamespaceFromExternal(namespace *corev1.Namespace) *projectapi.Project {
	internalFinalizers := []kapi.FinalizerName{}
	for _, externalFinalizer := range namespace.Spec.Finalizers {
		internalFinalizers = append(internalFinalizers, kapi.FinalizerName(externalFinalizer))
	}

	return &projectapi.Project{
		ObjectMeta: namespace.ObjectMeta,
		Spec: projectapi.ProjectSpec{
			Finalizers: internalFinalizers,
		},
		Status: projectapi.ProjectStatus{
			Phase: kapi.NamespacePhase(namespace.Status.Phase),
		},
	}
}
827547
func (st *State) Space(name string) (*Space, error) {
	spaces, closer := st.db().GetCollection(spacesC)
	defer closer()

	var doc spaceDoc
	err := spaces.FindId(name).One(&doc)
	if err == mgo.ErrNotFound {
		return nil, errors.NotFoundf("space %q", name)
	}
	if err != nil {
		return nil, errors.Annotatef(err, "cannot get space %q", name)
	}
	return &Space{st, doc}, nil
}