forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_org_default_isolation_segment_command.go
54 lines (43 loc) · 1.57 KB
/
set_org_default_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
package v7
import (
"code.cloudfoundry.org/cli/command/flag"
)
type SetOrgDefaultIsolationSegmentCommand struct {
BaseCommand
RequiredArgs flag.OrgIsolationArgs `positional-args:"yes"`
usage interface{} `usage:"CF_NAME set-org-default-isolation-segment ORG_NAME SEGMENT_NAME"`
relatedCommands interface{} `related_commands:"org, set-space-isolation-segment"`
}
func (cmd SetOrgDefaultIsolationSegmentCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(false, false)
if err != nil {
return err
}
user, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
cmd.UI.DisplayTextWithFlavor("Setting isolation segment {{.IsolationSegmentName}} to default on org {{.OrgName}} as {{.CurrentUser}}...", map[string]interface{}{
"IsolationSegmentName": cmd.RequiredArgs.IsolationSegmentName,
"OrgName": cmd.RequiredArgs.OrganizationName,
"CurrentUser": user.Name,
})
org, warnings, err := cmd.Actor.GetOrganizationByName(cmd.RequiredArgs.OrganizationName)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
isoSeg, warnings, err := cmd.Actor.GetIsolationSegmentByName(cmd.RequiredArgs.IsolationSegmentName)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
warnings, err = cmd.Actor.SetOrganizationDefaultIsolationSegment(org.GUID, isoSeg.GUID)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
cmd.UI.DisplayOK()
cmd.UI.DisplayText("TIP: Restart applications in this organization to relocate them to this isolation segment.")
return nil
}