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
@@ -12,10 +12,11 @@ module Fog
12
12
 
13
13
  class Real
14
14
 
15
- def list_machine_types
15
+ def list_machine_types(zone_name)
16
16
  api_method = @compute.machine_types.list
17
17
  parameters = {
18
- 'project' => 'google'
18
+ 'project' => @project,
19
+ 'zone' => zone_name,
19
20
  }
20
21
 
21
22
  result = self.build_result(api_method, parameters)
@@ -73,7 +73,7 @@ module Fog
73
73
  if (bucket = self.data[:buckets][bucket_name]) && (object = bucket[:objects][object_name])
74
74
  if options['If-Match'] && options['If-Match'] != object['ETag']
75
75
  response.status = 412
76
- elsif options['If-Modified-Since'] && options['If-Modified-Since'] > Time.parse(object['Last-Modified'])
76
+ elsif options['If-Modified-Since'] && options['If-Modified-Since'] >= Time.parse(object['Last-Modified'])
77
77
  response.status = 304
78
78
  elsif options['If-None-Match'] && options['If-None-Match'] == object['ETag']
79
79
  response.status = 304
@@ -43,7 +43,7 @@ module Fog
43
43
  if (object = container[:objects][object_name])
44
44
  if options['If-Match'] && options['If-Match'] != object['ETag']
45
45
  response.status = 412
46
- elsif options['If-Modified-Since'] && options['If-Modified-Since'] > Time.parse(object['Last-Modified'])
46
+ elsif options['If-Modified-Since'] && options['If-Modified-Since'] >= Time.parse(object['Last-Modified'])
47
47
  response.status = 304
48
48
  elsif options['If-None-Match'] && options['If-None-Match'] == object['ETag']
49
49
  response.status = 304
@@ -10,8 +10,11 @@ module Fog
10
10
  recognizes :persistent, :connection_options
11
11
  recognizes :hp_use_upass_auth_style, :hp_auth_version, :user_agent
12
12
  recognizes :hp_access_key, :hp_account_id # :hp_account_id is deprecated use hp_access_key instead
13
+
14
+ # :os_account_meta_temp_url_key is an OpenStack specific setting used to generate temporary urls.
15
+ recognizes :os_account_meta_temp_url_key
13
16
 
14
- secrets :hp_secret_key
17
+ secrets :hp_secret_key, :os_account_meta_temp_url_key
15
18
 
16
19
  model_path 'fog/hp/models/storage'
17
20
  model :directory
@@ -167,14 +170,26 @@ module Fog
167
170
  encoded_path = "#{path}/#{Fog::HP.escape(container)}/#{Fog::HP.escape(object)}"
168
171
 
169
172
  string_to_sign = "#{method}\n#{expires}\n#{sig_path}"
170
- # Only works with 1.9+ Not compatible with 1.8.7
171
- #signed_string = Digest::HMAC.hexdigest(string_to_sign, @hp_secret_key, Digest::SHA1)
172
- # Compatible with 1.8.7 onwards
173
- hmac = OpenSSL::HMAC.new(@hp_secret_key, OpenSSL::Digest::SHA1.new)
174
- signed_string = hmac.update(string_to_sign).hexdigest
175
-
176
- signature = @hp_tenant_id.to_s + ":" + @hp_access_key.to_s + ":" + signed_string
177
- signature = Fog::HP.escape(signature)
173
+
174
+ signature = nil
175
+
176
+ # HP uses a different strategy to create the signature that is passed to swift than OpenStack.
177
+ # As the HP provider is broadly used by OpenStack users the OpenStack strategy is applied when
178
+ # the @os_account_meta_temp_url_key is given.
179
+ if @os_account_meta_temp_url_key then
180
+ hmac = OpenSSL::HMAC.new(@os_account_meta_temp_url_key, OpenSSL::Digest::SHA1.new)
181
+ signature= hmac.update(string_to_sign).hexdigest
182
+ else
183
+ # Only works with 1.9+ Not compatible with 1.8.7
184
+ #signed_string = Digest::HMAC.hexdigest(string_to_sign, @hp_secret_key, Digest::SHA1)
185
+
186
+ # Compatible with 1.8.7 onwards
187
+ hmac = OpenSSL::HMAC.new(@hp_secret_key, OpenSSL::Digest::SHA1.new)
188
+ signed_string = hmac.update(string_to_sign).hexdigest
189
+
190
+ signature = @hp_tenant_id.to_s + ":" + @hp_access_key.to_s + ":" + signed_string
191
+ signature = Fog::HP.escape(signature)
192
+ end
178
193
 
179
194
  # generate the temp url using the signature and expiry
180
195
  "#{scheme}://#{host}:#{port}#{encoded_path}?temp_url_sig=#{signature}&temp_url_expires=#{expires}"
