github.com/loafoe/cli@v7.1.0+incompatible/command/v7/create_isolation_segment_command.go (about) 1 package v7 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/actionerror" 5 "code.cloudfoundry.org/cli/actor/v7action" 6 "code.cloudfoundry.org/cli/command/flag" 7 ) 8 9 type CreateIsolationSegmentCommand struct { 10 BaseCommand 11 RequiredArgs flag.IsolationSegmentName `positional-args:"yes"` 12 usage interface{} `usage:"CF_NAME create-isolation-segment SEGMENT_NAME\n\nNOTES:\n The isolation segment name must match the placement tag applied to the Diego cell."` 13 relatedCommands interface{} `related_commands:"enable-org-isolation, isolation-segments"` 14 } 15 16 func (cmd CreateIsolationSegmentCommand) Execute(args []string) error { 17 err := cmd.SharedActor.CheckTarget(false, false) 18 if err != nil { 19 return err 20 } 21 22 user, err := cmd.Config.CurrentUser() 23 if err != nil { 24 return err 25 } 26 27 cmd.UI.DisplayTextWithFlavor("Creating isolation segment {{.SegmentName}} as {{.CurrentUser}}...", map[string]interface{}{ 28 "SegmentName": cmd.RequiredArgs.IsolationSegmentName, 29 "CurrentUser": user.Name, 30 }) 31 32 warnings, err := cmd.Actor.CreateIsolationSegmentByName(v7action.IsolationSegment{ 33 Name: cmd.RequiredArgs.IsolationSegmentName, 34 }) 35 cmd.UI.DisplayWarnings(warnings) 36 if _, ok := err.(actionerror.IsolationSegmentAlreadyExistsError); ok { 37 cmd.UI.DisplayWarning("Isolation segment '{{.IsolationSegmentName}}' already exists.", map[string]interface{}{ 38 "IsolationSegmentName": cmd.RequiredArgs.IsolationSegmentName, 39 }) 40 } else if err != nil { 41 return err 42 } 43 44 cmd.UI.DisplayOK() 45 46 return nil 47 }