fog 1.12.1 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/.travis.yml +1 -1
  2. data/Gemfile +5 -0
  3. data/Rakefile +14 -4
  4. data/bin/fog +22 -0
  5. data/changelog.txt +262 -0
  6. data/fog.gemspec +8 -4
  7. data/lib/fog/aws.rb +11 -0
  8. data/lib/fog/aws/auto_scaling.rb +15 -18
  9. data/lib/fog/aws/beanstalk.rb +8 -10
  10. data/lib/fog/aws/cloud_formation.rb +9 -12
  11. data/lib/fog/aws/compute.rb +8 -10
  12. data/lib/fog/aws/credential_fetcher.rb +6 -6
  13. data/lib/fog/aws/elasticache.rb +13 -17
  14. data/lib/fog/aws/elb.rb +29 -31
  15. data/lib/fog/aws/iam.rb +10 -13
  16. data/lib/fog/aws/models/auto_scaling/group.rb +6 -3
  17. data/lib/fog/aws/models/compute/spot_request.rb +1 -11
  18. data/lib/fog/aws/models/rds/log_file.rb +26 -0
  19. data/lib/fog/aws/models/rds/log_files.rb +50 -0
  20. data/lib/fog/aws/models/rds/server.rb +3 -1
  21. data/lib/fog/aws/models/rds/snapshot.rb +1 -0
  22. data/lib/fog/aws/models/rds/snapshots.rb +20 -13
  23. data/lib/fog/aws/parsers/rds/db_parser.rb +1 -1
  24. data/lib/fog/aws/parsers/rds/describe_db_log_files.rb +44 -0
  25. data/lib/fog/aws/parsers/rds/download_db_logfile_portion.rb +26 -0
  26. data/lib/fog/aws/parsers/ses/verify_domain_identity.rb +26 -0
  27. data/lib/fog/aws/parsers/storage/complete_multipart_upload.rb +1 -1
  28. data/lib/fog/aws/parsers/sts/assume_role.rb +30 -0
  29. data/lib/fog/aws/rds.rb +27 -14
  30. data/lib/fog/aws/requests/auto_scaling/create_auto_scaling_group.rb +8 -0
  31. data/lib/fog/aws/requests/auto_scaling/update_auto_scaling_group.rb +8 -1
  32. data/lib/fog/aws/requests/compute/create_volume.rb +3 -3
  33. data/lib/fog/aws/requests/rds/create_db_instance.rb +3 -1
  34. data/lib/fog/aws/requests/rds/describe_db_log_files.rb +67 -0
  35. data/lib/fog/aws/requests/rds/download_db_logfile_portion.rb +63 -0
  36. data/lib/fog/aws/requests/ses/send_raw_email.rb +1 -1
  37. data/lib/fog/aws/requests/ses/verify_domain_identity.rb +30 -0
  38. data/lib/fog/aws/requests/storage/complete_multipart_upload.rb +6 -2
  39. data/lib/fog/aws/requests/storage/get_object.rb +1 -1
  40. data/lib/fog/aws/requests/sts/assume_role.rb +46 -0
  41. data/lib/fog/aws/ses.rb +26 -9
  42. data/lib/fog/aws/storage.rb +2 -1
  43. data/lib/fog/aws/sts.rb +31 -21
  44. data/lib/fog/bin.rb +0 -1
  45. data/lib/fog/bin/openstack.rb +5 -0
  46. data/lib/fog/brightbox/compute.rb +20 -212
  47. data/lib/fog/brightbox/compute/shared.rb +232 -0
  48. data/lib/fog/brightbox/models/compute/collaboration.rb +43 -0
  49. data/lib/fog/brightbox/models/compute/collaborations.rb +23 -0
  50. data/lib/fog/brightbox/models/compute/user_collaboration.rb +29 -0
  51. data/lib/fog/brightbox/models/compute/user_collaborations.rb +23 -0
  52. data/lib/fog/brightbox/requests/compute/accept_user_collaboration.rb +21 -0
  53. data/lib/fog/brightbox/requests/compute/create_collaboration.rb +23 -0
  54. data/lib/fog/brightbox/requests/compute/delete_collaboration.rb +28 -0
  55. data/lib/fog/brightbox/requests/compute/delete_user_collaboration.rb +28 -0
  56. data/lib/fog/brightbox/requests/compute/destroy_user_collaboration.rb +21 -0
  57. data/lib/fog/brightbox/requests/compute/get_collaboration.rb +21 -0
  58. data/lib/fog/brightbox/requests/compute/get_user_collaboration.rb +21 -0
  59. data/lib/fog/brightbox/requests/compute/list_collaborations.rb +19 -0
  60. data/lib/fog/brightbox/requests/compute/list_user_collaborations.rb +19 -0
  61. data/lib/fog/brightbox/requests/compute/reject_user_collaboration.rb +21 -0
  62. data/lib/fog/brightbox/requests/compute/resend_collaboration.rb +21 -0
  63. data/lib/fog/cloudsigma/docs/getting_started.md +59 -0
  64. data/lib/fog/core.rb +7 -2
  65. data/lib/fog/core/connection.rb +62 -29
  66. data/lib/fog/core/deprecated/connection.rb +24 -0
  67. data/lib/fog/core/parser.rb +1 -1
  68. data/lib/fog/digitalocean/examples/getting_started.md +1 -1
  69. data/lib/fog/digitalocean/models/compute/server.rb +2 -2
  70. data/lib/fog/google/compute.rb +31 -7
  71. data/lib/fog/google/models/compute/disk.rb +80 -0
  72. data/lib/fog/google/models/compute/disks.rb +28 -0
  73. data/lib/fog/google/models/compute/image.rb +36 -0
  74. data/lib/fog/google/models/compute/server.rb +46 -33
  75. data/lib/fog/google/models/compute/servers.rb +15 -8
  76. data/lib/fog/google/requests/compute/delete_server.rb +5 -2
  77. data/lib/fog/google/requests/compute/get_disk.rb +3 -0
  78. data/lib/fog/google/requests/compute/get_server.rb +7 -1
  79. data/lib/fog/google/requests/compute/insert_disk.rb +8 -2
  80. data/lib/fog/google/requests/compute/insert_server.rb +51 -22
  81. data/lib/fog/google/requests/compute/list_machine_types.rb +3 -2
  82. data/lib/fog/google/requests/storage/get_object.rb +1 -1
  83. data/lib/fog/hp/requests/storage/get_object.rb +1 -1
  84. data/lib/fog/hp/storage.rb +26 -9
  85. data/lib/fog/ibm/requests/compute/create_instance.rb +20 -15
  86. data/lib/fog/internet_archive/requests/storage/get_object.rb +1 -1
  87. data/lib/fog/{core/json.rb → json.rb} +13 -2
  88. data/lib/fog/metering.rb +25 -0
  89. data/lib/fog/openstack.rb +1 -0
  90. data/lib/fog/openstack/metering.rb +215 -0
  91. data/lib/fog/openstack/models/compute/flavors.rb +2 -2
  92. data/lib/fog/openstack/models/compute/metadata.rb +1 -1
  93. data/lib/fog/openstack/models/compute/server.rb +5 -2
  94. data/lib/fog/openstack/models/image/images.rb +1 -1
  95. data/lib/fog/openstack/models/metering/meter.rb +0 -0
  96. data/lib/fog/openstack/models/metering/meters.rb +0 -0
  97. data/lib/fog/openstack/models/metering/resource.rb +24 -0
  98. data/lib/fog/openstack/models/metering/resources.rb +25 -0
  99. data/lib/fog/openstack/models/volume/volume.rb +3 -1
  100. data/lib/fog/openstack/models/volume/volumes.rb +2 -1
  101. data/lib/fog/openstack/network.rb +1 -1
  102. data/lib/fog/openstack/requests/compute/create_flavor.rb +1 -1
  103. data/lib/fog/openstack/requests/compute/create_server.rb +19 -1
  104. data/lib/fog/openstack/requests/compute/detach_volume.rb +2 -1
  105. data/lib/fog/openstack/requests/compute/list_flavors_detail.rb +4 -3
  106. data/lib/fog/openstack/requests/compute/list_security_groups.rb +1 -1
  107. data/lib/fog/openstack/requests/identity/create_tenant.rb +2 -2
  108. data/lib/fog/openstack/requests/metering/get_resource.rb +32 -0
  109. data/lib/fog/openstack/requests/metering/get_samples.rb +55 -0
  110. data/lib/fog/openstack/requests/metering/get_statistics.rb +56 -0
  111. data/lib/fog/openstack/requests/metering/list_meters.rb +50 -0
  112. data/lib/fog/openstack/requests/metering/list_resources.rb +32 -0
  113. data/lib/fog/openstack/requests/volume/create_volume.rb +4 -2
  114. data/lib/fog/rackspace.rb +16 -1
  115. data/lib/fog/rackspace/block_storage.rb +13 -28
  116. data/lib/fog/rackspace/cdn.rb +10 -24
  117. data/lib/fog/rackspace/compute.rb +17 -45
  118. data/lib/fog/rackspace/compute_v2.rb +13 -33
  119. data/lib/fog/rackspace/databases.rb +13 -29
  120. data/lib/fog/rackspace/dns.rb +27 -23
  121. data/lib/fog/rackspace/identity.rb +10 -26
  122. data/lib/fog/rackspace/load_balancers.rb +13 -29
  123. data/lib/fog/rackspace/mock_data.rb +3 -3
  124. data/lib/fog/rackspace/models/compute/server.rb +1 -1
  125. data/lib/fog/rackspace/models/dns/zones.rb +34 -21
  126. data/lib/fog/rackspace/models/identity/users.rb +2 -2
  127. data/lib/fog/rackspace/models/storage/file.rb +1 -0
  128. data/lib/fog/rackspace/requests/dns/list_domains.rb +2 -2
  129. data/lib/fog/rackspace/requests/storage/delete_multiple_objects.rb +75 -0
  130. data/lib/fog/rackspace/requests/storage/delete_static_large_object.rb +50 -0
  131. data/lib/fog/rackspace/requests/storage/get_object.rb +3 -1
  132. data/lib/fog/rackspace/requests/storage/put_dynamic_obj_manifest.rb +44 -0
  133. data/lib/fog/rackspace/requests/storage/put_object_manifest.rb +3 -30
  134. data/lib/fog/rackspace/requests/storage/put_static_obj_manifest.rb +60 -0
  135. data/lib/fog/rackspace/service.rb +43 -1
  136. data/lib/fog/rackspace/storage.rb +25 -43
  137. data/lib/fog/riakcs/provisioning.rb +2 -1
  138. data/lib/fog/riakcs/usage.rb +2 -1
  139. data/lib/fog/vcloud/requests/compute/configure_vm_cpus.rb +1 -1
  140. data/lib/fog/vcloud/requests/compute/configure_vm_memory.rb +1 -1
  141. data/lib/fog/version.rb +1 -1
  142. data/lib/fog/vsphere/requests/compute/get_folder.rb +1 -1
  143. data/lib/fog/xenserver/compute.rb +2 -0
  144. data/lib/fog/xenserver/models/compute/server.rb +9 -7
  145. data/lib/fog/xenserver/requests/compute/snapshot_revert.rb +22 -0
  146. data/lib/fog/xenserver/requests/compute/snapshot_server.rb +22 -0
  147. data/lib/fog/xml.rb +21 -0
  148. data/lib/fog/xml/sax_parser_connection.rb +43 -0
  149. data/lib/tasks/changelog_task.rb +1 -0
  150. data/tests/aws/models/auto_scaling/groups_test.rb +22 -0
  151. data/tests/aws/requests/compute/volume_tests.rb +3 -3
  152. data/tests/aws/requests/rds/helper.rb +14 -0
  153. data/tests/aws/requests/rds/log_file_tests.rb +19 -0
  154. data/tests/aws/requests/ses/verified_domain_identity_tests.rb +16 -0
  155. data/tests/aws/requests/sts/assume_role_tests.rb +19 -0
  156. data/tests/brightbox/requests/compute/collaboration_tests.rb +41 -0
  157. data/tests/brightbox/requests/compute/helper.rb +46 -2
  158. data/tests/brightbox/requests/compute/user_collaboration_tests.rb +67 -0
  159. data/tests/core/connection_tests.rb +26 -0
  160. data/tests/helper.rb +13 -0
  161. data/tests/openstack/requests/metering/meter_tests.rb +52 -0
  162. data/tests/openstack/requests/metering/resource_tests.rb +19 -0
  163. data/tests/openvz/helper.rb +14 -8
  164. data/tests/rackspace/block_storage_tests.rb +9 -0
  165. data/tests/rackspace/compute_tests.rb +9 -0
  166. data/tests/rackspace/compute_v2_tests.rb +9 -0
  167. data/tests/rackspace/databases_tests.rb +9 -0
  168. data/tests/rackspace/dns_tests.rb +20 -0
  169. data/tests/rackspace/helper.rb +12 -1
  170. data/tests/rackspace/identity_tests.rb +25 -0
  171. data/tests/rackspace/load_balancer_tests.rb +10 -0
  172. data/tests/rackspace/models/block_storage/volume_tests.rb +2 -2
  173. data/tests/rackspace/models/compute_v2/metadata_tests.rb +2 -2
  174. data/tests/rackspace/models/compute_v2/server_tests.rb +22 -21
  175. data/tests/rackspace/models/dns/zones_tests.rb +19 -5
  176. data/tests/rackspace/models/storage/file_tests.rb +22 -6
  177. data/tests/rackspace/rackspace_tests.rb +35 -0
  178. data/tests/rackspace/requests/block_storage/snapshot_tests.rb +2 -3
  179. data/tests/rackspace/requests/block_storage/volume_type_tests.rb +4 -11
  180. data/tests/rackspace/requests/compute_v2/address_tests.rb +1 -1
  181. data/tests/rackspace/requests/compute_v2/attachment_tests.rb +8 -9
  182. data/tests/rackspace/requests/compute_v2/flavor_tests.rb +1 -1
  183. data/tests/rackspace/requests/compute_v2/metadata_tests.rb +4 -4
  184. data/tests/rackspace/requests/databases/database_tests.rb +23 -20
  185. data/tests/rackspace/requests/databases/user_tests.rb +6 -6
  186. data/tests/rackspace/requests/identity/user_tests.rb +4 -1
  187. data/tests/rackspace/requests/load_balancers/usage_tests.rb +4 -2
  188. data/tests/rackspace/requests/storage/large_object_tests.rb +303 -59
  189. data/tests/rackspace/requests/storage/object_tests.rb +73 -18
  190. data/tests/rackspace/service_tests.rb +83 -0
  191. data/tests/rackspace/storage_tests.rb +9 -0
  192. data/tests/xenserver/models/compute/server_tests.rb +11 -1
  193. metadata +89 -19
  194. data/tests/core/user_agent_tests.rb +0 -6
