-
Notifications
You must be signed in to change notification settings - Fork 20
/
firewall_create.go
55 lines (47 loc) · 1.2 KB
/
firewall_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
package cmd
import (
"fmt"
"os"
"github.com/exoscale/cli/table"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
var firewallCreateCmd = &cobra.Command{
Use: "create NAME",
Short: "Create a Security Group",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
desc, err := cmd.Flags().GetString("description")
if err != nil {
return err
}
syncTasks := []task{}
for _, arg := range args {
syncTasks = append(syncTasks, task{
egoscale.CreateSecurityGroup{Name: arg, Description: desc},
fmt.Sprintf("Creating Security Group %q", arg),
})
}
taskResponses := asyncTasks(syncTasks)
errors := filterErrors(taskResponses)
if len(errors) > 0 {
return errors[0]
}
if !gQuiet {
table := table.NewTable(os.Stdout)
table.SetHeader([]string{"ID", "Name", "Description"})
for _, resp := range taskResponses {
r := resp.resp.(*egoscale.SecurityGroup)
table.Append([]string{r.ID.String(), r.Name, r.Description})
}
table.Render()
}
return nil
},
}
func init() {
firewallCreateCmd.Flags().StringP("description", "d", "", "Security Group description")
firewallCmd.AddCommand(firewallCreateCmd)
}