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
@@ -18,7 +18,7 @@ module Fog
18
18
  requires :parent
19
19
  metadata = service.list_metadata(collection_name, @parent.id).body['metadata']
20
20
  metas = []
21
- metadata.each_pair {|k,v| metas << {"key" => k, "value" => v} }
21
+ metadata.each_pair {|k,v| metas << {"key" => k, "value" => v} } unless metadata.nil?
22
22
  load(metas)
23
23
  end
24
24
 
@@ -41,6 +41,7 @@ module Fog
41
41
 
42
42
  attr_reader :password
43
43
  attr_writer :image_ref, :flavor_ref, :nics, :os_scheduler_hints
44
+ attr_accessor :block_device_mapping
44
45
 
45
46
 
46
47
  def initialize(attributes={})
@@ -52,6 +53,7 @@ module Fog
52
53
  self.max_count = attributes.delete(:max_count)
53
54
  self.nics = attributes.delete(:nics)
54
55
  self.os_scheduler_hints = attributes.delete(:os_scheduler_hints)
56
+ self.block_device_mapping = attributes.delete(:block_device_mapping)
55
57
 
56
58
  super
57
59
  end
@@ -267,10 +269,10 @@ module Fog
267
269
  true
268
270
  end
269
271
 
270
- # TODO: Implement /os-volumes-boot support with 'block_device_mapping'
271
272
  def save
272
273
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
273
- requires :flavor_ref, :image_ref, :name
274
+ requires :flavor_ref, :name
275
+ requires_one :image_ref, :block_device_mapping
274
276
  options = {
275
277
  'personality' => personality,
276
278
  'accessIPv4' => accessIPv4,
@@ -283,6 +285,7 @@ module Fog
283
285
  'max_count' => @max_count,
284
286
  'nics' => @nics,
285
287
  'os:scheduler_hints' => @os_scheduler_hints,
288
+ 'block_device_mapping' => @block_device_mapping
286
289
  }
287
290
  options['metadata'] = metadata.to_hash unless @metadata.nil?
288
291
  options = options.reject {|key, value| value.nil?}
@@ -16,7 +16,7 @@ module Fog
16
16
  end
17
17
 
18
18
  def find_by_id(id)
19
- self.find {|image| image.id == id}
19
+ all.find {|image| image.id == id}
20
20
  end
21
21
  alias_method :get, :find_by_id
22
22
 
@@ -0,0 +1,24 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Metering
5
+ class OpenStack
6
+
7
+ class Resource < Fog::Model
8
+
9
+ identity :resource_id
10
+
11
+ attribute :project_id
12
+ attribute :user_id
13
+ attribute :metadata
14
+
15
+ def initialize(attributes)
16
+ prepare_service_value(attributes)
17
+ super
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,25 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/openstack/models/metering/resource'
3
+
4
+ module Fog
5
+ module Metering
6
+ class OpenStack
7
+
8
+ class Resources < Fog::Collection
9
+ model Fog::Metering::OpenStack::Resource
10
+
11
+ def all(detailed=true)
12
+ load(service.list_resources.body)
13
+ end
14
+
15
+ def find_by_id(resource_id)
16
+ resource = service.get_resource(resource_id).body
17
+ new(resource)
18
+ rescue Fog::Metering::OpenStack::NotFound
19
+ nil
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -12,11 +12,13 @@ module Fog
12
12
  attribute :display_description, :aliases => 'displayDescription'
13
13
  attribute :status
14
14
  attribute :size
15
- attribute :type, :aliases => 'volumeType'
15
+ attribute :volume_type, :aliases => ['volumeType', 'type']
16
16
  attribute :snapshot_id, :aliases => 'snapshotId'
17
+ attribute :imageRef, :aliases => 'image_id'
17
18
  attribute :availability_zone, :aliases => 'availabilityZone'
18
19
  attribute :created_at, :aliases => 'createdAt'
19
20
  attribute :attachments
21
+ attribute :source_volid
20
22
 
21
23
 
22
24
  def initialize(attributes)
@@ -12,13 +12,14 @@ module Fog
12
12
  load(service.list_volumes(detailed).body['volumes'])
13
13
  end
14
14
 
15
- def find_by_id(volume_id)
15
+ def get(volume_id)
16
16
  if volume = service.get_volume_details(volume_id).body['volume']
17
17
  new(volume)
18
18
  end
19
19
  rescue Fog::Volume::OpenStack::NotFound
20
20
  nil
21
21
  end
22
+ alias_method :find_by_id, :get
22
23
  end
23
24
 
24
25
  end
