profitbricks-sdk-ruby 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +202 -0
- data/README.md +44 -0
- data/Rakefile +7 -0
- data/docs/guide.md +223 -0
- data/docs/reference.md +376 -0
- data/lib/profitbricks/config.rb +30 -0
- data/lib/profitbricks/datacenter.rb +113 -0
- data/lib/profitbricks/firewall.rb +65 -0
- data/lib/profitbricks/image.rb +51 -0
- data/lib/profitbricks/ipblock.rb +74 -0
- data/lib/profitbricks/lan.rb +75 -0
- data/lib/profitbricks/loadbalancer.rb +126 -0
- data/lib/profitbricks/location.rb +28 -0
- data/lib/profitbricks/model.rb +116 -0
- data/lib/profitbricks/nic.rb +86 -0
- data/lib/profitbricks/profitbricks.rb +137 -0
- data/lib/profitbricks/request.rb +36 -0
- data/lib/profitbricks/server.rb +165 -0
- data/lib/profitbricks/snapshot.rb +78 -0
- data/lib/profitbricks/version.rb +3 -0
- data/lib/profitbricks/volume.rb +199 -0
- data/lib/profitbricks/wait_for.rb +16 -0
- data/lib/profitbricks.rb +24 -0
- data/profitbricks-sdk-ruby.gemspec +26 -0
- data/spec/datacenter_spec.rb +230 -0
- data/spec/firewall_spec.rb +95 -0
- data/spec/image_spec.rb +49 -0
- data/spec/ipblock_spec.rb +52 -0
- data/spec/lan_spec.rb +70 -0
- data/spec/loadbalancer_spec.rb +117 -0
- data/spec/location_spec.rb +20 -0
- data/spec/nic_spec.rb +88 -0
- data/spec/profitbricks_spec.rb +1 -0
- data/spec/request_spec.rb +37 -0
- data/spec/server_spec.rb +209 -0
- data/spec/snapshot_spec.rb +113 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/resource_helper.rb +64 -0
- data/spec/volume_spec.rb +113 -0
- metadata +172 -0
data/docs/reference.md
ADDED
@@ -0,0 +1,376 @@
|
|
1
|
+
|
2
|
+
# Table of Contents
|
3
|
+
|
4
|
+
* [Resource Methods](#resource-methods)
|
5
|
+
* [Datacenter](#datacenter)
|
6
|
+
* [Server](#server)
|
7
|
+
* [Server Volumes](#server-volumes)
|
8
|
+
* [Server CD-ROMs](#server-cd-roms)
|
9
|
+
* [NIC](#nic)
|
10
|
+
* [Firewall Rule](#firewall-rule)
|
11
|
+
* [Volume](#volume)
|
12
|
+
* [Loadbalancer](#loadbalancer)
|
13
|
+
* [LAN](#lan)
|
14
|
+
* [Location](#location)
|
15
|
+
* [IP Block](#ip-block)
|
16
|
+
* [Image](#image)
|
17
|
+
* [Snapshot](#snapshot)
|
18
|
+
* [Request](#request)
|
19
|
+
|
20
|
+
# Resource Methods
|
21
|
+
|
22
|
+
```wait_for(timeout, interval)``` - Poll a resource until the **DONE** status is returned.
|
23
|
+
|
24
|
+
datacenter = Datacenter.create(name: "dc1", location: "us/las")
|
25
|
+
datacenter.wait_for( { ready? }
|
26
|
+
server = datacenter.create(name: "server1", cores: 1, ram: 1024)
|
27
|
+
server.wait_for { ready? }
|
28
|
+
|
29
|
+
```reload``` - Retrieve latest properties of a resource.
|
30
|
+
|
31
|
+
datacenter.reload
|
32
|
+
server.reload
|
33
|
+
|
34
|
+
# Datacenter
|
35
|
+
|
36
|
+
List all datacenters:
|
37
|
+
|
38
|
+
Datacenter.list
|
39
|
+
|
40
|
+
Retrieve a single datacenter:
|
41
|
+
|
42
|
+
datacenter = Datacenter.get(datacenter_id)
|
43
|
+
|
44
|
+
Create a datacenter:
|
45
|
+
|
46
|
+
datacenter = Datacenter.create(name: "dc1", description: "My Datacenter", location: "las/us")
|
47
|
+
|
48
|
+
Update a datacenter:
|
49
|
+
|
50
|
+
datacenter.update(description: "New datacenter description")
|
51
|
+
|
52
|
+
Remove a datacenter:
|
53
|
+
|
54
|
+
datacenter.delete
|
55
|
+
|
56
|
+
# Server
|
57
|
+
|
58
|
+
List all servers within a datacenter:
|
59
|
+
|
60
|
+
datacenter = Datacenter.get(datacenter_id)
|
61
|
+
servers = datacenter.list_servers
|
62
|
+
|
63
|
+
Retrieve a server within a datacenter:
|
64
|
+
|
65
|
+
datacenter = Datacenter.get(datacenter_id)
|
66
|
+
server = datacenter.get_server(server_id)
|
67
|
+
|
68
|
+
Create a server:
|
69
|
+
|
70
|
+
datacenter = Datacenter.get(datacenter_id)
|
71
|
+
server = datacenter.create_server(name: "server1", cores: 2, ram: 4096)
|
72
|
+
|
73
|
+
Update a server:
|
74
|
+
|
75
|
+
server.update(description: "My Server", cores: 4)
|
76
|
+
|
77
|
+
Remove a server:
|
78
|
+
|
79
|
+
server.delete
|
80
|
+
|
81
|
+
Start a server:
|
82
|
+
|
83
|
+
server.start
|
84
|
+
|
85
|
+
Stop a server:
|
86
|
+
|
87
|
+
server.stop
|
88
|
+
|
89
|
+
Restart a server:
|
90
|
+
|
91
|
+
server.reboot
|
92
|
+
|
93
|
+
## Server Volumes
|
94
|
+
|
95
|
+
List attached server volumes:
|
96
|
+
|
97
|
+
server.list_volumes
|
98
|
+
|
99
|
+
Retrieve an attached volume:
|
100
|
+
|
101
|
+
server.get_volume(volume_id)
|
102
|
+
|
103
|
+
Attach volume to a server:
|
104
|
+
|
105
|
+
server.attach_volume(volume_id)
|
106
|
+
|
107
|
+
Detach volume from a server:
|
108
|
+
|
109
|
+
server.detach_volume(volume_id)
|
110
|
+
|
111
|
+
## Server CD-ROMs
|
112
|
+
|
113
|
+
List attached CD-ROMs:
|
114
|
+
|
115
|
+
server.list_cdroms
|
116
|
+
|
117
|
+
Retrieve attached CD-ROMs:
|
118
|
+
|
119
|
+
server.get_cdrom(image_id)
|
120
|
+
|
121
|
+
Attach CD-ROM to a server:
|
122
|
+
|
123
|
+
server.attach_cdrom(image_id)
|
124
|
+
|
125
|
+
Detach CD-ROM from a server:
|
126
|
+
|
127
|
+
server.detach_cdrom(image_id)
|
128
|
+
|
129
|
+
# NIC
|
130
|
+
|
131
|
+
List all NICs:
|
132
|
+
|
133
|
+
server = datacenter.get_server(server_id)
|
134
|
+
server.list_nics
|
135
|
+
|
136
|
+
Retrieve a NIC:
|
137
|
+
|
138
|
+
server = datacenter.get_server(server_id)
|
139
|
+
server.get_nic(nic_id)
|
140
|
+
|
141
|
+
Create a NIC:
|
142
|
+
|
143
|
+
server.create_nic(name: "nic1")
|
144
|
+
|
145
|
+
Update a NIC:
|
146
|
+
|
147
|
+
nic = server.get_nic(nic_id)
|
148
|
+
nic.update(name: "nic1_rename")
|
149
|
+
|
150
|
+
Remove NIC:
|
151
|
+
|
152
|
+
nic = server.get_nic(nic_id)
|
153
|
+
nic.delete
|
154
|
+
|
155
|
+
# Firewall Rule
|
156
|
+
|
157
|
+
List all NIC firewall rules:
|
158
|
+
|
159
|
+
server = datacenter.get_server(server_id)
|
160
|
+
nic = server.get_nic(nic_id)
|
161
|
+
nic.list_firewall_rules
|
162
|
+
|
163
|
+
*Alias method*: ```nic.list_fwrules```
|
164
|
+
|
165
|
+
Retrieve a NIC firewall rule:
|
166
|
+
|
167
|
+
server = datacenter.get_server(server_id)
|
168
|
+
nic = server.get_nic(nic_id)
|
169
|
+
fwrule = nic.get_firewall_rule(fwrule_id)
|
170
|
+
|
171
|
+
*Alias method*: ```nic.get_fwrule(fwrule_id)```
|
172
|
+
|
173
|
+
Create a firewall rule:
|
174
|
+
|
175
|
+
fwrule = nic.create_firewall_rule(name: "OpenSSH port", protocol: "TCP", sourceMac: "01:23:45:67:89:00", portRangeStart: 22, portRangeEnd: 22)
|
176
|
+
|
177
|
+
*Alias method*: ```nic.create_fwrule(name: "OpenSSH port", ...)```
|
178
|
+
|
179
|
+
Update a firewall rule:
|
180
|
+
|
181
|
+
fwrule.update(name: "SSH port")
|
182
|
+
|
183
|
+
Remove a firewall rule:
|
184
|
+
|
185
|
+
fwrule.delete
|
186
|
+
|
187
|
+
# Volume
|
188
|
+
|
189
|
+
List all volumes within a datacenter:
|
190
|
+
|
191
|
+
datacenter = Datacenter.get(datacenter_id)
|
192
|
+
datacenter.list_volumes
|
193
|
+
|
194
|
+
Retrieve a volume:
|
195
|
+
|
196
|
+
volume = datacenter.get_volume(volume_id)
|
197
|
+
|
198
|
+
Create a volume:
|
199
|
+
|
200
|
+
volume = datacenter.create_volume(name: "volume1", size: 20)
|
201
|
+
|
202
|
+
Update a volume:
|
203
|
+
|
204
|
+
volume.update(description: "My Volume", size: 40)
|
205
|
+
|
206
|
+
Remove a volume:
|
207
|
+
|
208
|
+
volume.delete
|
209
|
+
|
210
|
+
Attach volume to a server:
|
211
|
+
|
212
|
+
volume.attach(server_id)
|
213
|
+
|
214
|
+
Detach volume from a server:
|
215
|
+
|
216
|
+
volume.detach
|
217
|
+
|
218
|
+
Create volume snapshot:
|
219
|
+
|
220
|
+
volume.create_snapshot(name: "snapshot1", description: My Snapshot")
|
221
|
+
|
222
|
+
Restore a snapshot:
|
223
|
+
|
224
|
+
volume.restore_snapshot(snapshot_id)
|
225
|
+
|
226
|
+
# Loadbalancer
|
227
|
+
|
228
|
+
List all loadbalancers within a datacenter:
|
229
|
+
|
230
|
+
datacenter = Datacenter.get(datacenter_id)
|
231
|
+
datacenter.list_loadbalancers
|
232
|
+
|
233
|
+
Retrieve a loadbalancer:
|
234
|
+
|
235
|
+
lb = datacenter.get_loadbalancer(lb_id)
|
236
|
+
|
237
|
+
Create a loadbalancer:
|
238
|
+
|
239
|
+
lb = datacenter.create_loadbalancer(name: “lb1”, …)
|
240
|
+
|
241
|
+
Update a loadbalancer:
|
242
|
+
|
243
|
+
lb.update(name: “lb1_rename”)
|
244
|
+
|
245
|
+
Remove a loadbalancer:
|
246
|
+
|
247
|
+
lb.delete
|
248
|
+
|
249
|
+
List all balanced NICs:
|
250
|
+
|
251
|
+
lb.list_balanced_nics
|
252
|
+
|
253
|
+
*Alias method*: lb.list_nics
|
254
|
+
|
255
|
+
Associate NIC with a loadbalancer:
|
256
|
+
|
257
|
+
lb.associate_balanced_nic(nic_id)
|
258
|
+
|
259
|
+
*Alias method*: lb.associate_nic(nic_id)
|
260
|
+
|
261
|
+
Retrieve a balanced NIC:
|
262
|
+
|
263
|
+
lb.get_balanced_nic(nic_id)
|
264
|
+
|
265
|
+
*Alias method*: lb.get_nic(nic_id)
|
266
|
+
|
267
|
+
Remove a balanced NIC:
|
268
|
+
|
269
|
+
lb = datacenter.get_loadbalancer(lb_id)
|
270
|
+
balanced_nic = lb.get_balanced_nic(nic_id)
|
271
|
+
balanced_nic.remove
|
272
|
+
|
273
|
+
# LAN
|
274
|
+
|
275
|
+
List all LANs:
|
276
|
+
|
277
|
+
datacenter = Datacenter.get(datacenter_id)
|
278
|
+
datacenter.list_lans
|
279
|
+
|
280
|
+
Retrieve a LAN:
|
281
|
+
|
282
|
+
lan = datacenter.get_lan(lan_id)
|
283
|
+
|
284
|
+
Create a LAN:
|
285
|
+
|
286
|
+
lan = datacenter.create_lan(name: "lan1", public: "true")
|
287
|
+
|
288
|
+
Update a LAN:
|
289
|
+
|
290
|
+
lan.update(name: "lan1_rename")
|
291
|
+
|
292
|
+
Remove LAN:
|
293
|
+
|
294
|
+
lan.delete
|
295
|
+
|
296
|
+
List LAN Members:
|
297
|
+
|
298
|
+
lan.list_members
|
299
|
+
|
300
|
+
# Location
|
301
|
+
|
302
|
+
List all locations:
|
303
|
+
|
304
|
+
Locations.list
|
305
|
+
|
306
|
+
Retrieve a location:
|
307
|
+
|
308
|
+
Location.get(location_id)
|
309
|
+
|
310
|
+
# IP Block
|
311
|
+
|
312
|
+
List reserved IP blocks:
|
313
|
+
|
314
|
+
IPBlock.list
|
315
|
+
|
316
|
+
Retrieve an IP block:
|
317
|
+
|
318
|
+
ipblock = IPBlock.get(ipblock_id)
|
319
|
+
|
320
|
+
Reserve an IP block:
|
321
|
+
|
322
|
+
ipblock = IPBlock.reserve(location: "us/las", size: 5)
|
323
|
+
|
324
|
+
Release an IP block:
|
325
|
+
|
326
|
+
ipblock.release
|
327
|
+
|
328
|
+
# Image
|
329
|
+
|
330
|
+
List all images:
|
331
|
+
|
332
|
+
Image.list
|
333
|
+
|
334
|
+
Retrieve an image:
|
335
|
+
|
336
|
+
image = Image.get(image_id)
|
337
|
+
|
338
|
+
Update an image:
|
339
|
+
|
340
|
+
image.update(name: "image1_rename")
|
341
|
+
|
342
|
+
Remove an image:
|
343
|
+
|
344
|
+
image.delete
|
345
|
+
|
346
|
+
# Snapshot
|
347
|
+
|
348
|
+
List all snapshots:
|
349
|
+
|
350
|
+
Snapshot.list
|
351
|
+
|
352
|
+
Retrieve a snapshot:
|
353
|
+
|
354
|
+
snapshot = Snapshot.get(snapshot_id)
|
355
|
+
|
356
|
+
Update a snapshot:
|
357
|
+
|
358
|
+
snapshot.update(name: "snapshot1_rename")
|
359
|
+
|
360
|
+
Remove a snapshot:
|
361
|
+
|
362
|
+
snapshot.delete
|
363
|
+
|
364
|
+
# Request
|
365
|
+
|
366
|
+
List all requests:
|
367
|
+
|
368
|
+
Request.list
|
369
|
+
|
370
|
+
Retrieve a request:
|
371
|
+
|
372
|
+
request = Request.get(request_id)
|
373
|
+
|
374
|
+
Retrieve status of a request:
|
375
|
+
|
376
|
+
request.status
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ProfitBricks
|
2
|
+
class Config
|
3
|
+
class << self
|
4
|
+
# ProfitBricks URL, default: https://api.profitbricks.com
|
5
|
+
attr_accessor :url
|
6
|
+
# ProfitBricks username (required)
|
7
|
+
attr_accessor :username
|
8
|
+
# ProfitBricks password (required)
|
9
|
+
attr_accessor :password
|
10
|
+
# ProfitBricks URL protocol, default: https
|
11
|
+
attr_accessor :protocol
|
12
|
+
# ProfitBricks URL host
|
13
|
+
attr_accessor :host
|
14
|
+
# ProfitBricks URL port, default: 443
|
15
|
+
attr_accessor :port
|
16
|
+
# ProfitBricks URL path prefix, default: /rest/
|
17
|
+
attr_accessor :path_prefix
|
18
|
+
# Custom HTTP request headers
|
19
|
+
attr_accessor :headers
|
20
|
+
# Disable namespacing the classes, set to false to avoid name conflicts, default: true
|
21
|
+
attr_accessor :global_classes
|
22
|
+
# Timeout value for wait_for() method, default: 60 seconds
|
23
|
+
attr_accessor :timeout
|
24
|
+
# Polling interval value for wait_for() method, default: 3 seconds
|
25
|
+
attr_accessor :interval
|
26
|
+
# Enable or disable Excon debugging, default: false
|
27
|
+
attr_accessor :debug
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module ProfitBricks
|
2
|
+
# Datacenter class
|
3
|
+
class Datacenter < ProfitBricks::Model
|
4
|
+
def delete
|
5
|
+
ProfitBricks.request(
|
6
|
+
method: :delete,
|
7
|
+
path: "/datacenters/#{self.id}",
|
8
|
+
expects: 202
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def update(options = {})
|
13
|
+
response = ProfitBricks.request(
|
14
|
+
path: "/datacenters/#{self.id}",
|
15
|
+
method: :patch,
|
16
|
+
expects: 202,
|
17
|
+
body: options.to_json
|
18
|
+
)
|
19
|
+
if response
|
20
|
+
# @properties = @properties.merge!(response['properties'])
|
21
|
+
@properties.merge!(response['properties'])
|
22
|
+
end
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def list_servers
|
27
|
+
ProfitBricks::Server.list(self.id)
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_server(server_id)
|
31
|
+
ProfitBricks::Server.get(self.id, server_id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_server(options = {})
|
35
|
+
ProfitBricks::Server.create(self.id, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def list_volumes
|
39
|
+
ProfitBricks::Volume.list(self.id)
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_volume(volume_id)
|
43
|
+
ProfitBricks::Volume.get(self.id, nil, volume_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_volume(options = {})
|
47
|
+
ProfitBricks::Volume.create(self.id, options)
|
48
|
+
end
|
49
|
+
|
50
|
+
def list_loadbalancers
|
51
|
+
ProfitBricks::Loadbalancer.list(self.id)
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_loadbalancer(loadbalancer_id)
|
55
|
+
ProfitBricks::Loadbalancer.get(self.id, loadbalancer_id)
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_loadbalancer(options = {})
|
59
|
+
ProfitBricks::Loadbalancer.create(self.id, options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def list_lans
|
63
|
+
ProfitBricks::LAN.list(self.id)
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_lan(lan_id)
|
67
|
+
ProfitBricks::LAN.get(self.id, lan_id)
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_lan(options = {})
|
71
|
+
ProfitBricks::LAN.create(self.id, options)
|
72
|
+
end
|
73
|
+
|
74
|
+
alias_method :server, :get_server
|
75
|
+
alias_method :servers, :list_servers
|
76
|
+
alias_method :volume, :get_volume
|
77
|
+
alias_method :volumes, :list_volumes
|
78
|
+
alias_method :loadbalancer, :get_loadbalancer
|
79
|
+
alias_method :loadbalancers, :list_loadbalancers
|
80
|
+
alias_method :lan, :get_lan
|
81
|
+
alias_method :lans, :list_lans
|
82
|
+
|
83
|
+
class << self
|
84
|
+
def create(options = {})
|
85
|
+
response = ProfitBricks.request(
|
86
|
+
method: :post,
|
87
|
+
path: '/datacenters',
|
88
|
+
body: { properties: options }.to_json,
|
89
|
+
expects: 202
|
90
|
+
)
|
91
|
+
instantiate_objects(response)
|
92
|
+
end
|
93
|
+
|
94
|
+
def list
|
95
|
+
response = ProfitBricks.request(
|
96
|
+
method: :get,
|
97
|
+
path: '/datacenters',
|
98
|
+
expects: 200
|
99
|
+
)
|
100
|
+
instantiate_objects(response)
|
101
|
+
end
|
102
|
+
|
103
|
+
def get(datacenter_id)
|
104
|
+
response = ProfitBricks.request(
|
105
|
+
method: :get,
|
106
|
+
path: "/datacenters/#{datacenter_id}",
|
107
|
+
expects: 200
|
108
|
+
)
|
109
|
+
instantiate_objects(response)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module ProfitBricks
|
2
|
+
# Firewall class
|
3
|
+
class Firewall < ProfitBricks::Model
|
4
|
+
|
5
|
+
# Delete the firewall rule.
|
6
|
+
def delete
|
7
|
+
ProfitBricks.request(
|
8
|
+
method: :delete,
|
9
|
+
path: "/datacenters/#{self.datacenterId}/servers/#{self.serverId}/nics/#{self.nicId}/firewallrules/#{self.id}",
|
10
|
+
expects: 202
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Update the firewall rule.
|
15
|
+
def update(options = {})
|
16
|
+
response = ProfitBricks.request(
|
17
|
+
method: :patch,
|
18
|
+
path: "/datacenters/#{self.datacenterId}/servers/#{self.serverId}/nics/#{self.nicId}/firewallrules/#{self.id}",
|
19
|
+
expects: 202,
|
20
|
+
body: options.to_json
|
21
|
+
)
|
22
|
+
if response
|
23
|
+
@properties = @properties.merge(response['properties'])
|
24
|
+
end
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
|
30
|
+
# Create a new firewall rule.
|
31
|
+
def create(datacenter_id, server_id, nic_id, options = {})
|
32
|
+
response = ProfitBricks.request(
|
33
|
+
method: :post,
|
34
|
+
path: "/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}/firewallrules",
|
35
|
+
expects: 202,
|
36
|
+
body: { properties: options }.to_json
|
37
|
+
)
|
38
|
+
add_parent_identities(response)
|
39
|
+
instantiate_objects(response)
|
40
|
+
end
|
41
|
+
|
42
|
+
# List all firewall rules assigned to a NIC.
|
43
|
+
def list(datacenter_id, server_id, nic_id)
|
44
|
+
response = ProfitBricks.request(
|
45
|
+
method: :get,
|
46
|
+
path: "/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}/firewallrules",
|
47
|
+
expects: 200
|
48
|
+
)
|
49
|
+
add_parent_identities(response)
|
50
|
+
instantiate_objects(response)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Retrieve a firewall rule assigned to a NIC.
|
54
|
+
def get(datacenter_id, server_id, nic_id, fwrule_id)
|
55
|
+
response = ProfitBricks.request(
|
56
|
+
method: :get,
|
57
|
+
path: "/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}/firewallrules/#{fwrule_id}",
|
58
|
+
expects: 200
|
59
|
+
)
|
60
|
+
add_parent_identities(response)
|
61
|
+
instantiate_objects(response)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module ProfitBricks
|
2
|
+
# Image class
|
3
|
+
class Image < ProfitBricks::Model
|
4
|
+
|
5
|
+
# Delete the image.
|
6
|
+
def delete
|
7
|
+
ProfitBricks.request(
|
8
|
+
method: :delete,
|
9
|
+
path: "/images/#{self.id}",
|
10
|
+
expects: 202
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Update the image.
|
15
|
+
def update(options = {})
|
16
|
+
response = ProfitBricks.request(
|
17
|
+
method: :patch,
|
18
|
+
path: "/images/#{self.id}",
|
19
|
+
expects: 202,
|
20
|
+
body: options.to_json
|
21
|
+
)
|
22
|
+
if response
|
23
|
+
@properties = @properties.merge(response['properties'])
|
24
|
+
end
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
|
30
|
+
# List all images.
|
31
|
+
def list
|
32
|
+
response = ProfitBricks.request(
|
33
|
+
method: :get,
|
34
|
+
path: '/images',
|
35
|
+
expects: 200
|
36
|
+
)
|
37
|
+
instantiate_objects(response)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Retrieve an image.
|
41
|
+
def get(image_id)
|
42
|
+
response = ProfitBricks.request(
|
43
|
+
method: :get,
|
44
|
+
path: "/images/#{image_id}",
|
45
|
+
expects: 200
|
46
|
+
)
|
47
|
+
instantiate_objects(response)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module ProfitBricks
|
2
|
+
# IPBlock class
|
3
|
+
class IPBlock < ProfitBricks::Model
|
4
|
+
# Release an IP block.
|
5
|
+
def release
|
6
|
+
ProfitBricks.request(
|
7
|
+
method: :delete,
|
8
|
+
path: "/ipblocks/#{self.id}",
|
9
|
+
expects: 202
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
alias_method :delete, :release
|
14
|
+
|
15
|
+
class << self
|
16
|
+
# Reserve an IP block.
|
17
|
+
#
|
18
|
+
# ==== Parameters
|
19
|
+
# * +options+<Hash>:
|
20
|
+
# - +location+<String> - *Required*, must be one of the following locations:
|
21
|
+
# * +us/las+ - United States / Las Vegas
|
22
|
+
# * +de/fra+ - Germany / Frankfurt
|
23
|
+
# * +de/fkb+ - Germany / Karlsruhe
|
24
|
+
# - +size+<Integer> - *Required*, the desired size of the IP block.
|
25
|
+
#
|
26
|
+
# ==== Returns
|
27
|
+
# * +id+<String> - Universally unique identifer of resource
|
28
|
+
# * +type+<String> - Resource type
|
29
|
+
# * +href+<String> - Resource URL representation
|
30
|
+
# * +metadata+<Hash>:
|
31
|
+
# - +lastModifiedDate+
|
32
|
+
# - +lastModifiedBy+
|
33
|
+
# - +createdDate+
|
34
|
+
# - +createdBy+
|
35
|
+
# - +etag+
|
36
|
+
# * +properties+<Hash>:
|
37
|
+
# - +size+<Integer> - Size of the IP block
|
38
|
+
# - +ips+<Array> - A collection of IP addresses associated with the IP block
|
39
|
+
# - +location+<String> - Location of IP block
|
40
|
+
#
|
41
|
+
def reserve(options = {})
|
42
|
+
response = ProfitBricks.request(
|
43
|
+
method: :post,
|
44
|
+
path: '/ipblocks',
|
45
|
+
expects: 202,
|
46
|
+
body: { properties: options }.to_json
|
47
|
+
)
|
48
|
+
instantiate_objects(response)
|
49
|
+
end
|
50
|
+
|
51
|
+
# List all reserved IP blocks.
|
52
|
+
def list
|
53
|
+
response = ProfitBricks.request(
|
54
|
+
method: :get,
|
55
|
+
path: '/ipblocks',
|
56
|
+
expects: 200
|
57
|
+
)
|
58
|
+
instantiate_objects(response)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Retrieve a reserved IP block.
|
62
|
+
def get(ipblock_id)
|
63
|
+
response = ProfitBricks.request(
|
64
|
+
method: :get,
|
65
|
+
path: "/ipblocks/#{ipblock_id}",
|
66
|
+
expects: 200
|
67
|
+
)
|
68
|
+
instantiate_objects(response)
|
69
|
+
end
|
70
|
+
|
71
|
+
alias_method :create, :reserve
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|