// Update a space.
//
// Librato API docs: http://dev.librato.com/v1/put/spaces/:id
161312
func (s *SpacesService) Update(spaceID uint, space *Space) (*http.Response, error) {
	u := fmt.Sprintf("spaces/%d", spaceID)
	req, err := s.client.NewRequest("PUT", u, space)
	if err != nil {
		return nil, err
	}

	return s.client.Do(req, nil)
}
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
}
229886
func Librato(email, token, source string, r *Registry, d time.Duration) {
	for now := range time.Tick(d) {
		b := batch{
			Source:      source,
			Gauges:      []map[string]interface{}{},
			MeasureTime: now.Unix(),
		}
		for k, m := range r.Instruments() {
			var s int64
			switch i := m.(type) {
			case instruments.Discrete:
				s = i.Snapshot()
			case instruments.Sample:
				s = instruments.Quantile(i.Snapshot(), 0.95)
			}
			b.Gauges = append(b.Gauges, map[string]interface{}{
				"name":   k,
				"value":  float64(s),
				"period": d.Seconds(),
			})
		}
		b.Post(email, token)
	}
}
708270
func (wr *Wrangler) UpdateSrvKeyspacePartitions(ctx context.Context, keyspace, shard string, tabletType topodatapb.TabletType, cells []string, remove bool) (err error) {
	// lock the keyspace
	ctx, unlock, lockErr := wr.ts.LockKeyspace(ctx, keyspace, "UpdateSrvKeyspacePartitions")
	if lockErr != nil {
		return lockErr
	}
	defer unlock(&err)

	si, err := wr.ts.GetShard(ctx, keyspace, shard)
	if err != nil {
		return err
	}

	if remove {
		return wr.ts.DeleteSrvKeyspacePartitions(ctx, keyspace, []*topo.ShardInfo{si}, tabletType, cells)
	}
	return wr.ts.AddSrvKeyspacePartitions(ctx, keyspace, []*topo.ShardInfo{si}, tabletType, cells)
}
858084
func (c *Client) Update(namespace string, originalReader, targetReader io.Reader, force bool, recreate bool, timeout int64, shouldWait bool) error {
	return c.UpdateWithOptions(namespace, originalReader, targetReader, UpdateOptions{
		Force:      force,
		Recreate:   recreate,
		Timeout:    timeout,
		ShouldWait: shouldWait,
	})
}
502338
func (s *ServicesService) Update(serviceID uint, service *Service) (*http.Response, error) {
	u := fmt.Sprintf("services/%d", serviceID)
	req, err := s.client.NewRequest("PUT", u, service)
	if err != nil {
		return nil, err
	}

	return s.client.Do(req, nil)
}
259449
func (env *maasEnviron) Spaces(ctx context.ProviderCallContext) ([]network.SpaceInfo, error) {
	if !env.usingMAAS2() {
		return env.spaces1(ctx)
	}
	return env.spaces2(ctx)
}
168734
func (actor Actor) SetSpaceQuota(spaceGUID, quotaGUID string) (Warnings, error) {
	warnings, err := actor.CloudControllerClient.SetSpaceQuota(spaceGUID, quotaGUID)
	return Warnings(warnings), err
}
1192204
func (cmd *TargetCommand) setSpace() error {
	if !cmd.Config.HasTargetedOrganization() {
		return translatableerror.NoOrganizationTargetedError{BinaryName: cmd.Config.BinaryName()}
	}

	space, warnings, err := cmd.Actor.GetSpaceByOrganizationAndName(cmd.Config.TargetedOrganization().GUID, cmd.Space)
	cmd.UI.DisplayWarnings(warnings)
	if err != nil {
		return err
	}

	cmd.Config.SetSpaceInformation(space.GUID, space.Name, space.AllowSSH)

	return nil
}
149087
func (d *Decoder) space() {
	for {
		b, ok := d.getc()
		if !ok {
			return
		}
		switch b {
		case ' ', '\r', '\n', '\t':
		default:
			d.ungetc(b)
			return
		}
	}
}
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
}
1070094
func (client *Client) GetSpaceSummary(spaceGUID string) (SpaceSummary, Warnings, error) {
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.GetSpaceSummaryRequest,
		URIParams:   Params{"space_guid": spaceGUID},
	})
	if err != nil {
		return SpaceSummary{}, nil, err
	}

	var spaceSummary SpaceSummary
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &spaceSummary,
	}

	err = client.connection.Make(request, &response)
	return spaceSummary, response.Warnings, err
}
1369885
func (s *witServiceImpl) GetSpace(ctx context.Context, spaceID string) (space *wit.Space, e error) {
	remoteWITService, err := s.createClientWithContextSigner(ctx)
	if err != nil {
		return nil, err
	}

	spaceIDUUID, err := uuid.FromString(spaceID)
	if err != nil {
		return nil, err
	}

	res, err := remoteWITService.ShowSpace(ctx, witservice.ShowSpacePath(spaceIDUUID), nil, nil)
	if err != nil {
		return nil, err
	}

	defer rest.CloseResponse(res)
	if res.StatusCode != http.StatusOK {
		bodyString := rest.ReadBody(res.Body)
		log.Error(ctx, map[string]interface{}{
			"spaceId":         spaceID,
			"response_status": res.Status,
			"response_body":   bodyString,
		}, "unable to get space from WIT")
		return nil, errors.Errorf("unable to get space from WIT. Response status: %s. Response body: %s", res.Status, bodyString)
	}

	spaceSingle, err := remoteWITService.DecodeSpaceSingle(res)
	if err != nil {
		return nil, err
	}

	return &wit.Space{
		ID:          *spaceSingle.Data.ID,
		Name:        *spaceSingle.Data.Attributes.Name,
		Description: *spaceSingle.Data.Attributes.Description,
		OwnerID:     *spaceSingle.Data.Relationships.OwnedBy.Data.ID}, nil
}
246033
func (c *ciliumEndpoints) Update(ciliumEndpoint *v2.CiliumEndpoint) (result *v2.CiliumEndpoint, err error) {
	result = &v2.CiliumEndpoint{}
	err = c.client.Put().
		Namespace(c.ns).
		Resource("ciliumendpoints").
		Name(ciliumEndpoint.Name).
		Body(ciliumEndpoint).
		Do().
		Into(result)
	return
}
192809
func (aSpace *addrSpace) Key() []string {
	aSpace.Lock()
	defer aSpace.Unlock()
	return []string{aSpace.id}
}
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
}
293970
func (c CountUnit) Space(s SpaceUnit, dimension int8) MetricUnit {
	return (&metricUnit{uint32(c)}).Space(s, dimension)
}