@@ -176,7 +176,7 @@ module Fog
176
176
  @openstack_must_reauthenticate = false
177
177
  @openstack_service_type = options[:openstack_service_type] || ['network']
178
178
  @openstack_service_name = options[:openstack_service_name]
179
- @openstack_endpoint_type = options[:openstack_endpoint_type] || 'adminURL'
179
+ @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL'
180
180
  @openstack_region = options[:openstack_region]
181
181
 
182
182
  @connection_options = options[:connection_options] || {}
@@ -12,7 +12,7 @@ module Fog
12
12
  def create_flavor(attributes)
13
13
  # Get last flavor id
14
14
  flavor_ids = Array.new
15
- flavors = list_flavors_detail.body['flavors']
15
+ flavors = list_flavors_detail.body['flavors'] + list_flavors_detail(:is_public => false).body['flavors']
16
16
  flavors.each do |flavor|
17
17
  flavor_ids << flavor['id'].to_i
18
18
  end
@@ -56,11 +56,29 @@ module Fog
56
56
  data['os:scheduler_hints'] = options['os:scheduler_hints']
57
57
  end
58
58
 
59
+ if options['block_device_mapping']
60
+ data['server']['block_device_mapping'] =
61
+ [options['block_device_mapping']].flatten.map do |mapping|
62
+ {
63
+ 'volume_size' => mapping[:volume_size],
64
+ 'volume_id' => mapping[:volume_id],
65
+ 'delete_on_termination' => mapping[:delete_on_termination],
66
+ 'device_name' => mapping[:device_name]
67
+ }
68
+ end
69
+ end
70
+
71
+ path = if data['server']['block_device_mapping']
72
+ 'os-volumes_boot.json'
73
+ else
74
+ 'servers.json'
75
+ end
76
+
59
77
  request(
60
78
  :body => Fog::JSON.encode(data),
61
79
  :expects => [200, 202],
62
80
  :method => 'POST',
63
- :path => 'servers.json'
81
+ :path => path
64
82
  )
65
83
  end
66
84
 
@@ -17,7 +17,8 @@ module Fog
17
17
 
18
18
  def detach_volume(server_id, attachment_id)
19
19
  response = Excon::Response.new
20
- if self.data[:volumes][attachment_id]['attachments'].reject! { |attachment| attachment['serverId'] == server_id }
20
+ if self.data[:volumes][attachment_id] &&
21
+ self.data[:volumes][attachment_id]['attachments'].reject! { |attachment| attachment['serverId'] == server_id }
21
22
  response.status = 202
22
23
  response
23
24
  else
@@ -3,11 +3,12 @@ module Fog
3
3
  class OpenStack
4
4
  class Real
5
5
 
6
- def list_flavors_detail
6
+ def list_flavors_detail(options = {})
7
7
  request(
8
8
  :expects => [200, 203],
9
9
  :method => 'GET',
10
- :path => 'flavors/detail.json'
10
+ :path => 'flavors/detail.json',
11
+ :query => options
11
12
  )
12
13
  end
13
14
 
@@ -15,7 +16,7 @@ module Fog
15
16
 
16
17
  class Mock
17
18
 
18
- def list_flavors_detail
19
+ def list_flavors_detail(options = {})
19
20
  response = Excon::Response.new
20
21
  response.status = 200
