-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdedicatedcloud.go
199 lines (187 loc) · 6.63 KB
/
dedicatedcloud.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package main
import (
"fmt"
"strconv"
"github.com/codegangsta/cli"
"github.com/toorop/govh"
"github.com/toorop/govh/dedicatedcloud"
)
// getDedicatedCloudCmds return commands for Dedicated Cloud subsection
func getDedicatedCloudCmds(client *govh.OVHClient) (dedicatedCloudCmds []cli.Command) {
sr, err := dedicatedcloud.New(client)
if err != nil {
return
}
dedicatedCloudCmds = []cli.Command{
{
Name: "list",
Usage: "Return a list of Dedicated Cloud",
Description: "ovh dedicatedcloud list [--json]" + NLTAB + TAB + "Example: ovh dedicatedcloud list",
Flags: []cli.Flag{
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dedicatedClouds, err := sr.List()
dieOnError(err)
for _, dedicatedCloud := range dedicatedClouds {
fmt.Println(dedicatedCloud)
}
dieOk()
},
},
{
Name: "properties",
Usage: "Return properties of a Dedicated Cloud",
Description: "ovh dedicatedcloud properties DEDICATEDCLOUD [--json]" + NLTAB + TAB + "Example: ovh dedicatedcloud properties pcc-123-123-123-123",
Flags: []cli.Flag{
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 1)
properties, err := sr.GetProperties(c.Args().First())
dieOnError(err)
println(formatOutput(properties, c.Bool("json")))
dieOk()
},
},
{
Name: "users",
Usage: "Return a list of users for a Dedicated Cloud",
Description: "ovh dedicatedcloud users DEDICATEDCLOUD [--name NAME] [--json]" + NLTAB + TAB + "Example: ovh dedicatedcloud users pcc-123-123-123-123 --name admin",
Flags: []cli.Flag{
cli.StringFlag{Name: "name", Value: "", Usage: "(optional) : filter by user name."},
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 1)
users, err := sr.GetUsers(c.Args().First(), c.String("name"))
dieOnError(err)
println(formatOutput(users, c.Bool("json")))
dieOk()
},
},
{
Name: "user",
Usage: "Return properties of a Dedicated Cloud user",
Description: "ovh dedicatedcloud user DEDICATEDCLOUD USERID [--json]" + NLTAB + TAB + "Example: ovh dedicatedcloud user pcc-123-123-123-123 456",
Flags: []cli.Flag{
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 2)
userID, err := strconv.ParseInt(c.Args().Get(1), 10, 64)
if err != nil {
dieError(err)
}
user, err := sr.GetUser(c.Args().First(), int(userID))
dieOnError(err)
println(formatOutput(user, c.Bool("json")))
dieOk()
},
},
{
Name: "datacenters",
Usage: "Return a list of datacenters for a Dedicated Cloud",
Description: "ovh dedicatedcloud datacenters DEDICATEDCLOUD [--json]" + NLTAB + TAB + "Example: ovh dedicatedcloud datacenters pcc-123-123-123-123",
Flags: []cli.Flag{
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 1)
datacenters, err := sr.GetDatacenters(c.Args().First())
dieOnError(err)
println(formatOutput(datacenters, c.Bool("json")))
dieOk()
},
},
{
Name: "datacenter",
Usage: "Return properties of a Dedicated Cloud datacenter",
Description: "ovh dedicatedcloud datacenter DEDICATEDCLOUD DATACENTERID [--json]" + NLTAB + TAB + "Example: ovh dedicatedcloud datacenter pcc-123-123-123-123 456",
Flags: []cli.Flag{
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 2)
datacenterID, err := strconv.ParseInt(c.Args().Get(1), 10, 64)
if err != nil {
dieError(err)
}
datacenter, err := sr.GetDatacenter(c.Args().First(), int(datacenterID))
dieOnError(err)
println(formatOutput(datacenter, c.Bool("json")))
dieOk()
},
},
{
Name: "tasks",
Usage: "Return a list of tasks for a Dedicated Cloud",
Description: "ovh dedicatedcloud tasks DEDICATEDCLOUD [--state STATE] [--json]" + NLTAB + TAB + "Example: ovh dedicatedcloud tasks pcc-123-123-123-123 --state done",
Flags: []cli.Flag{
cli.StringFlag{Name: "state", Value: "", Usage: "(optional) : filter by state. See [OVH doc](https://api.ovh.com/console/#/dedicatedCloud/%7BserviceName%%7D/task#GET) for availables states."},
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 1)
tasks, err := sr.GetTasks(c.Args().First(), c.String("state"))
dieOnError(err)
println(formatOutput(tasks, c.Bool("json")))
dieOk()
},
},
{
Name: "task",
Usage: "Return properties of a Dedicated Cloud task",
Description: "ovh dedicatedcloud task DEDICATEDCLOUD TASKID [--json]" + NLTAB + TAB + "Example: ovh dedicatedcloud task pcc-123-123-123-123 456",
Flags: []cli.Flag{
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 2)
taskID, err := strconv.ParseInt(c.Args().Get(1), 10, 64)
if err != nil {
dieError(err)
}
task, err := sr.GetTask(c.Args().First(), int(taskID))
dieOnError(err)
println(formatOutput(task, c.Bool("json")))
dieOk()
},
},
{
Name: "allowednetworks",
Usage: "Return a list of AllowedNetwork for a Dedicated Cloud",
Description: "ovh dedicatedcloud tasks DEDICATEDCLOUD [--state STATE] [--json]" + NLTAB + TAB + "Example: ovh dedicatedcloud allowednetworks pcc-123-123-123-123",
Flags: []cli.Flag{
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 1)
tasks, err := sr.GetAllowedNetworks(c.Args().First())
dieOnError(err)
println(formatOutput(tasks, c.Bool("json")))
dieOk()
},
},
{
Name: "allowednetwork",
Usage: "Return properties of a Dedicated Cloud allowednetworks",
Description: "ovh dedicatedcloud allowednetwork DEDICATEDCLOUD ALLOWEDNETWORKID [--json]" + NLTAB + TAB + "Example: ovh dedicatedcloud allowednetwork pcc-123-123-123-123 456",
Flags: []cli.Flag{
cli.BoolFlag{Name: "json", Usage: "output as JSON"},
},
Action: func(c *cli.Context) {
dieIfArgsMiss(len(c.Args()), 2)
allowedNetworkID, err := strconv.ParseInt(c.Args().Get(1), 10, 64)
if err != nil {
dieError(err)
}
task, err := sr.GetAllowedNetwork(c.Args().First(), int(allowedNetworkID))
dieOnError(err)
println(formatOutput(task, c.Bool("json")))
dieOk()
},
},
}
return
}