@@ -0,0 +1,32 @@
1
+ module Fog
2
+ module Metering
3
+ class OpenStack
4
+ class Real
5
+
6
+ def list_resources(options = {})
7
+ request(
8
+ :expects => 200,
9
+ :method => 'GET',
10
+ :path => 'resources'
11
+ )
12
+ end
13
+
14
+ end
15
+
16
+ class Mock
17
+
18
+ def list_resources(options = {})
19
+ response = Excon::Response.new
20
+ response.status = 200
21
+ response.body = [{
22
+ 'resource_id'=>'glance',
23
+ 'project_id'=>'d646b40dea6347dfb8caee2da1484c56',
24
+ 'user_id'=>'1d5fd9eda19142289a60ed9330b5d284',
25
+ 'metadata'=>{}}]
26
+ response
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -12,7 +12,8 @@ module Fog
12
12
  }
13
13
  }
14
14
 
15
- vanilla_options = ['snapshot_id']
15
+ vanilla_options = [:snapshot_id, :imageRef, :volume_type,
16
+ :source_volid]
16
17
  vanilla_options.select{|o| options[o]}.each do |key|
17
18
  data['volume'][key] = options[key]
18
19
  end
@@ -38,7 +39,8 @@ module Fog
38
39
  'display_description' => description,
