-
Notifications
You must be signed in to change notification settings - Fork 20
/
affinitygroup.go
59 lines (45 loc) · 1.09 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
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 getAffinityGroupByNameOrID(v string) (*egoscale.AffinityGroup, error) {
aff := &egoscale.AffinityGroup{}
id, err := egoscale.ParseUUID(v)
if err == nil {
aff.ID = id
} else {
aff.Name = v
}
resp, err := cs.GetWithContext(gContext, aff)
switch err {
case nil:
return resp.(*egoscale.AffinityGroup), nil
case egoscale.ErrNotFound:
return nil, fmt.Errorf("unknown Affinity Group %q", v)
case egoscale.ErrTooManyFound:
return nil, fmt.Errorf("multiple Affinity Groups match %q", v)
default:
return nil, err
}
}
func getAffinityGroupIDs(params []string) ([]egoscale.UUID, error) {
ids := make([]egoscale.UUID, len(params))
for i, aff := range params {
s, err := getAffinityGroupByNameOrID(aff)
if err != nil {
return nil, err
}
ids[i] = *s.ID
}
return ids, nil
}
func init() {
RootCmd.AddCommand(affinitygroupCmd)
}