-
Notifications
You must be signed in to change notification settings - Fork 19
/
affinitygroup.go
48 lines (38 loc) · 992 Bytes
/
affinitygroup.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 (
"fmt"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// affinitygroupCmd represents the affinitygroup command
var affinitygroupCmd = &cobra.Command{
Use: "affinitygroup",
Short: "Affinity groups management",
}
func getAffinityGroupByName(name string) (*egoscale.AffinityGroup, error) {
aff := &egoscale.AffinityGroup{}
id, err := egoscale.ParseUUID(name)
if err == nil {
aff.ID = id
} else {
aff.Name = name
}
resp, err := cs.GetWithContext(gContext, aff)
if err != nil {
if e, ok := err.(*egoscale.ErrorResponse); ok && e.ErrorCode == egoscale.ParamError {
return nil, fmt.Errorf("missing Affinity Group %q", name)
}
return nil, err
}
return resp.(*egoscale.AffinityGroup), nil
}
func getAffinityGroups(vm *egoscale.VirtualMachine) []string {
ags := make([]string, len(vm.AffinityGroup))
for i, agN := range vm.AffinityGroup {
ags[i] = agN.Name
}
return ags
}
func init() {
RootCmd.AddCommand(affinitygroupCmd)
}