-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmds.go
101 lines (85 loc) · 1.64 KB
/
cmds.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/lalyos/onlabs/online"
)
func cmdListImages() {
cl := online.NewClient()
images, err := cl.Images()
if err != nil {
log.Error(err)
return
}
for _, i := range images {
fmt.Printf(" %-40s %s\n", i.Name, i.Id)
}
}
func cmdListServers() {
cl := online.NewClient()
servers, err := cl.Servers()
if err != nil {
log.Error(err)
return
}
for _, s := range servers {
fmt.Printf("%8s %-15s %-15s %v %s\n", s.State, s.Name, s.PublicIp.Address, s.Id, s.Image.Name)
}
}
func sizeInGB(s int64) string {
gb := s / 1000000000
return fmt.Sprintf("%d GB", gb)
}
func cmdListVolumes() {
cl := online.NewClient()
all, err := cl.Volumes()
if err != nil {
log.Error(err)
return
}
for _, o := range all {
fmt.Printf(" %-20s %s %10s\n", o.Name, o.Id, sizeInGB(o.Size))
}
}
func cmdListSnapshots() {
cl := online.NewClient()
all, err := cl.Snapshots()
if err != nil {
log.Error(err)
return
}
for _, o := range all {
fmt.Printf(" %-20s %s %10s\n", o.Name, o.Id, sizeInGB(o.Size))
}
}
func cmdListIPs() {
cl := online.NewClient()
all, err := cl.IPs()
if err != nil {
log.Error(err)
return
}
for _, o := range all {
fmt.Printf(" %-20s %10s\n", o.Address, o.Id)
}
}
func cmdListActions(serverId string) {
cl := online.NewClient()
all, err := cl.ListActions(serverId)
if err != nil {
log.Error(err)
return
}
for _, o := range all {
fmt.Printf(" %-21s\n", o)
}
}
func cmdDoActions(serverId string, action string) {
cl := online.NewClient()
r, err := cl.DoActions(serverId, action)
if err != nil {
log.Error(err)
return
}
log.Info(r)
}