-
Notifications
You must be signed in to change notification settings - Fork 20
/
affinitygroup_create.go
53 lines (43 loc) · 1.18 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
49
50
51
52
53
package cmd
import (
"fmt"
"strings"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
var affinitygroupCreateCmd = &cobra.Command{
Use: "create NAME",
Short: "Create an Anti-Affinity Group",
Long: fmt.Sprintf(`This command creates an Anti-Affinity Group.
Supported output template annotations: %s`,
strings.Join(outputterTemplateAnnotations(&affinityGroupShowOutput{}), ", ")),
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 output(createAffinityGroup(args[0], desc))
},
}
func createAffinityGroup(name, desc string) (outputter, error) {
resp, err := cs.RequestWithContext(gContext, &egoscale.CreateAffinityGroup{
Name: name,
Description: desc,
Type: "host anti-affinity",
})
if err != nil {
return nil, err
}
if !gQuiet {
return showAffinityGroup(resp.(*egoscale.AffinityGroup))
}
return nil, nil
}
func init() {
affinitygroupCreateCmd.Flags().StringP("description", "d", "", "Anti-Affinity Group description")
affinitygroupCmd.AddCommand(affinitygroupCreateCmd)
}