-
Notifications
You must be signed in to change notification settings - Fork 18
/
firewall_create.go
56 lines (48 loc) · 1.24 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
56
package cmd
import (
"fmt"
"os"
"github.com/exoscale/cli/table"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// createCmd represents the create command
var firewallCreateCmd = &cobra.Command{
Use: "create <name>+",
Short: "Create 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("Create 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)
}