func (cmd *CreateService) Execute(c flags.FlagContext) { serviceName := c.Args()[0] planName := c.Args()[1] serviceInstanceName := c.Args()[2] params := c.String("c") tags := c.String("t") tagsList := ui_helpers.ParseTags(tags) paramsMap, err := json.ParseJsonFromFileOrString(params) if err != nil { cmd.ui.Failed(T("Invalid configuration provided for -c flag. Please provide a valid JSON object or path to a file containing a valid JSON object.")) } cmd.ui.Say(T("Creating service instance {{.ServiceName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", map[string]interface{}{ "ServiceName": terminal.EntityNameColor(serviceInstanceName), "OrgName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), "CurrentUser": terminal.EntityNameColor(cmd.config.Username()), })) plan, err := cmd.CreateService(serviceName, planName, serviceInstanceName, paramsMap, tagsList) switch err.(type) { case nil: err := printSuccessMessageForServiceInstance(serviceInstanceName, cmd.serviceRepo, cmd.ui) if err != nil { cmd.ui.Failed(err.Error()) } if !plan.Free { cmd.ui.Say("") cmd.ui.Say(T("Attention: The plan `{{.PlanName}}` of service `{{.ServiceName}}` is not free. The instance `{{.ServiceInstanceName}}` will incur a cost. Contact your administrator if you think this is in error.", map[string]interface{}{ "PlanName": terminal.EntityNameColor(plan.Name), "ServiceName": terminal.EntityNameColor(serviceName), "ServiceInstanceName": terminal.EntityNameColor(serviceInstanceName), })) cmd.ui.Say("") } case *errors.ModelAlreadyExistsError: cmd.ui.Ok() cmd.ui.Warn(err.Error()) default: cmd.ui.Failed(err.Error()) } }
func (cmd *UpdateService) Run(c *cli.Context) { planName := c.String("p") params := c.String("c") tagsSet := c.IsSet("t") tagsList := c.String("t") if planName == "" && params == "" && tagsSet == false { cmd.ui.Ok() cmd.ui.Say(T("No changes were made")) return } serviceInstanceName := c.Args()[0] serviceInstance, err := cmd.serviceRepo.FindInstanceByName(serviceInstanceName) if err != nil { cmd.ui.Failed(err.Error()) } paramsMap, err := json.ParseJsonFromFileOrString(params) if err != nil { cmd.ui.Failed(T("Invalid configuration provided for -c flag. Please provide a valid JSON object or path to a file containing a valid JSON object.")) } tags := ui_helpers.ParseTags(tagsList) var plan models.ServicePlanFields if planName != "" { cmd.checkUpdateServicePlanApiVersion() err, plan = cmd.findPlan(serviceInstance, planName) if err != nil { cmd.ui.Failed(err.Error()) } } cmd.printUpdatingServiceInstanceMessage(serviceInstanceName) err = cmd.serviceRepo.UpdateServiceInstance(serviceInstance.Guid, plan.Guid, paramsMap, tags) if err != nil { cmd.ui.Failed(err.Error()) } err = printSuccessMessageForServiceInstance(serviceInstanceName, cmd.serviceRepo, cmd.ui) if err != nil { cmd.ui.Failed(err.Error()) } }