@@ -217,6 +232,7 @@ module Fog
217
232
  end
218
233
  @hp_secret_key = options[:hp_secret_key]
219
234
  @hp_tenant_id = options[:hp_tenant_id]
235
+ @os_account_meta_temp_url_key = options[:os_account_meta_temp_url_key]
220
236
  end
221
237
 
222
238
  def data
@@ -254,6 +270,7 @@ module Fog
254
270
  options[:hp_service_type] = "Object Storage"
255
271
  @hp_tenant_id = options[:hp_tenant_id]
256
272
  @hp_avl_zone = options[:hp_avl_zone]
273
+ @os_account_meta_temp_url_key = options[:os_account_meta_temp_url_key]
257
274
 
258
275
  ### Make the authentication call
259
276
  if (auth_version == :v2)
@@ -15,7 +15,7 @@ module Fog
15
15
  # * :ip<~String> - The ID of a static IP address to associate with this instance
16
16
  # * :volume_id<~String> - The ID of a storage volume to associate with this instance
17
17
  # * :vlan_id<~String> - The ID of a Vlan offering to associate with this instance.
18
- # * :secondary_ip<~String> - The ID of a static IP address to associate with this instance as secondary IP
18
+ # * :secondary_ip<~String> - Comma separated list of static IP IDs to associate with this instance.
19
19
  # * :is_mini_ephermal<~Boolean> - Whether or not the instance should be provisioned with the root segment only
20
20
  # * :configuration_data<~Hash> - Arbitrary name/value pairs defined by the image being created
21
21
  # * :anti_collocation_instance<~String> - The ID of an existing anti-collocated instance.
@@ -32,24 +32,29 @@ module Fog
32
32
  # * 'imageId'<~String>:
33
33
  # * 'launchTime'<~Integer>: epoch time in ms representing when the instance was launched
34
34
  def create_instance(name, image_id, instance_type, location, options={})
35
+ body_data = {
36
+ 'name' => name,
37
+ 'imageID' => image_id,
38
+ 'instanceType' => instance_type,
39
+ 'location' => location,
40
+ 'publicKey' => options[:key_name],
41
+ 'ip' => options[:ip],
42
+ 'volumeID' => options[:volume_id],
43
+ 'vlanID' => options[:vlan_id],
44
+ 'isMiniEphemeral' => options[:is_mini_ephemeral],
45
+ 'Configuration Data' => options[:configuration_data],
46
+ 'antiCollocationInstance' => options[:anti_collocation_instance]
47
+ }
48
+ if options[:secondary_ip]
49
+ options[:secondary_ip].split(',').map(&:strip).each_with_index do |n, idx|
50
+ body_data.merge!({"secondary.ip.#{idx}" => n})
51
+ end
52
+ end
35
53
  request(
36
54
  :method => 'POST',
37
55
  :expects => 200,
38
56
  :path => '/instances',
39
- :body => {
40
- 'name' => name,
41
- 'imageID' => image_id,
42
- 'instanceType' => instance_type,
43
- 'location' => location,
44
- 'publicKey' => options[:key_name],
45
- 'ip' => options[:ip],
46
- 'volumeID' => options[:volume_id],
47
- 'vlanID' => options[:vlan_id],
48
- 'SecondaryIP' => options[:secondary_ip],
49
- 'isMiniEphemeral' => options[:is_mini_ephemeral],
50
- 'Configuration Data' => options[:configuration_data],
51
- 'antiCollocationInstance' => options[:anti_collocation_instance],
52
- }
57
+ :body => body_data
53
58
  )
54
59
  end
55
60
 
@@ -78,7 +78,7 @@ module Fog
78
78
  if (object && !object[:delete_marker])
79
79
  if options['If-Match'] && options['If-Match'] != object['ETag']
80
80
  response.status = 412
81
- elsif options['If-Modified-Since'] && options['If-Modified-Since'] > Time.parse(object['Last-Modified'])
81
+ elsif options['If-Modified-Since'] && options['If-Modified-Since'] >= Time.parse(object['Last-Modified'])
82
82
  response.status = 304
83
83
  elsif options['If-None-Match'] && options['If-None-Match'] == object['ETag']
84
84
  response.status = 304
@@ -1,6 +1,18 @@
1
- require 'multi_json'
1
+ require "multi_json"
2
2
 
3
3
  module Fog
4
+
5
+ # @note Extracting JSON components out of core is a work in progress.
6
+ #
7
+ # The {JSON} module includes functionality that is common between APIs using
8
+ # JSON to send and receive data.
9
+ #
10
+ # The intent is to provide common code for provider APIs using JSON but not
11
+ # require it for those using XML.
12
+ #
13
+ # @todo Add +require "fog/json" and/or +include Fog::JSON+ to providers using
14
+ # its services
15
+ #
4
16
  module JSON
