squall 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +100 -0
- data/LICENSE +1 -1
- data/README.md +69 -0
- data/Rakefile +48 -42
- data/lib/squall/base.rb +96 -0
- data/lib/squall/config.rb +26 -0
- data/lib/squall/exception.rb +13 -0
- data/lib/squall/hypervisor.rb +46 -16
- data/lib/squall/ip_address.rb +13 -0
- data/lib/squall/network.rb +42 -0
- data/lib/squall/params.rb +50 -0
- data/lib/squall/role.rb +56 -0
- data/lib/squall/statistic.rb +10 -0
- data/lib/squall/template.rb +22 -0
- data/lib/squall/transaction.rb +16 -0
- data/lib/squall/user.rb +87 -0
- data/lib/squall/version.rb +3 -0
- data/lib/squall/virtual_machine.rb +169 -41
- data/lib/squall.rb +76 -20
- data/spec/params_spec.rb +195 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/squall/base_spec.rb +135 -0
- data/spec/squall/config_spec.rb +44 -0
- data/spec/squall/hypervisor_spec.rb +143 -0
- data/spec/squall/ip_address_spec.rb +32 -0
- data/spec/squall/network_spec.rb +121 -0
- data/spec/squall/role_spec.rb +123 -0
- data/spec/squall/statistic_spec.rb +23 -0
- data/spec/squall/template_spec.rb +59 -0
- data/spec/squall/transaction_spec.rb +42 -0
- data/spec/squall/user_spec.rb +195 -0
- data/spec/squall/virtual_machine_spec.rb +471 -0
- data/spec/squall_spec.rb +67 -0
- data/spec/vcr_cassettes/hypervisor/create.yml +77 -0
- data/spec/vcr_cassettes/hypervisor/delete.yml +77 -0
- data/spec/vcr_cassettes/hypervisor/edit.yml +79 -0
- data/spec/vcr_cassettes/hypervisor/list.yml +40 -0
- data/spec/vcr_cassettes/hypervisor/reboot.yml +77 -0
- data/spec/vcr_cassettes/hypervisor/show.yml +77 -0
- data/spec/vcr_cassettes/ipaddress/list.yml +77 -0
- data/spec/vcr_cassettes/network/create.yml +196 -0
- data/spec/vcr_cassettes/network/delete.yml +77 -0
- data/spec/vcr_cassettes/network/edit.yml +233 -0
- data/spec/vcr_cassettes/network/list.yml +40 -0
- data/spec/vcr_cassettes/role/create.yml +77 -0
- data/spec/vcr_cassettes/role/delete.yml +77 -0
- data/spec/vcr_cassettes/role/edit.yml +139 -0
- data/spec/vcr_cassettes/role/list.yml +40 -0
- data/spec/vcr_cassettes/role/permissions.yml +40 -0
- data/spec/vcr_cassettes/role/show.yml +77 -0
- data/spec/vcr_cassettes/statistic/usage_statistics.yml +40 -0
- data/spec/vcr_cassettes/template/download.yml +40 -0
- data/spec/vcr_cassettes/template/list.yml +40 -0
- data/spec/vcr_cassettes/template/make_public.yml +77 -0
- data/spec/vcr_cassettes/transaction/list.yml +40 -0
- data/spec/vcr_cassettes/transaction/show.yml +77 -0
- data/spec/vcr_cassettes/user/activate.yml +40 -0
- data/spec/vcr_cassettes/user/create.yml +116 -0
- data/spec/vcr_cassettes/user/delete.yml +77 -0
- data/spec/vcr_cassettes/user/edit_role.yml +116 -0
- data/spec/vcr_cassettes/user/generate_api_key.yml +40 -0
- data/spec/vcr_cassettes/user/list.yml +40 -0
- data/spec/vcr_cassettes/user/show.yml +77 -0
- data/spec/vcr_cassettes/user/stats.yml +40 -0
- data/spec/vcr_cassettes/user/suspend.yml +40 -0
- data/spec/vcr_cassettes/user/virtual_machines.yml +79 -0
- data/spec/vcr_cassettes/virtual_machine/build.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/change_owner.yml +108 -0
- data/spec/vcr_cassettes/virtual_machine/change_password.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/create.yml +40 -0
- data/spec/vcr_cassettes/virtual_machine/delete.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/edit.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/list.yml +40 -0
- data/spec/vcr_cassettes/virtual_machine/migrate.yml +116 -0
- data/spec/vcr_cassettes/virtual_machine/reboot.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/resize.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/show.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/shutdown.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/startup.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/stop.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/suspend.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/unlock.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/unsuspend.yml +77 -0
- data/squall.gemspec +25 -62
- metadata +224 -42
- data/.document +0 -5
- data/README.rdoc +0 -17
- data/VERSION.yml +0 -5
- data/lib/squall/client.rb +0 -87
- data/test/fixtures/virtual_machines.json +0 -1
- data/test/fixtures/virtual_machines_1.json +0 -1
- data/test/helper.rb +0 -31
- data/test/test_client.rb +0 -152
- data/test/test_squall.rb +0 -12
- data/test/test_virtual_machine.rb +0 -98
@@ -0,0 +1,471 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Squall::VirtualMachine do
|
4
|
+
before(:each) do
|
5
|
+
default_config
|
6
|
+
@virtual_machine = Squall::VirtualMachine.new
|
7
|
+
@valid = {:label => 'testmachine', :hypervisor_id => 5, :hostname => 'testmachine', :memory => 512, :cpus => 1,
|
8
|
+
:cpu_shares => 10, :primary_disk_size => 10}
|
9
|
+
@keys = ["monthly_bandwidth_used", "cpus", "label", "created_at", "operating_system_distro",
|
10
|
+
"cpu_shares", "operating_system", "template_id", "allowed_swap", "local_remote_access_port",
|
11
|
+
"memory", "updated_at", "allow_resize_without_reboot", "recovery_mode", "hypervisor_id", "id",
|
12
|
+
"xen_id", "user_id", "total_disk_size", "booted", "hostname", "template_label", "identifier",
|
13
|
+
"initial_root_password", "min_disk_size", "remote_access_password", "built", "locked", "ip_addresses"]
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#list" do
|
17
|
+
use_vcr_cassette "virtual_machine/list"
|
18
|
+
|
19
|
+
it "returns a virtual_machine list" do
|
20
|
+
virtual_machines = @virtual_machine.list
|
21
|
+
virtual_machines.size.should be(2)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "contains first virtual_machines data" do
|
25
|
+
virtual_machine = @virtual_machine.list.first
|
26
|
+
virtual_machine.keys.should include(*@keys)
|
27
|
+
virtual_machine['label'].should == 'ohhai.server.com'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#show" do
|
32
|
+
use_vcr_cassette "virtual_machine/show"
|
33
|
+
it "requires an id" do
|
34
|
+
expect { @virtual_machine.show }.to raise_error(ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns not found for invalid virtual_machines" do
|
38
|
+
expect { @virtual_machine.show(404) }.to raise_error(Squall::NotFound)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns a virtual_machine" do
|
42
|
+
virtual_machine = @virtual_machine.show(1)
|
43
|
+
virtual_machine.keys.should include(*@keys)
|
44
|
+
virtual_machine['label'].should == 'bob'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#create" do
|
49
|
+
use_vcr_cassette "virtual_machine/create"
|
50
|
+
# validates :label, :hypervisor_id, :hostname, :memory, :cpus, :presence => true
|
51
|
+
it "requires label" do
|
52
|
+
requires_attr(:label) { @virtual_machine.create }
|
53
|
+
end
|
54
|
+
|
55
|
+
it "requires hypervisor_id" do
|
56
|
+
requires_attr(:hypervisor_id) { @virtual_machine.create(:label => @valid[:label]) }
|
57
|
+
end
|
58
|
+
|
59
|
+
it "requires hostname" do
|
60
|
+
requires_attr(:hostname) {
|
61
|
+
@virtual_machine.create(:label => @valid[:label], :hypervisor_id => @valid[:hypervisor_id])
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
it "requires memory" do
|
66
|
+
requires_attr(:memory) {
|
67
|
+
@virtual_machine.create(:label => @valid[:label], :hypervisor_id => @valid[:hypervisor_id], :hostname => @valid[:hostname])
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
it "requires cpus" do
|
72
|
+
requires_attr(:cpus) {
|
73
|
+
@virtual_machine.create(:label => @valid[:label], :hypervisor_id => @valid[:hypervisor_id], :hostname => @valid[:hostname],
|
74
|
+
:memory => @valid[:memory])
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
it "requires cpu_shares" do
|
79
|
+
requires_attr(:cpu_shares) {
|
80
|
+
@virtual_machine.create(:label => @valid[:label], :hypervisor_id => @valid[:hypervisor_id], :hostname => @valid[:hostname],
|
81
|
+
:memory => @valid[:memory], :cpus => @valid[:cpu_shares])
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
it "requires primary_disk_size" do
|
86
|
+
requires_attr(:primary_disk_size) {
|
87
|
+
@virtual_machine.create(:label => @valid[:label], :hypervisor_id => @valid[:hypervisor_id],
|
88
|
+
:hostname => @valid[:hostname], :memory => @valid[:memory], :cpus => @valid[:cpu_shares],
|
89
|
+
:cpu_shares => @valid[:cpu_shares])
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
it "raises error on unknown params" do
|
94
|
+
expect {
|
95
|
+
@virtual_machine.create(:label => @valid[:label], :hypervisor_id => @valid[:hypervisor_id], :hostname => @valid[:hostname],
|
96
|
+
:memory => @valid[:memory], :cpus => @valid[:cpus], :cpu_shares => @valid[:cpu_shares], :what => 'what')
|
97
|
+
}.to raise_error(ArgumentError, 'Missing required params: primary_disk_size')
|
98
|
+
end
|
99
|
+
|
100
|
+
it "allows all optional params" do
|
101
|
+
optional = [:cpu_shares,
|
102
|
+
:swap_disk_size,
|
103
|
+
:primary_network_id,
|
104
|
+
:required_automatic_backup,
|
105
|
+
:rate_limit,
|
106
|
+
:required_ip_address_assignment,
|
107
|
+
:required_virtual_machine_build,
|
108
|
+
:admin_note,
|
109
|
+
:note,
|
110
|
+
:allowed_hot_migrate,
|
111
|
+
:template_id,
|
112
|
+
:initial_root_password
|
113
|
+
]
|
114
|
+
|
115
|
+
@virtual_machine.should_receive(:request).exactly(optional.size).times.and_return Hash.new('virtual_machine' => [])
|
116
|
+
optional.each do |k,v|
|
117
|
+
@virtual_machine.create(@valid.merge(k.to_sym => v))
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
it "creates a virtual_machine" do
|
122
|
+
virtual_machine = @virtual_machine.create(@valid)
|
123
|
+
@valid.each do |k,v|
|
124
|
+
virtual_machine[k].should == @valid[k.to_s]
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "#build" do
|
130
|
+
use_vcr_cassette "virtual_machine/build"
|
131
|
+
it "requires an id" do
|
132
|
+
expect { @virtual_machine.build }.to raise_error(ArgumentError)
|
133
|
+
@virtual_machine.success.should be_false
|
134
|
+
end
|
135
|
+
|
136
|
+
it "accepts :template_id and :required_startup" do
|
137
|
+
hash = [:post, "/virtual_machines/1/build.json", {:query=>{:virtual_machine=>{:template_id=>1, :required_startup=>1}}}]
|
138
|
+
@virtual_machine.should_receive(:request).with(*hash).once.and_return({'virtual_machine'=>{}})
|
139
|
+
@virtual_machine.build(1, :template_id => 1, :required_startup => 1)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "raises error on unknown params" do
|
143
|
+
expect { @virtual_machine.build(1, :asdf => 1) }.to raise_error(ArgumentError, 'Unknown params: asdf')
|
144
|
+
@virtual_machine.success.should be_false
|
145
|
+
end
|
146
|
+
|
147
|
+
it "returns not found for invalid virtual_machines" do
|
148
|
+
expect { @virtual_machine.build(404) }.to raise_error(Squall::NotFound)
|
149
|
+
@virtual_machine.success.should be_false
|
150
|
+
end
|
151
|
+
|
152
|
+
it "builds the VM" do
|
153
|
+
build = @virtual_machine.build(72)
|
154
|
+
|
155
|
+
@virtual_machine.success.should be_true
|
156
|
+
build['label'].should == 'Testingagain'
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "#edit" do
|
161
|
+
use_vcr_cassette "virtual_machine/edit"
|
162
|
+
|
163
|
+
it "requires an id" do
|
164
|
+
expect { @virtual_machine.edit }.to raise_error(ArgumentError)
|
165
|
+
@virtual_machine.success.should be_false
|
166
|
+
end
|
167
|
+
|
168
|
+
it "raises error on unknown params" do
|
169
|
+
expect { @virtual_machine.edit(1, :blah => 1) }.to raise_error(ArgumentError, 'Unknown params: blah')
|
170
|
+
@virtual_machine.success.should be_false
|
171
|
+
end
|
172
|
+
|
173
|
+
it "404s on not found" do
|
174
|
+
expect { @virtual_machine.edit(404, :label => 1) }.to raise_error(Squall::NotFound)
|
175
|
+
end
|
176
|
+
|
177
|
+
it "accepts all valid keys" do
|
178
|
+
keys = [:label,
|
179
|
+
:hypervisor_id,
|
180
|
+
:hostname,
|
181
|
+
:memory,
|
182
|
+
:cpus,
|
183
|
+
:cpu_shares,
|
184
|
+
:primary_disk_size,
|
185
|
+
:cpu_shares,
|
186
|
+
:swap_disk_size,
|
187
|
+
:primary_network_id,
|
188
|
+
:required_automatic_backup,
|
189
|
+
:rate_limit,
|
190
|
+
:required_ip_address_assignment,
|
191
|
+
:required_virtual_machine_build,
|
192
|
+
:admin_note,
|
193
|
+
:note,
|
194
|
+
:allowed_hot_migrate,
|
195
|
+
:template_id,
|
196
|
+
:initial_root_password
|
197
|
+
]
|
198
|
+
keys.each do |k|
|
199
|
+
opts = @virtual_machine.default_params(k.to_sym => 1)
|
200
|
+
args = [:put, '/virtual_machines/1.json', opts]
|
201
|
+
@virtual_machine.should_receive(:request).with(*args).once.and_return([])
|
202
|
+
@virtual_machine.edit(1, k.to_sym => 1 )
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
it "updates the label" do
|
207
|
+
@virtual_machine.edit(1, :label => 'testing')
|
208
|
+
@virtual_machine.success.should be_true
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "#change_owner" do
|
213
|
+
use_vcr_cassette "virtual_machine/change_owner"
|
214
|
+
it "requires an id" do
|
215
|
+
expect { @virtual_machine.change_owner }.to raise_error(ArgumentError)
|
216
|
+
@virtual_machine.success.should be_false
|
217
|
+
end
|
218
|
+
|
219
|
+
it "requires a user_id" do
|
220
|
+
expect { @virtual_machine.change_owner 1 }.to raise_error(ArgumentError)
|
221
|
+
@virtual_machine.success.should be_false
|
222
|
+
end
|
223
|
+
|
224
|
+
it "404s on not found" do
|
225
|
+
expect { @virtual_machine.change_owner(404, 1) }.to raise_error(Squall::NotFound)
|
226
|
+
@virtual_machine.success.should be_false
|
227
|
+
end
|
228
|
+
|
229
|
+
it "returns error on unknown user" do
|
230
|
+
expect { @virtual_machine.change_owner(1, 404) }.to raise_error(Squall::ServerError)
|
231
|
+
@virtual_machine.success.should be_false
|
232
|
+
end
|
233
|
+
|
234
|
+
it "changes the user" do
|
235
|
+
result = @virtual_machine.change_owner(1, 2)
|
236
|
+
@virtual_machine.success.should be_true
|
237
|
+
|
238
|
+
result['user_id'].should == 2
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "#change_password" do
|
243
|
+
use_vcr_cassette "virtual_machine/change_password"
|
244
|
+
it "requires an id" do
|
245
|
+
expect { @virtual_machine.change_password }.to raise_error(ArgumentError)
|
246
|
+
@virtual_machine.success.should be_false
|
247
|
+
end
|
248
|
+
|
249
|
+
it "requires a password" do
|
250
|
+
expect { @virtual_machine.change_password 1 }.to raise_error(ArgumentError)
|
251
|
+
@virtual_machine.success.should be_false
|
252
|
+
end
|
253
|
+
|
254
|
+
it "404s on not found" do
|
255
|
+
expect { @virtual_machine.change_password(404, 'password') }.to raise_error(Squall::NotFound)
|
256
|
+
@virtual_machine.success.should be_false
|
257
|
+
end
|
258
|
+
|
259
|
+
it "changes the password" do
|
260
|
+
result = @virtual_machine.change_password(1, 'passwordsareimportant')
|
261
|
+
@virtual_machine.success.should be_true
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
describe "#migrate" do
|
266
|
+
use_vcr_cassette "virtual_machine/migrate"
|
267
|
+
it "requires an id" do
|
268
|
+
expect { @virtual_machine.migrate }.to raise_error(ArgumentError)
|
269
|
+
@virtual_machine.success.should be_false
|
270
|
+
end
|
271
|
+
|
272
|
+
it "requires a destination" do
|
273
|
+
requires_attr(:destination) { @virtual_machine.migrate 1 }
|
274
|
+
@virtual_machine.success.should be_false
|
275
|
+
end
|
276
|
+
|
277
|
+
it "accepts cold_migrate_on_rollback" do
|
278
|
+
hash = [:post, "/virtual_machines/1/migrate.json", {:query => {:destination => 1, :cold_migrate_on_rollback => 1} }]
|
279
|
+
@virtual_machine.should_receive(:request).with(*hash).once.and_return({'virtual_machine'=>{}})
|
280
|
+
@virtual_machine.migrate 1, :destination => 1, :cold_migrate_on_rollback => 1
|
281
|
+
end
|
282
|
+
|
283
|
+
it "404s on not found" do
|
284
|
+
expect { @virtual_machine.migrate(404, :destination => 1) }.to raise_error(Squall::NotFound)
|
285
|
+
@virtual_machine.success.should be_false
|
286
|
+
end
|
287
|
+
|
288
|
+
it "returns error on unknown destination" do
|
289
|
+
pending "Broken in OnApp" do
|
290
|
+
expect { @virtual_machine.migrate(1, :destination => 404) }.to raise_error(Squall::ServerError)
|
291
|
+
@virtual_machine.success.should be_false
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
it "changes the destination" do
|
296
|
+
pending "Broken in OnApp" do
|
297
|
+
result = @virtual_machine.migrate(1, :destination => 2)
|
298
|
+
@virtual_machine.success.should be_true
|
299
|
+
result['hypervisor_id'].should == 2
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
describe "#delete" do
|
305
|
+
use_vcr_cassette "virtual_machine/delete"
|
306
|
+
it "requires an id" do
|
307
|
+
expect { @virtual_machine.delete }.to raise_error(ArgumentError)
|
308
|
+
end
|
309
|
+
|
310
|
+
it "returns not found for invalid virtual_machines" do
|
311
|
+
expect { @virtual_machine.delete(404) }.to raise_error(Squall::NotFound)
|
312
|
+
end
|
313
|
+
|
314
|
+
it "deletes a virtual_machine" do
|
315
|
+
virtual_machine = @virtual_machine.delete(2)
|
316
|
+
@virtual_machine.success.should be_true
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
describe "#resize" do
|
321
|
+
use_vcr_cassette "virtual_machine/resize"
|
322
|
+
it "requires an id" do
|
323
|
+
expect { @virtual_machine.resize }.to raise_error(ArgumentError)
|
324
|
+
end
|
325
|
+
|
326
|
+
it "returns not found for invalid virtual_machines" do
|
327
|
+
expect { @virtual_machine.resize(404, :memory => 1) }.to raise_error(Squall::NotFound)
|
328
|
+
end
|
329
|
+
|
330
|
+
it "requires memory" do
|
331
|
+
@virtual_machine.stub(:request)
|
332
|
+
requires_attr(:memory) { @virtual_machine.resize(1) }
|
333
|
+
end
|
334
|
+
|
335
|
+
it "accepts allow_migration" do
|
336
|
+
hash = [:post, "/virtual_machines/1/resize.json", @virtual_machine.default_params(:memory => 1, :allow_migration => 1)]
|
337
|
+
@virtual_machine.should_receive(:request).with(*hash).once.and_return({'virtual_machine'=>{}})
|
338
|
+
@virtual_machine.resize 1, :memory => 1, :allow_migration => 1
|
339
|
+
end
|
340
|
+
|
341
|
+
it "resizes a virtual_machine" do
|
342
|
+
virtual_machine = @virtual_machine.resize(2, :memory => 1000)
|
343
|
+
@virtual_machine.success.should be_true
|
344
|
+
|
345
|
+
virtual_machine['memory'].should == 1000
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
describe "#suspend" do
|
350
|
+
use_vcr_cassette "virtual_machine/suspend"
|
351
|
+
it "requires an id" do
|
352
|
+
expect { @virtual_machine.suspend }.to raise_error(ArgumentError)
|
353
|
+
end
|
354
|
+
|
355
|
+
it "returns not found for invalid virtual_machines" do
|
356
|
+
expect { @virtual_machine.suspend(404) }.to raise_error(Squall::NotFound)
|
357
|
+
end
|
358
|
+
|
359
|
+
it "suspends a virtual_machine" do
|
360
|
+
virtual_machine = @virtual_machine.suspend(1)
|
361
|
+
virtual_machine['suspended'].should be_true
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
describe "#unsuspend" do
|
366
|
+
use_vcr_cassette "virtual_machine/unsuspend"
|
367
|
+
it "requires an id" do
|
368
|
+
expect { @virtual_machine.unsuspend }.to raise_error(ArgumentError)
|
369
|
+
end
|
370
|
+
|
371
|
+
it "returns not found for invalid virtual_machines" do
|
372
|
+
expect { @virtual_machine.unsuspend(404) }.to raise_error(Squall::NotFound)
|
373
|
+
end
|
374
|
+
|
375
|
+
it "unsuspends a virtual_machine" do
|
376
|
+
virtual_machine = @virtual_machine.unsuspend(1)
|
377
|
+
virtual_machine['suspended'].should be_false
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
describe "#unlock" do
|
382
|
+
use_vcr_cassette "virtual_machine/unlock"
|
383
|
+
it "requires an id" do
|
384
|
+
expect { @virtual_machine.unlock }.to raise_error(ArgumentError)
|
385
|
+
end
|
386
|
+
|
387
|
+
it "returns not found for invalid virtual_machines" do
|
388
|
+
expect { @virtual_machine.unlock(404) }.to raise_error(Squall::NotFound)
|
389
|
+
end
|
390
|
+
|
391
|
+
it "unlocks a virtual_machine" do
|
392
|
+
virtual_machine = @virtual_machine.unlock(1)
|
393
|
+
virtual_machine['locked'].should be_false
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
describe "#startup" do
|
398
|
+
use_vcr_cassette "virtual_machine/startup"
|
399
|
+
it "requires an id" do
|
400
|
+
expect { @virtual_machine.startup }.to raise_error(ArgumentError)
|
401
|
+
@virtual_machine.success.should be_false
|
402
|
+
end
|
403
|
+
|
404
|
+
it "returns not found for invalid virtual_machines" do
|
405
|
+
expect { @virtual_machine.startup(404) }.to raise_error(Squall::NotFound)
|
406
|
+
@virtual_machine.success.should be_false
|
407
|
+
end
|
408
|
+
|
409
|
+
it "startups a virtual_machine" do
|
410
|
+
@virtual_machine.startup(1)
|
411
|
+
@virtual_machine.success.should be_true
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
describe "#shutdown" do
|
416
|
+
use_vcr_cassette "virtual_machine/shutdown"
|
417
|
+
it "requires an id" do
|
418
|
+
expect { @virtual_machine.shutdown }.to raise_error(ArgumentError)
|
419
|
+
@virtual_machine.success.should be_false
|
420
|
+
end
|
421
|
+
|
422
|
+
it "returns not found for invalid virtual_machines" do
|
423
|
+
expect { @virtual_machine.shutdown(404) }.to raise_error(Squall::NotFound)
|
424
|
+
@virtual_machine.success.should be_false
|
425
|
+
end
|
426
|
+
|
427
|
+
it "will shutdown a virtual_machine" do
|
428
|
+
virtual_machine = @virtual_machine.shutdown(1)
|
429
|
+
@virtual_machine.success.should be_true
|
430
|
+
virtual_machine['id'].should == 1
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
describe "#stop" do
|
435
|
+
use_vcr_cassette "virtual_machine/stop"
|
436
|
+
it "requires an id" do
|
437
|
+
expect { @virtual_machine.stop }.to raise_error(ArgumentError)
|
438
|
+
@virtual_machine.success.should be_false
|
439
|
+
end
|
440
|
+
|
441
|
+
it "returns not found for invalid virtual_machines" do
|
442
|
+
expect { @virtual_machine.stop(404) }.to raise_error(Squall::NotFound)
|
443
|
+
@virtual_machine.success.should be_false
|
444
|
+
end
|
445
|
+
|
446
|
+
it "will stop a virtual_machine" do
|
447
|
+
virtual_machine = @virtual_machine.stop(1)
|
448
|
+
@virtual_machine.success.should be_true
|
449
|
+
virtual_machine['id'].should == 1
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
describe "#reboot" do
|
454
|
+
use_vcr_cassette "virtual_machine/reboot"
|
455
|
+
it "requires an id" do
|
456
|
+
expect { @virtual_machine.reboot }.to raise_error(ArgumentError)
|
457
|
+
@virtual_machine.success.should be_false
|
458
|
+
end
|
459
|
+
|
460
|
+
it "returns not found for invalid virtual_machines" do
|
461
|
+
expect { @virtual_machine.reboot(404) }.to raise_error(Squall::NotFound)
|
462
|
+
@virtual_machine.success.should be_false
|
463
|
+
end
|
464
|
+
|
465
|
+
it "will reboot a virtual_machine" do
|
466
|
+
virtual_machine = @virtual_machine.reboot(1)
|
467
|
+
@virtual_machine.success.should be_true
|
468
|
+
virtual_machine['id'].should == 1
|
469
|
+
end
|
470
|
+
end
|
471
|
+
end
|
data/spec/squall_spec.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Squall do
|
4
|
+
describe "VERSION" do
|
5
|
+
it "has a valid format" do
|
6
|
+
Squall::VERSION.should match /\d+/
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#config" do
|
11
|
+
it "yields a configuration with a block" do
|
12
|
+
Squall.should_receive(:config).and_yield(Squall::Config.new)
|
13
|
+
Squall.config { |c| c }
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns the config after yield" do
|
17
|
+
Squall.config { |c| c }.should == {}
|
18
|
+
Squall.config.should == {}
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
it "returns the config without a block" do
|
23
|
+
Squall.config.should == {}
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets the base URI" do
|
27
|
+
Squall.config { |c| c.base_uri 'hi'}
|
28
|
+
Squall.config.should_not be_empty
|
29
|
+
Squall.config[:base_uri] == 'hi'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#reset" do
|
34
|
+
it "resets the configuration to defaults" do
|
35
|
+
default_config
|
36
|
+
Squall.config.should_not be_empty
|
37
|
+
Squall.reset_config
|
38
|
+
Squall.config.should be_empty
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#config_file" do
|
43
|
+
it "defaults to ~/.squall" do
|
44
|
+
file = File.join(ENV['HOME'], '.squall.yml')
|
45
|
+
config = {'username' => 'test', 'password' => 'pass', 'base_uri' => 'http://example.com'}
|
46
|
+
|
47
|
+
File.stub(:exists?).and_return(true)
|
48
|
+
YAML.should_receive(:load_file).with(file).and_return(config)
|
49
|
+
|
50
|
+
Squall.configuration_file.should be_nil
|
51
|
+
Squall.config_file
|
52
|
+
Squall.configuration_file.should == file
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns an error if the file doesn't exist" do
|
56
|
+
expect { Squall.config_file '/tmp/missing.yml'}.to raise_error(ArgumentError, "Config file doesn't exist '/tmp/missing.yml'")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "loads the yaml" do
|
60
|
+
File.stub(:exists?).and_return(true)
|
61
|
+
config = {'username' => 'test', 'password' => 'pass', 'base_uri' => 'http://example.com'}
|
62
|
+
YAML.should_receive(:load_file).with('/tmp/exists.yml').and_return(config)
|
63
|
+
Squall.config_file '/tmp/exists.yml'
|
64
|
+
Squall.config.should include(:username => config['username'], :password => config['password'], :base_uri => config['base_uri'])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :post
|
5
|
+
uri: http://user:pass@www.example.com:80/settings/hypervisors.json?hypervisor[ip_address]=123.123.123.123&hypervisor[hypervisor_type]=xen&hypervisor[label]=Testing
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
content-type:
|
9
|
+
- application/json
|
10
|
+
authorization:
|
11
|
+
- Basic WHAT
|
12
|
+
response: !ruby/struct:VCR::Response
|
13
|
+
status: !ruby/struct:VCR::ResponseStatus
|
14
|
+
code: 422
|
15
|
+
message: Unprocessable Entity
|
16
|
+
headers:
|
17
|
+
x-ua-compatible:
|
18
|
+
- IE=Edge,chrome=1
|
19
|
+
x-powered-by:
|
20
|
+
- Phusion Passenger (mod_rails/mod_rack) 3.0.1
|
21
|
+
content-type:
|
22
|
+
- application/json; charset=utf-8
|
23
|
+
date:
|
24
|
+
- Fri, 15 Apr 2011 20:51:38 GMT
|
25
|
+
server:
|
26
|
+
- Apache/2.2.3 (CentOS)
|
27
|
+
x-runtime:
|
28
|
+
- "0.009919"
|
29
|
+
set-cookie:
|
30
|
+
- _onapp_session=WHAT; path=/; HttpOnly
|
31
|
+
cache-control:
|
32
|
+
- no-cache
|
33
|
+
status:
|
34
|
+
- "422"
|
35
|
+
transfer-encoding:
|
36
|
+
- chunked
|
37
|
+
body: "{\"label\":[\"has already been taken\"],\"ip_address\":[\"has already been taken\"]}"
|
38
|
+
http_version: "1.1"
|
39
|
+
- !ruby/struct:VCR::HTTPInteraction
|
40
|
+
request: !ruby/struct:VCR::Request
|
41
|
+
method: :post
|
42
|
+
uri: http://user:pass@www.example.com:80/settings/hypervisors.json?hypervisor[ip_address]=126.126.126.126&hypervisor[hypervisor_type]=xen&hypervisor[label]=Brand%20new
|
43
|
+
body:
|
44
|
+
headers:
|
45
|
+
content-type:
|
46
|
+
- application/json
|
47
|
+
authorization:
|
48
|
+
- Basic WHAT
|
49
|
+
response: !ruby/struct:VCR::Response
|
50
|
+
status: !ruby/struct:VCR::ResponseStatus
|
51
|
+
code: 201
|
52
|
+
message: Created
|
53
|
+
headers:
|
54
|
+
x-ua-compatible:
|
55
|
+
- IE=Edge,chrome=1
|
56
|
+
location:
|
57
|
+
- http://www.example.com/settings/hypervisors/3
|
58
|
+
x-powered-by:
|
59
|
+
- Phusion Passenger (mod_rails/mod_rack) 3.0.1
|
60
|
+
content-type:
|
61
|
+
- application/json; charset=utf-8
|
62
|
+
x-runtime:
|
63
|
+
- "0.016771"
|
64
|
+
server:
|
65
|
+
- Apache/2.2.3 (CentOS)
|
66
|
+
date:
|
67
|
+
- Fri, 15 Apr 2011 20:52:02 GMT
|
68
|
+
set-cookie:
|
69
|
+
- _onapp_session=WHAT; path=/; HttpOnly
|
70
|
+
status:
|
71
|
+
- "201"
|
72
|
+
cache-control:
|
73
|
+
- no-cache
|
74
|
+
transfer-encoding:
|
75
|
+
- chunked
|
76
|
+
body: "{\"hypervisor\":{\"called_in_at\":null,\"label\":\"Brand new\",\"created_at\":\"2011-04-15T20:52:02Z\",\"spare\":false,\"hypervisor_type\":\"xen\",\"updated_at\":\"2011-04-15T20:52:02Z\",\"enabled\":true,\"hypervisor_group_id\":null,\"id\":3,\"xen_info\":null,\"failure_count\":0,\"health\":null,\"memory_overhead\":464,\"ip_address\":\"126.126.126.126\",\"locked\":false,\"online\":false}}"
|
77
|
+
http_version: "1.1"
|
@@ -0,0 +1,77 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :delete
|
5
|
+
uri: http://user:pass@www.example.com:80/settings/hypervisors/404.json
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
content-type:
|
9
|
+
- application/json
|
10
|
+
authorization:
|
11
|
+
- Basic WHAT
|
12
|
+
response: !ruby/struct:VCR::Response
|
13
|
+
status: !ruby/struct:VCR::ResponseStatus
|
14
|
+
code: 404
|
15
|
+
message: Not Found
|
16
|
+
headers:
|
17
|
+
x-ua-compatible:
|
18
|
+
- IE=Edge,chrome=1
|
19
|
+
x-powered-by:
|
20
|
+
- Phusion Passenger (mod_rails/mod_rack) 3.0.1
|
21
|
+
content-type:
|
22
|
+
- application/json; charset=utf-8
|
23
|
+
date:
|
24
|
+
- Mon, 18 Apr 2011 17:13:08 GMT
|
25
|
+
server:
|
26
|
+
- Apache/2.2.3 (CentOS)
|
27
|
+
x-runtime:
|
28
|
+
- "0.117341"
|
29
|
+
set-cookie:
|
30
|
+
- _onapp_session=WHAT; path=/; HttpOnly
|
31
|
+
cache-control:
|
32
|
+
- no-cache
|
33
|
+
status:
|
34
|
+
- "404"
|
35
|
+
transfer-encoding:
|
36
|
+
- chunked
|
37
|
+
body: "{\"error\":\"Resource not found\"}"
|
38
|
+
http_version: "1.1"
|
39
|
+
- !ruby/struct:VCR::HTTPInteraction
|
40
|
+
request: !ruby/struct:VCR::Request
|
41
|
+
method: :delete
|
42
|
+
uri: http://user:pass@www.example.com:80/settings/hypervisors/3.json
|
43
|
+
body:
|
44
|
+
headers:
|
45
|
+
content-type:
|
46
|
+
- application/json
|
47
|
+
authorization:
|
48
|
+
- Basic WHAT
|
49
|
+
response: !ruby/struct:VCR::Response
|
50
|
+
status: !ruby/struct:VCR::ResponseStatus
|
51
|
+
code: 200
|
52
|
+
message: OK
|
53
|
+
headers:
|
54
|
+
x-ua-compatible:
|
55
|
+
- IE=Edge,chrome=1
|
56
|
+
etag:
|
57
|
+
- "\"99914b932bd37a50b983c5e7c90ae93b\""
|
58
|
+
x-powered-by:
|
59
|
+
- Phusion Passenger (mod_rails/mod_rack) 3.0.1
|
60
|
+
content-type:
|
61
|
+
- application/json; charset=utf-8
|
62
|
+
x-runtime:
|
63
|
+
- "0.192936"
|
64
|
+
server:
|
65
|
+
- Apache/2.2.3 (CentOS)
|
66
|
+
date:
|
67
|
+
- Mon, 18 Apr 2011 17:13:08 GMT
|
68
|
+
set-cookie:
|
69
|
+
- _onapp_session=WHAT; path=/; HttpOnly
|
70
|
+
status:
|
71
|
+
- "200"
|
72
|
+
cache-control:
|
73
|
+
- max-age=0, private, must-revalidate
|
74
|
+
transfer-encoding:
|
75
|
+
- chunked
|
76
|
+
body: "{}"
|
77
|
+
http_version: "1.1"
|