39
40
  'size' => size,
40
41
  'status' => 'creating',
41
- 'snapshot_id' => options["snapshot_id"] || nil,
42
+ 'snapshot_id' => options[:snapshot_id] || nil,
43
+ 'image_id' => options[:imageRef] || nil,
42
44
  'volume_type' => nil,
43
45
  'availability_zone' => 'nova',
44
46
  'created_at' => Time.now,
@@ -28,7 +28,7 @@ module Fog
28
28
  unless error.response.body.empty?
29
29
  begin
30
30
  data = Fog::JSON.decode(error.response.body)
31
- message = data.values.first ? data.values.first['message'] : data['message']
31
+ message = extract_message(data)
32
32
  rescue => e
33
33
  Fog::Logger.warning("Received exception '#{e}' while decoding>> #{error.response.body}")
34
34
  message = error.response.body
@@ -42,6 +42,16 @@ module Fog
42
42
  new_error.instance_variable_set(:@status_code, status_code)
43
43
  new_error
44
44
  end
45
+
46
+ private
47
+
48
+ def self.extract_message(data)
49
+ if data.is_a?(Hash)
50
+ message = data.values.first['message'] if data.values.first.is_a?(Hash)
51
+ message ||= data['message']
52
+ end
53
+ message || data.inspect
54
+ end
45
55
  end
