github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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 "code.cloudfoundry.org/clock" 12 ) 13 14 //go:generate counterfeiter . ResetSpaceIsolationSegmentActor 15 16 type ResetSpaceIsolationSegmentActor interface { 17 ResetSpaceIsolationSegment(orgGUID string, spaceGUID string) (string, v7action.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.GetNewClientsAndConnectToCF(config, ui, "") 44 if err != nil { 45 return err 46 } 47 cmd.Actor = v7action.NewActor(ccClient, config, nil, nil, clock.NewClock()) 48 49 ccClientV2, uaaClientV2, err := sharedV2.GetNewClientsAndConnectToCF(config, ui) 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 := cmd.SharedActor.CheckTarget(true, false) 60 if err != nil { 61 return err 62 } 63 64 user, err := cmd.Config.CurrentUser() 65 if err != nil { 66 return err 67 } 68 69 cmd.UI.DisplayTextWithFlavor("Resetting isolation segment assignment of space {{.SpaceName}} in org {{.OrgName}} as {{.CurrentUser}}...", map[string]interface{}{ 70 "SpaceName": cmd.RequiredArgs.SpaceName, 71 "OrgName": cmd.Config.TargetedOrganization().Name, 72 "CurrentUser": user.Name, 73 }) 74 75 space, v2Warnings, err := cmd.ActorV2.GetSpaceByOrganizationAndName(cmd.Config.TargetedOrganization().GUID, cmd.RequiredArgs.SpaceName) 76 cmd.UI.DisplayWarnings(v2Warnings) 77 if err != nil { 78 return err 79 } 80 81 newIsolationSegmentName, warnings, err := cmd.Actor.ResetSpaceIsolationSegment(cmd.Config.TargetedOrganization().GUID, space.GUID) 82 cmd.UI.DisplayWarnings(warnings) 83 if err != nil { 84 return err 85 } 86 87 cmd.UI.DisplayOK() 88 89 if newIsolationSegmentName == "" { 90 cmd.UI.DisplayText("Applications in this space will be placed in the platform default isolation segment.") 91 } else { 92 cmd.UI.DisplayText("Applications in this space will be placed in isolation segment {{.orgIsolationSegment}}.", map[string]interface{}{ 93 "orgIsolationSegment": newIsolationSegmentName, 94 }) 95 } 96 cmd.UI.DisplayText("Running applications need a restart to be moved there.") 97 98 return nil 99 }