-
Notifications
You must be signed in to change notification settings - Fork 20
/
affinitygroup_create.go
48 lines (39 loc) · 1.17 KB
/
affinitygroup_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
package cmd
import (
"os"
"github.com/exoscale/cli/table"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// createCmd represents the create command
var affinitygroupCreateCmd = &cobra.Command{
Use: "create <name>",
Short: "Create affinity group",
Aliases: gCreateAlias,
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
}
return createAffinityGroup(args[0], desc)
},
}
func createAffinityGroup(name, desc string) error {
resp, err := cs.RequestWithContext(gContext, &egoscale.CreateAffinityGroup{Name: name, Description: desc, Type: "host anti-affinity"})
if err != nil {
return err
}
affinityGroup := resp.(*egoscale.AffinityGroup)
table := table.NewTable(os.Stdout)
table.SetHeader([]string{"Name", "Description", "ID"})
table.Append([]string{affinityGroup.Name, affinityGroup.Description, affinityGroup.ID.String()})
table.Render()
return nil
}
func init() {
affinitygroupCreateCmd.Flags().StringP("description", "d", "", "affinity group description")
affinitygroupCmd.AddCommand(affinitygroupCreateCmd)
}