func (cmd *unbindFromRunningGroup) Run(context *cli.Context) { name := context.Args()[0] securityGroup, err := cmd.securityGroupRepo.Read(name) switch (err).(type) { case nil: case *errors.ModelNotFoundError: cmd.ui.Ok() cmd.ui.Warn(T("Security group {{.security_group}} {{.error_message}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(name), "error_message": terminal.WarningColor(T("does not exist.")), })) return default: cmd.ui.Failed(err.Error()) } cmd.ui.Say(T("Unbinding security group {{.security_group}} from defaults for running as {{.username}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(securityGroup.Name), "username": terminal.EntityNameColor(cmd.configRepo.Username()), })) err = cmd.runningGroupRepo.UnbindFromRunningSet(securityGroup.Guid) if err != nil { cmd.ui.Failed(err.Error()) } cmd.ui.Ok() cmd.ui.Say("\n\n") cmd.ui.Say(T("TIP: Changes will not apply to existing running applications until they are restarted.")) }
func (cmd Authenticate) Metadata() command_metadata.CommandMetadata { return command_metadata.CommandMetadata{ Name: "auth", Description: T("Authenticate user non-interactively"), Usage: T("CF_NAME auth USERNAME PASSWORD\n\n") + terminal.WarningColor(T("WARNING:\n Providing your password as a command line option is highly discouraged\n Your password may be visible to others and may be recorded in your shell history\n\n")) + T("EXAMPLE:\n") + T(" CF_NAME auth [email protected] \"my password\" (use quotes for passwords with a space)\n") + T(" CF_NAME auth [email protected] \"\\\"password\\\"\" (escape quotes if used in password)"), } }
func (cmd *Stop) Run(c *cli.Context) { app := cmd.appReq.GetApplication() if app.State == "stopped" { cmd.ui.Say(terminal.WarningColor(T("App ") + app.Name + T(" is already stopped"))) } else { cmd.ApplicationStop(app, cmd.config.OrganizationFields().Name, cmd.config.SpaceFields().Name) } }
func ColoredAppState(app models.ApplicationFields) string { appState := strings.ToLower(app.State) if app.RunningInstances == 0 { if appState == "stopped" { return appState } else { return terminal.CrashedColor(appState) } } if app.RunningInstances < app.InstanceCount { return terminal.WarningColor(appState) } return appState }
func (cmd *Start) ApplicationStart(app models.Application, orgName, spaceName string) (updatedApp models.Application, err error) { if app.State == "started" { cmd.ui.Say(terminal.WarningColor(T("App ") + app.Name + T(" is already started"))) return } return cmd.ApplicationWatchStaging(app, orgName, spaceName, func(app models.Application) (models.Application, error) { cmd.ui.Say(T("Starting app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.CurrentUser}}...", map[string]interface{}{ "AppName": terminal.EntityNameColor(app.Name), "OrgName": terminal.EntityNameColor(orgName), "SpaceName": terminal.EntityNameColor(spaceName), "CurrentUser": terminal.EntityNameColor(cmd.config.Username())})) state := "STARTED" return cmd.appRepo.Update(app.Guid, models.AppParams{State: &state}) }) }
func ColoredInstanceState(instance models.AppInstanceFields) (colored string) { state := string(instance.State) switch state { case "started", "running": colored = T("running") case "stopped": colored = terminal.StoppedColor(T("stopped")) case "flapping": colored = terminal.CrashedColor(T("crashing")) case "down": colored = terminal.CrashedColor(T("down")) case "starting": colored = terminal.AdvisoryColor(T("starting")) default: colored = terminal.WarningColor(state) } return }
func (cmd CreateSecurityGroup) Run(context *cli.Context) { name := context.Args()[0] pathToJSONFile := context.Args()[1] rules, err := json.ParseJSON(pathToJSONFile) if err != nil { cmd.ui.Failed(T(`Incorrect json format: file: {{.JSONFile}} Valid json file example: [ { "protocol": "tcp", "destination": "10.244.1.18", "ports": "3306" } ]`, map[string]interface{}{"JSONFile": pathToJSONFile})) } cmd.ui.Say(T("Creating security group {{.security_group}} as {{.username}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(name), "username": terminal.EntityNameColor(cmd.configRepo.Username()), })) err = cmd.securityGroupRepo.Create(name, rules) httpErr, ok := err.(errors.HttpError) if ok && httpErr.ErrorCode() == errors.SECURITY_GROUP_EXISTS { cmd.ui.Ok() cmd.ui.Warn(T("Security group {{.security_group}} {{.error_message}}", map[string]interface{}{ "security_group": terminal.EntityNameColor(name), "error_message": terminal.WarningColor(T("already exists")), })) return } if err != nil { cmd.ui.Failed(err.Error()) } cmd.ui.Ok() }
func ColoredAppInstances(app models.ApplicationFields) string { healthString := fmt.Sprintf("%d/%d", app.RunningInstances, app.InstanceCount) if app.RunningInstances < 0 { healthString = fmt.Sprintf("?/%d", app.InstanceCount) } if app.RunningInstances == 0 { if strings.ToLower(app.State) == "stopped" { return healthString } else { return terminal.CrashedColor(healthString) } } if app.RunningInstances < app.InstanceCount { return terminal.WarningColor(healthString) } return healthString }