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,33 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # ニフティクラウドSDK for Ruby
4
+ #
5
+ # Ruby Gem Name:: nifty-cloud-sdk
6
+ # Author:: NIFTY Corporation
7
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://cloud.nifty.com/api/
10
+ #++
11
+
12
+ require 'rubygems'
13
+ require File.dirname(__FILE__) + "/../../lib/NIFTY"
14
+ require 'pp'
15
+
16
+ ACCESS_KEY = ENV["NIFTY_CLOUD_ACCESS_KEY"] || "<Your Access Key ID>"
17
+ SECRET_KEY = ENV["NIFTY_CLOUD_SECRET_KEY"] || "<Your Secret Access Key>"
18
+
19
+
20
+ ncs4r = NIFTY::Cloud::Base.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY)
21
+
22
+ options = {
23
+ #:group_name => "groupName",
24
+ #:activity_date => "yyyymmdd",
25
+ #:range_all => false,
26
+ #:range_start_number => 1,
27
+ #:range_end_number => 100
28
+ }
29
+
30
+ pp response = ncs4r.describe_security_activities(options)
31
+
32
+ p response.groupName
33
+ p response.log
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # ニフティクラウドSDK for Ruby
4
+ #
5
+ # Ruby Gem Name:: nifty-cloud-sdk
6
+ # Author:: NIFTY Corporation
7
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://cloud.nifty.com/api/
10
+ #++
11
+
12
+ require 'rubygems'
13
+ require File.dirname(__FILE__) + "/../../lib/NIFTY"
14
+ require 'pp'
15
+
16
+ ACCESS_KEY = ENV["NIFTY_CLOUD_ACCESS_KEY"] || "<Your Access Key ID>"
17
+ SECRET_KEY = ENV["NIFTY_CLOUD_SECRET_KEY"] || "<Your Secret Access Key>"
18
+
19
+
20
+ ncs4r = NIFTY::Cloud::Base.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY)
21
+
22
+ options = {
23
+ #:group_name => ["groupName"],
24
+ #:filter => [{:name => "group-name",
25
+ # :value => "groupName"}]
26
+ }
27
+
28
+ pp response = ncs4r.describe_security_groups(options)
29
+
30
+ response.securityGroupInfo.item.each do |security_group|
31
+ p security_group.ownerId
32
+ p security_group.groupName
33
+ p security_group.groupDescription
34
+ p security_group.groupStatus
35
+ if ip_permissions = security_group.ipPermissions
36
+ ip_permissions.item.each do |ip_permission|
37
+ p ip_permission.ipProtocol
38
+ p ip_permission.fromPort
39
+ p ip_permission.toPort
40
+ p ip_permission.inOut
41
+ if groups = ip_permission.groups
42
+ groups.item.each do |group|
43
+ p group.userId
44
+ p group.groupName
45
+ end
46
+ end
47
+ if ip_ranges = ip_permission.ipRanges
48
+ ip_ranges.item.each do |ip_range|
49
+ p ip_range.cidrIp
50
+ end
51
+ end
52
+ end
53
+ end
54
+ if instances_set = security_group.instancesSet
55
+ instances_set.item.each do |instance|
56
+ p instance.instanceId
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # ニフティクラウドSDK for Ruby
4
+ #
5
+ # Ruby Gem Name:: nifty-cloud-sdk
6
+ # Author:: NIFTY Corporation
7
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://cloud.nifty.com/api/
10
+ #++
11
+
12
+ require 'rubygems'
13
+ require File.dirname(__FILE__) + "/../../lib/NIFTY"
14
+ require 'pp'
15
+
16
+ ACCESS_KEY = ENV["NIFTY_CLOUD_ACCESS_KEY"] || "<Your Access Key ID>"
17
+ SECRET_KEY = ENV["NIFTY_CLOUD_SECRET_KEY"] || "<Your Secret Access Key>"
18
+
19
+
20
+ ncs4r = NIFTY::Cloud::Base.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY)
21
+
22
+ options = {
23
+ #:group_name => "groupName",
24
+ #:instance_id => ["instanceId"]
25
+ }
26
+
27
+ pp response = ncs4r.register_instances_with_security_group(options)
28
+
29
+ response.instancesSet.item.each do |instance|
30
+ p instance.instanceId
31
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # ニフティクラウドSDK for Ruby
4
+ #
5
+ # Ruby Gem Name:: nifty-cloud-sdk
6
+ # Author:: NIFTY Corporation
7
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://cloud.nifty.com/api/
10
+ #++
11
+
12
+ require 'rubygems'
13
+ require File.dirname(__FILE__) + "/../../lib/NIFTY"
14
+ require 'pp'
15
+
16
+ ACCESS_KEY = ENV["NIFTY_CLOUD_ACCESS_KEY"] || "<Your Access Key ID>"
17
+ SECRET_KEY = ENV["NIFTY_CLOUD_SECRET_KEY"] || "<Your Secret Access Key>"
18
+
19
+
20
+ ncs4r = NIFTY::Cloud::Base.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY)
21
+
22
+ options = {
23
+ #:user_id => "userId",
24
+ #:group_name => "group01",
25
+ #:ip_permissions => [{:ip_protocl => "ipProtocol",
26
+ # :from_port => 0,
27
+ # :to_port => 0,
28
+ # :in_out => "inOut",
29
+ # :user_id => "userId",
30
+ # :group_name => "groupName",
31
+ # :cidr_ip => "*.*.*.*"}]
32
+ }
33
+
34
+ pp response = ncs4r.revoke_security_group_ingress(options)
35
+
36
+ p response.return
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # ニフティクラウドSDK for Ruby
4
+ #
5
+ # Ruby Gem Name:: nifty-cloud-sdk
6
+ # Author:: NIFTY Corporation
7
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://cloud.nifty.com/api/
10
+ #++
11
+
12
+ require 'rubygems'
13
+ require File.dirname(__FILE__) + "/../../lib/NIFTY"
14
+ require 'pp'
15
+
16
+ ACCESS_KEY = ENV["NIFTY_CLOUD_ACCESS_KEY"] || "<Your Access Key ID>"
17
+ SECRET_KEY = ENV["NIFTY_CLOUD_SECRET_KEY"] || "<Your Secret Access Key>"
18
+
19
+
20
+ ncs4r = NIFTY::Cloud::Base.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY)
21
+
22
+ options = {
23
+ #:group_name => "groupName",
24
+ #:group_name_update => "groupNameUpdate",
25
+ #:group_description_update => "groupDescriptionUpdate"
26
+ }
27
+
28
+ pp response = ncs4r.update_security_group(options)
29
+
30
+ p response.return
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # ニフティクラウドSDK for Ruby
4
+ #
5
+ # Ruby Gem Name:: nifty-cloud-sdk
6
+ # Author:: NIFTY Corporation
7
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://cloud.nifty.com/api/
10
+ #++
11
+
12
+ require 'rubygems'
13
+ require File.dirname(__FILE__) + "/../../lib/NIFTY"
14
+ require 'pp'
15
+
16
+ ACCESS_KEY = ENV["NIFTY_CLOUD_ACCESS_KEY"] || "<Your Access Key ID>"
17
+ SECRET_KEY = ENV["NIFTY_CLOUD_SECRET_KEY"] || "<Your Secret Access Key>"
18
+
19
+
20
+ ncs4r = NIFTY::Cloud::Base.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY)
21
+
22
+ options = {
23
+ #:volume_id => "volumeId",
24
+ #:instance_id => "instanceId",
25
+ #:device => "device"
26
+ }
27
+
28
+ pp response = ncs4r.attach_volume(options)
29
+
30
+ p response.volumeId
31
+ p response.instanceId
32
+ p response.device
33
+ p response.status
34
+ p response.attachTime
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # ニフティクラウドSDK for Ruby
4
+ #
5
+ # Ruby Gem Name:: nifty-cloud-sdk
6
+ # Author:: NIFTY Corporation
7
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://cloud.nifty.com/api/
10
+ #++
11
+
12
+ require 'rubygems'
13
+ require File.dirname(__FILE__) + "/../../lib/NIFTY"
14
+ require 'pp'
15
+
16
+ ACCESS_KEY = ENV["NIFTY_CLOUD_ACCESS_KEY"] || "<Your Access Key ID>"
17
+ SECRET_KEY = ENV["NIFTY_CLOUD_SECRET_KEY"] || "<Your Secret Access Key>"
18
+
19
+
20
+ ncs4r = NIFTY::Cloud::Base.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY)
21
+
22
+ options = {
23
+ #:size => "size",
24
+ #:snapshot_id => "snapshotId",
25
+ #:availability_zone => "availabilityZone",
26
+ #:volume_id => "volumeId",
27
+ #:disk_type => "diskType",
28
+ #:instance_id => "instanceId"
29
+ }
30
+
31
+ pp response = ncs4r.create_volume(options)
32
+ p response.volumeId
33
+ p response["size"]
34
+ p response.diskType
35
+ p response.snapshotId
36
+ p response.availabilityZone
37
+ p response.status
38
+ p response.createTime
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # ニフティクラウドSDK for Ruby
4
+ #
5
+ # Ruby Gem Name:: nifty-cloud-sdk
6
+ # Author:: NIFTY Corporation
7
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://cloud.nifty.com/api/
10
+ #++
11
+
12
+ require 'rubygems'
13
+ require File.dirname(__FILE__) + "/../../lib/NIFTY"
14
+ require 'pp'
15
+
16
+ ACCESS_KEY = ENV["NIFTY_CLOUD_ACCESS_KEY"] || "<Your Access Key ID>"
17
+ SECRET_KEY = ENV["NIFTY_CLOUD_SECRET_KEY"] || "<Your Secret Access Key>"
18
+
19
+
20
+ ncs4r = NIFTY::Cloud::Base.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY)
21
+
22
+ options = {
23
+ #:volume_id => "volumeId"
24
+ }
25
+
26
+ pp response = ncs4r.delete_volume(options)
27
+
28
+ p response.return
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # ニフティクラウドSDK for Ruby
4
+ #
5
+ # Ruby Gem Name:: nifty-cloud-sdk
6
+ # Author:: NIFTY Corporation
7
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://cloud.nifty.com/api/
10
+ #++
11
+
12
+ require 'rubygems'
13
+ require File.dirname(__FILE__) + "/../../lib/NIFTY"
14
+ require 'pp'
15
+
16
+ ACCESS_KEY = ENV["NIFTY_CLOUD_ACCESS_KEY"] || "<Your Access Key ID>"
17
+ SECRET_KEY = ENV["NIFTY_CLOUD_SECRET_KEY"] || "<Your Secret Access Key>"
18
+
19
+
20
+ ncs4r = NIFTY::Cloud::Base.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY)
21
+
22
+ options = {
23
+ #:volume_id => ["volumeId"]
24
+ }
25
+
26
+ pp response = ncs4r.describe_volumes(options)
27
+
28
+ response.volumeSet.item.each do |volume|
29
+ p volume.volumeId
30
+ p volume["size"]
31
+ p volume.diskType
32
+ p volume.snapshotId
33
+ p volume.availabilityZone
34
+ p volume.status
35
+ p volume.createTime
36
+ volume.attachmentSet.item.each do |attachment|
37
+ p attachment.volumeId
38
+ p attachment.instanceId
39
+ p attachment.device
40
+ p attachment.status
41
+ p attachment.attachTime
42
+ p attachment.deleteOnTermination
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # ニフティクラウドSDK for Ruby
4
+ #
5
+ # Ruby Gem Name:: nifty-cloud-sdk
6
+ # Author:: NIFTY Corporation
7
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://cloud.nifty.com/api/
10
+ #++
11
+
12
+ require 'rubygems'
13
+ require File.dirname(__FILE__) + "/../../lib/NIFTY"
14
+ require 'pp'
15
+
16
+ ACCESS_KEY = ENV["NIFTY_CLOUD_ACCESS_KEY"] || "<Your Access Key ID>"
17
+ SECRET_KEY = ENV["NIFTY_CLOUD_SECRET_KEY"] || "<Your Secret Access Key>"
18
+
19
+
20
+ ncs4r = NIFTY::Cloud::Base.new(:access_key => ACCESS_KEY, :secret_key => SECRET_KEY)
21
+
22
+ options = {
23
+ #:volume_id => "volumeId",
24
+ #:instance_id => "instanceId",
25
+ #:device => "device",
26
+ #:force => false
27
+ }
28
+
29
+ pp response = ncs4r.detach_volume(options)
30
+
31
+ p response.volumeId
32
+ p response.instanceId
33
+ p response.device
34
+ p response.status
35
+ p response.attachTime
@@ -0,0 +1,186 @@
1
+ #!ruby -W0
2
+ #--
3
+ # ニフティクラウドSDK for Ruby
4
+ #
5
+ # Ruby Gem Name:: nifty-cloud-sdk
6
+ # Author:: NIFTY Corporation
7
+ # Copyright:: Copyright 2011 NIFTY Corporation All Rights Reserved.
8
+ # License:: Distributes under the same terms as Ruby
9
+ # Home:: http://cloud.nifty.com/api/
10
+ #++
11
+
12
+ require File.dirname(__FILE__) + '/test_helper.rb'
13
+
14
+ context "Base" do
15
+
16
+ before do
17
+ @modify_instance_attribute_response_body = <<-RESPONSE
18
+ <ModifyInstanceAttributeResponse xmlns="https://cp.cloud.nifty.com/api/">
19
+ <return>true</return>
20
+ </ModifyInstanceAttributeResponse>
21
+ RESPONSE
22
+
23
+ @error_response_body = <<-RESPONSE
24
+ <Response>
25
+ <Errors>
26
+ <Error>
27
+ <Code>Client.InvalidInstanceID.NotFound</Code>
28
+ <Message>The instance ID 'noserver' does not exist.</Message>
29
+ </Error>
30
+ </Errors>
31
+ <RequestID>4908b840-5d2c-42b7-a151-abeb01d4c755</RequestID>
32
+ </Response>
33
+ RESPONSE
34
+
35
+ @options = {
36
+ :access_key_id => "accesskey",
37
+ :secret_access_key => "secretkey",
38
+ :use_ssl => true,
39
+ :server => "cp.cloud.nifty.com",
40
+ :path => "/api/1.7",
41
+ :proxy_server => nil,
42
+ :port => 443,
43
+ :connection_timeout => 30,
44
+ :socket_timeout => 30,
45
+ :user_agent => "useragent",
46
+ :max_retry => 3,
47
+ :signature_version => "2",
48
+ :signature_method => "HmacSHA256"
49
+ }
50
+ end
51
+
52
+ specify "オプション不正" do
53
+ # No access key
54
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:access_key => nil)) }.should.raise(NIFTY::ArgumentError)
55
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:access_key => "")) }.should.raise(NIFTY::ArgumentError)
56
+
57
+ # No secret key
58
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:secret_key => nil)) }.should.raise(NIFTY::ArgumentError)
59
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:secret_key => "")) }.should.raise(NIFTY::ArgumentError)
60
+
61
+ # No use ssl
62
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:use_ssl => nil)) }.should.raise(NIFTY::ArgumentError)
63
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:use_ssl => "")) }.should.raise(NIFTY::ArgumentError)
64
+
65
+ # Invalid use ssl
66
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:use_ssl => false)) }.should.raise(NIFTY::ArgumentError)
67
+
68
+ # No server
69
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:server => nil)) }.should.raise(NIFTY::ArgumentError)
70
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:server => "")) }.should.raise(NIFTY::ArgumentError)
71
+
72
+ # No path
73
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:path => nil)) }.should.raise(NIFTY::ArgumentError)
74
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:path => "")) }.should.raise(NIFTY::ArgumentError)
75
+
76
+ # Invalid signature version
77
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:signature_version => "-1")) }.should.raise(NIFTY::ArgumentError)
78
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:signature_version => "3")) }.should.raise(NIFTY::ArgumentError)
79
+
80
+ # Invalid signature method
81
+ lambda { @api = NIFTY::Cloud::Base.new(@options.merge(:signature_method => "HmacSHA2")) }.should.raise(NIFTY::ArgumentError)
82
+ end
83
+
84
+ specify "オプション正常" do
85
+ @options.merge!(:access_key_id => 'access', :secret_access_key => 'secret', :use_ssl => true,
86
+ :server => 'cp.cloud.nifty.com', :path => '/api/1.7/')
87
+ @api = NIFTY::Cloud::Base.new(@options)
88
+ @api.use_ssl.should.equal true
89
+ @api.server.should.equal 'cp.cloud.nifty.com'
90
+ @api.path.should.equal '/api/1.7/'
91
+
92
+ # max retry
93
+ @options[:max_retry] = 3
94
+ @api = NIFTY::Cloud::Base.new(@options)
95
+ @api.max_retry.should.equal 3
96
+
97
+ # connection timeout
98
+ @options[:connection_timeout] = 30
99
+ @api = NIFTY::Cloud::Base.new(@options)
100
+ @api.connection_timeout.should.equal 30
101
+ @options[:connection_timeout] = -1
102
+ @api = NIFTY::Cloud::Base.new(@options)
103
+ @api.connection_timeout.should.equal -1
104
+
105
+ # socket timeout
106
+ @options[:socket_timeout] = 30
107
+ @api = NIFTY::Cloud::Base.new(@options)
108
+ @api.socket_timeout.should.equal 30
109
+ @options[:socket_timeout] = 0
110
+ @api = NIFTY::Cloud::Base.new(@options)
111
+ @api.socket_timeout.should.equal 0
112
+
113
+ # user agent
114
+ @options[:user_agent] = 'user'
115
+ @api = NIFTY::Cloud::Base.new(@options)
116
+ @api.user_agent.should.equal 'user'
117
+
118
+ # signature version
119
+ @options[:signature_version] = '0'
120
+ lambda {
121
+ @api = NIFTY::Cloud::Base.new(@options)
122
+ @api.signature_version.should.equal '0'
123
+ @api.stubs(:exec_request).returns stub(:body => @modify_instance_attribute_response_body, :is_a? => true)
124
+ @api.describe_instances
125
+ }.should.not.raise(NIFTY::ConfigurationError)
126
+ @options[:signature_version] = '1'
127
+ lambda {
128
+ @api = NIFTY::Cloud::Base.new(@options)
129
+ @api.signature_version.should.equal '1'
130
+ @api.stubs(:exec_request).returns stub(:body => @modify_instance_attribute_response_body, :is_a? => true)
131
+ @api.describe_instances
132
+ }.should.not.raise(NIFTY::ConfigurationError)
133
+ @options[:signature_method] = 'HmacSHA1'
134
+ @options[:signature_version] = '2'
135
+ lambda {
136
+ @api = NIFTY::Cloud::Base.new(@options)
137
+ @api.signature_version.should.equal '2'
138
+ @api.stubs(:exec_request).returns stub(:body => @modify_instance_attribute_response_body, :is_a? => true)
139
+ @api.describe_instances
140
+ }.should.not.raise(NIFTY::ConfigurationError)
141
+
142
+ # signature method
143
+ @options[:signature_method] = 'HmacSHA1'
144
+ lambda {
145
+ @api = NIFTY::Cloud::Base.new(@options)
146
+ @api.signature_method.should.equal 'HmacSHA1'
147
+ @api.stubs(:exec_request).returns stub(:body => @modify_instance_attribute_response_body, :is_a? => true)
148
+ @api.describe_instances
149
+ }.should.not.raise(NIFTY::ConfigurationError)
150
+ @options[:signature_method] = 'HmacSHA256'
151
+ lambda {
152
+ @api = NIFTY::Cloud::Base.new(@options)
153
+ @api.signature_method.should.equal 'HmacSHA256'
154
+ @api.stubs(:exec_request).returns stub(:body => @modify_instance_attribute_response_body, :is_a? => true)
155
+ @api.describe_instances
156
+ }.should.not.raise(NIFTY::ConfigurationError)
157
+ end
158
+
159
+ specify "pathhashlist引数不正" do
160
+ @options.merge!(:access_key_id => 'access', :secret_access_key => 'secret', :use_ssl => true,
161
+ :server => 'cp.cloud.nifty.com', :path => '/api/1.7/', :signature_version => 2, :signature_method => 'HmacSHA256')
162
+ @api = NIFTY::Cloud::Base.new(@options)
163
+ lambda { @api.run_instances(:image_id => '1', :key_name => 'key', :password => 'pass', :instance_id => 'serv', :block_device_mapping => 'mapping') }.should.raise(NIFTY::ArgumentError)
164
+ end
165
+
166
+ specify "pathkvlist引数不正" do
167
+ @options.merge!(:access_key_id => 'access', :secret_access_key => 'secret', :use_ssl => true,
168
+ :server => 'cp.cloud.nifty.com', :path => '/api/1.7/', :signature_version => 2, :signature_method => 'HmacSHA256')
169
+ @api = NIFTY::Cloud::Base.new(@options)
170
+ lambda { @api.describe_security_groups(:group_name => 'gr1', :filter => 'filter') }.should.raise(NIFTY::ArgumentError)
171
+ end
172
+
173
+ specify "レスポンスエラー" do
174
+ @options.merge!(:access_key_id => 'access', :secret_access_key => 'secret', :use_ssl => true,
175
+ :server => 'cp.cloud.nifty.com', :path => '/api/1.7/', :signature_version => 2, :signature_method => 'HmacSHA256')
176
+ @api = NIFTY::Cloud::Base.new(@options)
177
+ @api.stubs(:exec_request).returns stub(:body => @error_response_body, :is_a? => false)
178
+ lambda { @api.describe_instances(:instance_id => 'noserver') }.should.raise(NIFTY::ResponseError)
179
+ begin
180
+ @api.describe_instances(:instance_id => 'noserver')
181
+ rescue => e
182
+ e.error_code.should.equal 'Client.InvalidInstanceID.NotFound'
183
+ e.error_message.should.equal "The instance ID 'noserver' does not exist."
184
+ end
185
+ end
186
+ end