profitbricks-sdk-ruby 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +202 -0
  5. data/README.md +44 -0
  6. data/Rakefile +7 -0
  7. data/docs/guide.md +223 -0
  8. data/docs/reference.md +376 -0
  9. data/lib/profitbricks/config.rb +30 -0
  10. data/lib/profitbricks/datacenter.rb +113 -0
  11. data/lib/profitbricks/firewall.rb +65 -0
  12. data/lib/profitbricks/image.rb +51 -0
  13. data/lib/profitbricks/ipblock.rb +74 -0
  14. data/lib/profitbricks/lan.rb +75 -0
  15. data/lib/profitbricks/loadbalancer.rb +126 -0
  16. data/lib/profitbricks/location.rb +28 -0
  17. data/lib/profitbricks/model.rb +116 -0
  18. data/lib/profitbricks/nic.rb +86 -0
  19. data/lib/profitbricks/profitbricks.rb +137 -0
  20. data/lib/profitbricks/request.rb +36 -0
  21. data/lib/profitbricks/server.rb +165 -0
  22. data/lib/profitbricks/snapshot.rb +78 -0
  23. data/lib/profitbricks/version.rb +3 -0
  24. data/lib/profitbricks/volume.rb +199 -0
  25. data/lib/profitbricks/wait_for.rb +16 -0
  26. data/lib/profitbricks.rb +24 -0
  27. data/profitbricks-sdk-ruby.gemspec +26 -0
  28. data/spec/datacenter_spec.rb +230 -0
  29. data/spec/firewall_spec.rb +95 -0
  30. data/spec/image_spec.rb +49 -0
  31. data/spec/ipblock_spec.rb +52 -0
  32. data/spec/lan_spec.rb +70 -0
  33. data/spec/loadbalancer_spec.rb +117 -0
  34. data/spec/location_spec.rb +20 -0
  35. data/spec/nic_spec.rb +88 -0
  36. data/spec/profitbricks_spec.rb +1 -0
  37. data/spec/request_spec.rb +37 -0
  38. data/spec/server_spec.rb +209 -0
  39. data/spec/snapshot_spec.rb +113 -0
  40. data/spec/spec_helper.rb +18 -0
  41. data/spec/support/resource_helper.rb +64 -0
  42. data/spec/volume_spec.rb +113 -0
  43. metadata +172 -0
