-
Notifications
You must be signed in to change notification settings - Fork 19
/
security_group_create.go
71 lines (53 loc) · 1.74 KB
/
security_group_create.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
package cmd
import (
"fmt"
"strings"
egoscale "github.com/exoscale/egoscale/v2"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
type securityGroupCreateCmd struct {
cliCommandSettings `cli-cmd:"-"`
_ bool `cli-cmd:"create"`
Name string `cli-arg:"#"`
Description string `cli-usage:"Security Group description"`
}
func (c *securityGroupCreateCmd) cmdAliases() []string { return gCreateAlias }
func (c *securityGroupCreateCmd) cmdShort() string {
return "Create a Security Group"
}
func (c *securityGroupCreateCmd) cmdLong() string {
return fmt.Sprintf(`This command creates a Compute instance Security Group.
Supported output template annotations: %s`,
strings.Join(outputterTemplateAnnotations(&securityGroupShowOutput{}), ", "))
}
func (c *securityGroupCreateCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *securityGroupCreateCmd) cmdRun(_ *cobra.Command, _ []string) error {
zone := gCurrentAccount.DefaultZone
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(gCurrentAccount.Environment, zone))
securityGroup := &egoscale.SecurityGroup{
Description: nonEmptyStringPtr(c.Description),
Name: &c.Name,
}
var err error
decorateAsyncOperation(fmt.Sprintf("Creating Security Group %q...", c.Name), func() {
securityGroup, err = cs.CreateSecurityGroup(ctx, zone, securityGroup)
})
if err != nil {
return err
}
if !gQuiet {
return (&securityGroupShowCmd{
cliCommandSettings: c.cliCommandSettings,
SecurityGroup: *securityGroup.ID,
}).cmdRun(nil, nil)
}
return nil
}
func init() {
cobra.CheckErr(registerCLICommand(securityGroupCmd, &securityGroupCreateCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}