46
56
 
47
57
  class InternalServerError < ServiceError; end
@@ -96,6 +106,11 @@ module Fog
96
106
  end
97
107
  end
98
108
 
109
+ def self.json_response?(response)
110
+ return false unless response && response.headers
111
+ response.headers['Content-Type'] =~ %r{application/json}i ? true : false
112
+ end
113
+
99
114
  def self.normalize_url(endpoint)
100
115
  return nil unless endpoint
101
116
  str = endpoint.chomp " "
@@ -87,40 +87,25 @@ module Fog
87
87
  @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
88
88
  end
89
89
 
90
- def request(params)
91
- begin
92
- response = @connection.request(params.merge!({
93
- :headers => {
94
- 'Content-Type' => 'application/json',
95
- 'Accept' => 'application/json',
96
- 'X-Auth-Token' => auth_token
97
- }.merge!(params[:headers] || {}),
98
- :host => endpoint_uri.host,
99
- :path => "#{endpoint_uri.path}/#{params[:path]}"
100
- }))
101
- rescue Excon::Errors::NotFound => error
102
- raise NotFound.slurp(error, region)
103
- rescue Excon::Errors::BadRequest => error
104
- raise BadRequest.slurp error
105
- rescue Excon::Errors::InternalServerError => error
106
- raise InternalServerError.slurp error
107
- rescue Excon::Errors::HTTPStatusError => error
108
- raise ServiceError.slurp error
109
- end
110
- unless response.body.empty?
111
- response.body = Fog::JSON.decode(response.body)
112
- end
113
- response
90
+ def request(params, parse_json = true, &block)
91
+ super(params, parse_json, &block)
92
+ rescue Excon::Errors::NotFound => error
93
+ raise NotFound.slurp(error, region)
94
+ rescue Excon::Errors::BadRequest => error
95
+ raise BadRequest.slurp error
96
+ rescue Excon::Errors::InternalServerError => error
97
+ raise InternalServerError.slurp error
98
+ rescue Excon::Errors::HTTPStatusError => error
99
+ raise ServiceError.slurp error
114
100
  end
