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