data/spec/nic_spec.rb ADDED
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe ProfitBricks::NIC do
4
+ before(:all) do
5
+ @datacenter = ProfitBricks::Datacenter.create(options[:datacenter])
6
+ @datacenter.wait_for { ready? }
7
+
8
+ @server = ProfitBricks::Server.create(@datacenter.id, options[:server])
9
+ @server.wait_for { ready? }
10
+
11
+ @nic = ProfitBricks::NIC.create(@datacenter.id, @server.id, options[:nic])
12
+ @nic.wait_for { ready? }
13
+
14
+ @fwrule = @nic.create_firewall_rule(options[:fwrule])
15
+ @fwrule.wait_for { ready? }
16
+ end
17
+
18
+ after(:all) do
19
+ @datacenter.delete
20
+ end
21
+
22
+ it '#create' do
23
+ expect(@nic.type).to eq('nic')
24
+ expect(@nic.id).to be_kind_of(String)
25
+ expect(@nic.properties['name']).to eq('nic1')
26
+ expect(@nic.properties['ips']).to be_kind_of(Array)
27
+ expect(@nic.properties['dhcp']).to be true
28
+ expect(@nic.properties['lan']).to eq(1)
29
+ end
30
+
31
+ it '#list' do
32
+ nics = ProfitBricks::NIC.list(@datacenter.id, @server.id)
33
+
34
+ expect(nics.count).to be > 0
35
+ expect(nics[0].type).to eq('nic')
36
+ expect(nics[0].id).to eq(@nic.id)
37
+ expect(nics[0].properties['name']).to eq('nic1')
38
+ expect(nics[0].properties['ips']).to be_kind_of(Array)
39
+ expect(nics[0].properties['dhcp']).to be true
40
+ expect(nics[0].properties['lan']).to eq(1)
41
+ end
42
+
43
+ it '#get' do
44
+ nic = ProfitBricks::NIC.get(@datacenter.id, @server.id, @nic.id)
45
+
46
+ expect(nic.type).to eq('nic')
47
+ expect(nic.id).to eq(@nic.id)
48
+ expect(nic.properties['name']).to eq('nic1')
49
+ expect(nic.properties['ips']).to be_kind_of(Array)
50
+ expect(nic.properties['dhcp']).to be true
51
+ expect(nic.properties['lan']).to eq(1)
52
+ end
53
+
54
+ it '#update' do
55
+ nic = @nic.update(ips: ['10.1.1.1', '10.1.1.2'])
56
+
57
+ expect(nic.type).to eq('nic')
58
+ expect(nic.id).to eq(@nic.id)
59
+ expect(nic.properties['name']).to eq('nic1')
60
+ expect(nic.properties['ips']).to be_kind_of(Array)
61
+ expect(nic.properties['dhcp']).to be true
62
+ expect(nic.properties['lan']).to eq(1)
63
+ end
64
+
65
+ it '#delete' do
66
+ nic = ProfitBricks::NIC.create(@datacenter.id, @server.id, options[:nic])
67
+ nic.wait_for { ready? }
68
+
69
+ expect(nic.delete).to be_kind_of(Hash)
70
+ end
71
+
72
+ it '#list_firewall_rules' do
73
+ fwrules = @nic.list_firewall_rules
74
+
75
+ expect(fwrules.count).to be > 0
76
+ expect(fwrules[0].type).to eq('firewall-rule')
77
+ expect(fwrules[0].id).to eq(@fwrule.id)
78
+ expect(fwrules[0].properties).to be_kind_of(Hash)
79
+ end
80
+
81
+ it '#create_firewall_rule, get_firewall_rule' do
82
+ fwrule = @nic.get_firewall_rule(@fwrule.id)
83
+
84
+ expect(fwrule.type).to eq('firewall-rule')
85
+ expect(fwrule.id).to eq(@fwrule.id)
86
+ expect(fwrule.properties).to be_kind_of(Hash)
87
+ end
88
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe ProfitBricks::Request do
4
+ before(:all) do
5
+ @datacenter = ProfitBricks::Datacenter.create(options[:datacenter])
6
+ @datacenter.wait_for { ready? }
7
+
8
+ @request = ProfitBricks::Request.get(@datacenter.requestId)
9
+ end
10
+
11
+ after(:all) do
12
+ @datacenter.delete
13
+ end
14
+
15
+ it '#list' do
16
+ requests = ProfitBricks::Request.list
17
+
18
+ expect(requests.count).to be > 0
19
+ expect(requests[0].type).to eq('request')
20
+ expect(requests[0].id).to be_kind_of(String)
21
+ end
22
+
23
+ it '#get' do
24
+ request = ProfitBricks::Request.get(@request.id)
25
+
26
+ expect(request.type).to eq('request')
27
+ expect(request.id).to be_kind_of(String)
28
+ expect(request.properties['method']).to eq('POST')
29
+ end
30
+
31
+ it '#status' do
32
+ status = @request.status
33
+
34
+ expect(status.type).to eq('request-status')
35
+ expect(status.metadata['status']).to eq('DONE')
36
+ end
37
+ end
@@ -0,0 +1,209 @@
1
+ require 'spec_helper'
2
+
3
+ describe ProfitBricks::Server do
4
+ before(:all) do
5
+ @datacenter = ProfitBricks::Datacenter.create(options[:datacenter])
6
+ @datacenter.wait_for { ready? }
7
+
8
+ @server = ProfitBricks::Server.create(@datacenter.id, options[:server])
9
+ @server.wait_for { ready? }
10
+
11
+ @nic = @server.create_nic(options[:nic])
12
+ @nic.wait_for { ready? }
13
+
14
+ @volume = ProfitBricks::Volume.create(@datacenter.id, options[:volume])
15
+ @volume.wait_for { ready? }
16
+ @volume.attach(@server.id)
17
+
18
+ @image = ProfitBricks::Image.list[0]
19
+ @server.attach_cdrom(@image.id)
20
+ end
21
+
22
+ before do
23
+ @server.wait_for { ready? }
24
+ @server.reload
25
+ end
26
+
27
+ after(:all) do
28
+ @datacenter.delete
29
+ end
30
+
31
+ it '#create' do
32
+ expect(@server.type).to eq('server')
33
+ expect(@server.id).to match(
34
+ /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i
35
+ )
36
+ expect(@server.properties['name']).to eq('New Server')
37
+ expect(@server.properties['cores']).to eq(1)
38
+ expect(@server.properties['ram']).to eq(1024)
39
+ expect(@server.properties['availabilityZone']).to eq('AUTO')
40
+ expect(@server.properties['vmState']).to eq('RUNNING')
41
+ end
42
+
43
+ it '#list' do
44
+ servers = ProfitBricks::Server.list(@datacenter.id)
45
+
46
+ expect(servers.count).to be > 0
47
+ expect(servers[0].type).to eq('server')
48
+ expect(servers[0].id).to eq(@server.id)
49
+ expect(servers[0].properties['name']).to eq('New Server')
50
+ expect(servers[0].properties['cores']).to eq(1)
51
+ expect(servers[0].properties['ram']).to eq(1024)
52
+ expect(servers[0].properties['availabilityZone']).to eq('AUTO')
53
+ expect(servers[0].properties['vmState']).to eq('RUNNING')
54
+ expect(servers[0].properties['bootVolume']).to be nil
55
+ expect(servers[0].properties['bootCdrom']).to be nil
56
+ end
57
+
58
+ it '#get' do
59
+ server = ProfitBricks::Server.get(@datacenter.id, @server.id)
60
+
61
+ expect(server.type).to eq('server')
62
+ expect(server.id).to eq(@server.id)
63
+ expect(server.properties['name']).to eq('New Server')
64
+ expect(server.properties['cores']).to eq(1)
65
+ expect(server.properties['ram']).to eq(1024)
66
+ expect(server.properties['availabilityZone']).to eq('AUTO')
67
+ expect(server.properties['vmState']).to eq('RUNNING')
68
+ expect(server.properties['bootVolume']).to be nil
69
+ expect(server.properties['bootCdrom']).to be nil
70
+ end
71
+
72
+ it '#update' do
73
+ server = @server.update(
74
+ name: 'New Server - Updated',
75
+ cores: 2
76
+ )
77
+
78
+ expect(server.id).to eq(@server.id)
79
+ expect(server.properties['name']).to eq('New Server - Updated')
80
+ expect(server.properties['cores']).to eq(2)
81
+ expect(server.properties['ram']).to eq(1024)
82
+ expect(server.properties['availabilityZone']).to eq('AUTO')
83
+ expect(server.properties['vmState']).to eq('RUNNING')
84
+ expect(server.properties['bootVolume']).to be nil
85
+ expect(server.properties['bootCdrom']).to be nil
86
+ end
87
+
88
+ it '#delete' do
89
+ server = ProfitBricks::Server.create(@datacenter.id, options[:server])
90
+ server.wait_for { ready? }
91
+
92
+ expect(server.delete).to be_kind_of(Hash)
93
+ expect(server.wait_for { ready? }).to be_kind_of(Hash)
94
+ end
95
+
96
+ it '#stop, reboot, start' do
97
+ expect(@server.stop)
98
+ expect(@server.wait_for { ready? }).to be_kind_of(Hash)
99
+ expect(@server.reboot)
100
+ expect(@server.wait_for { ready? }).to be_kind_of(Hash)
101
+ expect(@server.start)
102
+ expect(@server.wait_for { ready? }).to be_kind_of(Hash)
103
+ end
104
+
105
+ it '#list_volumes' do
106
+ volumes = @server.list_volumes
107
+
108
+ expect(volumes.count).to be > 0
109
+ expect(volumes[0].type).to eq('volume')
110
+ expect(volumes[0].properties['name']).to eq('my boot volume for server 1')
111
+ expect(volumes[0].properties['size']).to be_kind_of(Integer)
112
+ expect(volumes[0].properties['bus']).to eq('VIRTIO')
113
+ end
114
+
115
+ it '#get_volume' do
116
+ volume = @server.get_volume(@volume.id)
117
+
118
+ expect(volume.type).to eq('volume')
119
+ expect(volume.properties['name']).to eq('my boot volume for server 1')
120
+ expect(volume.properties['size']).to be_kind_of(Integer)
121
+ expect(volume.properties['bus']).to eq('VIRTIO')
122
+ end
123
+
124
+ it '#attach_volume' do
125
+ volume = @server.attach_volume(@volume.id)
126
+
127
+ expect(volume.type).to eq('volume')
128
+ expect(volume.properties['name']).to eq('my boot volume for server 1')
129
+ expect(volume.properties['size']).to be_kind_of(Integer)
130
+ expect(volume.properties['bus']).to eq('VIRTIO')
131
+ end
132
+
133
+ it '#detach_volume' do
134
+ volume = @server.detach_volume(@volume.id)
135
+
136
+ expect(volume).to be_kind_of(Hash)
137
+ end
138
+
139
+ #it '#list_cdroms' do
140
+ # cdroms = @server.list_cdroms
141
+
142
+ # expect(cdroms.count).to be > 0
143
+ # expect(cdroms[0].type).to eq('image')
144
+ # expect(cdroms[0].properties['name']).to eq('Ubuntu 14.04')
145
+ # expect(cdroms[0].properties['description']).to eq('Ubuntu image description')
146
+ # expect(cdroms[0].properties['size']).to be_kind_of(Integer)
147
+ #end
148
+
149
+ #it '#get_cdrom' do
150
+ # cdrom = @server.get_cdrom(@image.id)
151
+
152
+ # expect(cdrom.type).to eq('image')
153
+ # expect(cdrom.properties['name']).to eq('Ubuntu 14.04')
154
+ # expect(cdrom.properties['description']).to eq('Ubuntu image description')
155
+ # expect(cdrom.properties['size']).to be_kind_of(Integer)
156
+ #end
157
+
158
+ #it '#attach_cdrom, detach_cdrom' do
159
+ # # Detach existing image
160
+ # expect(@server.detach_cdrom(@image.id)).to be true
161
+
162
+ # # Attach image
163
+ # image = @server.attach_cdrom(@image.id)
164
+
165
+ # expect(image.type).to eq('image')
166
+ # expect(image.properties['name']).to be_kind_of(String)
167
+ # # expect(image.properties['description']).to eq('Ubuntu image description')
168
+ # expect(image.properties['size']).to be_kind_of(Integer)
169
+ #end
170
+
171
+ # it '#detach_cdrom' do
172
+ # @server.attach_cdrom(@image.id)
173
+ # cdrom = @server.detach_cdrom(@image.id)
174
+
175
+ # expect(cdrom).to be true
176
+ # end
177
+
178
+ it '#create_nic' do
179
+ expect(@nic.type).to eq('nic')
180
+ expect(@nic.id).to be_kind_of(String)
181
+ expect(@nic.properties['name']).to eq('nic1')
182
+ expect(@nic.properties['ips']).to be_kind_of(Array)
183
+ expect(@nic.properties['dhcp']).to be true
184
+ expect(@nic.properties['lan']).to eq(1)
185
+ end
186
+
187
+ it '#list_nic' do
188
+ nics = @server.list_nics
189
+
190
+ expect(nics.count).to be > 0
191
+ expect(nics[0].type).to eq('nic')
192
+ expect(nics[0].id).to be_kind_of(String)
193
+ expect(nics[0].properties['name']).to eq('nic1')
194
+ expect(nics[0].properties['ips']).to be_kind_of(Array)
195
+ expect(nics[0].properties['dhcp']).to be true
196
+ expect(nics[0].properties['lan']).to eq(1)
197
+ end
198
+
199
+ it '#get_nic' do
200
+ nic = @server.get_nic(@nic.id)
201
+
202
+ expect(nic.type).to eq('nic')
203
+ expect(nic.id).to be_kind_of(String)
204
+ expect(nic.properties['name']).to eq('nic1')
205
+ expect(nic.properties['ips']).to be_kind_of(Array)
206
+ expect(nic.properties['dhcp']).to be true
207
+ expect(nic.properties['lan']).to eq(1)
208
+ end
209
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ describe ProfitBricks::Snapshot do
4
+ before(:all) do
5
+ @datacenter = ProfitBricks::Datacenter.create(options[:datacenter])
6
+ @datacenter.wait_for { ready? }
7
+
8
+ @volume = ProfitBricks::Volume.create(@datacenter.id, options[:volume])
9
+ @volume.wait_for { ready? }
10
+
11
+ @snapshot = ProfitBricks::Snapshot.create(@datacenter.id, @volume.id, options[:snapshot])
12
+ @snapshot.wait_for { ready? }
13
+ end
14
+
15
+ after(:all) do
16
+ @datacenter.delete
17
+ end
18
+
19
+ it '#create' do
20
+ expect(@snapshot.type).to eq('snapshot')
21
+ expect(@snapshot.id).to be_kind_of(String)
22
+ expect(@snapshot.properties['name']).to eq('Snapshot of storage X on 12.12.12 12:12:12 - updated')
23
+ expect(@snapshot.properties['description']).to eq('description of a snapshot - updated')
24
+ expect(@snapshot.properties['location']).to match(/\w+\/\w+/)
25
+ expect(@snapshot.properties['size']).to be nil
26
+ expect(@snapshot.properties['cpuHotPlug']).to be false
27
+ expect(@snapshot.properties['cpuHotUnplug']).to be false
28
+ expect(@snapshot.properties['ramHotPlug']).to be false
29
+ expect(@snapshot.properties['ramHotUnplug']).to be false
30
+ expect(@snapshot.properties['nicHotPlug']).to be false
31
+ expect(@snapshot.properties['nicHotUnplug']).to be false
32
+ expect(@snapshot.properties['discVirtioHotPlug']).to be false
33
+ expect(@snapshot.properties['discVirtioHotUnplug']).to be false
34
+ expect(@snapshot.properties['discScsiHotPlug']).to be false
35
+ expect(@snapshot.properties['discScsiHotUnplug']).to be false
36
+ expect(@snapshot.properties['licenceType']).to be nil
37
+ end
38
+
39
+ it '#list' do
40
+ snapshots = ProfitBricks::Snapshot.list
41
+
42
+ expect(snapshots.count).to be > 0
43
+ expect(snapshots[0].type).to eq('snapshot')
44
+ expect(snapshots[0].id).to be_kind_of(String)
45
+ expect(snapshots[0].properties['name']).to be_kind_of(String)
46
+ expect(snapshots[0].properties['description']).to be_kind_of(String)
47
+ expect(snapshots[0].properties['location']).to match(/\w+\/\w+/)
48
+ expect(snapshots[0].properties['size']).to be_kind_of(Integer)
49
+ expect(snapshots[0].properties['cpuHotPlug']).to be false
50
+ expect(snapshots[0].properties['cpuHotUnplug']).to be false
51
+ expect(snapshots[0].properties['ramHotPlug']).to be false
52
+ expect(snapshots[0].properties['ramHotUnplug']).to be false
53
+ expect(snapshots[0].properties['nicHotPlug']).to be false
54
+ expect(snapshots[0].properties['nicHotUnplug']).to be false
55
+ expect(snapshots[0].properties['discVirtioHotPlug']).to be false
56
+ expect(snapshots[0].properties['discVirtioHotUnplug']).to be false
57
+ expect(snapshots[0].properties['discScsiHotPlug']).to be false
58
+ expect(snapshots[0].properties['discScsiHotUnplug']).to be false
59
+ expect(snapshots[0].properties['licenceType']).to be_kind_of(String)
60
+ end
61
+
62
+ it '#get' do
63
+ snapshot = ProfitBricks::Snapshot.get(@snapshot.id)
64
+
65
+ expect(snapshot.type).to eq('snapshot')
66
+ expect(snapshot.id).to eq(@snapshot.id)
67
+ expect(snapshot.properties['name']).to be_kind_of(String)
68
+ expect(snapshot.properties['description']).to be_kind_of(String)
69
+ expect(snapshot.properties['location']).to match(/\w+\/\w+/)
70
+ expect(snapshot.properties['size']).to be_kind_of(Integer)
71
+ expect(snapshot.properties['cpuHotPlug']).to be false
72
+ expect(snapshot.properties['cpuHotUnplug']).to be false
73
+ expect(snapshot.properties['ramHotPlug']).to be false
74
+ expect(snapshot.properties['ramHotUnplug']).to be false
75
+ expect(snapshot.properties['nicHotPlug']).to be false
76
+ expect(snapshot.properties['nicHotUnplug']).to be false
77
+ expect(snapshot.properties['discVirtioHotPlug']).to be false
78
+ expect(snapshot.properties['discVirtioHotUnplug']).to be false
79
+ expect(snapshot.properties['discScsiHotPlug']).to be false
80
+ expect(snapshot.properties['discScsiHotUnplug']).to be false
81
+ expect(snapshot.properties['licenceType']).to eq('UNKNOWN')
82
+ end
83
+
84
+ it '#update' do
85
+ snapshot = @snapshot.update(name: 'New name')
86
+ snapshot.wait_for { ready? }
87
+
88
+ expect(snapshot.type).to eq('snapshot')
89
+ expect(snapshot.id).to be_kind_of(String)
90
+ expect(snapshot.properties['name']).to eq('New name')
91
+ expect(snapshot.properties['description']).to be_kind_of(String)
92
+ expect(snapshot.properties['location']).to match(/\w+\/\w+/)
93
+ expect(snapshot.properties['size']).to be_kind_of(Integer)
94
+ expect(snapshot.properties['cpuHotPlug']).to be false
95
+ expect(snapshot.properties['cpuHotUnplug']).to be false
96
+ expect(snapshot.properties['ramHotPlug']).to be false
97
+ expect(snapshot.properties['ramHotUnplug']).to be false
98
+ expect(snapshot.properties['nicHotPlug']).to be false
99
+ expect(snapshot.properties['nicHotUnplug']).to be false
100
+ expect(snapshot.properties['discVirtioHotPlug']).to be false
101
+ expect(snapshot.properties['discVirtioHotUnplug']).to be false
102
+ expect(snapshot.properties['discScsiHotPlug']).to be false
103
+ expect(snapshot.properties['discScsiHotUnplug']).to be false
104
+ expect(snapshot.properties['licenceType']).to eq('UNKNOWN')
105
+ end
106
+
107
+ it '#delete' do
108
+ snapshot = @volume.create_snapshot(options[:snapshot])
109
+ snapshot.wait_for { ready? }
110
+
111
+ expect(snapshot.delete).to have_key(:requestId)
112
+ end
113
+ end
@@ -0,0 +1,18 @@
1
+ require 'bundler/setup'
2
+ require 'profitbricks'
3
+ require 'support/resource_helper'
4
+
5
+ Bundler.setup
6
+
7
+ RSpec.configure do |config|
8
+ config.include Helpers
9
+ end
10
+
11
+ ProfitBricks.configure do |config|
12
+ config.url = 'https://api.profitbricks.com/rest/'
13
+ config.username = ''
14
+ config.password = ''
15
+ config.debug = false
16
+ config.timeout = 60
17
+ config.interval = 5
18
+ end
@@ -0,0 +1,64 @@
1
+ module Helpers
2
+ def options
3
+ {
4
+ datacenter: {
5
+ name: 'My New Datacenter',
6
+ description: 'Production environment',
7
+ location: 'de/fkb'
8
+ },
9
+
10
+ server: {
11
+ name: 'New Server',
12
+ ram: 1024,
13
+ cores: 1
14
+ },
15
+
16
+ volume: {
17
+ name: 'my boot volume for server 1',
18
+ size: 10,
19
+ licenceType: 'UNKNOWN'
20
+ },
21
+
22
+ snapshot: {
23
+ name: 'Snapshot of storage X on 12.12.12 12:12:12 - updated',
24
+ description: 'description of a snapshot - updated'
25
+ },
26
+
27
+ nic: {
28
+ name: 'nic1',
29
+ # ips: [ '10.1.1.1' ],
30
+ dhcp: 'true',
31
+ lan: 1,
32
+ firewallActive: true
33
+ },
34
+
35
+ fwrule: {
36
+ name: 'Open SSH port',
37
+ protocol: 'TCP',
38
+ sourceMac: '01:23:45:67:89:00',
39
+ sourceIp: nil,
40
+ targetIp: nil,
41
+ portRangeStart: 22,
42
+ portRangeEnd: 22,
43
+ icmpType: nil,
44
+ icmpCode: nil
45
+ },
46
+
47
+ loadbalancer: {
48
+ name: 'My LB',
49
+ # ip: '10.2.2.3',
50
+ dhcp: 'true'
51
+ },
52
+
53
+ lan: {
54
+ name: 'public Lan 4',
55
+ public: 'true'
56
+ },
57
+
58
+ ipblock: {
59
+ location: "de/fra",
60
+ size: 1
61
+ }
62
+ }
63
+ end
64
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ describe ProfitBricks::Volume do
4
+ before(:all) do
5
+ @datacenter = ProfitBricks::Datacenter.create(options[:datacenter])
6
+ @datacenter.wait_for { ready? }
7
+
8
+ @server = ProfitBricks::Server.create(@datacenter.id, options[:server])
9
+ @server.wait_for { ready? }
10
+
11
+ @volume = ProfitBricks::Volume.create(@datacenter.id, options[:volume])
12
+ @volume.wait_for { ready? }
13
+
14
+ @volume.attach(@server.id)
15
+ @volume.wait_for { ready? }
16
+
17
+ @snapshot = @volume.create_snapshot(options[:snapshot])
18
+ @snapshot.wait_for { ready? }
19
+ end
20
+
21
+ # before do
22
+ # @volume.wait_for { ready? }
23
+ # @volume.reload
24
+ # end
25
+
26
+ after(:all) do
27
+ @datacenter.delete
28
+ end
29
+
30
+ it '#create' do
31
+ expect(@volume.type).to eq('volume')
32
+ expect(@volume.id).to match(
33
+ /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i
34
+ )
35
+ expect(@volume.properties['name']).to eq('my boot volume for server 1')
36
+ expect(@volume.properties['size']).to be_kind_of(Integer)
37
+ expect(@volume.properties['bus']).to be nil
38
+ #expect(@volume.properties['type']).to eq('HDD')
39
+ expect(@volume.properties['type']).to be nil
40
+ end
41
+
42
+ it '#list' do
43
+ volumes = ProfitBricks::Volume.list(@datacenter.id)
44
+
45
+ expect(volumes.count).to be > 0
46
+ expect(volumes[0].type).to eq('volume')
47
+ expect(volumes[0].id).to eq(@volume.id)
48
+ expect(volumes[0].properties['name']).to eq('my boot volume for server 1')
49
+ expect(volumes[0].properties['size']).to be_kind_of(Integer)
50
+ expect(volumes[0].properties['bus']).to eq('VIRTIO')
51
+ expect(volumes[0].properties['type']).to eq('HDD')
52
+ end
53
+
54
+ it '#get' do
55
+ volume = ProfitBricks::Volume.get(@datacenter.id, @volume.id)
56
+
57
+ expect(volume.type).to eq('volume')
58
+ expect(volume.id).to eq(@volume.id)
59
+ expect(volume.properties['name']).to eq('my boot volume for server 1')
60
+ expect(volume.properties['size']).to be_kind_of(Integer)
61
+ expect(volume.properties['bus']).to eq('VIRTIO')
62
+ expect(volume.properties['type']).to eq('HDD')
63
+ end
64
+
65
+ it '#update' do
66
+ volume = @volume.update(
67
+ name: 'Resized storage to 15 GB',
68
+ size: 15
69
+ )
70
+
71
+ expect(volume.type).to eq('volume')
72
+ expect(volume.id).to eq(@volume.id)
73
+ expect(volume.properties['name']).to eq('Resized storage to 15 GB')
74
+ expect(volume.properties['size']).to be_kind_of(Integer)
75
+ expect(volume.properties['bus']).to eq('VIRTIO')
76
+ expect(volume.properties['type']).to eq('HDD')
77
+ end
78
+
79
+ it '#delete' do
80
+ volume = ProfitBricks::Volume.create(@datacenter.id, options[:volume])
81
+ volume.wait_for { ready? }
82
+
83
+ expect(volume.delete).to be_kind_of(Hash)
84
+ end
85
+
86
+ it '#attach' do
87
+ volume = @volume.attach(@server.id)
88
+
89
+ expect(volume.type).to eq('volume')
90
+ expect(volume.id).to eq(@volume.id)
91
+ expect(volume.properties['name']).to be_kind_of(String)
92
+ expect(volume.properties['size']).to be_kind_of(Integer)
93
+ expect(volume.properties['bus']).to eq('VIRTIO')
94
+ expect(volume.properties['type']).to eq('HDD')
95
+ end
96
+
97
+ it '#detach' do
98
+ volume = @volume.detach(@server.id)
99
+
100
+ expect(volume).to be_kind_of(Hash)
101
+ end
102
+
103
+ it '#create_snapshop' do
104
+ # Confirm snapshot has been created.
105
+ expect(@snapshot.type).to eq('snapshot')
106
+ expect(@snapshot.properties['name']).to eq('Snapshot of storage X on 12.12.12 12:12:12 - updated')
107
+ expect(@snapshot.properties['description']).to eq('description of a snapshot - updated')
108
+ end
109
+
110
+ it '#restore_snapshot' do
111
+ expect(@volume.restore_snapshot(@snapshot.id)).to have_key(:requestId)
112
+ end
113
+ end