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