github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/command/v6/reset_space_isolation_segment_command.go (about) 1 package v6 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/sharedaction" 5 "code.cloudfoundry.org/cli/actor/v2action" 6 "code.cloudfoundry.org/cli/actor/v3action" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 8 "code.cloudfoundry.org/cli/command" 9 "code.cloudfoundry.org/cli/command/flag" 10 "code.cloudfoundry.org/cli/command/v6/shared" 11 ) 12 13 //go:generate counterfeiter . ResetSpaceIsolationSegmentActor 14 15 type ResetSpaceIsolationSegmentActor interface { 16 CloudControllerAPIVersion() string 17 ResetSpaceIsolationSegment(orgGUID string, spaceGUID string) (string, v3action.Warnings, error) 18 } 19 20 //go:generate counterfeiter . ResetSpaceIsolationSegmentActorV2 21 22 type ResetSpaceIsolationSegmentActorV2 interface { 23 GetSpaceByOrganizationAndName(orgGUID string, spaceName string) (v2action.Space, v2action.Warnings, error) 24 } 25 26 type ResetSpaceIsolationSegmentCommand struct { 27 RequiredArgs flag.ResetSpaceIsolationArgs `positional-args:"yes"` 28 usage interface{} `usage:"CF_NAME reset-space-isolation-segment SPACE_NAME"` 29 relatedCommands interface{} `related_commands:"org, restart, space"` 30 31 UI command.UI 32 Config command.Config 33 SharedActor command.SharedActor 34 Actor ResetSpaceIsolationSegmentActor 35 ActorV2 ResetSpaceIsolationSegmentActorV2 36 } 37 38 func (cmd *ResetSpaceIsolationSegmentCommand) Setup(config command.Config, ui command.UI) error { 39 cmd.UI = ui 40 cmd.Config = config 41 cmd.SharedActor = sharedaction.NewActor(config) 42 43 ccClient, _, err := shared.NewV3BasedClients(config, ui, true, "") 44 if err != nil { 45 return err 46 } 47 cmd.Actor = v3action.NewActor(ccClient, config, nil, nil) 48 49 ccClientV2, uaaClientV2, err := shared.NewClients(config, ui, true) 50 if err != nil { 51 return err 52 } 53 cmd.ActorV2 = v2action.NewActor(ccClientV2, uaaClientV2, config) 54 55 return nil 56 } 57 58 func (cmd ResetSpaceIsolationSegmentCommand) Execute(args []string) error { 59 err := command.MinimumCCAPIVersionCheck(cmd.Actor.CloudControllerAPIVersion(), ccversion.MinVersionIsolationSegmentV3) 60 if err != nil { 61 return err 62 } 63 64 err = cmd.SharedActor.CheckTarget(true, false) 65 if err != nil { 66 return err 67 } 68 69 user, err := cmd.Config.CurrentUser() 70 if err != nil { 71 return err 72 } 73 74 cmd.UI.DisplayTextWithFlavor("Resetting isolation segment assignment of space {{.SpaceName}} in org {{.OrgName}} as {{.CurrentUser}}...", map[string]interface{}{ 75 "SpaceName": cmd.RequiredArgs.SpaceName, 76 "OrgName": cmd.Config.TargetedOrganization().Name, 77 "CurrentUser": user.Name, 78 }) 79 80 space, v2Warnings, err := cmd.ActorV2.GetSpaceByOrganizationAndName(cmd.Config.TargetedOrganization().GUID, cmd.RequiredArgs.SpaceName) 81 cmd.UI.DisplayWarnings(v2Warnings) 82 if err != nil { 83 return err 84 } 85 86 newIsolationSegmentName, warnings, err := cmd.Actor.ResetSpaceIsolationSegment(cmd.Config.TargetedOrganization().GUID, space.GUID) 87 cmd.UI.DisplayWarnings(warnings) 88 if err != nil { 89 return err 90 } 91 92 cmd.UI.DisplayOK() 93 cmd.UI.DisplayNewline() 94 95 if newIsolationSegmentName == "" { 96 cmd.UI.DisplayText("Applications in this space will be placed in the platform default isolation segment.") 97 } else { 98 cmd.UI.DisplayText("Applications in this space will be placed in isolation segment {{.orgIsolationSegment}}.", map[string]interface{}{ 99 "orgIsolationSegment": newIsolationSegmentName, 100 }) 101 } 102 cmd.UI.DisplayText("Running applications need a restart to be moved there.") 103 104 return nil 105 }