5
17
 
6
18
  def self.sanitize(data)
@@ -28,6 +40,5 @@ module Fog
28
40
  def self.decode(obj)
29
41
  MultiJson.decode(obj)
30
42
  end
31
-
32
43
  end
33
44
  end
@@ -0,0 +1,25 @@
1
+ module Fog
2
+ module Metering
3
+
4
+ def self.[](provider)
5
+ self.new(:provider => provider)
6
+ end
7
+
8
+ def self.new(attributes)
9
+ attributes = attributes.dup # Prevent delete from having side effects
10
+ provider = attributes.delete(:provider).to_s.downcase.to_sym
11
+ if self.providers.include?(provider)
12
+ require "fog/#{provider}/metering"
13
+ return Fog::Metering.const_get(Fog.providers[provider]).new(attributes)
14
+ end
15
+
16
+ raise ArgumentError.new("#{provider} has no identity service")
17
+ end
18
+
19
+ def self.providers
20
+ Fog.services[:metering]
21
+ end
22
+
23
+ end
24
+ end
25
+
@@ -47,6 +47,7 @@ module Fog
47
47
  service(:network, 'openstack/network', 'Network')
48
48
  service(:storage, 'openstack/storage', 'Storage')
49
49
  service(:volume, 'openstack/volume', 'Volume')
50
+ service(:metering, 'openstack/metering', 'Metering')
50
51
 
51
52
  # legacy v1.0 style auth
52
53
  def self.authenticate_v1(options, connection_options = {})
