deltacloud-client 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. data/README.md +73 -0
  2. data/Rakefile +88 -5
  3. data/lib/deltacloud/client.rb +79 -0
  4. data/lib/deltacloud/client/base_error.rb +80 -0
  5. data/lib/deltacloud/client/connection.rb +139 -0
  6. data/lib/deltacloud/client/helpers/model_helper.rb +69 -0
  7. data/lib/deltacloud/client/helpers/property_helper.rb +103 -0
  8. data/lib/deltacloud/client/helpers/xml_helper.rb +33 -0
  9. data/lib/deltacloud/client/methods.rb +33 -0
  10. data/lib/deltacloud/client/methods/address.rb +67 -0
  11. data/lib/deltacloud/client/methods/api.rb +96 -0
  12. data/lib/deltacloud/client/methods/backward_compatiblity.rb +72 -0
  13. data/lib/deltacloud/client/methods/blob.rb +91 -0
  14. data/lib/deltacloud/client/methods/bucket.rb +55 -0
  15. data/lib/deltacloud/client/methods/common.rb +46 -0
  16. data/lib/deltacloud/client/methods/driver.rb +53 -0
  17. data/lib/deltacloud/client/methods/firewall.rb +67 -0
  18. data/lib/deltacloud/client/methods/hardware_profile.rb +41 -0
  19. data/lib/deltacloud/client/methods/image.rb +61 -0
  20. data/lib/deltacloud/client/methods/instance.rb +141 -0
  21. data/lib/deltacloud/client/methods/instance_state.rb +41 -0
  22. data/lib/deltacloud/client/methods/key.rb +58 -0
  23. data/lib/deltacloud/client/methods/load_balancer.rb +96 -0
  24. data/lib/deltacloud/client/methods/metric.rb +54 -0
  25. data/lib/deltacloud/client/methods/realm.rb +42 -0
  26. data/lib/deltacloud/client/methods/storage_snapshot.rb +61 -0
  27. data/lib/deltacloud/client/methods/storage_volume.rb +94 -0
  28. data/lib/deltacloud/client/models.rb +32 -0
  29. data/lib/deltacloud/client/models/address.rb +57 -0
  30. data/lib/deltacloud/client/models/base.rb +153 -0
  31. data/lib/deltacloud/client/models/blob.rb +56 -0
  32. data/lib/deltacloud/client/models/bucket.rb +65 -0
  33. data/lib/deltacloud/client/models/driver.rb +87 -0
  34. data/lib/deltacloud/client/models/firewall.rb +64 -0
  35. data/lib/deltacloud/client/models/hardware_profile.rb +68 -0
  36. data/lib/deltacloud/client/models/image.rb +60 -0
  37. data/lib/deltacloud/client/models/instance.rb +142 -0
  38. data/lib/deltacloud/client/models/instance_address.rb +40 -0
  39. data/lib/{instance_state.rb → deltacloud/client/models/instance_state.rb} +11 -3
  40. data/lib/deltacloud/client/models/key.rb +52 -0
  41. data/lib/deltacloud/client/models/load_balancer.rb +55 -0
  42. data/lib/deltacloud/client/models/metric.rb +72 -0
  43. data/lib/deltacloud/client/models/realm.rb +29 -0
  44. data/lib/deltacloud/client/models/storage_snapshot.rb +54 -0
  45. data/lib/deltacloud/client/models/storage_volume.rb +96 -0
  46. data/lib/deltacloud/core_ext.rb +19 -0
  47. data/lib/deltacloud/core_ext/element.rb +32 -0
  48. data/lib/deltacloud/core_ext/fixnum.rb +30 -0
  49. data/lib/deltacloud/core_ext/nil.rb +22 -0
  50. data/lib/{string.rb → deltacloud/core_ext/string.rb} +16 -26
  51. data/lib/deltacloud/error_response.rb +93 -0
  52. data/tests/client/client_test.rb +51 -0
  53. data/tests/client/connection_test.rb +77 -0
  54. data/tests/core_ext/element_test.rb +40 -0
  55. data/tests/core_ext/fixnum_test.rb +35 -0
  56. data/tests/core_ext/nil.rb +27 -0
  57. data/tests/core_ext/string_test.rb +47 -0
  58. data/tests/fixtures/instances_cleanup.yml +681 -0
  59. data/tests/fixtures/test_0001_connects_to_Deltacloud_API.yml +60 -0
  60. data/tests/fixtures/test_0001_support_cpu.yml +444 -0
  61. data/tests/fixtures/test_0001_support_original_body.yml +116 -0
  62. data/tests/fixtures/test_0001_supports_addresses.yml +178 -0
  63. data/tests/fixtures/test_0001_supports_api_host.yml +60 -0
  64. data/tests/fixtures/test_0001_supports_attached_.yml +282 -0
  65. data/tests/fixtures/test_0001_supports_blobs.yml +475 -0
  66. data/tests/fixtures/test_0001_supports_bucket.yml +200 -0
  67. data/tests/fixtures/test_0001_supports_buckets.yml +160 -0
  68. data/tests/fixtures/test_0001_supports_drivers.yml +202 -0
  69. data/tests/fixtures/test_0001_supports_firewalls.yml +399 -0
  70. data/tests/fixtures/test_0001_supports_hardware_profiles.yml +262 -0
  71. data/tests/fixtures/test_0001_supports_images.yml +224 -0
  72. data/tests/fixtures/test_0001_supports_instance_states.yml +156 -0
  73. data/tests/fixtures/test_0001_supports_instances.yml +486 -0
  74. data/tests/fixtures/test_0001_supports_keys.yml +198 -0
  75. data/tests/fixtures/test_0001_supports_path.yml +60 -0
  76. data/tests/fixtures/test_0001_supports_realms.yml +152 -0
  77. data/tests/fixtures/test_0001_supports_storage_snapshots.yml +164 -0
  78. data/tests/fixtures/test_0001_supports_storage_volumes.yml +176 -0
  79. data/tests/fixtures/test_0001_supports_to_get_providers.yml +410 -0
  80. data/tests/fixtures/test_0002_support_blob.yml +148 -0
  81. data/tests/fixtures/test_0002_support_instance_state.yml +204 -0
  82. data/tests/fixtures/test_0002_support_memory.yml +444 -0
  83. data/tests/fixtures/test_0002_support_on_Provider.yml +130 -0
  84. data/tests/fixtures/test_0002_supports_api_port.yml +60 -0
  85. data/tests/fixtures/test_0002_supports_api_uri.yml +60 -0
  86. data/tests/fixtures/test_0002_supports_driver.yml +219 -0
  87. data/tests/fixtures/test_0002_supports_extract_xml_body_using_faraday_connection.yml +117 -0
  88. data/tests/fixtures/test_0002_supports_filtering_addresses_by_id_param.yml +156 -0
  89. data/tests/fixtures/test_0002_supports_filtering_buckets_by_id_param.yml +156 -0
  90. data/tests/fixtures/test_0002_supports_filtering_firewalls_by_id_param.yml +207 -0
  91. data/tests/fixtures/test_0002_supports_filtering_hardware_profiles_by_id_param.yml +158 -0
  92. data/tests/fixtures/test_0002_supports_filtering_images_by_id_param.yml +165 -0
  93. data/tests/fixtures/test_0002_supports_filtering_instances_by_id_param.yml +164 -0
  94. data/tests/fixtures/test_0002_supports_filtering_keys_by_id_param.yml +178 -0
  95. data/tests/fixtures/test_0002_supports_filtering_realms_by_id.yml +104 -0
  96. data/tests/fixtures/test_0002_supports_filtering_storage_snapshots_by_id_param.yml +155 -0
  97. data/tests/fixtures/test_0002_supports_filtering_storage_volumes_by_id_param.yml +157 -0
  98. data/tests/fixtures/test_0002_supports_hardware_profiles.yml +262 -0
  99. data/tests/fixtures/test_0002_supports_is_compatible_.yml +116 -0
  100. data/tests/fixtures/test_0002_supports_snapshot_.yml +202 -0
  101. data/tests/fixtures/test_0002_supports_version.yml +60 -0
  102. data/tests/fixtures/test_0003_caches_the_API_entrypoint.yml +60 -0
  103. data/tests/fixtures/test_0003_support_address.yml +197 -0
  104. data/tests/fixtures/test_0003_support_bucket.yml +198 -0
  105. data/tests/fixtures/test_0003_support_create_blob.yml +105 -0
  106. data/tests/fixtures/test_0003_support_create_blob_and_destroy_blob.yml +138 -0
  107. data/tests/fixtures/test_0003_support_firewall.yml +768 -0
  108. data/tests/fixtures/test_0003_support_hardware_profile.yml +199 -0
  109. data/tests/fixtures/test_0003_support_image.yml +207 -0
  110. data/tests/fixtures/test_0003_support_instance.yml +206 -0
  111. data/tests/fixtures/test_0003_support_key.yml +220 -0
  112. data/tests/fixtures/test_0003_support_realm.yml +195 -0
  113. data/tests/fixtures/test_0003_support_storage.yml +444 -0
  114. data/tests/fixtures/test_0003_support_storage_snapshot.yml +196 -0
  115. data/tests/fixtures/test_0003_support_storage_volume.yml +197 -0
  116. data/tests/fixtures/test_0003_support_to_change_driver_with_Client.yml +72 -0
  117. data/tests/fixtures/test_0003_supports_connect.yml +60 -0
  118. data/tests/fixtures/test_0003_supports_extract_xml_body_using_nokogiri_document.yml +117 -0
  119. data/tests/fixtures/test_0003_supports_instance.yml +396 -0
  120. data/tests/fixtures/test_0003_supports_is_compatible_.yml +116 -0
  121. data/tests/fixtures/test_0003_supports_lunch_image.yml +367 -0
  122. data/tests/fixtures/test_0003_supports_providers.yml +102 -0
  123. data/tests/fixtures/test_0003_supports_version.yml +60 -0
  124. data/tests/fixtures/test_0004_support_architecture.yml +444 -0
  125. data/tests/fixtures/test_0004_support_create_address.yml +197 -0
  126. data/tests/fixtures/test_0004_support_create_blob_and_destroy_blob_with_meta_params.yml +139 -0
  127. data/tests/fixtures/test_0004_support_create_bucket.yml +180 -0
  128. data/tests/fixtures/test_0004_support_create_bucket_and_destroy_bucket.yml +180 -0
  129. data/tests/fixtures/test_0004_support_create_firewall_and_destroy_firewall.yml +496 -0
  130. data/tests/fixtures/test_0004_support_create_image_and_destroy_image.yml +1527 -0
  131. data/tests/fixtures/test_0004_support_create_instance.yml +115 -0
  132. data/tests/fixtures/test_0004_support_create_key_and_destroy_key.yml +206 -0
  133. data/tests/fixtures/test_0004_support_create_volume.yml +105 -0
  134. data/tests/fixtures/test_0004_support_create_volume_and_destroy_volume.yml +181 -0
  135. data/tests/fixtures/test_0004_support_to_test_of_valid_DC_connection.yml +60 -0
  136. data/tests/fixtures/test_0004_supports_current_driver.yml +60 -0
  137. data/tests/fixtures/test_0004_supports_extract_xml_body_using_nokogiri_element.yml +117 -0
  138. data/tests/fixtures/test_0004_supports_lunch_image.yml +312 -0
  139. data/tests/fixtures/test_0004_supports_valid_credentials_.yml +215 -0
  140. data/tests/fixtures/test_0004_supports_with_config.yml +129 -0
  141. data/tests/fixtures/test_0005_support_attach_storage_volume.yml +102 -0
  142. data/tests/fixtures/test_0005_support_attach_storage_volume_and_detach_storage_volume.yml +142 -0
  143. data/tests/fixtures/test_0005_support_create_instance_with_hwp_id.yml +115 -0
  144. data/tests/fixtures/test_0005_support_opaque_.yml +152 -0
  145. data/tests/fixtures/test_0005_supports_current_provider.yml +134 -0
  146. data/tests/fixtures/test_0005_supports_id.yml +116 -0
  147. data/tests/fixtures/test_0005_supports_switching_drivers_per_instance.yml +129 -0
  148. data/tests/fixtures/test_0005_supports_use_driver.yml +60 -0
  149. data/tests/fixtures/test_0006_support_create_instance_with_realm_id.yml +115 -0
  150. data/tests/fixtures/test_0006_supports_discovered_.yml +60 -0
  151. data/tests/fixtures/test_0006_supports_supported_collections.yml +60 -0
  152. data/tests/fixtures/test_0006_supports_switching_providers_per_instance.yml +208 -0
  153. data/tests/fixtures/test_0007_support_create_instance_with_name.yml +115 -0
  154. data/tests/fixtures/test_0007_support_switching_provider_without_credentials.yml +208 -0
  155. data/tests/fixtures/test_0007_supports_support_.yml +60 -0
  156. data/tests/fixtures/test_0007_supports_valid_credentials_on_class.yml +370 -0
  157. data/tests/fixtures/test_0008_support_stop_instance.yml +166 -0
  158. data/tests/fixtures/test_0008_supports_must_support_.yml +60 -0
  159. data/tests/fixtures/test_0009_support_start_instance.yml +217 -0
  160. data/tests/fixtures/test_0009_supports_features.yml +60 -0
  161. data/tests/fixtures/test_0010_support_reboot_instance.yml +166 -0
  162. data/tests/fixtures/test_0010_supports_feature_.yml +60 -0
  163. data/tests/helpers/model_test.rb +33 -0
  164. data/tests/helpers/xml_test.rb +56 -0
  165. data/tests/methods/address_test.rb +64 -0
  166. data/tests/methods/api_test.rb +97 -0
  167. data/tests/methods/backward_compatibility_test.rb +87 -0
  168. data/tests/methods/blob_test.rb +64 -0
  169. data/tests/methods/bucket_test.rb +62 -0
  170. data/tests/methods/driver_test.rb +48 -0
  171. data/tests/methods/firewall_test.rb +84 -0
  172. data/tests/methods/hardware_profile_test.rb +53 -0
  173. data/tests/methods/image_test.rb +64 -0
  174. data/tests/methods/instance_state_test.rb +43 -0
  175. data/tests/methods/instance_test.rb +126 -0
  176. data/tests/methods/key_test.rb +63 -0
  177. data/tests/methods/realm_test.rb +50 -0
  178. data/tests/methods/storage_snapshot_test.rb +53 -0
  179. data/tests/methods/storage_volume_test.rb +81 -0
  180. data/tests/models/blob_test.rb +40 -0
  181. data/tests/models/bucket_test.rb +37 -0
  182. data/tests/models/driver_test.rb +42 -0
  183. data/tests/models/hardware_profile_test.rb +80 -0
  184. data/tests/models/image_test.rb +65 -0
  185. data/tests/models/storage_volume_test.rb +52 -0
  186. data/tests/test_helper.rb +59 -11
  187. metadata +392 -41
  188. data/lib/base_object.rb +0 -386
  189. data/lib/client_bucket_methods.rb +0 -69
  190. data/lib/deltacloud.rb +0 -486
  191. data/lib/documentation.rb +0 -59
  192. data/lib/errors.rb +0 -140
  193. data/lib/hwp_properties.rb +0 -61
  194. data/tests/buckets_test.rb +0 -141
  195. data/tests/client_test.rb +0 -59
  196. data/tests/content_negotiation_test.rb +0 -127
  197. data/tests/errors_test.rb +0 -57
  198. data/tests/hardware_profiles_test.rb +0 -75
  199. data/tests/images_test.rb +0 -102
  200. data/tests/instance_states_test.rb +0 -66
  201. data/tests/instances_test.rb +0 -203
  202. data/tests/keys_test.rb +0 -81
  203. data/tests/realms_test.rb +0 -64
  204. data/tests/storage_snapshot_test.rb +0 -76
  205. data/tests/storage_volume_test.rb +0 -86