115
101
 
116
- def authenticate
117
- options = {
102
+ def authenticate(options={})
103
+ super({
118
104
  :rackspace_api_key => @rackspace_api_key,
119
105
  :rackspace_username => @rackspace_username,
120
106
  :rackspace_auth_url => @rackspace_auth_url,
121
107
  :connection_options => @connection_options
122
- }
123
- super(options)
108
+ })
124
109
  end
125
110
 
126
111
  def service_name
@@ -152,30 +152,16 @@ module Fog
152
152
  true
153
153
  end
154
154
 
155
- def request(params, parse_json = true)
156
- begin
157
- response = @connection.request(params.merge!({
158
- :headers => {
159
- 'Content-Type' => 'application/json',
160
- 'Accept' => 'application/json',
161
- 'X-Auth-Token' => auth_token
162
- }.merge!(params[:headers] || {}),
163
- :host => endpoint_uri.host,
164
- :path => "#{endpoint_uri.path}/#{params[:path]}",
165
- }))
166
- rescue Excon::Errors::NotFound => error
167
- raise Fog::Storage::Rackspace::NotFound.slurp(error, region)
168
- rescue Excon::Errors::BadRequest => error
169
- raise Fog::Storage::Rackspace::BadRequest.slurp error
170
- rescue Excon::Errors::InternalServerError => error
171
- raise Fog::Storage::Rackspace::InternalServerError.slurp error
172
- rescue Excon::Errors::HTTPStatusError => error
173
- raise Fog::Storage::Rackspace::ServiceError.slurp error
174
- end
175
- if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json}
176
- response.body = Fog::JSON.decode(response.body)
177
- end
178
- response
155
+ def request(params, parse_json = true, &block)
156
+ super(params, parse_json, &block)
157
+ rescue Excon::Errors::NotFound => error
158
+ raise Fog::Storage::Rackspace::NotFound.slurp(error, region)
159
+ rescue Excon::Errors::BadRequest => error
160
+ raise Fog::Storage::Rackspace::BadRequest.slurp error
161
+ rescue Excon::Errors::InternalServerError => error
162
+ raise Fog::Storage::Rackspace::InternalServerError.slurp error
163
+ rescue Excon::Errors::HTTPStatusError => error
164
+ raise Fog::Storage::Rackspace::ServiceError.slurp error
179
165
  end
