MCPcopy Index your code
hub / github.com/cloudfoundry/cli / CreateServiceInstance

Method CreateServiceInstance

cf/api/services.go:141–167  ·  view source on GitHub ↗
(name, planGUID string, params map[string]interface{}, tags []string)

Source from the content-addressed store, hash-verified

139}
140
141func (repo CloudControllerServiceRepository) CreateServiceInstance(name, planGUID string, params map[string]interface{}, tags []string) (err error) {
142 path := "/v2/service_instances?accepts_incomplete=true"
143 request := models.ServiceInstanceCreateRequest{
144 Name: name,
145 PlanGUID: planGUID,
146 SpaceGUID: repo.config.SpaceFields().GUID,
147 Params: params,
148 Tags: tags,
149 }
150
151 jsonBytes, err := json.Marshal(request)
152 if err != nil {
153 return err
154 }
155
156 err = repo.gateway.CreateResource(repo.config.APIEndpoint(), path, bytes.NewReader(jsonBytes))
157
158 if httpErr, ok := err.(errors.HTTPError); ok && httpErr.ErrorCode() == errors.ServiceInstanceNameTaken {
159 serviceInstance, findInstanceErr := repo.FindInstanceByName(name)
160
161 if findInstanceErr == nil && serviceInstance.ServicePlan.GUID == planGUID {
162 return errors.NewModelAlreadyExistsError("Service", name)
163 }
164 }
165
166 return
167}
168
169func (repo CloudControllerServiceRepository) UpdateServiceInstance(instanceGUID, planGUID string, params map[string]interface{}, tags *[]string) (err error) {
170 path := fmt.Sprintf("/v2/service_instances/%s?accepts_incomplete=true", instanceGUID)

Callers

nothing calls this directly

Calls 6

FindInstanceByNameMethod · 0.95
CreateResourceMethod · 0.80
SpaceFieldsMethod · 0.65
APIEndpointMethod · 0.65
ErrorCodeMethod · 0.65

Tested by

no test coverage detected