nifty-cloud-sdk 1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/CHANGELOG +112 -0
  2. data/Gemfile +4 -0
  3. data/INSTALL +30 -0
  4. data/LICENSE.txt +58 -0
  5. data/README.rdoc +375 -0
  6. data/Rakefile +61 -0
  7. data/lib/NIFTY.rb +405 -0
  8. data/lib/NIFTY/Cloud.rb +24 -0
  9. data/lib/NIFTY/Cloud/availability_zones.rb +23 -0
  10. data/lib/NIFTY/Cloud/certificates.rb +283 -0
  11. data/lib/NIFTY/Cloud/images.rb +134 -0
  12. data/lib/NIFTY/Cloud/instances.rb +372 -0
  13. data/lib/NIFTY/Cloud/keypairs.rb +76 -0
  14. data/lib/NIFTY/Cloud/load_balancers.rb +433 -0
  15. data/lib/NIFTY/Cloud/security_groups.rb +357 -0
  16. data/lib/NIFTY/Cloud/volumes.rb +140 -0
  17. data/lib/NIFTY/config.rb +41 -0
  18. data/lib/NIFTY/exceptions.rb +32 -0
  19. data/lib/NIFTY/responses.rb +19 -0
  20. data/lib/NIFTY/version.rb +3 -0
  21. data/nifty-cloud-sdk.gemspec +28 -0
  22. data/sample/availability_zones/describe-availability-zones.rb +37 -0
  23. data/sample/certificate/create-ssl-certificate.rb +41 -0
  24. data/sample/certificate/delete-ssl-certificate.rb +28 -0
  25. data/sample/certificate/describe-ssl-certificate-attribute.rb +58 -0
  26. data/sample/certificate/describe-ssl-certificates.rb +49 -0
  27. data/sample/certificate/download-ssl-certificate.rb +31 -0
  28. data/sample/certificate/modify-ssl-certificate-attribute.rb +29 -0
  29. data/sample/certificate/register-corporate-info-for-certificate.rb +57 -0
  30. data/sample/certificate/upload-ssl-certificate.rb +32 -0
  31. data/sample/images/create-image.rb +33 -0
  32. data/sample/images/delete-image.rb +26 -0
  33. data/sample/images/describe-images.rb +70 -0
  34. data/sample/images/modify-image-attribute.rb +33 -0
  35. data/sample/instances/cancel_copy_instances.rb +26 -0
  36. data/sample/instances/copy-instances.rb +41 -0
  37. data/sample/instances/describe-instance-attribute.rb +78 -0
  38. data/sample/instances/describe-instances.rb +100 -0
  39. data/sample/instances/modify-instance-attribute.rb +30 -0
  40. data/sample/instances/reboot-instances.rb +29 -0
  41. data/sample/instances/run-instances.rb +104 -0
  42. data/sample/instances/start-instances.rb +36 -0
  43. data/sample/instances/stop-instances.rb +35 -0
  44. data/sample/instances/terminate-instances.rb +34 -0
  45. data/sample/keypairs/create-key-pair.rb +31 -0
  46. data/sample/keypairs/delete-key-pair.rb +28 -0
  47. data/sample/keypairs/describe-key-pairs.rb +31 -0
  48. data/sample/load_balancers/configure-health-check.rb +41 -0
  49. data/sample/load_balancers/create-load-balancer.rb +35 -0
  50. data/sample/load_balancers/delete-load-balancer.rb +28 -0
  51. data/sample/load_balancers/deregister-instances-from-load-balancer.rb +35 -0
  52. data/sample/load_balancers/describe-instance-health.rb +36 -0
  53. data/sample/load_balancers/describe-load-balancers.rb +89 -0
  54. data/sample/load_balancers/register-instances-with-load-balancer.rb +33 -0
  55. data/sample/load_balancers/register-port-with-load-balancer.rb +37 -0
  56. data/sample/load_balancers/set-filter-for-load-balancer.rb +38 -0
  57. data/sample/load_balancers/update-load-balancer.rb +33 -0
  58. data/sample/security_groups/authorize-security-group-ingress.rb +36 -0
  59. data/sample/security_groups/create-security-group.rb +29 -0
  60. data/sample/security_groups/delete-security-group.rb +28 -0
  61. data/sample/security_groups/deregister-instances-from-security-group.rb +31 -0
  62. data/sample/security_groups/describe-security-activities.rb +33 -0
  63. data/sample/security_groups/describe-security-groups.rb +59 -0
  64. data/sample/security_groups/register-instances-with-security-group.rb +31 -0
  65. data/sample/security_groups/revoke-security-group-ingress.rb +36 -0
  66. data/sample/security_groups/update-security-group.rb +30 -0
  67. data/sample/volumes/attach-volumes.rb +34 -0
  68. data/sample/volumes/create-volume.rb +38 -0
  69. data/sample/volumes/delete-volume.rb +28 -0
  70. data/sample/volumes/describe-volumes.rb +44 -0
  71. data/sample/volumes/detach-volume.rb +35 -0
  72. data/test/test_Cloud.rb +186 -0
  73. data/test/test_Cloud_availability_zones.rb +50 -0
  74. data/test/test_Cloud_certificates.rb +627 -0
  75. data/test/test_Cloud_images.rb +284 -0
  76. data/test/test_Cloud_instances.rb +941 -0
  77. data/test/test_Cloud_keypairs.rb +177 -0
  78. data/test/test_Cloud_load_balancers.rb +1183 -0
  79. data/test/test_Cloud_responses.rb +43 -0
  80. data/test/test_Cloud_security_groups.rb +699 -0
  81. data/test/test_Cloud_volumes.rb +325 -0
  82. data/test/test_helper.rb +23 -0
  83. metadata +275 -0