180
166
 
181
167
  private
@@ -190,7 +190,6 @@ module Fog
190
190
  @rackspace_servicenet = options[:rackspace_servicenet]
191
191
  @rackspace_auth_token = options[:rackspace_auth_token]
192
192
  @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_compute_v1_url] || options[:rackspace_management_url])
193
- @rackspace_must_reauthenticate = false
194
193
  @connection_options = options[:connection_options] || {}
195
194
  authenticate
196
195
  Excon.defaults[:ssl_verify_peer] = false if service_net?
@@ -202,56 +201,29 @@ module Fog
202
201
  @connection.reset
203
202
  end
204
203
 
205
- def request(params)
206
- begin
207
- response = @connection.request(params.merge({
208
- :headers => {
209
- 'Content-Type' => 'application/json',
210
- 'X-Auth-Token' => auth_token
211
- }.merge!(params[:headers] || {}),
212
- :host => endpoint_uri.host,
213
- :path => "#{endpoint_uri.path}/#{params[:path]}",
214
- }))
215
- rescue Excon::Errors::Unauthorized => error
216
- if error.response.body != 'Bad username or password' # token expiration
217
- @rackspace_must_reauthenticate = true
218
- authenticate
219
- retry
220
- else # bad credentials
221
- raise error
222
- end
223
- rescue Excon::Errors::HTTPStatusError => error
224
- raise case error
225
- when Excon::Errors::NotFound
226
- NotFound.slurp(error, region)
227
- else
228
- error
229
- end
230
- end
231
- unless response.body.empty?
232
- response.body = Fog::JSON.decode(response.body)
233
- end
234
- response
204
+ def request(params, parse_json = true, &block)
205
+ super(params, parse_json, &block)
206
+ rescue Excon::Errors::NotFound => error
207
+ raise NotFound.slurp(error, region)
208
+ rescue Excon::Errors::BadRequest => error
209
+ raise BadRequest.slurp error
210
+ rescue Excon::Errors::InternalServerError => error
211
+ raise InternalServerError.slurp error
212
+ rescue Excon::Errors::HTTPStatusError => error
213
+ raise ServiceError.slurp error
235
214
  end
236
215
 
237
-
238
216
  def service_net?
239
217
  @rackspace_servicenet == true
240
218
  end
241
219
 
242
- def authenticate
243
- if @rackspace_must_reauthenticate || @rackspace_auth_token.nil?
244
- options = {
245
- :rackspace_api_key => @rackspace_api_key,
246
- :rackspace_username => @rackspace_username,
247
- :rackspace_auth_url => @rackspace_auth_url,
248
- :connection_options => @connection_options
249
- }
250
- super(options)
251
- else
252
- @auth_token = @rackspace_auth_token
253
- @uri = URI.parse(@rackspace_endpoint)
254
- end
220
+ def authenticate(options={})
221
+ super({
222
+ :rackspace_api_key => @rackspace_api_key,
223
+ :rackspace_username => @rackspace_username,
224
+ :rackspace_auth_url => @rackspace_auth_url,
225
+ :connection_options => @connection_options
226
+ })
255
227
  end
