github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/command/v6/reset_org_default_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 . ResetOrgDefaultIsolationSegmentActor 14 15 type ResetOrgDefaultIsolationSegmentActor interface { 16 CloudControllerAPIVersion() string 17 ResetOrganizationDefaultIsolationSegment(orgGUID string) (v3action.Warnings, error) 18 } 19 20 //go:generate counterfeiter . ResetOrgDefaultIsolationSegmentActorV2 21 22 type ResetOrgDefaultIsolationSegmentActorV2 interface { 23 GetOrganizationByName(orgName string) (v2action.Organization, v2action.Warnings, error) 24 } 25 26 type ResetOrgDefaultIsolationSegmentCommand struct { 27 RequiredArgs flag.ResetOrgDefaultIsolationArgs `positional-args:"yes"` 28 usage interface{} `usage:"CF_NAME reset-org-default-isolation-segment ORG_NAME"` 29 relatedCommands interface{} `related_commands:"org, restart"` 30 31 UI command.UI 32 Config command.Config 33 SharedActor command.SharedActor 34 Actor ResetOrgDefaultIsolationSegmentActor 35 ActorV2 ResetOrgDefaultIsolationSegmentActorV2 36 } 37 38 func (cmd *ResetOrgDefaultIsolationSegmentCommand) Setup(config command.Config, ui command.UI) error { 39 cmd.UI = ui 40 cmd.Config = config 41 cmd.SharedActor = sharedaction.NewActor(config) 42 43 client, _, err := shared.NewV3BasedClients(config, ui, true, "") 44 if err != nil { 45 return err 46 } 47 cmd.Actor = v3action.NewActor(client, 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 ResetOrgDefaultIsolationSegmentCommand) 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 default isolation segment of org {{.OrgName}} as {{.CurrentUser}}...", map[string]interface{}{ 75 "OrgName": cmd.RequiredArgs.OrgName, 76 "CurrentUser": user.Name, 77 }) 78 79 organization, v2Warnings, err := cmd.ActorV2.GetOrganizationByName(cmd.RequiredArgs.OrgName) 80 cmd.UI.DisplayWarnings(v2Warnings) 81 if err != nil { 82 return err 83 } 84 85 warnings, err := cmd.Actor.ResetOrganizationDefaultIsolationSegment(organization.GUID) 86 cmd.UI.DisplayWarnings(warnings) 87 if err != nil { 88 return err 89 } 90 91 cmd.UI.DisplayOK() 92 cmd.UI.DisplayNewline() 93 94 cmd.UI.DisplayText("Applications in spaces of this org that have no isolation segment assigned will be placed in the platform default isolation segment.") 95 cmd.UI.DisplayText("Running applications need a restart to be moved there.") 96 97 return nil 98 }