-
Notifications
You must be signed in to change notification settings - Fork 20
/
serviceoffering.go
69 lines (53 loc) · 1.38 KB
/
serviceoffering.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
60
61
62
63
64
65
66
67
68
69
package cmd
import (
"fmt"
"os"
"github.com/exoscale/cli/table"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// serviceofferingCmd represents the serviceoffering command
var serviceofferingCmd = &cobra.Command{
Use: "serviceoffering",
Short: "List available services offerings with details",
RunE: func(cmd *cobra.Command, args []string) error {
return listServiceOffering()
},
}
func listServiceOffering() error {
serviceOffering, err := cs.ListWithContext(gContext, &egoscale.ServiceOffering{})
if err != nil {
return err
}
table := table.NewTable(os.Stdout)
table.SetHeader([]string{"Name", "cpu", "ram"})
for _, soff := range serviceOffering {
f := soff.(*egoscale.ServiceOffering)
ram := ""
if f.Memory > 1000 {
ram = fmt.Sprintf("%d GB", f.Memory>>10)
} else if f.Memory < 1000 {
ram = fmt.Sprintf("%d MB", f.Memory)
}
table.Append([]string{f.Name, fmt.Sprintf("%d× %d MHz", f.CPUNumber, f.CPUSpeed), ram})
}
table.Render()
return nil
}
func getServiceOfferingByName(name string) (*egoscale.ServiceOffering, error) {
so := &egoscale.ServiceOffering{}
id, err := egoscale.ParseUUID(name)
if err != nil {
so.Name = name
} else {
so.ID = id
}
resp, err := cs.GetWithContext(gContext, so)
if err != nil {
return nil, err
}
return resp.(*egoscale.ServiceOffering), nil
}
func init() {
vmCmd.AddCommand(serviceofferingCmd)
}