256
228
 
257
229
  def service_name
@@ -139,45 +139,25 @@ module Fog
139
139
  @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
140
140
  end
141
141
 
142
- def request(params)
143
- begin
144
- response = @connection.request(params.merge!({
145
- :headers => {
146
- 'Content-Type' => 'application/json',
147
- 'Accept' => 'application/json',
148
- 'X-Auth-Token' => auth_token
149
- }.merge!(params[:headers] || {}),
150
- :host => endpoint_uri.host,
151
- :path => "#{endpoint_uri.path}/#{params[:path]}"
152
- }))
153
- rescue Excon::Errors::NotFound => error
154
- raise NotFound.slurp(error, region)
155
- rescue Excon::Errors::BadRequest => error
156
- raise BadRequest.slurp error
157
- rescue Excon::Errors::InternalServerError => error
158
- raise InternalServerError.slurp error
159
- rescue Excon::Errors::HTTPStatusError => error
160
- raise ServiceError.slurp error
161
- end
162
-
163
- unless response.body.empty?
164
- begin
165
- response.body = Fog::JSON.decode(response.body)
166
- rescue MultiJson::DecodeError => e
167
- response.body = {}
168
- end
169
- end
170
- response
142
+ def request(params, parse_json = true, &block)
143
+ super(params, parse_json, &block)
144
+ rescue Excon::Errors::NotFound => error
145
+ raise NotFound.slurp(error, region)
146
+ rescue Excon::Errors::BadRequest => error
147
+ raise BadRequest.slurp error
148
+ rescue Excon::Errors::InternalServerError => error
149
+ raise InternalServerError.slurp error
150
+ rescue Excon::Errors::HTTPStatusError => error
151
+ raise ServiceError.slurp error
171
152
  end
172
153
 
173
- def authenticate
174
- options = {
154
+ def authenticate(options={})
155
+ super({
175
156
  :rackspace_api_key => @rackspace_api_key,
176
157
  :rackspace_username => @rackspace_username,
177
158
  :rackspace_auth_url => @rackspace_auth_url,
178
159
  :connection_options => @connection_options
179
- }
180
- super(options)
160
+ })
181
161
  end
182
162
 
183
163
  def service_name
@@ -85,45 +85,29 @@ module Fog
85
85
  @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
86
86
  end
87
87
 
88
- def request(params)
89
- begin
90
- response = @connection.request(params.merge!({
91
- :headers => {
92
- 'Content-Type' => 'application/json',
93
- 'Accept' => 'application/json',
94
- 'X-Auth-Token' => auth_token
95
- }.merge!(params[:headers] || {}),
96
- :host => endpoint_uri.host,
97
- :path => "#{endpoint_uri.path}/#{params[:path]}"
98
- }))
99
- rescue Excon::Errors::NotFound => error
100
- raise NotFound.slurp(error, region)
101
- rescue Excon::Errors::BadRequest => error
102
- raise BadRequest.slurp error
103
- rescue Excon::Errors::InternalServerError => error
104
- raise InternalServerError.slurp error
105
- rescue Excon::Errors::HTTPStatusError => error
106
- raise ServiceError.slurp error
107
- end
108
- unless response.body.empty?
109
- response.body = Fog::JSON.decode(response.body)
110
- end
111
- response
88
+ def request(params, parse_json = true, &block)
89
+ super(params, parse_json, &block)
90
+ rescue Excon::Errors::NotFound => error
91
+ raise NotFound.slurp(error, region)
92
+ rescue Excon::Errors::BadRequest => error
93
+ raise BadRequest.slurp error
94
+ rescue Excon::Errors::InternalServerError => error
95
+ raise InternalServerError.slurp error
96
+ rescue Excon::Errors::HTTPStatusError => error
97
+ raise ServiceError.slurp error
112
98
  end
113
99
 
114
100
  def endpoint_uri(service_endpoint_url=nil)
115
101
  @uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_database_url)