21
22
  response.body = {
@@ -23,7 +23,7 @@ module Fog
23
23
 
24
24
  groups = if server_id then
25
25
  server_group_names =
26
- self.data[:server_security_group_map][server_id]
26
+ Array(self.data[:server_security_group_map][server_id])
27
27
 
28
28
  server_group_names.map do |name|
29
29
  security_groups.find do |sg|
@@ -19,9 +19,9 @@ module Fog
19
19
  response.body = {
20
20
  'tenant' => {
21
21
  'id' => "df9a815161eba9b76cc748fd5c5af73e",
22
- 'description' => attributes['description'] || 'normal tenant',
22
+ 'description' => attributes[:description] || 'normal tenant',
23
23
  'enabled' => true,
24
- 'name' => attributes['name'] || 'default'
24
+ 'name' => attributes[:name] || 'default'
25
25
  }
26
26
  }
27
27
  response
@@ -0,0 +1,32 @@
1
+ module Fog
2
+ module Metering
3
+ class OpenStack
4
+ class Real
5
+
6
+ def get_resource(resource_id)
7
+ request(
8
+ :expects => 200,
9
+ :method => 'GET',
10
+ :path => "resources/#{resource_id}"
11
+ )
12
+ end
13
+
14
+ end
15
+
16
+ class Mock
17
+
18
+ def get_resource(resource_id)
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
@@ -0,0 +1,55 @@
1
+ module Fog
2
+ module Metering
3
+ class OpenStack
4
+ class Real
5
+
6
+ def get_samples(meter_id, options=[])
7
+
8
+ data = {
9
+ 'q' => Array.new
10
+ }
11
+
12
+ options.each do |opt|
13
+ filter = {}
14
+
15
+ ['field', 'op', 'value'].each do |key|
16
+ filter[key] = opt[key] if opt[key]
17
+ end
18
+
19
+ data['q'] << filter unless filter.empty?
20
+ end
21
+
22
+ request(
23
+ :body => Fog::JSON.encode(data),
24
+ :expects => 200,
25
+ :method => 'GET',
26
+ :path => "meters/#{meter_id}"
27
+ )
28
+ end
29
+
30
+ end
31
+
32
+ class Mock
33
+
34
+ def get_samples(meter_id)
35
+ response = Excon::Response.new
36
+ response.status = 200
37
+ response.body = [{
38
+ 'counter_name'=>'image.size',
39
+ 'user_id'=>'1d5fd9eda19142289a60ed9330b5d284',
40
+ 'resource_id'=>'glance',
41
+ 'timestamp'=>'2013-04-03T23:44:21',
42
+ 'resource_metadata'=>{},
43
+ 'source'=>'artificial',
44
+ 'counter_unit'=>'bytes',
45
+ 'counter_volume'=>10.0,
46
+ 'project_id'=>'d646b40dea6347dfb8caee2da1484c56',
47
+ 'message_id'=>'14e4a902-9cf3-11e2-a054-003048f5eafc',
48
+ 'counter_type'=>'gauge'}]
49
+ response
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,56 @@
1
+ module Fog
2
+ module Metering
3
+ class OpenStack
4
+ class Real
5
+
6
+ def get_statistics(meter_id, options={})
7
+
8
+ data = {
9
+ 'period' => options['period'],
10
+ 'q' => Array.new
11
+ }
12
+
13
+ options['q'].each do |opt|
14
+ filter = {}
15
+
16
+ ['field', 'op', 'value'].each do |key|
17
+ filter[key] = opt[key] if opt[key]
18
+ end
19
+
20
+ data['q'] << filter unless filter.empty?
21
+ end if options['q'].is_a? Array
22
+
23
+ request(
24
+ :body => Fog::JSON.encode(data),
25
+ :expects => 200,
26
+ :method => 'GET',
27
+ :path => "meters/#{meter_id}/statistics"
28
+ )
29
+ end
30
+
31
+ end
32
+
33
+ class Mock
34
+
35
+ def get_statistics(meter_id, options={})
36
+ response = Excon::Response.new
37
+ response.status = 200
38
+ response.body = [{
39
+ 'count'=>143,
40
+ 'duration_start'=>'2013-04-03T23:44:21',
41
+ 'min'=>10.0,
42
+ 'max'=>10.0,
43
+ 'duration_end'=>'2013-04-04T23:24:21',
44
+ 'period'=>0,
45
+ 'period_end'=>'2013-04-04T23:24:21',
46
+ 'duration'=>85200.0,
47
+ 'period_start'=>'2013-04-03T23:44:21',
48
+ 'avg'=>10.0,
49
+ 'sum'=>1430.0}]
50
+ response
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,50 @@
1
+ module Fog
2
+ module Metering
3
+ class OpenStack
4
+ class Real
5
+
6
+ def list_meters(options=[])
7
+
8
+ data = {
9
+ 'q' => Array.new
10
+ }
11
+
12
+ options.each do |opt|
13
+ filter = {}
14
+
15
+ ['field', 'op', 'value'].each do |key|
16
+ filter[key] = opt[key] if opt[key]
17
+ end
18
+
19
+ data['q'] << filter unless filter.empty?
20
+ end
21
+
22
+ request(
23
+ :body => Fog::JSON.encode(data),
24
+ :expects => 200,
25
+ :method => 'GET',
26
+ :path => 'meters'
27
+ )
28
+ end
29
+
30
+ end
31
+
32
+ class Mock
33
+
34
+ def list_meters(options={})
35
+ response = Excon::Response.new
36
+ response.status = 200
37
+ response.body = [{
38
+ 'user_id'=>'1d5fd9eda19142289a60ed9330b5d284',
39
+ 'name'=>'image.size',
40
+ 'resource_id'=>'glance',
41
+ 'project_id'=>'d646b40dea6347dfb8caee2da1484c56',
42
+ 'type'=>'gauge',
43
+ 'unit'=>'bytes'}]
44
+ response
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end