// NewSpaceUsage returns a new SpaceUsage instance
351653
func NewSpaceUsage(Used uint64, Allocation *SpaceAllocation) *SpaceUsage {
	s := new(SpaceUsage)
	s.Used = Used
	s.Allocation = Allocation
	return s
}
52939
func NewSpaceController(service *goa.Service, app application.Application) *SpaceController {
	return &SpaceController{Controller: service.NewController("SpaceController"), app: app}
}
908083
func NewSpaceTrackerQueriesController(service *goa.Service, db application.DB, config SpaceTrackerQueriesControllerConfig) *SpaceTrackerQueriesController {
	return &SpaceTrackerQueriesController{
		Controller: service.NewController("SpaceTrackerQueriesController"),
		db:         db,
		config:     config,
	}
}
1179701
func (f *GoFlags) AddExtraUsage(eu string) {
	f.UsageMsgs = append(f.UsageMsgs, eu)
}
277530
func (s *Service) SpaceInfo(ctx context.Context, spaceIdentity string) (*Space, error) {
	var space Space
	return &space, s.Get(ctx, &space, fmt.Sprintf("/spaces/%v", spaceIdentity), nil, nil)
}
834018
func NewNamespace(NamespaceName node.Node, Stmts []node.Node) *Namespace {
	return &Namespace{
		FreeFloating:  nil,
		NamespaceName: NamespaceName,
		Stmts:         Stmts,
	}
}
381249
func (s *spaceService) DeleteSpace(ctx context.Context, byIdentityID uuid.UUID, spaceID string) error {

	err := s.ExecuteInTransaction(func() error {
		// Check if the space exists first to make sure we return NotFoundError if it doesn't instead of Forbidden when checking permissions
		err := s.Repositories().ResourceRepository().CheckExists(ctx, spaceID)
		if err != nil {
			return err
		}
		err = s.Services().PermissionService().RequireScope(ctx, byIdentityID, spaceID, authorization.DeleteSpaceScope)
		if err != nil {
			return err
		}
		return s.Services().ResourceService().Delete(ctx, spaceID)
	})

	return err
}
762821
func (st *State) AddSpace(name string, providerId network.Id, subnets []string, isPublic bool) (newSpace *Space, err error) {
	defer errors.DeferredAnnotatef(&err, "adding space %q", name)
	if !names.IsValidSpace(name) {
		return nil, errors.NewNotValid(nil, "invalid space name")
	}

	spaceDoc := spaceDoc{
		Life:       Alive,
		Name:       name,
		IsPublic:   isPublic,
		ProviderId: string(providerId),
	}
	newSpace = &Space{doc: spaceDoc, st: st}

	ops := []txn.Op{{
		C:      spacesC,
		Id:     name,
		Assert: txn.DocMissing,
		Insert: spaceDoc,
	}}

	if providerId != "" {
		ops = append(ops, st.networkEntityGlobalKeyOp("space", providerId))
	}

	for _, subnetId := range subnets {
		// TODO:(mfoord) once we have refcounting for subnets we should
		// also assert that the refcount is zero as moving the space of a
		// subnet in use is not permitted.
		ops = append(ops, txn.Op{
			C:      subnetsC,
			Id:     subnetId,
			Assert: bson.D{bson.DocElem{"fan-local-underlay", bson.D{{"$exists", false}}}},
			Update: bson.D{{"$set", bson.D{{"space-name", name}}}},
		})
	}

	if err := st.db().RunTransaction(ops); err == txn.ErrAborted {
		if _, err := st.Space(name); err == nil {
			return nil, errors.AlreadyExistsf("space %q", name)
		}
		for _, subnetId := range subnets {
			subnet, err := st.Subnet(subnetId)
			if errors.IsNotFound(err) {
				return nil, err
			}
			if subnet.FanLocalUnderlay() != "" {
				return nil, errors.Errorf("Can't set space for FAN subnet %q - it's always inherited from underlay", subnet.CIDR())
			}
		}
		if err := newSpace.Refresh(); err != nil {
			if errors.IsNotFound(err) {
				return nil, errors.Errorf("ProviderId %q not unique", providerId)
			}
			return nil, errors.Trace(err)
		}
		return nil, errors.Trace(err)
	} else if err != nil {
		return nil, err
	}
	return newSpace, nil
}
648107
func (client *Client) CreateSpace(spaceName string, orgGUID string) (Space, Warnings, error) {
	requestBody := createSpaceRequestBody{
		Name:             spaceName,
		OrganizationGUID: orgGUID,
	}

	bodyBytes, _ := json.Marshal(requestBody)

	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.PostSpaceRequest,
		Body:        bytes.NewReader(bodyBytes),
	})

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

	var space Space
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &space,
	}

	err = client.connection.Make(request, &response)

	return space, response.Warnings, err
}
169195
func newServiceAccounts(c *Client, ns string) ServiceAccountsInterface {
	return &serviceAccounts{
		client:    c,
		namespace: ns,
	}
}
552475
func NewService(gitFactory git.ClientFactory, cache *cache.Cache, parallelismLimit int64) *Service {
	var parallelismLimitSemaphore *semaphore.Weighted
	if parallelismLimit > 0 {
		parallelismLimitSemaphore = semaphore.NewWeighted(parallelismLimit)
	}
	return &Service{
		parallelismLimitSemaphore: parallelismLimitSemaphore,

		repoLock:   util.NewKeyLock(),
		gitFactory: gitFactory,
		cache:      cache,
	}
}
225500
func (c *ServiceAccountsController) namespaceUpdated(oldObj interface{}, newObj interface{}) {
	newNamespace := newObj.(*v1.Namespace)
	c.queue.Add(newNamespace.Name)
}
1160665
func NewService(config Config, publisher events.Publisher) (*Service, error) {
	if config.Namespace == "" {
		return nil, fmt.Errorf("shim namespace cannot be empty")
	}
	ctx := namespaces.WithNamespace(context.Background(), config.Namespace)
	ctx = log.WithLogger(ctx, logrus.WithFields(logrus.Fields{
		"namespace": config.Namespace,
		"path":      config.Path,
		"pid":       os.Getpid(),
	}))
	s := &Service{
		config:    config,
		context:   ctx,
		processes: make(map[string]rproc.Process),
		events:    make(chan interface{}, 128),
		ec:        Default.Subscribe(),
	}
	go s.processExits()
	if err := s.initPlatform(); err != nil {
		return nil, errors.Wrap(err, "failed to initialized platform behavior")
	}
	go s.forward(publisher)
	return s, nil
}
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)
}
1224410
func (i *Info) Namespaced() bool {
	return i.Mapping != nil && i.Mapping.Scope.Name() == meta.RESTScopeNameNamespace
}
230138
func (config *Config) SetSpaceInformation(guid string, name string, allowSSH bool) {
	config.V7SetSpaceInformation(guid, name)
	config.ConfigFile.TargetedSpace.AllowSSH = allowSSH
}
239666
func NewUsage(client docker.Client, config *api.Config) (*Usage, error) {
	b, err := New(client, config, fs.NewFileSystem(), build.Overrides{})
	if err != nil {
		return nil, err
	}
	usage := Usage{
		handler: b,
		config:  config,
		garbage: b.garbage,
	}
	return &usage, nil
}