@@ -0,0 +1,284 @@
1
+ #--
2
+ # ニフティクラウドSDK for Ruby
3
+ #
4
+ # Ruby Gem Name:: nifty-cloud-sdk
5
+ # Author:: NIFTY Corporation
6
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://cloud.nifty.com/api/
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ context "images" do
14
+
15
+ before do
16
+ @api = NIFTY::Cloud::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret",
17
+ :server => 'cp.cloud.nifty.com', :path => '/api/1.7/', :user_agent => 'NIFTY Cloud API Ruby SDK',
18
+ :signature_version => '2', :signature_method => 'HmacSHA256')
19
+ @valid_owner = %w(niftycloud self)
20
+
21
+ @create_image_response_body = <<-RESPONSE
22
+ <CreateImageResponse xmlns="https://cp.cloud.nifty.com/api/1.5/">
23
+ <RequestId>f6dd8353-eb6b-6b4fd32e4f05</RequestId>
24
+ <imageId>21</imageId>
25
+ <imageState>pending</imageState>
26
+ </CreateImageResponse>
27
+ RESPONSE
28
+
29
+ @describe_images_response_body = <<-RESPONSE
30
+ <DescribeImagesResponse xmlns="http://xxxx.nifty.com/xxx/xxx/">
31
+ <imagesSet>
32
+ <item>
33
+ <imageId>1</imageId>
34
+ <imageState>available</imageState>
35
+ <isPublic>true</isPublic>
36
+ <architecture>i386</architecture>
37
+ <imageType>machine</imageType>
38
+ <platform>centos</platform>
39
+ <name>CentOS 5.3 32bit Plain</name>
40
+ <rootDeviceType>disk</rootDeviceType>
41
+ </item>
42
+ </imagesSet>
43
+ </DescribeImagesResponse>
44
+ RESPONSE
45
+
46
+ @delete_image_response_body = <<-RESPONSE
47
+ <DeleteImageResponse xmlns="https://cp.cloud.nifty.com/api/1.5/">
48
+ <requestId>f6dd8353-eb6b-6b4fd32e4f05</requestId>
49
+ </DeleteImageResponse>
50
+ RESPONSE
51
+
52
+
53
+ @modify_image_attribute_response_body = <<-RESPONSE
54
+ <ModifyImageAttributeResponse xmlns="https://cp.cloud.nifty.com/api/1.5/">
55
+ <requestId>f6dd8353-eb6b-6b4fd32e4f05</requestId>
56
+ </ModifyImageAttributeResponse>
57
+ RESPONSE
58
+ end
59
+
60
+
61
+ # create_image
62
+ specify "create_image - レスポンスを正しく解析できるか" do
63
+ @api.stubs(:exec_request).returns stub(:body => @create_image_response_body, :is_a? => true)
64
+ response = @api.create_image(:instance_id => 'server01', :name => 'image')
65
+ response.RequestId.should.equal 'f6dd8353-eb6b-6b4fd32e4f05'
66
+ response.imageId.should.equal '21'
67
+ response.imageState.should.equal 'pending'
68
+ end
69
+
70
+ specify "create_image - パラメータが正しく作られるか" do
71
+ @api.stubs(:make_request).with("Action" => "CreateImage",
72
+ "InstanceId" => "a",
73
+ "Name" => "a",
74
+ "Description" => "a",
75
+ "NoReboot" => "a",
76
+ "LeftInstance" => "true"
77
+ ).returns stub(:body => @create_image_response_body, :is_a? => true)
78
+ @api.stubs(:exec_request).returns stub(:body => @create_image_response_body, :is_a? => true)
79
+ response = @api.create_image( :instance_id => "a", :name => "a", :description => "a", :no_reboot => "a", :left_instance => true )
80
+ end
81
+
82
+ specify "create_image - :instance_id, :name正常" do
83
+ @api.stubs(:exec_request).returns stub(:body => @create_image_response_body, :is_a? => true)
84
+ lambda { @api.create_image(:instance_id => 'foo', :name => 'bar') }.should.not.raise(NIFTY::ArgumentError)
85
+ end
86
+
87
+ specify "create_image - :description正常" do
88
+ @api.stubs(:exec_request).returns stub(:body => @create_image_response_body, :is_a? => true)
89
+ lambda { @api.create_image(:instance_id => 'foo', :name => 'bar', :description => 'メモ情報') }.should.not.raise(NIFTY::ArgumentError)
90
+ lambda { @api.create_image(:instance_id => 'foo', :name => 'bar', :description => 'desc') }.should.not.raise(NIFTY::ArgumentError)
91
+ end
92
+
93
+ specify "create_image - :no_reboot正常" do
94
+ @api.stubs(:exec_request).returns stub(:body => @create_image_response_body, :is_a? => true)
95
+ lambda { @api.create_image(:instance_id => 'foo', :name => 'bar', :no_reboot => 'hoge') }.should.not.raise(NIFTY::ArgumentError)
96
+ end
97
+
98
+ specify "create_image - :left_instance正常" do
99
+ @api.stubs(:exec_request).returns stub(:body => @create_image_response_body, :is_a? => true)
100
+ lambda { @api.create_image(:instance_id => 'foo', :name => 'bar', :left_instance => true) }.should.not.raise(NIFTY::ArgumentError)
101
+ lambda { @api.create_image(:instance_id => 'foo', :name => 'bar', :left_instance => false) }.should.not.raise(NIFTY::ArgumentError)
102
+ end
103
+
104
+ specify "create_image - :instance_id未指定" do
105
+ lambda { @api.create_image }.should.raise(NIFTY::ArgumentError)
106
+ lambda { @api.create_image(:instance_id => nil) }.should.raise(NIFTY::ArgumentError)
107
+ lambda { @api.create_image(:instance_id => '') }.should.raise(NIFTY::ArgumentError)
108
+ end
109
+
110
+ specify "create_image - :name未指定" do
111
+ lambda { @api.create_image(:instance_id => 'foo') }.should.raise(NIFTY::ArgumentError)
112
+ lambda { @api.create_image(:instance_id => 'foo', :name => nil) }.should.raise(NIFTY::ArgumentError)
113
+ lambda { @api.create_image(:instance_id => 'foo', :name => '') }.should.raise(NIFTY::ArgumentError)
114
+ end
115
+
116
+ specify "create_image - :left_instance異常" do
117
+ lambda { @api.create_image(:instance_id => 'foo', :name => 'bar', :left_instance => 'hoge') }.should.raise(NIFTY::ArgumentError)
118
+ lambda { @api.create_image(:instance_id => 'foo', :name => 'bar', :left_instance => 1) }.should.raise(NIFTY::ArgumentError)
119
+ end
120
+
121
+
122
+ # describe_images
123
+ specify "describe_images - レスポンスを正しく解析できるか" do
124
+ @api.stubs(:exec_request).returns stub(:body => @describe_images_response_body, :is_a? => true)
125
+ response = @api.describe_images
126
+ response.imagesSet.item[0].imageId.should.equal '1'
127
+ response.imagesSet.item[0].imageState.should.equal 'available'
128
+ response.imagesSet.item[0].isPublic.should.equal 'true'
129
+ response.imagesSet.item[0].architecture.should.equal 'i386'
130
+ response.imagesSet.item[0].imageType.should.equal 'machine'
131
+ response.imagesSet.item[0].platform.should.equal 'centos'
132
+ response.imagesSet.item[0].name.should.equal 'CentOS 5.3 32bit Plain'
133
+ response.imagesSet.item[0].rootDeviceType.should.equal 'disk'
134
+ end
135
+
136
+ specify "describe_images - パラメータが正しく作られるか" do
137
+ @api.stubs(:make_request).with("Action" => "DescribeImages",
138
+ "ExecutableBy.1" => "a",
139
+ "ExecutableBy.2" => "a",
140
+ "ImageId.1" => "1",
141
+ "ImageId.2" => "1",
142
+ "ImageName.1" => "a",
143
+ "ImageName.2" => "a",
144
+ "Owner.1" => "niftycloud",
145
+ "Owner.2" => "self"
146
+ ).returns stub(:body => @describe_images_response_body, :is_a? => true)
147
+ @api.stubs(:exec_request).returns stub(:body => @describe_images_response_body, :is_a? => true)
148
+ response = @api.describe_images(:executable_by => %w(a a), :image_id => %w(1 1), :image_name => %w(a a), :owner => %w(niftycloud self))
149
+ end
150
+
151
+ specify "describe_images - :executable_by正常" do
152
+ @api.stubs(:exec_request).returns stub(:body => @describe_images_response_body, :is_a? => true)
153
+ lambda { @api.describe_images(:executable_by => 'exec') }.should.not.raise(NIFTY::ArgumentError)
154
+ lambda { @api.describe_images(:executable_by => %w(ex1 ex2 ex3)) }.should.not.raise(NIFTY::ArgumentError)
155
+ end
156
+
157
+ specify "describe_images - :image_id正常" do
158
+ @api.stubs(:exec_request).returns stub(:body => @describe_images_response_body, :is_a? => true)
159
+ lambda { @api.describe_images(:image_id => 1) }.should.not.raise(NIFTY::ArgumentError)
160
+ lambda { @api.describe_images(:image_id => 12000) }.should.not.raise(NIFTY::ArgumentError)
161
+ lambda { @api.describe_images(:image_id => '12000') }.should.not.raise(NIFTY::ArgumentError)
162
+ end
163
+
164
+ specify "describe_images - :image_name正常" do
165
+ @api.stubs(:exec_request).returns stub(:body => @describe_images_response_body, :is_a? => true)
166
+ lambda { @api.describe_images(:image_name => 'foo') }.should.not.raise(NIFTY::ArgumentError)
167
+ lambda { @api.describe_images(:image_name => %w(name1 name2 name3)) }.should.not.raise(NIFTY::ArgumentError)
168
+ end
169
+
170
+ specify "describe_images - :owner正常" do
171
+ @api.stubs(:exec_request).returns stub(:body => @describe_images_response_body, :is_a? => true)
172
+ @valid_owner.each do |ow|
173
+ lambda { @api.describe_images(:owner => ow) }.should.not.raise(NIFTY::ArgumentError)
174
+ lambda { @api.describe_images(:owner => [ow, ow]) }.should.not.raise(NIFTY::ArgumentError)
175
+ end
176
+ end
177
+
178
+ specify "describe_images - :image_id未指定" do
179
+ lambda { @api.describe_images(:image_id => 0) }.should.raise(NIFTY::ArgumentError)
180
+ lambda { @api.describe_images(:image_id => -1) }.should.raise(NIFTY::ArgumentError)
181
+ lambda { @api.describe_images(:image_id => 'foo') }.should.raise(NIFTY::ArgumentError)
182
+ end
183
+
184
+ specify "describe_images - :owner不正" do
185
+ lambda { @api.describe_images(:owner => 'owner') }.should.raise(NIFTY::ArgumentError)
186
+ lambda { @api.describe_images(:owner => %w(niftycloud owner)) }.should.raise(NIFTY::ArgumentError)
187
+ end
188
+
189
+
190
+ # delete_image
191
+ specify "delete_image - レスポンスを正しく解析できるか" do
192
+ @api.stubs(:exec_request).returns stub(:body => @delete_image_response_body, :is_a? => true)
193
+ response = @api.delete_image(:image_id => 10000)
194
+ response.requestId.should.equal 'f6dd8353-eb6b-6b4fd32e4f05'
195
+ end
196
+
197
+ specify "delete_image - パラメータが正しく作られるか" do
198
+ @api.stubs(:make_request).with("Action" => "DeleteImage", "ImageId" => "10000").returns stub(:body => @delete_image_response_body, :is_a? => true)
199
+ @api.stubs(:exec_request).returns stub(:body => @delete_image_response_body, :is_a? => true)
200
+ response = @api.delete_image(:image_id => 10000)
201
+ end
202
+
203
+ specify "delete_image - :image_id正常" do
204
+ @api.stubs(:exec_request).returns stub(:body => @delete_image_response_body, :is_a? => true)
205
+ lambda { @api.delete_image(:image_id => 10000) }.should.not.raise(NIFTY::ArgumentError)
206
+ lambda { @api.delete_image(:image_id => '12000') }.should.not.raise(NIFTY::ArgumentError)
207
+ lambda { @api.delete_image(:image_id => 10000) }.should.not.raise(NIFTY::ArgumentError)
208
+ end
209
+
210
+ specify "delete_image - :image_id未指定" do
211
+ lambda { @api.delete_image }.should.raise(NIFTY::ArgumentError)
212
+ lambda { @api.delete_image(:image_id => nil) }.should.raise(NIFTY::ArgumentError)
213
+ lambda { @api.delete_image(:image_id => '') }.should.raise(NIFTY::ArgumentError)
214
+ end
215
+
216
+
217
+ # modify_image_attribute
218
+ specify "modify_image_attribute - レスポンスを正しく解析できるか" do
219
+ @api.stubs(:exec_request).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
220
+ response = @api.modify_image_attribute(:image_id => 10000, :attribute => 'imageName')
221
+ response.requestId.should.equal 'f6dd8353-eb6b-6b4fd32e4f05'
222
+ end
223
+
224
+ specify "modify_image_attribute - パラメータが正しく作られるか" do
225
+ @api.stubs(:make_request).with("Action" => "ModifyImageAttribute",
226
+ "ImageId" => "10000",
227
+ "Attribute" => "description",
228
+ "Value" => "a",
229
+ "LaunchPermission.Add.1.UserId" => "a",
230
+ "LaunchPermission.Add.2.UserId" => "a",
231
+ "LaunchPermission.Remove.1.UserId" => "a",
232
+ "LaunchPermission.Remove.2.UserId" => "a",
233
+ "LaunchPermission.Add.1.Group" => "a",
234
+ "LaunchPermission.Add.2.Group" => "a",
235
+ "LaunchPermission.Remove.1.Group" => "a",
236
+ "LaunchPermission.Remove.2.Group" => "a",
237
+ "ProductCode.1" => "a",
238
+ "ProductCode.2" => "a"
239
+ ).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
240
+ @api.stubs(:exec_request).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
241
+ response = @api.modify_image_attribute(:image_id => 10000, :attribute => "description", :value => "a", :launch_permission_add => [{:user_id => "a", :group => "a"},{:user_id => "a", :group => "a"}], :launch_permission_remove => [{:user_id => "a", :group => "a"},{:user_id => "a", :group => "a"}], :product_code => %w(a a))
242
+ end
243
+
244
+ specify "modify_image_attribute - :image_id, :attribute正常" do
245
+ @api.stubs(:exec_request).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
246
+ lambda { @api.modify_image_attribute(:image_id => 10000, :attribute => 'description') }.should.not.raise(NIFTY::ArgumentError)
247
+ lambda { @api.modify_image_attribute(:image_id => '10000', :attribute => 'imageName') }.should.not.raise(NIFTY::ArgumentError)
248
+ lambda { @api.modify_image_attribute(:image_id => '12000', :attribute => 'imageName') }.should.not.raise(NIFTY::ArgumentError)
249
+ end
250
+
251
+ specify "modify_image_attribute - :launch_permission_add正常" do
252
+ @api.stubs(:exec_request).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
253
+ lambda { @api.modify_image_attribute(:image_id => 10000, :attribute => 'description', :launch_permission_add => {:user_id => 'user', :group => 'gr1'}) }.should.not.raise(NIFTY::ArgumentError)
254
+ end
255
+
256
+ specify "modify_image_attribute - :launch_permission_remove常" do
257
+ @api.stubs(:exec_request).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
258
+ lambda { @api.modify_image_attribute(:image_id => 10000, :attribute => 'description', :launch_permission_remove => {:user_id => 'user', :group => 'gr1'}) }.should.not.raise(NIFTY::ArgumentError)
259
+ end
260
+
261
+ specify "modify_image_attribute - :product_code正常" do
262
+ @api.stubs(:exec_request).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
263
+ lambda { @api.modify_image_attribute(:image_id => 10000, :attribute => 'description', :product_code => 'pcode') }.should.not.raise(NIFTY::ArgumentError)
264
+ lambda { @api.modify_image_attribute(:image_id => 10000, :attribute => 'description', :product_code => %w(pc1 pc2)) }.should.not.raise(NIFTY::ArgumentError)
265
+ end
266
+
267
+ specify "modify_image_attribute - :image_id未指定/不正" do
268
+ lambda { @api.modify_image_attribute }.should.raise(NIFTY::ArgumentError)
269
+ lambda { @api.modify_image_attribute(:image_id => nil) }.should.raise(NIFTY::ArgumentError)
270
+ lambda { @api.modify_image_attribute(:image_id => '') }.should.raise(NIFTY::ArgumentError)
271
+ lambda { @api.modify_image_attribute(:image_id => 0) }.should.raise(NIFTY::ArgumentError)
272
+ lambda { @api.modify_image_attribute(:image_id => 100) }.should.raise(NIFTY::ArgumentError)
273
+ lambda { @api.modify_image_attribute(:image_id => 9999) }.should.raise(NIFTY::ArgumentError)
274
+ lambda { @api.modify_image_attribute(:image_id => 'foo') }.should.raise(NIFTY::ArgumentError)
275
+ end
276
+
277
+ specify "modify_image_attribute - :attribute未指定/異常" do
278
+ lambda { @api.modify_image_attribute(:image_id => 'foo') }.should.raise(NIFTY::ArgumentError)
279
+ lambda { @api.modify_image_attribute(:image_id => 'foo', :attribute => nil) }.should.raise(NIFTY::ArgumentError)
280
+ lambda { @api.modify_image_attribute(:image_id => 'foo', :attribute => '') }.should.raise(NIFTY::ArgumentError)
281
+ lambda { @api.modify_image_attribute(:image_id => 'foo', :attribute => 'foo') }.should.raise(NIFTY::ArgumentError)
282
+ end
283
+
284
+ end
@@ -0,0 +1,941 @@
1
+ #--
2
+ # ニフティクラウドSDK for Ruby
3
+ #
4
+ # Ruby Gem Name:: nifty-cloud-sdk
5
+ # Author:: NIFTY Corporation
6
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://cloud.nifty.com/api/
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ context "instances" do
14
+
15
+ before do
16
+ @api = NIFTY::Cloud::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret",
17
+ :server => 'cp.cloud.nifty.com', :path => '/api/1.7/', :user_agent => 'NIFTY Cloud API Ruby SDK',
18
+ :signature_version => '2', :signature_method => 'HmacSHA256')
19
+ @valid_instance_type = %w(mini small small2 small4 medium medium4 medium8 large large8 large16)
20
+ @valid_ip_type = %w(static dynamic)
21
+ @accounting_type = [1, 2, '1', '2']
22
+
23
+ @basic_run_instances_options = {:security_group => "gr01", :image_id => 2, :key_name => 'foo', :password => 'password'}
24
+
25
+ @run_instances_response_body = <<-RESPONSE
26
+ <RunInstancesResponse xmlns="https://cp.cloud.nifty.com/api/1.3/">
27
+  <instancesSet>
28
+   <item>
29
+    <instanceId>server04</instanceId>
30
+    <imageId>CentOS 5.3 32bit Plain</imageId>
31
+    <instanceState>
32
+     <code>0</code>
33
+     <name>pending</name>
34
+    </instanceState>
35
+    <privateDnsName>10.0.5.113</privateDnsName>
36
+    <dnsName/>
37
+    <keyName>sshkey01</keyName>
38
+    <admin />
39
+    <instanceType>medium</instanceType>
40
+    <launchTime>2010-05-17T11:22:33.456Z </launchTime>
41
+    <placement>
42
+     <availabilityZone>ap-japan-1a</availabilityZone>
43
+    </placement>
44
+ <privateIpAddress>10.0.5.113</privateIpAddress>
45
+ <ipAddress />
46
+ <privateIpAddressV6>xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx</privateIpAddressV6>
47
+ <ipAddressV6 />
48
+ <architecture>i386</architecture>
49
+ <rootDeviceType>disk</rootDeviceType>
50
+ <blockDeviceMapping />
51
+ <accountingType>2</accountingType>
52
+ <ipType>static</ipType>
53
+   </item>
54
+  </instancesSet>
55
+ </RunInstancesResponse>
56
+ RESPONSE
57
+
58
+ @describe_instances_response_body = <<-RESPONSE
59
+ <DescribeInstancesResponse xmlns="https://cp.cloud.nifty.com/api/1.3/">
60
+ <requestId>320fc738-a1c7-4a2f-abcb-20813a4e997c</requestId>
61
+ <reservationSet>
62
+ <item>
63
+ <reservationId />
64
+ <ownerId />
65
+ <groupSet />
66
+ <instancesSet>
67
+ <item>
68
+ <instanceId>server01</instanceId>
69
+ <imageId>1</imageId>
70
+ <instanceState>
71
+ <code>80</code>
72
+ <name>stopped</name>
73
+ </instanceState>
74
+ <privateDnsName>10.10.10.10</privateDnsName>
75
+ <dnsName />
76
+ <reason />
77
+ <keyName>ZYP3211ssh2</keyName>
78
+ <admin />
79
+ <amiLaunchIndex />
80
+ <productCodes />
81
+ <instanceType>mini</instanceType>
82
+ <launchTime>2010-05-17T11:22:33.456Z</launchTime>
83
+ <placement>
84
+ <availabilityZone>ap-japan-1a</availabilityZone>
85
+ </placement>
86
+ <kernelId />
87
+ <ramdiskId />
88
+ <platform />
89
+ <monitoring>
90
+ <state>disabled</state>
91
+ </monitoring>
92
+ <subnetId />
93
+ <vpcId />
94
+ <privateIpAddress>10.10.10.10</privateIpAddress>
95
+ <ipAddress />
96
+ <privateIpAddressV6>xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx</privateIpAddressV6>
97
+ <ipAddressV6 />
98
+ <stateReason />
99
+ <architecture>i386</architecture>
100
+ <rootDeviceType>disk</rootDeviceType>
101
+ <rootDeviceName />
102
+ <blockDeviceMapping>
103
+ <item>
104
+ <deviceName>SCSI (0:1)</deviceName>
105
+ <ebs>
106
+ <volumeId>disk0001</volumeId>
107
+ <status>attached</status>
108
+ <attachTime>2010-10-13T19:17:28.799+09:00</attachTime>
109
+ <deleteOnTermination>false</deleteOnTermination>
110
+ </ebs>
111
+ </item>
112
+ </blockDeviceMapping>
113
+ <instanceLifecycle />
114
+ <spotInstanceRequestId />
115
+ <accountingType>2</accountingType>
116
+ <loadbalancing />
117
+ <copyInfo />
118
+ <autoscaling />
119
+ <ipType>static</ipType>
120
+ <description>メモ情報</description>
121
+ </item>
122
+ </instancesSet>
123
+ </item>
124
+ </reservationSet>
125
+ </DescribeInstancesResponse>
126
+ RESPONSE
127
+
128
+ @describe_instance_attribute_response_body = <<-RESPONSE
129
+ <DescribeInstanceAttributeResponse xmlns="http://xxxx.nifty.com/xxx/xxx/">
130
+ <instanceId>i-10a64379</instanceId>
131
+ <instanceType>
132
+ <value>mini</value>
133
+ </instanceType>
134
+ </DescribeInstanceAttributeResponse>
135
+ RESPONSE
136
+
137
+ @modify_instance_attribute_response_body = <<-RESPONSE
138
+ <ModifyInstanceAttributeResponse xmlns="https://cp.cloud.nifty.com/api/">
139
+ <return>true</return>
140
+ </ModifyInstanceAttributeResponse>
141
+ RESPONSE
142
+
143
+ @reboot_instances_response_body = <<-RESPONSE
144
+ <RebootInstancesResponse xmlns="http://xxxx.nifty.com/xxx/xxx/">
145
+ <return>true</return>
146
+ </RebootInstancesResponse>
147
+ RESPONSE
148
+
149
+ @start_instances_response_body = <<-RESPONSE
150
+ <StartInstancesResponse xmlns="https://xxxx.nifty.com/xxx/xxx/">
151
+ <instancesSet>
152
+ <item>
153
+ <instanceId>i-10a64379</instanceId>
154
+ <currentState>
155
+ <code>0</code>
156
+ <name>pending</name>
157
+ </currentState>
158
+ <previousState>
159
+ <code>80</code>
160
+ <name>stopped</name>
161
+ </previousState>
162
+ </item>
163
+ </instancesSet>
164
+ </StartInstancesResponse>
165
+ RESPONSE
166
+
167
+ @stop_instances_response_body = <<-RESPONSE
168
+ <StopInstancesResponse xmlns="http://xxxx.nifty.com/xxx/xxx/">
169
+ <instancesSet>
170
+ <item>
171
+ <instanceId>i-10a64379</instanceId>
172
+ <currentState>
173
+ <code>64</code>
174
+ <name>stopping</name>
175
+ </currentState>
176
+ <previousState>
177
+ <code>16</code>
178
+ <name>running</name>
179
+ </previousState>
180
+ </item>
181
+ </instancesSet>
182
+ </StopInstancesResponse>
183
+ RESPONSE
184
+
185
+ @terminate_instances_response_body = <<-RESPONSE
186
+ <TerminateInstancesResponse xmlns="http://xxxx.nifty.com/xxx/xxx/">
187
+ <instancesSet>
188
+ <item>
189
+ <instanceId>i-3ea74257</instanceId>
190
+ <currentState />
191
+ <previousState />
192
+ </item>
193
+ </instancesSet>
194
+ </TerminateInstancesResponse>
195
+ RESPONSE
196
+
197
+ @copy_instances_response_body = <<-RESPONSE
198
+ <CopyInstancesResponse xmlns="https://cp.cloud.nifty.com/api/1.5/">
199
+ <requestId>f6dd8353-eb6b-6b4fd32e4f05</requestId>
200
+ <copyInstanceSet>
201
+ <member>
202
+ <instanceId>copyinstance-01</instanceId>
203
+ <instanceState>creating</instanceState>
204
+ </member>
205
+ <member>
206
+ <instanceId>copyinstance-02</instanceId>
207
+ <instanceState>wait</instanceState>
208
+ </member>
209
+ </copyInstanceSet>
210
+ </CopyInstancesResponse>
211
+ RESPONSE
212
+
213
+ @cancel_copy_instances_response_body = <<-RESPONSE
214
+ <CancelCopyInstancesResponse xmlns="https://cp.cloud.nifty.com/api/">
215
+ <requestId>f6dd8353-eb6b-6b4fd32e4f05</requestId>
216
+ </CancelCopyInstancesResponse>
217
+ RESPONSE
218
+ end
219
+
220
+
221
+ # describe_instances
222
+ specify "describe_instances - レスポンスを正しく解析できるか" do
223
+ @api.stubs(:exec_request).returns stub(:body => @describe_instances_response_body, :is_a? => true)
224
+
225
+ response = @api.describe_instances( :instance_id => "server01" )
226
+ response.reservationSet.item[0].reservationId.should.equal nil
227
+ response.reservationSet.item[0].ownerId.should.equal nil
228
+ response.reservationSet.item[0].groupSet.should.equal nil
229
+ response.reservationSet.item[0].instancesSet.item[0].instanceId.should.equal "server01"
230
+ response.reservationSet.item[0].instancesSet.item[0].imageId.should.equal "1"
231
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.code.should.equal "80"
232
+ response.reservationSet.item[0].instancesSet.item[0].instanceState.name.should.equal "stopped"
233
+ response.reservationSet.item[0].instancesSet.item[0].privateDnsName.should.equal "10.10.10.10"
234
+ response.reservationSet.item[0].instancesSet.item[0].dnsName.should.equal nil
235
+ response.reservationSet.item[0].instancesSet.item[0].reason.should.equal nil
236
+ response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "ZYP3211ssh2"
237
+ response.reservationSet.item[0].instancesSet.item[0].admin.should.equal nil
238
+ response.reservationSet.item[0].instancesSet.item[0].amiLaunchIndex.should.equal nil
239
+ response.reservationSet.item[0].instancesSet.item[0].instanceType.should.equal "mini"
240
+ response.reservationSet.item[0].instancesSet.item[0].launchTime.should.equal "2010-05-17T11:22:33.456Z"
241
+ response.reservationSet.item[0].instancesSet.item[0].placement.availabilityZone.should.equal "ap-japan-1a"
242
+ response.reservationSet.item[0].instancesSet.item[0].kernelId.should.equal nil
243
+ response.reservationSet.item[0].instancesSet.item[0].ramdiskId.should.equal nil
244
+ response.reservationSet.item[0].instancesSet.item[0].platform.should.equal nil
245
+ response.reservationSet.item[0].instancesSet.item[0].monitoring.state.should.equal "disabled"
246
+ response.reservationSet.item[0].instancesSet.item[0].subnetId.should.equal nil
247
+ response.reservationSet.item[0].instancesSet.item[0].vpcId.should.equal nil
248
+ response.reservationSet.item[0].instancesSet.item[0].privateIpAddress.should.equal "10.10.10.10"
249
+ response.reservationSet.item[0].instancesSet.item[0].ipAddress.should.equal nil
250
+ response.reservationSet.item[0].instancesSet.item[0].privateIpAddressV6.should.equal "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx"
251
+ response.reservationSet.item[0].instancesSet.item[0].ipAddressV6.should.equal nil
252
+ response.reservationSet.item[0].instancesSet.item[0].stateReason.should.equal nil
253
+ response.reservationSet.item[0].instancesSet.item[0].architecture.should.equal "i386"
254
+ response.reservationSet.item[0].instancesSet.item[0].blockDeviceMapping.item[0].deviceName.should.equal "SCSI (0:1)"
255
+ response.reservationSet.item[0].instancesSet.item[0].blockDeviceMapping.item[0].ebs.volumeId.should.equal "disk0001"
256
+ response.reservationSet.item[0].instancesSet.item[0].blockDeviceMapping.item[0].ebs.status.should.equal "attached"
257
+ response.reservationSet.item[0].instancesSet.item[0].blockDeviceMapping.item[0].ebs.attachTime.should.equal "2010-10-13T19:17:28.799+09:00"
258
+ response.reservationSet.item[0].instancesSet.item[0].blockDeviceMapping.item[0].ebs.deleteOnTermination.should.equal "false"
259
+ response.reservationSet.item[0].instancesSet.item[0].instanceLifecycle.should.equal nil
260
+ response.reservationSet.item[0].instancesSet.item[0].spotInstanceRequestId.should.equal nil
261
+ response.reservationSet.item[0].instancesSet.item[0].accountingType.should.equal "2"
262
+ response.reservationSet.item[0].instancesSet.item[0].loadbalancing.should.equal nil
263
+ response.reservationSet.item[0].instancesSet.item[0].copyInfo.should.equal nil
264
+ response.reservationSet.item[0].instancesSet.item[0].autoscaling.should.equal nil
265
+ response.reservationSet.item[0].instancesSet.item[0].ipType.should.equal "static"
266
+ response.reservationSet.item[0].instancesSet.item[0].description.should.equal "メモ情報"
267
+ end
268
+
269
+ specify "describe_instances - パラメータが正しく作られるか" do
270
+ @api.stubs(:make_request).with('Action' => 'DescribeInstances',
271
+ 'InstanceId.1' => 'server01',
272
+ 'InstanceId.2' => 'server02').returns stub(:body => @describe_instances_response_body, :is_a? => true)
273
+ @api.stubs(:exec_request).returns stub(:body => @describe_instances_response_body, :is_a? => true)
274
+ response = @api.describe_instances( :instance_id => %w(server01 server02) )
275
+ end
276
+
277
+ specify "describe_instances - :instance_id正常" do
278
+ @api.stubs(:exec_request).returns stub(:body => @describe_instances_response_body, :is_a? => true)
279
+ lambda { @api.describe_instances(:instance_id => 12345) }.should.not.raise(NIFTY::ArgumentError)
280
+ lambda { @api.describe_instances(:instance_id => %w(foo bar hoge)) }.should.not.raise(NIFTY::ArgumentError)
281
+ end
282
+
283
+
284
+ # describe_instance_attribute
285
+ specify "describe_instance_attribute - レスポンスを正しく解析できるか" do
286
+ @api.stubs(:exec_request).returns stub(:body => @describe_instance_attribute_response_body, :is_a? => true)
287
+ response = @api.describe_instance_attribute(:instance_id => 'i-10a64379', :attribute => 'instanceType')
288
+ response.instanceId.should.equal 'i-10a64379'
289
+ response.instanceType.value.should.equal 'mini'
290
+ end
291
+
292
+ specify "describe_instance_attribute - パラメータが正しく作られるか" do
293
+ @api.stubs(:make_request).with("Action" => "DescribeInstanceAttribute",
294
+ "InstanceId" => "server01",
295
+ "Attribute" => "instanceType").returns stub(:body => @describe_instance_attribute_response_body, :is_a? => true)
296
+ @api.stubs(:exec_request).returns stub(:body => @describe_instance_attribute_response_body, :is_a? => true)
297
+ response = @api.describe_instance_attribute(:instance_id => 'server01', :attribute => 'instanceType')
298
+ end
299
+
300
+ specify "describe_instance_attribute - :attribute正常" do
301
+ @api.stubs(:exec_request).returns stub(:body => @describe_instance_attribute_response_body, :is_a? => true)
302
+ attributes = %w(
303
+ instanceType
304
+ disableApiTermination
305
+ blockDeviceMapping
306
+ accountingType
307
+ loadbalancing
308
+ copyInfo
309
+ autoscaling
310
+ ipType groupId
311
+ description
312
+ )
313
+ attributes.each do |attr|
314
+ lambda { @api.describe_instance_attribute(:instance_id => 'i-10a64379', :attribute => attr) }.should.not.raise(NIFTY::ArgumentError)
315
+ end
316
+ end
317
+
318
+ specify "describe_instance_attribute - :instance_id未指定" do
319
+ lambda { @api.describe_instance_attribute }.should.raise(NIFTY::ArgumentError)
320
+ lambda { @api.describe_instance_attribute(:attribute => nil) }.should.raise(NIFTY::ArgumentError)
321
+ lambda { @api.describe_instance_attribute(:attribute => '') }.should.raise(NIFTY::ArgumentError)
322
+ end
323
+
324
+ specify "describe_instance_attribute - :attribute不正" do
325
+ lambda { @api.describe_instance_attribute(:instance_id => 'i-10a64379', :attribute => 'hoge') }.should.raise(NIFTY::ArgumentError)
326
+ end
327
+
328
+
329
+ # modify_instance_attribute
330
+ specify "modify_instance_attribute - レスポンスを正しく解析できるか" do
331
+ @api.stubs(:exec_request).returns stub(:body => @modify_instance_attribute_response_body, :is_a? => true)
332
+ response = @api.modify_instance_attribute(:instance_id => "i-10a64379", :attribute => 'instanceType', :value => 'small4')
333
+ response.return.should.equal "true"
334
+ end
335
+
336
+ specify "modify_instance_attribute - パラメータが正しく作られるか" do
337
+ @api.stubs(:make_request).with('Action' => 'ModifyInstanceAttribute',
338
+ 'InstanceId' => 'server01',
339
+ 'Attribute' => 'instanceName',
340
+ 'Value' => 'server02').returns stub(:body => @modify_instance_attribute_response_body, :is_a? => true)
341
+ @api.stubs(:exec_request).returns stub(:body => @modify_instance_attribute_response_body, :is_a? => true)
342
+ response = @api.modify_instance_attribute( :instance_id => "server01", :attribute => 'instanceName', :value => 'server02' )
343
+ end
344
+
345
+ specify "modify_instance_attribute - :instance_id正常" do
346
+ @api.stubs(:exec_request).returns stub(:body => @modify_instance_attribute_response_body, :is_a? => true)
347
+ lambda { @api.modify_instance_attribute(:instance_id => 'foo', :attribute => 'instanceType', :value => 'mini') }.should.not.raise(NIFTY::ArgumentError)
348
+ lambda { @api.modify_instance_attribute(:instance_id => 12345, :attribute => 'instanceType', :value => 'mini') }.should.not.raise(NIFTY::ArgumentError)
349
+ end
350
+
351
+ specify "modify_instance_attribute - :attribute,:value正常" do
352
+ @api.stubs(:exec_request).returns stub(:body => @modify_instance_attribute_response_body, :is_a? => true)
353
+ { 'instanceType' => @valid_instance_type,
354
+ 'disableApiTermination' => [true, false, 'true', 'false'],
355
+ 'instanceName' => ['hoge'],
356
+ 'description' => ['hoge']
357
+ }.each do |attr, arr|
358
+ arr.each do |val|
359
+ lambda { @api.modify_instance_attribute(:instance_id => "i-10a64379", :attribute => attr, :value => val) }.should.not.raise(NIFTY::ArgumentError)
360
+ end
361
+ end
362
+ end
363
+
364
+ specify "modify_instance_attribute - :instance_id未指定" do
365
+ lambda { @api.modify_instance_attribute }.should.raise(NIFTY::ArgumentError)
366
+ [ nil, ''].each do |id|
367
+ lambda { @api.modify_instance_attribute(:instance_id => id) }.should.raise(NIFTY::ArgumentError)
368
+ end
369
+ lambda { @api.modify_instance_attribute }.should.raise(NIFTY::ArgumentError)
370
+ end
371
+
372
+ specify "modify_instance_attribute - :attribute未指定/不正" do
373
+ lambda { @api.modify_instance_attribute(:instance_id => "i-10a64379") }.should.raise(NIFTY::ArgumentError)
374
+ lambda { @api.modify_instance_attribute(:instance_id => "i-10a64379", :attribute => nil) }.should.raise(NIFTY::ArgumentError)
375
+ lambda { @api.modify_instance_attribute(:instance_id => "i-10a64379", :attribute => '') }.should.raise(NIFTY::ArgumentError)
376
+ lambda { @api.modify_instance_attribute(:instance_id => "i-10a64379", :attribute => 'hoge') }.should.raise(NIFTY::ArgumentError)
377
+ end
378
+
379
+ specify "modify_instance_attribute - :value未指定/不正" do
380
+ attribute = %w(instanceType disableApiTermination instanceName description)
381
+ attribute.each do |attr|
382
+ lambda { @api.modify_instance_attribute(:instance_id => "i-10a64379", :attribute => attr ) }.should.raise(NIFTY::ArgumentError)
383
+ lambda { @api.modify_instance_attribute(:instance_id => "i-10a64379", :attribute => attr, :value => nil ) }.should.raise(NIFTY::ArgumentError)
384
+ if attr == 'instanceType' || attr == 'disableApiTermination'
385
+ lambda { @api.modify_instance_attribute(:instance_id => "i-10a64379", :attribute => attr, :value => '' ) }.should.raise(NIFTY::ArgumentError)
386
+ lambda { @api.modify_instance_attribute(:instance_id => "i-10a64379", :attribute => attr, :value => 'hoge' ) }.should.raise(NIFTY::ArgumentError)
387
+ end
388
+ end
389
+ end
390
+
391
+
392
+ # run_instances
393
+ specify "run_instances - レスポンスを正しく解析できるか" do
394
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
395
+ response = @api.run_instances(:security_group => "gr01", :image_id => '1', :key_name => 'key', :password => 'pass')
396
+ response.instancesSet.item[0].instanceId.should.equal 'server04'
397
+ response.instancesSet.item[0].imageId.should.equal 'CentOS 5.3 32bit Plain'
398
+ response.instancesSet.item[0].instanceState.code.should.equal '0'
399
+ response.instancesSet.item[0].instanceState.name.should.equal 'pending'
400
+ response.instancesSet.item[0].privateDnsName.should.equal '10.0.5.113'
401
+ response.instancesSet.item[0].dnsName.should.equal nil
402
+ response.instancesSet.item[0].keyName.should.equal 'sshkey01'
403
+ response.instancesSet.item[0].admin.should.equal nil
404
+ response.instancesSet.item[0].instanceType.should.equal 'medium'
405
+ response.instancesSet.item[0].launchTime.should.equal '2010-05-17T11:22:33.456Z '
406
+ response.instancesSet.item[0].placement.availabilityZone.should.equal 'ap-japan-1a'
407
+ response.instancesSet.item[0].privateIpAddress.should.equal '10.0.5.113'
408
+ response.instancesSet.item[0].ipAddress.should.equal nil
409
+ response.instancesSet.item[0].privateIpAddressV6.should.equal 'xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx'
410
+ response.instancesSet.item[0].ipAddressV6.should.equal nil
411
+ response.instancesSet.item[0].architecture.should.equal 'i386'
412
+ response.instancesSet.item[0].rootDeviceType.should.equal 'disk'
413
+ response.instancesSet.item[0].blockDeviceMapping.should.equal nil
414
+ response.instancesSet.item[0].accountingType.should.equal '2'
415
+ response.instancesSet.item[0].ipType.should.equal 'static'
416
+ end
417
+
418
+ specify "run_instances - パラメータが正しく作られるか" do
419
+ @api.stubs(:make_request).with('Action' => 'RunInstances',
420
+ 'ImageId' => '1',
421
+ 'MinCount' => '1',
422
+ 'MaxCount' => '3',
423
+ 'KeyName' => 'key',
424
+ 'SecurityGroup.1' => 'gr1',
425
+ 'SecurityGroup.2' => 'gr2',
426
+ 'UserData' => 'data',
427
+ 'AddressingType' => 'type',
428
+ 'InstanceType' => 'mini',
429
+ 'Placement.GroupName' => 'gr1',
430
+ 'Placement.AvailabilityZone' => 'zone',
431
+ 'KernelId' => 'kernel',
432
+ 'RamdiskId' => 'ram',
433
+ 'BlockDeviceMapping.1.DeviceName' => 'dev1',
434
+ 'BlockDeviceMapping.1.VirtualName' => 'vir1',
435
+ 'BlockDeviceMapping.1.Ebs.SnapshotId' => 'snap1',
436
+ 'BlockDeviceMapping.1.Ebs.VolumeSize' => 'size1',
437
+ 'BlockDeviceMapping.1.Ebs.DeleteOnTermination' => 'del1',
438
+ 'BlockDeviceMapping.1.Ebs.NoDevice' => 'nodev1',
439
+ 'BlockDeviceMapping.2.DeviceName' => 'dev2',
440
+ 'BlockDeviceMapping.2.VirtualName' => 'vir2',
441
+ 'BlockDeviceMapping.2.Ebs.SnapshotId' => 'snap2',
442
+ 'BlockDeviceMapping.2.Ebs.VolumeSize' => 'size2',
443
+ 'BlockDeviceMapping.2.Ebs.DeleteOnTermination' => 'del2',
444
+ 'BlockDeviceMapping.2.Ebs.NoDevice' => 'nodev2',
445
+ 'Monitoring.Enabled' => 'en',
446
+ 'SubnetId' => 'sub',
447
+ 'DisableApiTermination' => 'false',
448
+ 'InstanceInitiatedShutdownBehavior' => 'aaa',
449
+ 'AccountingType' => '1',
450
+ 'InstanceId' => 'server01',
451
+ 'Admin' => 'admin',
452
+ 'Password' => 'pass',
453
+ 'IpType' => 'static'
454
+ ).returns stub(:body => @run_instances_response_body, :is_a? => true)
455
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
456
+ response = @api.run_instances(:image_id => 1, :min_count => 1, :max_count => 3, :key_name => 'key', :security_group => %w(gr1 gr2), :user_data => 'data',
457
+ :addressing_type => 'type', :instance_type => 'mini', :group_name => 'gr1', :availability_zone => 'zone', :kernel_id => 'kernel',
458
+ :ramdisk_id => 'ram',
459
+ :block_device_mapping => [{:device_name => 'dev1', :virtual_name => 'vir1', :ebs_snapshot_id => 'snap1', :ebs_volume_size => 'size1',
460
+ :ebs_delete_on_termination => 'del1', :ebs_no_device => 'nodev1'},
461
+ {:device_name => 'dev2', :virtual_name => 'vir2', :ebs_snapshot_id => 'snap2', :ebs_volume_size => 'size2',
462
+ :ebs_delete_on_termination => 'del2', :ebs_no_device => 'nodev2'}],
463
+ :monitoring_enabled => 'en', :subnet_id => 'sub', :disable_api_termination => false, :instance_initiated_shutdown_behavior => 'aaa',
464
+ :accounting_type => 1, :instance_id => 'server01', :admin => 'admin', :password => 'pass', :ip_type => 'static')
465
+ end
466
+
467
+ specify "run_instances - :image_id, :key_name, :password正常" do
468
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
469
+ lambda { @api.run_instances(:security_group => "gr01", :image_id => 2, :key_name => 'Keyname', :password => 'password') }.should.not.raise(NIFTY::ArgumentError)
470
+ lambda { @api.run_instances(:security_group => "gr01", :image_id => '10', :key_name => 'Keyname', :password => 'password') }.should.not.raise(NIFTY::ArgumentError)
471
+ lambda { @api.run_instances(:security_group => "gr01", :image_id => '10', :key_name => 'Keyname', :password => 'password') }.should.not.raise(NIFTY::ArgumentError)
472
+ lambda { @api.run_instances(:security_group => "gr01", :image_id => 10000, :password => 'Password') }.should.not.raise(NIFTY::ArgumentError)
473
+ end
474
+
475
+ specify "run_instances - :min_count正常" do
476
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
477
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:min_count => 1)) }.should.not.raise(NIFTY::ArgumentError)
478
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:min_count => '10')) }.should.not.raise(NIFTY::ArgumentError)
479
+ end
480
+
481
+ specify "run_instances - :max_count正常" do
482
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
483
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:max_count => 1)) }.should.not.raise(NIFTY::ArgumentError)
484
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:max_count => '10')) }.should.not.raise(NIFTY::ArgumentError)
485
+ end
486
+
487
+ specify "run_instances - :security_group正常" do
488
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
489
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:security_group => 'Group1')) }.should.not.raise(NIFTY::ArgumentError)
490
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:security_group => 'default(Linux)')) }.should.not.raise(NIFTY::ArgumentError)
491
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:security_group => 'default(Windows)')) }.should.not.raise(NIFTY::ArgumentError)
492
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:security_group => %w(Group1 Group2 Group3))) }.should.not.raise(NIFTY::ArgumentError)
493
+ end
494
+
495
+ specify "run_instances - :additional_info正常" do
496
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
497
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:additional_info => 'add')) }.should.not.raise(NIFTY::ArgumentError)
498
+ end
499
+
500
+ specify "run_instances - :user_data正常" do
501
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
502
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:user_data => 'data')) }.should.not.raise(NIFTY::ArgumentError)
503
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:user_data => 'data', :base64_encoded => true)) }.should.not.raise(NIFTY::ArgumentError)
504
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:user_data => 'data', :base64_encoded => false)) }.should.not.raise(NIFTY::ArgumentError)
505
+ end
506
+
507
+ specify "run_instances - :addressing_type正常" do
508
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
509
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:addressing_type => 'addressing')) }.should.not.raise(NIFTY::ArgumentError)
510
+ end
511
+
512
+ specify "run_instances - :instance_type正常" do
513
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
514
+ @valid_instance_type.each do |type|
515
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:instance_type => type)) }.should.not.raise(NIFTY::ArgumentError)
516
+ end
517
+ end
518
+
519
+ specify "run_instances - :availability_zone正常" do
520
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
521
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:availability_zone => 'ap-japan-1a')) }.should.not.raise(NIFTY::ArgumentError)
522
+ end
523
+
524
+ specify "run_instances - :group_name正常" do
525
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
526
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:group_name => 'group')) }.should.not.raise(NIFTY::ArgumentError)
527
+ end
528
+
529
+ specify "run_instances - :kernel_id正常" do
530
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
531
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:kernel_id => 'kernel')) }.should.not.raise(NIFTY::ArgumentError)
532
+ end
533
+
534
+ specify "run_instances - :ramdisk_id正常" do
535
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
536
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:ramdisk_id => 'ramdisk')) }.should.not.raise(NIFTY::ArgumentError)
537
+ end
538
+
539
+ specify "run_instances - :block_device_mapping正常" do
540
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
541
+ mapping = {
542
+ :device_name => 'dev', :virtual_name => 'virtual', :ebs_snapshot_id => 'snapshot', :ebs_volume_size => 'volsize',
543
+ :ebs_delete_on_termination => 'deleteOnTermination', :ebs_no_device => 'nodev'
544
+ }
545
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:block_device_mapping => mapping)) }.should.not.raise(NIFTY::ArgumentError)
546
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:block_device_mapping => [mapping, mapping])) }.should.not.raise(NIFTY::ArgumentError)
547
+ end
548
+
549
+ specify "run_instances - :monitoring_enabled正常" do
550
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
551
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:monitoring_enabled => 'enabled')) }.should.not.raise(NIFTY::ArgumentError)
552
+ end
553
+
554
+ specify "run_instances - :subnet_id正常" do
555
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
556
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:subnet_id => 'subnet')) }.should.not.raise(NIFTY::ArgumentError)
557
+ end
558
+
559
+ specify "run_instances - :disable_api_termination正常" do
560
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
561
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:disable_api_termination => true)) }.should.not.raise(NIFTY::ArgumentError)
562
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:disable_api_termination => false)) }.should.not.raise(NIFTY::ArgumentError)
563
+ end
564
+
565
+ specify "run_instances - :instance_initiated_shutdown_behavior正常" do
566
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
567
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:instance_initiated_shutdown_behavior => 'behavior')) }.should.not.raise(NIFTY::ArgumentError)
568
+ end
569
+
570
+ specify "run_instances - :accounting_type正常" do
571
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
572
+ @accounting_type.each do |type|
573
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:accounting_type => type)) }.should.not.raise(NIFTY::ArgumentError)
574
+ end
575
+ end
576
+
577
+ specify "run_instances - :instance_id正常" do
578
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
579
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:instance_id => 'server01')) }.should.not.raise(NIFTY::ArgumentError)
580
+ end
581
+
582
+ specify "run_instances - :admin正常" do
583
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
584
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:admin => 'admin')) }.should.not.raise(NIFTY::ArgumentError)
585
+ end
586
+
587
+ specify "run_instances - :ip_type正常" do
588
+ @api.stubs(:exec_request).returns stub(:body => @run_instances_response_body, :is_a? => true)
589
+ @valid_ip_type.each do |type|
590
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:ip_type => type)) }.should.not.raise(NIFTY::ArgumentError)
591
+ end
592
+ end
593
+
594
+ specify "run_instances - :image_id未指定/不正" do
595
+ lambda { @api.run_instances }.should.raise(NIFTY::ArgumentError)
596
+ lambda { @api.run_instances(:image_id => '') }.should.raise(NIFTY::ArgumentError)
597
+ lambda { @api.run_instances(:image_id => nil) }.should.raise(NIFTY::ArgumentError)
598
+ end
599
+
600
+ specify "run_instances - :key_name未指定/不正" do
601
+ lambda { @api.run_instances(:image_id => 1, :key_name => "Key_name") }.should.raise(NIFTY::ArgumentError)
602
+ lambda { @api.run_instances(:image_id => 10000, :key_name => "Key_name") }.should.raise(NIFTY::ArgumentError)
603
+ end
604
+
605
+ specify "run_instances - :security_group不正" do
606
+ lambda { @api.run_instances(:image_id => 10000, :key_name => "Keyname", :security_group => "Group_name") }.should.raise(NIFTY::ArgumentError)
607
+ lambda { @api.run_instances(:image_id => 10000, :key_name => "Keyname", :security_group => %w(Group1 Group_2)) }.should.raise(NIFTY::ArgumentError)
608
+ end
609
+
610
+ specify "run_instances - :instance_type不正" do
611
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:instance_type => 'type')) }.should.raise(NIFTY::ArgumentError)
612
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:instance_type => 5)) }.should.raise(NIFTY::ArgumentError)
613
+ end
614
+
615
+ specify "run_instances - :disable_api_termination不正" do
616
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:disable_api_termination => 'disable')) }.should.raise(NIFTY::ArgumentError)
617
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:disable_api_termination => 0)) }.should.raise(NIFTY::ArgumentError)
618
+ end
619
+
620
+ specify "run_instances - :accounting_type不正" do
621
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:accounting_type => 3)) }.should.raise(NIFTY::ArgumentError)
622
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:accounting_type => 'type')) }.should.raise(NIFTY::ArgumentError)
623
+ end
624
+
625
+ specify "run_instances - :password未指定/不正" do
626
+ lambda { @api.run_instances(:image_id => 1) }.should.raise(NIFTY::ArgumentError)
627
+ lambda { @api.run_instances(:image_id => 1, :password => nil) }.should.raise(NIFTY::ArgumentError)
628
+ lambda { @api.run_instances(:image_id => 1, :password => '') }.should.raise(NIFTY::ArgumentError)
629
+ lambda { @api.run_instances(:image_id => 1, :password => 'Pass_word') }.should.raise(NIFTY::ArgumentError)
630
+ end
631
+
632
+ specify "run_instances - :ip_type不正" do
633
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:ip_type => 'ip')) }.should.raise(NIFTY::ArgumentError)
634
+ lambda { @api.run_instances(@basic_run_instances_options.merge(:ip_type => 5)) }.should.raise(NIFTY::ArgumentError)
635
+ end
636
+
637
+
638
+ # start_instances
639
+ specify "start_instances - レスポンスを正しく解析できるか" do
640
+ @api.stubs(:exec_request).returns stub(:body => @start_instances_response_body, :is_a? => true)
641
+
642
+ response = @api.start_instances(:instance_id => 'i-10a64379')
643
+ response.instancesSet.item[0].instanceId.should.equal 'i-10a64379'
644
+ response.instancesSet.item[0].currentState.code.should.equal '0'
645
+ response.instancesSet.item[0].currentState.name.should.equal 'pending'
646
+ response.instancesSet.item[0].previousState.code.should.equal '80'
647
+ response.instancesSet.item[0].previousState.name.should.equal 'stopped'
648
+ end
649
+
650
+ specify "start_instances - パラメータが正しく作られるか" do
651
+ @api.stubs(:make_request).with('Action' => 'StartInstances',
652
+ 'InstanceId.1' => 'server01',
653
+ 'InstanceId.2' => 'server02',
654
+ 'InstanceType.1' => 'mini',
655
+ 'InstanceType.2' => 'mini',
656
+ 'AccountingType.1' => '1',
657
+ 'AccountingType.2' => '1'
658
+ ).returns stub(:body => @start_instances_response_body, :is_a? => true)
659
+ @api.stubs(:exec_request).returns stub(:body => @start_instances_response_body, :is_a? => true)
660
+ response = @api.start_instances( :instance_id => %w(server01 server02), :instance_type => %w(mini mini), :accounting_type => %w(1 1) )
661
+ end
662
+
663
+ specify "start_instances - :instance_id未指定" do
664
+ lambda { @api.start_instances }.should.raise(NIFTY::ArgumentError)
665
+ lambda { @api.start_instances(:instance_id => nil) }.should.raise(NIFTY::ArgumentError)
666
+ lambda { @api.start_instances(:instance_id => '') }.should.raise(NIFTY::ArgumentError)
667
+ end
668
+
669
+ specify "start_instances - :instance_type正常" do
670
+ @api.stubs(:exec_request).returns stub(:body => @start_instances_response_body, :is_a? => true)
671
+
672
+ @valid_instance_type.each do |type|
673
+ lambda { @api.start_instances(:instance_id => 'i-10a64379', :instance_type => type) }.should.not.raise(NIFTY::ArgumentError)
674
+ end
675
+ end
676
+
677
+ specify "start_instances - :instance_type不正" do
678
+ lambda { @api.start_instances(:instance_id => 'i-10a64379', :instance_type => 'foo') }.should.raise(NIFTY::ArgumentError)
679
+ end
680
+
681
+ specify "start_instances - :accounting_type正常" do
682
+ @api.stubs(:exec_request).returns stub(:body => @start_instances_response_body, :is_a? => true)
683
+
684
+ lambda { @api.start_instances(:instance_id => 'i-10a64379', :accounting_type => nil) }.should.not.raise(NIFTY::ArgumentError)
685
+ lambda { @api.start_instances(:instance_id => 'i-10a64379', :accounting_type => '') }.should.not.raise(NIFTY::ArgumentError)
686
+ lambda { @api.start_instances(:instance_id => 'i-10a64379', :accounting_type => '1') }.should.not.raise(NIFTY::ArgumentError)
687
+ lambda { @api.start_instances(:instance_id => 'i-10a64379', :accounting_type => '2') }.should.not.raise(NIFTY::ArgumentError)
688
+ end
689
+ specify "start_instances - :accounting_type不正" do
690
+ lambda { @api.start_instances(:instance_id => 'i-10a64379', :accounting_type => 'foo') }.should.raise(NIFTY::ArgumentError)
691
+ end
692
+
693
+
694
+ # stop_instances
695
+ specify "stop_instances - レスポンスを正しく解析できるか" do
696
+ @api.stubs(:exec_request).returns stub(:body => @stop_instances_response_body, :is_a? => true)
697
+
698
+ response = @api.stop_instances(:instance_id => ['i-10a64379'])
699
+ response.instancesSet.item[0].instanceId.should.equal 'i-10a64379'
700
+ response.instancesSet.item[0].currentState.code.should.equal '64'
701
+ response.instancesSet.item[0].currentState.name.should.equal 'stopping'
702
+ response.instancesSet.item[0].previousState.code.should.equal '16'
703
+ response.instancesSet.item[0].previousState.name.should.equal 'running'
704
+ end
705
+
706
+ specify "stop_instances - パラメータが正しく作られるか" do
707
+ @api.stubs(:make_request).with('Action' => 'StopInstances',
708
+ 'InstanceId.1' => 'server01',
709
+ 'InstanceId.2' => 'server02',
710
+ 'Force' => 'false'
711
+ ).returns stub(:body => @stop_instances_response_body, :is_a? => true)
712
+ @api.stubs(:exec_request).returns stub(:body => @stop_instances_response_body, :is_a? => true)
713
+ response = @api.stop_instances( :instance_id => %w(server01 server02), :force => false )
714
+ end
715
+
716
+ specify "stop_instances - :instance_id未指定" do
717
+ lambda { @api.stop_instances }.should.raise(NIFTY::ArgumentError)
718
+ lambda { @api.stop_instances(:instance_id => nil) }.should.raise(NIFTY::ArgumentError)
719
+ lambda { @api.stop_instances(:instance_id => '') }.should.raise(NIFTY::ArgumentError)
720
+ end
721
+
722
+ specify "stop_instances - :force正常" do
723
+ @api.stubs(:exec_request).returns stub(:body => @stop_instances_response_body, :is_a? => true)
724
+
725
+ lambda { response = @api.stop_instances(:instance_id => ['i-10a64379'], :force => true) }.should.not.raise(NIFTY::ArgumentError)
726
+ lambda { response = @api.stop_instances(:instance_id => ['i-10a64379'], :force => false) }.should.not.raise(NIFTY::ArgumentError)
727
+ lambda { @api.stop_instances(:instance_id => ['i-10a64379'], :force => '') }.should.not.raise(NIFTY::ArgumentError)
728
+ lambda { @api.stop_instances(:instance_id => ['i-10a64379'], :force => nil) }.should.not.raise(NIFTY::ArgumentError)
729
+ end
730
+
731
+ specify "stop_instances - :force不正" do
732
+ lambda { @api.stop_instances(:instance_id => ['i-10a64379'], :force => 'foo') }.should.raise(NIFTY::ArgumentError)
733
+ end
734
+
735
+
736
+ # reboot_instance
737
+ specify "reboot_instances - レスポンスを正しく解析できるか" do
738
+ @api.stubs(:exec_request).returns stub(:body => @reboot_instances_response_body, :is_a? => true)
739
+
740
+ response = @api.reboot_instances(:instance_id => ['i-28a64341'])
741
+ response.return.should.equal 'true'
742
+ end
743
+
744
+ specify "reboot_instances - パラメータが正しく作られるか" do
745
+ @api.stubs(:make_request).with('Action' => 'RebootInstances',
746
+ 'InstanceId.1' => 'server01',
747
+ 'InstanceId.2' => 'server02',
748
+ 'Force' => 'false'
749
+ ).returns stub(:body => @reboot_instances_response_body, :is_a? => true)
750
+ @api.stubs(:exec_request).returns stub(:body => @reboot_instances_response_body, :is_a? => true)
751
+ response = @api.reboot_instances( :instance_id => %w(server01 server02), :force => false )
752
+ end
753
+
754
+ specify "reboot_instances - :force正常" do
755
+ @api.stubs(:exec_request).returns stub(:body => @reboot_instances_response_body, :is_a? => true)
756
+ lambda { @api.reboot_instances(:instance_id => 'i-28a64341', :force => true) }.should.not.raise(NIFTY::ArgumentError)
757
+ lambda { @api.reboot_instances(:instance_id => 'i-28a64341', :force => false) }.should.not.raise(NIFTY::ArgumentError)
758
+ lambda { @api.reboot_instances(:instance_id => 'i-28a64341', :force => '') }.should.not.raise(NIFTY::ArgumentError)
759
+ lambda { @api.reboot_instances(:instance_id => 'i-28a64341', :force => nil) }.should.not.raise(NIFTY::ArgumentError)
760
+ end
761
+
762
+ specify "reboot_instances - :instance_id未指定" do
763
+ lambda { @api.reboot_instances }.should.raise(NIFTY::ArgumentError)
764
+ lambda { @api.reboot_instances(:instance_id => nil) }.should.raise(NIFTY::ArgumentError)
765
+ lambda { @api.reboot_instances(:instance_id => '') }.should.raise(NIFTY::ArgumentError)
766
+ end
767
+
768
+ specify "reboot_instances - :force異常" do
769
+ lambda { @api.reboot_instances(:instance_id => 'i-28a64341', :force => 'foo') }.should.raise(NIFTY::ArgumentError)
770
+ end
771
+
772
+
773
+ # terminate_instances
774
+ specify "terminate_instances - レスポンスを正しく解析できるか" do
775
+ @api.stubs(:exec_request).returns stub(:body => @terminate_instances_response_body, :is_a? => true)
776
+ response = @api.terminate_instances(:instance_id => 'i-3ea74257')
777
+ response.instancesSet.item[0].instanceId.should.equal 'i-3ea74257'
778
+ response.instancesSet.item[0].currentState.should.equal nil
779
+ response.instancesSet.item[0].previousState.should.equal nil
780
+ end
781
+
782
+ specify "terminate_instances - パラメータが正しく作られるか" do
783
+ @api.stubs(:make_request).with('Action' => 'TerminateInstances',
784
+ 'InstanceId.1' => 'server01',
785
+ 'InstanceId.2' => 'server02'
786
+ ).returns stub(:body => @terminate_instances_response_body, :is_a? => true)
787
+ @api.stubs(:exec_request).returns stub(:body => @terminate_instances_response_body, :is_a? => true)
788
+ response = @api.terminate_instances( :instance_id => %w(server01 server02) )
789
+ end
790
+
791
+
792
+ specify "terminate_instances - :instance_id正常" do
793
+ @api.stubs(:exec_request).returns stub(:body => @terminate_instances_response_body, :is_a? => true)
794
+ lambda { @api.terminate_instances(:instance_id => 'foo') }.should.not.raise(NIFTY::ArgumentError)
795
+ lambda { @api.terminate_instances(:instance_id => %w(foo bar hoge)) }.should.not.raise(NIFTY::ArgumentError)
796
+ end
797
+
798
+ specify "terminate_instances - :instance_id未指定" do
799
+ lambda { @api.terminate_instances }.should.raise(NIFTY::ArgumentError)
800
+ lambda { @api.terminate_instances(:instance_id => nil) }.should.raise(NIFTY::ArgumentError)
801
+ lambda { @api.terminate_instances(:instance_id => '') }.should.raise(NIFTY::ArgumentError)
802
+ end
803
+
804
+
805
+ # copy_instances
806
+ specify "copy_instances - レスポンスを正しく解析できるか" do
807
+ @api.stubs(:exec_request).returns stub(:body => @copy_instances_response_body, :is_a? => true)
808
+ response = @api.copy_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver')
809
+ response.copyInstanceSet.member[0].instanceId.should.equal 'copyinstance-01'
810
+ response.copyInstanceSet.member[0].instanceState.should.equal 'creating'
811
+ response.copyInstanceSet.member[1].instanceId.should.equal 'copyinstance-02'
812
+ response.copyInstanceSet.member[1].instanceState.should.equal 'wait'
813
+ end
814
+
815
+ specify "copy_instances - パラメータが正しく作られるか" do
816
+ @api.stubs(:make_request).with('Action' => 'CopyInstances',
817
+ 'InstanceId' => 'server01',
818
+ 'CopyInstance.InstanceName' => 'cpy',
819
+ 'CopyInstance.InstanceType' => 'mini',
820
+ 'CopyInstance.AccountingType' => '1',
821
+ 'CopyInstance.ipType' => 'static',
822
+ 'CopyInstance.LoadBalancers.1.LoadBalancerName' => 'lb1',
823
+ 'CopyInstance.LoadBalancers.1.LoadBalancerPort' => '80',
824
+ 'CopyInstance.LoadBalancers.1.InstancePort' => '80',
825
+ 'CopyInstance.LoadBalancers.2.LoadBalancerName' => 'lb2',
826
+ 'CopyInstance.LoadBalancers.2.LoadBalancerPort' => '80',
827
+ 'CopyInstance.LoadBalancers.2.InstancePort' => '80',
828
+ 'CopyInstance.SecurityGroup.1' => 'gr1',
829
+ 'CopyInstance.SecurityGroup.2' => 'gr2',
830
+ 'CopyCount' => '2'
831
+ ).returns stub(:body => @copy_instances_response_body, :is_a? => true)
832
+ @api.stubs(:exec_request).returns stub(:body => @copy_instances_response_body, :is_a? => true)
833
+ response = @api.copy_instances( :instance_id => "server01", :instance_name => 'cpy', :instance_type => 'mini', :accounting_type => 1, :ip_type => 'static',
834
+ :load_balancers => [{:load_balancer_name => 'lb1', :load_balancer_port => 80, :instance_port => 80},
835
+ {:load_balancer_name => 'lb2', :load_balancer_port => 80, :instance_port => 80}],
836
+ :security_group => %w(gr1 gr2), :copy_count => 2
837
+ )
838
+ end
839
+
840
+
841
+ specify "copy_instances - :instance_type正常" do
842
+ @api.stubs(:exec_request).returns stub(:body => @copy_instances_response_body, :is_a? => true)
843
+
844
+ @valid_instance_type.each do |type|
845
+ lambda { @api.reboot_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver', :instance_type => type) }.should.not.raise(NIFTY::ArgumentError)
846
+ end
847
+ end
848
+
849
+ specify "copy_instances - :instance_type異常" do
850
+
851
+ lambda { @api.copy_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver', :instance_type => 'foo') }.should.raise(NIFTY::ArgumentError)
852
+ end
853
+
854
+ specify "copy_instances - :accounting_type正常" do
855
+ @api.stubs(:exec_request).returns stub(:body => @copy_instances_response_body, :is_a? => true)
856
+
857
+ @accounting_type.each do |type|
858
+ lambda { @api.copy_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver', :accounting_type => type) }.should.not.raise(NIFTY::ArgumentError)
859
+ end
860
+ lambda { @api.copy_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver', :accounting_type => '') }.should.not.raise(NIFTY::ArgumentError)
861
+ end
862
+
863
+ specify "copy_instances - :accounting_type異常" do
864
+ lambda { @api.copy_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver', :accounting_type => 'foo') }.should.raise(NIFTY::ArgumentError)
865
+ end
866
+
867
+ specify "copy_instances - load_balancers正常" do
868
+ @api.stubs(:exec_request).returns stub(:body => @copy_instances_response_body, :is_a? => true)
869
+
870
+ [ [nil, nil, nil],
871
+ ['', '', ''],
872
+ ['lb1', 80, 80]
873
+ ].each do |val|
874
+ lambda { @api.copy_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver',
875
+ :load_balancers => {:load_balancer_name => val[0],
876
+ :load_balancer_port => val[1],
877
+ :instance_port => val[2]}) }.should.not.raise(NIFTY::ArgumentError)
878
+ end
879
+ lambda { @api.copy_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver', :load_balancers => nil) }.should.not.raise(NIFTY::ArgumentError)
880
+ lambda { @api.copy_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver', :load_balancers => {}) }.should.not.raise(NIFTY::ArgumentError)
881
+ lambda { @api.copy_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver', :load_balancers => []) }.should.not.raise(NIFTY::ArgumentError)
882
+ end
883
+
884
+ specify "copy_instances - :security_group正常" do
885
+ @api.stubs(:exec_request).returns stub(:body => @copy_instances_response_body, :is_a? => true)
886
+
887
+ lambda { @api.copy_instances(:instance_id => 'server01', :instance_name => 'copyserver', :security_group => [nil, '', 'foo', 'bar']) }.should.not.raise(NIFTY::ArgumentError)
888
+ lambda { @api.copy_instances(:instance_id => 'server01', :instance_name => 'copyserver', :security_group => "default(Linux)") }.should.not.raise(NIFTY::ArgumentError)
889
+ lambda { @api.copy_instances(:instance_id => 'server01', :instance_name => 'copyserver', :security_group => "default(Windows)") }.should.not.raise(NIFTY::ArgumentError)
890
+ end
891
+
892
+ specify "copy_instances - :copy_count正常" do
893
+ @api.stubs(:exec_request).returns stub(:body => @copy_instances_response_body, :is_a? => true)
894
+ [
895
+ 1, '6'
896
+ ].each do |count|
897
+ lambda { @api.copy_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver', :copy_count => 1) }.should.not.raise(NIFTY::ArgumentError)
898
+ lambda { @api.copy_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver', :copy_count => '5') }.should.not.raise(NIFTY::ArgumentError)
899
+ end
900
+ end
901
+
902
+ specify "copy_instances - :copy_count不正" do
903
+ [
904
+ 0, -1, 'foo'
905
+ ].each do |count|
906
+ lambda { @api.copy_instances(:security_group => "Group", :instance_id => 'server01', :instance_name => 'copyserver', :copy_count => count) }.should.raise(NIFTY::ArgumentError)
907
+ end
908
+ end
909
+
910
+ specify "copy_instances - :security_group不正" do
911
+ lambda { @api.copy_instances(:security_group => "Group_name", :instance_id => 'server01', :instance_name => 'copyserver') }.should.raise(NIFTY::ArgumentError)
912
+ end
913
+
914
+
915
+ # cancel_copy_instances
916
+ specify "cancel_copy_instances - レスポンスを正しく解析できるか" do
917
+ @api.stubs(:exec_request).returns stub(:body => @cancel_copy_instances_response_body, :is_a? => true)
918
+ response = @api.cancel_copy_instances(:instance_id => 'copyserver')
919
+ response.requestId.should.equal 'f6dd8353-eb6b-6b4fd32e4f05'
920
+ end
921
+
922
+ specify "cancel_copy_instances - パラメータが正しく作られるか" do
923
+ @api.stubs(:make_request).with('Action' => 'CancelCopyInstances', 'InstanceId' => 'server01'
924
+ ).returns stub(:body => @cancel_copy_instances_response_body, :is_a? => true)
925
+ @api.stubs(:exec_request).returns stub(:body => @cancel_copy_instances_response_body, :is_a? => true)
926
+ response = @api.cancel_copy_instances( :instance_id => "server01" )
927
+ end
928
+
929
+
930
+ specify "cancel_copy_instances - :instance_id正常" do
931
+ @api.stubs(:exec_request).returns stub(:body => @cancel_copy_instances_response_body, :is_a? => true)
932
+ lambda { @api.cancel_copy_instances(:instance_id => 'foo') }.should.not.raise(NIFTY::ArgumentError)
933
+ lambda { @api.cancel_copy_instances(:instance_id => 12345) }.should.not.raise(NIFTY::ArgumentError)
934
+ end
935
+
936
+ specify "cancel_copy_instances - :instance_id未指定" do
937
+ lambda { @api.cancel_copy_instances }.should.raise(NIFTY::ArgumentError)
938
+ lambda { @api.cancel_copy_instances(:instance_id => nil) }.should.raise(NIFTY::ArgumentError)
939
+ lambda { @api.cancel_copy_instances(:instance_id => '') }.should.raise(NIFTY::ArgumentError)
940
+ end
941
+ end