@@ -1,127 +0,0 @@
1
- # Licensed to the Apache Software Foundation (ASF) under one or more
2
- # contributor license agreements. See the NOTICE file distributed with
3
- # this work for additional information regarding copyright ownership. The
4
- # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
- # "License"); you may not use this file except in compliance with the
6
- # License. You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
- # License for the specific language governing permissions and limitations
14
- # under the License.
15
-
16
- require 'rubygems'
17
- require 'require_relative' if RUBY_VERSION =~ /^1\.8/
18
-
19
- require_relative './test_helper.rb'
20
-
21
- def client; RestClient::Resource.new(API_URL); end
22
-
23
- def headers(header)
24
- encoded_credentials = ["#{API_NAME}:#{API_PASSWORD}"].pack("m0").gsub(/\n/,'')
25
- { :authorization => "Basic " + encoded_credentials }.merge(header)
26
- end
27
-
28
- describe "return JSON" do
29
-
30
- it 'should return JSON when using application/json, */*' do
31
- header_hash = {
32
- # FIXME: There is a bug in rack-accept that cause to respond with HTML
33
- # to the configuration below.
34
- #
35
- # 'Accept' => "application/json, */*"
36
- 'Accept' => "application/json"
37
- }
38
- client.get(header_hash) do |response, request, &block|
39
- response.code.must_equal 200
40
- response.headers[:content_type].must_match /^application\/json/
41
- end
42
- end
43
-
44
- it 'should return JSON when using just application/json' do
45
- header_hash = {
46
- 'Accept' => "application/json"
47
- }
48
- client.get(header_hash) do |response, request, &block|
49
- response.code.must_equal 200
50
- response.headers[:content_type].must_match /^application\/json/
51
- end
52
- end
53
-
54
- end
55
-
56
- describe "return HTML in different browsers" do
57
-
58
- it "wants XML using format parameter" do
59
- client.get(:params => { 'format' => 'xml' }, 'Accept' => 'application/xhtml+xml') do |response, request, &block|
60
- response.code.must_equal 200
61
- response.headers[:content_type].must_match /^application\/xml/
62
- end
63
- end
64
-
65
- it "raise 406 error on wrong accept" do
66
- client['hardware_profiles'].get('Accept' => 'image/png;q=1') do |response, request, &block|
67
- response.code.must_equal 406
68
- end
69
- end
70
-
71
- it "wants HTML using format parameter and accept set to XML" do
72
- client.get(:params => { 'format' => 'html'}, 'Accept' => 'application/xml') do |response, request, &block|
73
- response.code.must_equal 200
74
- response.headers[:content_type].must_match /^text\/html/
75
- end
76
- end
77
-
78
- it "doesn't have accept header" do
79
- client.get('Accept' => '') do |response, request, &block|
80
- response.code.must_equal 200
81
- response.headers[:content_type].must_match /^application\/xml/
82
- end
83
- end
84
-
85
- it "can handle unknown formats" do
86
- client.get('Accept' => 'format/unknown') do |response, request, &block|
87
- response.code.must_equal 406
88
- end
89
- end
90
-
91
- it "wants explicitly XML" do
92
- client.get('Accept' => 'application/xml') do |response, request, &block|
93
- response.code.must_equal 200
94
- response.headers[:content_type].must_match /^application\/xml/
95
- end
96
- end
97
-
98
- it "Internet Explorer" do
99
- header_hash = {
100
- 'Accept' => "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*",
101
- 'User-agent' => "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)"
102
- }
103
- client.get(header_hash) do |response, request, &block|
104
- response.code.must_equal 200
105
- response.headers[:content_type].must_match /^text\/html/
106
- end
107
- end
108
-
109
- it "Mozilla Firefox" do
110
- client.get('Accept' => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") do |response, request, &block|
111
- response.code.must_equal 200
112
- response.headers[:content_type].must_match /^text\/html/
113
- end
114
- end
115
-
116
- it "Opera" do
117
- header_hash = {
118
- 'Accept' => "text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1",
119
- 'User-agent' => "Opera/9.80 (X11; Linux i686; U; ru) Presto/2.8.131 Version/11.11"
120
- }
121
- client.get(header_hash) do |response, request, &block|
122
- response.code.must_equal 200
123
- response.headers[:content_type].must_match /^text\/html/
124
- end
125
- end
126
-
127
- end
@@ -1,57 +0,0 @@
1
- # Licensed to the Apache Software Foundation (ASF) under one or more
2
- # contributor license agreements. See the NOTICE file distributed with
3
- # this work for additional information regarding copyright ownership. The
4
- # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
- # "License"); you may not use this file except in compliance with the
6
- # License. You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
- # License for the specific language governing permissions and limitations
14
- # under the License.
15
-
16
- require 'rubygems'
17
- require 'require_relative' if RUBY_VERSION =~ /^1\.8/
18
-
19
- require_relative './test_helper.rb'
20
-
21
- describe "server error handler" do
22
-
23
- it 'should capture HTTP 500 error as DeltacloudError' do
24
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
25
- lambda { client.realm('500') }.must_raise DeltaCloud::HTTPError::DeltacloudError
26
- end
27
- end
28
-
29
- it 'should capture HTTP 502 error as ProviderError' do
30
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
31
- lambda { client.realm('502') }.must_raise DeltaCloud::HTTPError::ProviderError
32
- end
33
- end
34
-
35
- it 'should capture HTTP 501 error as NotImplemented' do
36
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
37
- lambda { client.realm('501') }.must_raise DeltaCloud::HTTPError::NotImplemented
38
- end
39
- end
40
-
41
- it 'should capture HTTP 504 error as ProviderTimeout' do
42
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
43
- lambda { client.realm('504') }.must_raise DeltaCloud::HTTPError::ProviderTimeout
44
- end
45
- end
46
-
47
- end
48
-
49
- describe "client error handler" do
50
-
51
- it 'should capture HTTP 404 error as NotFound' do
52
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
53
- lambda { client.realm('non-existing-realm') }.must_raise DeltaCloud::HTTPError::NotFound
54
- end
55
- end
56
-
57
- end
@@ -1,75 +0,0 @@
1
- # Licensed to the Apache Software Foundation (ASF) under one or more
2
- # contributor license agreements. See the NOTICE file distributed with
3
- # this work for additional information regarding copyright ownership. The
4
- # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
- # "License"); you may not use this file except in compliance with the
6
- # License. You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
- # License for the specific language governing permissions and limitations
14
- # under the License.
15
-
16
- require 'rubygems'
17
- require 'require_relative' if RUBY_VERSION =~ /^1\.8/
18
-
19
- require_relative './test_helper.rb'
20
-
21
- def prop_check(prop, value_class)
22
- if prop.present?
23
- prop.value.wont_be_nil
24
- prop.value.must_be_kind_of value_class
25
- end
26
- end
27
-
28
- describe "Hardware Profiles" do
29
-
30
- it "should allow retrieval of all hardware profiles" do
31
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
32
- hardware_profiles = client.hardware_profiles
33
- hardware_profiles.wont_be_empty
34
- hardware_profiles.each do |hwp|
35
- hwp.uri.wont_be_nil
36
- hwp.uri.must_be_kind_of String
37
- prop_check(hwp.architecture, String) unless hwp.name.eql?("opaque")
38
- end
39
- end
40
- end
41
-
42
- it "should allow filtering of hardware_profiles by architecture" do
43
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
44
- hardware_profiles = client.hardware_profiles( :architecture=>'i386' )
45
- hardware_profiles.wont_be_empty
46
- hardware_profiles.size.must_equal 1
47
- hardware_profiles.first.architecture.value.must_equal 'i386'
48
- end
49
- end
50
-
51
- it "should allow fetching a hardware_profile by id" do
52
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
53
- hwp = client.hardware_profile( 'm1-small' )
54
- hwp.wont_be_nil
55
- hwp.id.must_equal 'm1-small'
56
- end
57
- end
58
-
59
- it "should allow fetching different hardware_profiles" do
60
- client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
61
- hwp1 = client.hardware_profile( 'm1-small' )
62
- hwp2 = client.hardware_profile( 'm1-large' )
63
- hwp1.storage.value.wont_equal hwp2.storage.value
64
- hwp1.memory.value.wont_equal hwp2.memory.value
65
- end
66
-
67
- it "should allow fetching a hardware_profile by URI" do
68
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
69
- hwp = client.fetch_hardware_profile( API_URL + '/hardware_profiles/m1-small' )
70
- hwp.wont_be_nil
71
- hwp.id.must_equal 'm1-small'
72
- end
73
- end
74
-
75
- end
@@ -1,102 +0,0 @@
1
- # Licensed to the Apache Software Foundation (ASF) under one or more
2
- # contributor license agreements. See the NOTICE file distributed with
3
- # this work for additional information regarding copyright ownership. The
4
- # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
- # "License"); you may not use this file except in compliance with the
6
- # License. You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
- # License for the specific language governing permissions and limitations
14
- # under the License.
15
-
16
- require 'rubygems'
17
- require 'require_relative' if RUBY_VERSION =~ /^1\.8/
18
-
19
- require_relative './test_helper.rb'
20
-
21
- describe "Images" do
22
-
23
- it "should allow retrieval of all images" do
24
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
25
- images = client.images
26
- images.wont_be_empty
27
- images.size.must_equal 3
28
- images.each do |image|
29
- image.uri.wont_be_nil
30
- image.uri.must_be_kind_of String
31
- image.description.wont_be_nil
32
- image.description.must_be_kind_of String
33
- image.architecture.wont_be_nil
34
- image.architecture.must_be_kind_of String
35
- image.owner_id.wont_be_nil
36
- image.owner_id.must_be_kind_of String
37
- end
38
- end
39
- end
40
-
41
- it "should allow retrieval of my own images" do
42
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
43
- images = client.images( :owner_id=>:self )
44
- images.wont_be_empty
45
- images.size.must_equal 1
46
- images.each do |image|
47
- image.uri.wont_be_nil
48
- image.uri.must_be_kind_of String
49
- image.description.wont_be_nil
50
- image.description.must_be_kind_of String
51
- image.architecture.wont_be_nil
52
- image.architecture.must_be_kind_of String
53
- image.owner_id.wont_be_nil
54
- image.owner_id.must_be_kind_of String
55
- end
56
- end
57
- end
58
-
59
- it "should allow retrieval of a single image by ID" do
60
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
61
- image = client.image( 'img1' )
62
- image.wont_be_nil
63
- image.uri.must_equal API_URL + '/images/img1'
64
- image.id.must_equal 'img1'
65
- image.architecture.must_equal 'x86_64'
66
- end
67
- end
68
-
69
- it "should allow retrieval of a single image by URI" do
70
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
71
- image = client.fetch_image( API_URL + '/images/img1' )
72
- image.wont_be_nil
73
- image.uri.must_equal API_URL + '/images/img1'
74
- image.id.must_equal 'img1'
75
- image.architecture.must_equal 'x86_64'
76
- end
77
- end
78
-
79
- describe "filtering by architecture" do
80
- it "return matching images" do
81
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
82
- images = client.images( :architecture=>'x86_64' )
83
- images.wont_be_empty
84
- images.each do |image|
85
- image.architecture.must_equal 'x86_64'
86
- end
87
- images = client.images( :architecture=>'i386' )
88
- images.wont_be_empty
89
- images.each do |image|
90
- image.architecture.must_equal 'i386'
91
- end
92
- end
93
- end
94
-
95
- it "should return an empty array for no matches" do
96
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
97
- images = client.images( :architecture=>'8088' )
98
- images.must_be_empty
99
- end
100
- end
101
- end
102
- end
@@ -1,66 +0,0 @@
1
- # Licensed to the Apache Software Foundation (ASF) under one or more
2
- # contributor license agreements. See the NOTICE file distributed with
3
- # this work for additional information regarding copyright ownership. The
4
- # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
- # "License"); you may not use this file except in compliance with the
6
- # License. You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
- # License for the specific language governing permissions and limitations
14
- # under the License.
15
-
16
- require 'rubygems'
17
- require 'require_relative' if RUBY_VERSION =~ /^1\.8/
18
-
19
- require_relative './test_helper.rb'
20
-
21
- describe "Instance States" do
22
-
23
- it "should allow retrieval of instance-state information" do
24
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
25
- instance_states = client.instance_states
26
- instance_states.wont_be_nil
27
- instance_states.wont_be_empty
28
-
29
- instance_states[0].name.must_equal 'start'
30
- instance_states[0].transitions.size.must_equal 1
31
- instance_states[0].transitions[0].wont_equal :auto
32
-
33
- instance_states[1].name.must_equal 'pending'
34
- instance_states[1].transitions.size.must_equal 1
35
- instance_states[1].transitions[0].wont_equal :auto
36
-
37
- instance_states[2].name.must_equal 'running'
38
- instance_states[2].transitions.size.must_equal 2
39
- includes_transition( instance_states[2].transitions, :reboot, :running ).must_equal true
40
- includes_transition( instance_states[2].transitions, :stop, :stopped ).must_equal true
41
- end
42
- end
43
-
44
- it "should allow retrieval of a single instance-state blob" do
45
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
46
- instance_state = client.instance_state( :pending )
47
- instance_state.wont_be_nil
48
- instance_state.name.must_equal 'pending'
49
- instance_state.transitions.size.must_equal 1
50
- instance_state.transitions[0].wont_equal :auto
51
-
52
- instance_state = client.instance_state( :running )
53
- instance_state.name.must_equal 'running'
54
- instance_state.transitions.size.must_equal 2
55
- includes_transition( instance_state.transitions, :reboot, :running ).must_equal true
56
- includes_transition( instance_state.transitions, :stop, :stopped ).must_equal true
57
- end
58
- end
59
-
60
- def includes_transition( transitions, action, to )
61
- found = transitions.find{|e| e.action.to_s == action.to_s && e.to.to_s == to.to_s }
62
- ! found.nil?
63
- end
64
-
65
-
66
- end
@@ -1,203 +0,0 @@
1
- # Licensed to the Apache Software Foundation (ASF) under one or more
2
- # contributor license agreements. See the NOTICE file distributed with
3
- # this work for additional information regarding copyright ownership. The
4
- # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
- # "License"); you may not use this file except in compliance with the
6
- # License. You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
- # License for the specific language governing permissions and limitations
14
- # under the License.
15
-
16
- require 'rubygems'
17
- require 'require_relative' if RUBY_VERSION =~ /^1\.8/
18
-
19
- require_relative './test_helper.rb'
20
-
21
- describe "Instances" do
22
-
23
- it "should allow retrieval of all instances" do
24
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
25
- instances = client.instances
26
- instances.wont_be_empty
27
- instances.each do |instance|
28
- instance.uri.wont_be_nil
29
- instance.uri.must_be_kind_of String
30
- instance.owner_id.wont_be_nil
31
- instance.owner_id.must_be_kind_of String
32
- instance.image.wont_be_nil
33
- instance.image.to_s.must_match /DeltaCloud::API::.*::Image/
34
- instance.hardware_profile.wont_be_nil
35
- instance.hardware_profile.must_be_kind_of DeltaCloud::API::Base::HardwareProfile
36
- instance.state.wont_be_nil
37
- instance.state.must_be_kind_of String
38
- instance.public_addresses.wont_be_nil
39
- instance.public_addresses.wont_be_empty
40
- instance.public_addresses.must_be_kind_of Array
41
- instance.private_addresses.wont_be_nil
42
- instance.private_addresses.wont_be_empty
43
- instance.private_addresses.must_be_kind_of Array
44
- end
45
- end
46
- end
47
-
48
- it "should allow navigation from instance to image" do
49
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
50
- instances = client.instances
51
- instances.wont_be_empty
52
- instance = instances.first
53
- instance.image.wont_be_nil
54
- instance.image.description.wont_be_nil
55
- instance.image.description.must_be_kind_of String
56
- end
57
- end
58
-
59
- it "should allow retrieval of a single instance" do
60
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
61
- instance = client.instance( "inst0" )
62
- instance.wont_be_nil
63
- instance.name.wont_be_nil
64
- instance.name.must_equal 'Mock Instance With Profile Change'
65
- instance.uri.wont_be_nil
66
- instance.uri.must_be_kind_of String
67
- instance.owner_id.must_equal "mockuser"
68
- instance.public_addresses.first.class.must_equal Hash
69
- instance.public_addresses.first[:type].must_equal 'hostname'
70
- instance.public_addresses.first[:address].must_equal 'img1.inst0.public.com'
71
- instance.image.wont_be_nil
72
- instance.image.uri.must_equal API_URL + "/images/img1"
73
- instance.hardware_profile.wont_be_nil
74
- instance.hardware_profile.wont_be_nil
75
- instance.hardware_profile.uri.must_equal API_URL + "/hardware_profiles/m1-large"
76
- instance.hardware_profile.memory.value.must_equal '10240'
77
- instance.hardware_profile.storage.value.must_equal '850'
78
- instance.state.must_equal "RUNNING"
79
- instance.actions.wont_be_nil
80
- end
81
- end
82
-
83
- it "should allow creation of new instances with reasonable defaults" do
84
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
85
- instance = client.create_instance( 'img1', :name=>'TestInstance', :hardware_profile => 'm1-large' )
86
- instance.wont_be_nil
87
- instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+}
88
- instance.id.must_match /inst[0-9]+/
89
- instance.name.must_equal 'TestInstance'
90
- instance.image.id.must_equal 'img1'
91
- instance.hardware_profile.id.must_equal 'm1-large'
92
- instance.realm.id.must_equal 'us'
93
- end
94
- end
95
-
96
- it "should allow creation of new instances with specific realm" do
97
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
98
- instance = client.create_instance( 'img1', :realm=>'eu', :hardware_profile => 'm1-large' )
99
- instance.wont_be_nil
100
- instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+}
101
- instance.id.must_match /inst[0-9]+/
102
- instance.image.id.must_equal 'img1'
103
- instance.hardware_profile.id.must_equal 'm1-large'
104
- instance.realm.id.must_equal 'eu'
105
- end
106
- end
107
-
108
- it "should allow creation of new instances with specific hardware profile" do
109
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
110
- instance = client.create_instance( 'img1',
111
- :hardware_profile=>'m1-xlarge' )
112
- instance.wont_be_nil
113
- instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+}
114
- instance.id.must_match /inst[0-9]+/
115
- instance.image.id.must_equal 'img1'
116
- instance.hardware_profile.id.must_equal 'm1-xlarge'
117
- instance.realm.id.must_equal 'us'
118
- end
119
- end
120
-
121
- it "should allow creation of new instances with specific hardware profile overriding memory" do
122
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
123
- hwp = { :id => 'm1-xlarge', :memory => 32768 }
124
- instance = client.create_instance( 'img1', :hardware_profile=> hwp )
125
- instance.wont_be_nil
126
- instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+}
127
- instance.id.must_match /inst[0-9]+/
128
- instance.image.id.must_equal 'img1'
129
- instance.hardware_profile.id.must_equal 'm1-xlarge'
130
- instance.hardware_profile.memory.value.must_equal'12288'
131
- instance.realm.id.must_equal 'us'
132
- end
133
- end
134
-
135
- it "should allow creation of new instances with specific realm and hardware profile" do
136
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
137
- instance = client.create_instance( 'img1', :realm=>'eu',
138
- :hardware_profile=>'m1-xlarge' )
139
- instance.wont_be_nil
140
- instance.uri.must_match %r{#{API_URL}/instances/inst[0-9]+}
141
- instance.id.must_match /inst[0-9]+/
142
- instance.image.id.must_equal 'img1'
143
- instance.hardware_profile.id.must_equal 'm1-xlarge'
144
- instance.realm.id.must_equal 'eu'
145
- end
146
- end
147
-
148
- it "should allow fetching of instances by id" do
149
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
150
- instance = client.instance( 'inst1' )
151
- instance.wont_be_nil
152
- instance.uri.wont_be_nil
153
- instance.uri.must_be_kind_of String
154
- end
155
- end
156
-
157
- it "should allow fetching of instances by URI" do
158
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
159
- instance = client.fetch_instance( API_URL + '/instances/inst1' )
160
- instance.wont_be_nil
161
- instance.uri.must_equal API_URL + '/instances/inst1'
162
- instance.id.must_equal 'inst1'
163
- end
164
- end
165
-
166
- describe "performing actions on instances" do
167
- it "should allow actions that are valid" do
168
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
169
- instance = client.instance( 'inst1' )
170
- instance.wont_be_nil
171
- instance.state.must_equal "RUNNING"
172
- instance.uri.must_equal API_URL + '/instances/inst1'
173
- instance.id.must_equal 'inst1'
174
- instance.stop!
175
- instance.state.must_equal "STOPPED"
176
- instance.start!
177
- instance.state.must_equal "RUNNING"
178
- end
179
- end
180
-
181
- it "should not allow actions that are invalid" do
182
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
183
- instance = client.instance( 'inst1' )
184
- instance.wont_be_nil
185
- unless instance.state.eql?("RUNNING")
186
- instance.start!
187
- end
188
- instance.state.must_equal "RUNNING"
189
- lambda{instance.start!}.must_raise NoMethodError
190
- end
191
- end
192
-
193
- it "should not throw exception when destroying an instance" do
194
- DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
195
- instance = client.create_instance( 'img1',
196
- :name=>'TestDestroyInstance',
197
- :hardware_profile => 'm1-xlarge' )
198
- instance.stop!
199
- instance.destroy!.must_be_nil
200
- end
201
- end
202
- end
203
- end