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