@@ -0,0 +1,215 @@
1
+ require 'fog/metering'
2
+ require 'fog/openstack'
3
+
4
+ module Fog
5
+ module Metering
6
+ class OpenStack < Fog::Service
7
+
8
+ requires :openstack_auth_url
9
+ recognizes :openstack_auth_token, :openstack_management_url, :persistent,
10
+ :openstack_service_type, :openstack_service_name, :openstack_tenant,
11
+ :openstack_api_key, :openstack_username,
12
+ :current_user, :current_tenant,
13
+ :openstack_endpoint_type
14
+
15
+ model_path 'fog/openstack/models/metering'
16
+
17
+ model :resource
18
+ collection :resources
19
+
20
+
21
+ request_path 'fog/openstack/requests/metering'
22
+
23
+ # Metering
24
+ request :get_resource
25
+ request :get_samples
26
+ request :get_statistics
27
+ request :list_meters
28
+ request :list_resources
29
+
30
+
31
+ class Mock
32
+ def self.data
33
+ @data ||= Hash.new do |hash, key|
34
+ hash[key] = {
35
+ :users => {},
36
+ :tenants => {}
37
+ }
38
+ end
39
+ end
40
+
41
+ def self.reset
42
+ @data = nil
43
+ end
44
+
45
+ def initialize(options={})
46
+ require 'multi_json'
47
+ @openstack_username = options[:openstack_username]
48
+ @openstack_tenant = options[:openstack_tenant]
49
+ @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
50
+
51
+ @auth_token = Fog::Mock.random_base64(64)
52
+ @auth_token_expiration = (Time.now.utc + 86400).iso8601
53
+
54
+ management_url = URI.parse(options[:openstack_auth_url])
55
+ management_url.port = 8776
56
+ management_url.path = '/v1'
57
+ @openstack_management_url = management_url.to_s
58
+
59
+ @data ||= { :users => {} }
60
+ unless @data[:users].find {|u| u['name'] == options[:openstack_username]}
61
+ id = Fog::Mock.random_numbers(6).to_s
62
+ @data[:users][id] = {
63
+ 'id' => id,
64
+ 'name' => options[:openstack_username],
65
+ 'email' => "#{options[:openstack_username]}@mock.com",
66
+ 'tenantId' => Fog::Mock.random_numbers(6).to_s,
67
+ 'enabled' => true
68
+ }
69
+ end
70
+ end
71
+
72
+ def data
73
+ self.class.data[@openstack_username]
74
+ end
75
+
76
+ def reset_data
77
+ self.class.data.delete(@openstack_username)
78
+ end
79
+
80
+ def credentials
81
+ { :provider => 'openstack',
82
+ :openstack_auth_url => @openstack_auth_uri.to_s,
83
+ :openstack_auth_token => @auth_token,
84
+ :openstack_management_url => @openstack_management_url }
85
+ end
86
+ end
87
+
88
+ class Real
89
+ attr_reader :current_user
90
+ attr_reader :current_tenant
91
+
92
+ def initialize(options={})
93
+ require 'multi_json'
94
+
95
+ @openstack_auth_token = options[:openstack_auth_token]
96
+
97
+ unless @openstack_auth_token
98
+ missing_credentials = Array.new
99
+ @openstack_api_key = options[:openstack_api_key]
100
+ @openstack_username = options[:openstack_username]
101
+
102
+ missing_credentials << :openstack_api_key unless @openstack_api_key
103
+ missing_credentials << :openstack_username unless @openstack_username
104
+ raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?
105
+ end
106
+
107
+ @openstack_tenant = options[:openstack_tenant]
108
+ @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
109
+ @openstack_management_url = options[:openstack_management_url]
110
+ @openstack_must_reauthenticate = false
111
+ @openstack_service_type = options[:openstack_service_type] || ['metering']
112
+ @openstack_service_name = options[:openstack_service_name]
113
+
114
+ @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL'
115
+ @connection_options = options[:connection_options] || {}
116
+
117
+ @current_user = options[:current_user]
118
+ @current_tenant = options[:current_tenant]
119
+
120
+ authenticate
121
+
122
+ @persistent = options[:persistent] || false
123
+ @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
124
+ end
125
+
126
+ def credentials
127
+ { :provider => 'openstack',
128
+ :openstack_auth_url => @openstack_auth_uri.to_s,
129
+ :openstack_auth_token => @auth_token,
130
+ :openstack_management_url => @openstack_management_url,
131
+ :current_user => @current_user,
132
+ :current_tenant => @current_tenant }
133
+ end
134
+
135
+ def reload
136
+ @connection.reset
137
+ end
138
+
139
+ def request(params)
140
+ begin
141
+ response = @connection.request(params.merge({
142
+ :headers => {
143
+ 'Content-Type' => 'application/json',
144
+ 'Accept' => 'application/json',
145
+ 'X-Auth-Token' => @auth_token
146
+ }.merge!(params[:headers] || {}),
147
+ :host => @host,
148
+ :path => "#{@path}/v2/#{params[:path]}"#,
149
+ # Causes errors for some requests like tenants?limit=1
150
+ # :query => ('ignore_awful_caching' << Time.now.to_i.to_s)
151
+ }))
152
+ rescue Excon::Errors::Unauthorized => error
153
+ if error.response.body != 'Bad username or password' # token expiration
154
+ @openstack_must_reauthenticate = true
155
+ authenticate
156
+ retry
157
+ else # bad credentials
158
+ raise error
159
+ end
160
+ rescue Excon::Errors::HTTPStatusError => error
161
+ raise case error
162
+ when Excon::Errors::NotFound
163
+ Fog::Compute::OpenStack::NotFound.slurp(error)
164
+ else
165
+ error
166
+ end
167
+ end
168
+ unless response.body.empty?
169
+ response.body = MultiJson.decode(response.body)
170
+ end
171
+ response
172
+ end
173
+
174
+ private
175
+
176
+ def authenticate
177
+ if !@openstack_management_url || @openstack_must_reauthenticate
178
+ options = {
179
+ :openstack_tenant => @openstack_tenant,
180
+ :openstack_api_key => @openstack_api_key,
181
+ :openstack_username => @openstack_username,
182
+ :openstack_auth_uri => @openstack_auth_uri,
183
+ :openstack_auth_token => @openstack_auth_token,
184
+ :openstack_service_type => @openstack_service_type,
185
+ :openstack_service_name => @openstack_service_name,
186
+ :openstack_endpoint_type => @openstack_endpoint_type
187
+ }
188
+
189
+ credentials = Fog::OpenStack.authenticate_v2(options, @connection_options)
190
+
191
+ @current_user = credentials[:user]
192
+ @current_tenant = credentials[:tenant]
193
+
194
+ @openstack_must_reauthenticate = false
195
+ @auth_token = credentials[:token]
196
+ @openstack_management_url = credentials[:server_management_url]
197
+ uri = URI.parse(@openstack_management_url)
198
+ else
199
+ @auth_token = @openstack_auth_token
200
+ uri = URI.parse(@openstack_management_url)
201
+ end
202
+
203
+ @host = uri.host
204
+ @path = uri.path
205
+ @path.sub!(/\/$/, '')
206
+ @port = uri.port
207
+ @scheme = uri.scheme
208
+ true
209
+ end
210
+
211
+ end
212
+ end
213
+ end
214
+ end
215
+
@@ -9,8 +9,8 @@ module Fog
9
9
 
10
10
  model Fog::Compute::OpenStack::Flavor
11
11
 
12
- def all
13
- data = service.list_flavors_detail.body['flavors']
12
+ def all(options = {})
13
+ data = service.list_flavors_detail(options).body['flavors']
14
14
  load(data)
15
15
  end
16
16