-
Notifications
You must be signed in to change notification settings - Fork 20
/
zone.go
57 lines (46 loc) · 1 KB
/
zone.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
package cmd
import (
"os"
"github.com/exoscale/cli/table"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// zoneCmd represents the zone command
var zoneCmd = &cobra.Command{
Use: "zone",
Short: "List all available zones",
RunE: func(cmd *cobra.Command, args []string) error {
return listZones()
},
}
func listZones() error {
zones, err := cs.ListWithContext(gContext, &egoscale.Zone{})
if err != nil {
return err
}
table := table.NewTable(os.Stdout)
table.SetHeader([]string{"Name", "ID"})
for _, zone := range zones {
z := zone.(*egoscale.Zone)
table.Append([]string{z.Name, z.ID.String()})
}
table.Render()
return nil
}
func getZoneIDByName(name string) (*egoscale.UUID, error) {
zone := &egoscale.Zone{}
id, err := egoscale.ParseUUID(name)
if err != nil {
zone.Name = name
} else {
zone.ID = id
}
resp, err := cs.GetWithContext(gContext, zone)
if err != nil {
return nil, err
}
return resp.(*egoscale.Zone).ID, nil
}
func init() {
RootCmd.AddCommand(zoneCmd)
}