116
102
  end
117
103
 
118
- def authenticate
119
- options = {
104
+ def authenticate(options={})
105
+ super({
120
106
  :rackspace_api_key => @rackspace_api_key,
121
107
  :rackspace_username => @rackspace_username,
122
108
  :rackspace_auth_url => @rackspace_auth_url,
123
109
  :connection_options => @connection_options
124
- }
125
-
126
- super(options)
110
+ })
127
111
  end
128
112
 
129
113
  private
@@ -6,6 +6,12 @@ module Fog
6
6
  class Rackspace < Fog::Service
7
7
  include Fog::Rackspace::Errors
8
8
 
9
+ class ServiceError < Fog::Rackspace::Errors::ServiceError; end
10
+ class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
11
+ class BadRequest < Fog::Rackspace::Errors::BadRequest; end
12
+ class Conflict < Fog::Rackspace::Errors::Conflict; end
13
+ class ServiceUnavailable < Fog::Rackspace::Errors::ServiceUnavailable; end
14
+
9
15
  class CallbackError < Fog::Errors::Error
10
16
  attr_reader :response, :message, :details
11
17
  def initialize(response)
@@ -95,9 +101,6 @@ module Fog
95
101
 
96
102
  deprecation_warnings(options)
97
103
 
98
- @connection_options[:headers] ||= {}
99
- @connection_options[:headers].merge!({ 'Content-Type' => 'application/json', 'X-Auth-Token' => auth_token })
100
-
101
104
  @persistent = options[:persistent] || false
102
105
  @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
103
106
  end
@@ -108,29 +111,32 @@ module Fog
108
111
 
109
112
  private
110
113
 
111
- def request(params)
112
- #TODO - Unify code with other rackspace services
114
+ def request(params, parse_json = true, &block)
113
115
  begin
114
- response = @connection.request(params.merge!({
115
- :path => "#{endpoint_uri.path}/#{params[:path]}"
116
- }))
117
- rescue Excon::Errors::BadRequest => error
118
- raise Fog::Rackspace::Errors::BadRequest.slurp error
119
- rescue Excon::Errors::Conflict => error
120
- raise Fog::Rackspace::Errors::Conflict.slurp error
116
+ super(params, parse_json, &block)
121
117
  rescue Excon::Errors::NotFound => error
122
118
  raise NotFound.slurp(error, region)
119
+ rescue Excon::Errors::BadRequest => error
120
+ raise BadRequest.slurp error
121
+ rescue Excon::Errors::InternalServerError => error
122
+ raise InternalServerError.slurp error
123
123
  rescue Excon::Errors::ServiceUnavailable => error
124
- raise Fog::Rackspace::Errors::ServiceUnavailable.slurp error
125
- end
126
- unless response.body.empty?
127
- response.body = Fog::JSON.decode(response.body)
124
+ raise ServiceUnavailable.slurp error
125
+ rescue Excon::Errors::Conflict => error
126
+ raise Conflict.slurp error
127
+ rescue Excon::Errors::HTTPStatusError => error
128
+ raise ServiceError.slurp error
128
129
  end
129
- response
130
130
  end
131
131
 
132
132
  def array_to_query_string(arr)
133
- arr.collect {|k,v| "#{k}=#{v}" }.join('&')
133
+ return "" unless arr
134
+ query_array = arr.collect do | k, v |
135
+ val_str = v.is_a?(Array) ? v.join(",") : v.to_s
136
+ "#{k}=#{val_str}"
137
+ end
138
+
139
+ query_array.join('&')
134
140
  end
135
141
 
136
142
  def validate_path_fragment(name, fragment)
@@ -158,15 +164,13 @@ module Fog
158
164
  @auth_token = credentials['X-Auth-Token']
159
165
  end
160
166
 
161
- def authenticate
162
- options = {
167
+ def authenticate(options={})
168
+ super({
163
169
  :rackspace_api_key => @rackspace_api_key,
164
170
  :rackspace_username => @rackspace_username,
165
171
  :rackspace_auth_url => @rackspace_auth_url,
166
172
  :connection_options => @connection_options
167
- }
168
-
169
- super(options)
173
+ })
170
174
  end
171
175
  end
172
176
  end