deltacloud-core 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. data/Rakefile +99 -141
  2. data/bin/deltacloudd +4 -1
  3. data/config.ru +13 -6
  4. data/config/drivers/aruba.yaml +8 -0
  5. data/config/drivers/fgcp.yaml +3 -2
  6. data/deltacloud-core.gemspec +13 -9
  7. data/lib/cimi/collections/cloud_entry_point.rb +1 -1
  8. data/lib/cimi/models.rb +1 -7
  9. data/lib/cimi/models/base.rb +1 -4
  10. data/lib/cimi/models/cloud_entry_point.rb +14 -0
  11. data/lib/cimi/models/machine.rb +4 -4
  12. data/lib/cimi/models/machine_admin.rb +1 -0
  13. data/lib/cimi/models/machine_configuration.rb +4 -4
  14. data/lib/cimi/models/schema.rb +17 -14
  15. data/lib/cimi/models/volume_image.rb +1 -1
  16. data/lib/cimi/server.rb +1 -1
  17. data/lib/deltacloud/api.rb +55 -3
  18. data/lib/deltacloud/collections/addresses.rb +1 -1
  19. data/lib/deltacloud/collections/buckets.rb +12 -10
  20. data/lib/deltacloud/collections/firewalls.rb +2 -1
  21. data/lib/deltacloud/collections/hardware_profiles.rb +1 -1
  22. data/lib/deltacloud/collections/images.rb +2 -2
  23. data/lib/deltacloud/collections/instance_states.rb +6 -3
  24. data/lib/deltacloud/collections/instances.rb +2 -1
  25. data/lib/deltacloud/collections/keys.rb +6 -2
  26. data/lib/deltacloud/collections/load_balancers.rb +8 -7
  27. data/lib/deltacloud/collections/metrics.rb +2 -1
  28. data/lib/deltacloud/collections/realms.rb +1 -1
  29. data/lib/deltacloud/collections/storage_snapshots.rb +2 -1
  30. data/lib/deltacloud/collections/storage_volumes.rb +2 -2
  31. data/lib/deltacloud/core_ext.rb +1 -7
  32. data/lib/deltacloud/core_ext/hash.rb +7 -5
  33. data/lib/deltacloud/core_ext/string.rb +1 -0
  34. data/lib/deltacloud/drivers/aruba/aruba_driver.rb +469 -0
  35. data/lib/deltacloud/drivers/base_driver.rb +12 -17
  36. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +50 -22
  37. data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +1 -1
  38. data/lib/deltacloud/drivers/exceptions.rb +12 -2
  39. data/lib/deltacloud/drivers/features.rb +8 -0
  40. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +21 -6
  41. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +169 -57
  42. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +1 -1
  43. data/lib/deltacloud/drivers/mock/mock_client.rb +2 -0
  44. data/lib/deltacloud/drivers/mock/mock_driver.rb +101 -13
  45. data/lib/deltacloud/drivers/opennebula/occi_client.rb +12 -6
  46. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +10 -18
  47. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +46 -1
  48. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +17 -17
  49. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +4 -4
  50. data/lib/deltacloud/helpers.rb +4 -4
  51. data/lib/deltacloud/helpers/blob_stream_helper.rb +4 -6
  52. data/lib/deltacloud/helpers/deltacloud_helper.rb +17 -1
  53. data/lib/deltacloud/helpers/driver_helper.rb +7 -3
  54. data/lib/deltacloud/helpers/url_helper.rb +4 -4
  55. data/lib/deltacloud/models/address.rb +1 -1
  56. data/lib/deltacloud/models/base_model.rb +0 -14
  57. data/lib/deltacloud/models/bucket.rb +0 -10
  58. data/lib/deltacloud/models/hardware_profile.rb +5 -26
  59. data/lib/deltacloud/models/image.rb +0 -12
  60. data/lib/deltacloud/models/instance.rb +6 -22
  61. data/lib/deltacloud/models/key.rb +2 -2
  62. data/lib/deltacloud/models/metric.rb +1 -1
  63. data/lib/deltacloud/models/storage_snapshot.rb +4 -0
  64. data/lib/deltacloud/server.rb +8 -2
  65. data/lib/deltacloud_rack.rb +40 -10
  66. data/lib/ec2/query_parser.rb +9 -4
  67. data/lib/ec2/server.rb +1 -1
  68. data/lib/ec2/views/create_key_pair.haml +3 -0
  69. data/lib/ec2/views/delete_key_pair.haml +1 -0
  70. data/lib/ec2/views/describe_availability_zones.haml +6 -0
  71. data/lib/ec2/views/describe_images.haml +10 -0
  72. data/lib/ec2/views/describe_instance_set.haml +24 -0
  73. data/lib/ec2/views/describe_instances.haml +9 -0
  74. data/lib/ec2/views/describe_key_pairs.haml +5 -0
  75. data/lib/ec2/views/error.haml +4 -0
  76. data/lib/ec2/views/instance_action.haml +9 -0
  77. data/lib/ec2/views/reboot_instances.haml +1 -0
  78. data/lib/ec2/views/run_instances.haml +7 -0
  79. data/lib/ec2/views/start_instances.haml +1 -0
  80. data/lib/ec2/views/stop_instances.haml +1 -0
  81. data/lib/ec2/views/terminate_instances.haml +9 -0
  82. data/lib/sinatra.rb +0 -1
  83. data/lib/sinatra/rack_accept.rb +1 -1
  84. data/lib/sinatra/rack_driver_select.rb +2 -2
  85. data/lib/sinatra/rack_etag.rb +5 -1
  86. data/lib/sinatra/rack_logger.rb +127 -0
  87. data/lib/sinatra/rack_matrix_params.rb +1 -1
  88. data/tests/cimi/collections/cloud_entry_point_test.rb +46 -0
  89. data/tests/cimi/collections/common.rb +17 -0
  90. data/tests/cimi/collections/machine_images_test.rb +44 -0
  91. data/tests/cimi/collections/machines_test.rb +41 -0
  92. data/tests/cimi/spec/cimi/model/machine_admin_spec.rb +35 -0
  93. data/tests/cimi/spec/cimi/model/machine_configuration_spec.rb +31 -0
  94. data/tests/cimi/spec/cimi/model/machine_image_spec.rb +33 -0
  95. data/tests/cimi/spec/cimi/model/machine_spec.rb +32 -0
  96. data/tests/cimi/spec/cimi/model/machine_template_spec.rb +32 -0
  97. data/tests/cimi/spec/cimi/model/schema_spec.rb +245 -0
  98. data/tests/cimi/spec/cimi/model/volume_configuration_spec.rb +34 -0
  99. data/tests/cimi/spec/cimi/model/volume_image_spec.rb +33 -0
  100. data/tests/cimi/spec/cimi/model/volume_spec.rb +32 -0
  101. data/tests/cimi/spec/cimi/model/volume_template_spec.rb +32 -0
  102. data/tests/cimi/spec/spec_helper.rb +136 -0
  103. data/tests/deltacloud/base_collection_test.rb +30 -0
  104. data/tests/deltacloud/collections/buckets_collection_test.rb +65 -0
  105. data/tests/deltacloud/collections/drivers_collection_test.rb +37 -0
  106. data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +53 -0
  107. data/tests/deltacloud/collections/images_collection_test.rb +59 -0
  108. data/tests/deltacloud/collections/instance_states_collection_test.rb +34 -0
  109. data/tests/deltacloud/collections/instances_collection_test.rb +63 -0
  110. data/tests/deltacloud/collections/keys_collection_test.rb +63 -0
  111. data/tests/deltacloud/collections_test.rb +35 -0
  112. data/tests/deltacloud/common.rb +14 -0
  113. data/tests/deltacloud/deltacloud_helper_test.rb +55 -0
  114. data/tests/deltacloud/drivers_test.rb +73 -0
  115. data/tests/deltacloud/rack_test.rb +51 -0
  116. data/tests/deltacloud/server_test.rb +149 -0
  117. data/tests/{api → deprecated/api}/common.rb +0 -0
  118. data/tests/{api → deprecated/api}/driver_test.rb +0 -0
  119. data/tests/deprecated/api/library_test.rb +6 -0
  120. data/tests/{cimi → deprecated/cimi}/features/step_definitions/common_steps.rb +0 -0
  121. data/tests/{cimi → deprecated/cimi}/features/step_definitions/machine_images_steps.rb +0 -0
  122. data/tests/{cimi → deprecated/cimi}/features/step_definitions/machines_steps.rb +0 -0
  123. data/tests/{cimi → deprecated/cimi}/features/step_definitions/volumes_steps.rb +0 -0
  124. data/tests/{cimi → deprecated/cimi}/features/support/env.rb +0 -0
  125. data/tests/{common.rb → deprecated/common.rb} +0 -0
  126. data/tests/{core_ext → deprecated/core_ext}/string.rb +0 -0
  127. data/tests/{drivers → deprecated/drivers}/ec2/api_test.rb +0 -0
  128. data/tests/deprecated/drivers/ec2/common.rb +23 -0
  129. data/tests/{drivers → deprecated/drivers}/ec2/drivers_test.rb +0 -0
  130. data/tests/{drivers → deprecated/drivers}/ec2/hardware_profiles_test.rb +0 -0
  131. data/tests/deprecated/drivers/ec2/images_test.rb +230 -0
  132. data/tests/{drivers → deprecated/drivers}/ec2/instances_test.rb +0 -0
  133. data/tests/deprecated/drivers/ec2/keys_test.rb +181 -0
  134. data/tests/deprecated/drivers/ec2/realms_test.rb +146 -0
  135. data/tests/{drivers → deprecated/drivers}/fgcp/api_test.rb +0 -0
  136. data/tests/{drivers → deprecated/drivers}/fgcp/hardware_profiles_test.rb +0 -0
  137. data/tests/{drivers → deprecated/drivers}/fgcp/realms_test.rb +0 -0
  138. data/tests/{drivers → deprecated/drivers}/fgcp/setup.rb +0 -0
  139. data/tests/{drivers → deprecated/drivers}/google/api_test.rb +0 -0
  140. data/tests/{drivers → deprecated/drivers}/google/buckets_test.rb +0 -0
  141. data/tests/{drivers → deprecated/drivers}/google/common.rb +2 -2
  142. data/tests/{drivers → deprecated/drivers}/mock/api_test.rb +0 -0
  143. data/tests/{drivers → deprecated/drivers}/mock/buckets_test.rb +0 -0
  144. data/tests/{drivers → deprecated/drivers}/mock/common.rb +0 -0
  145. data/tests/{drivers → deprecated/drivers}/mock/drivers_test.rb +0 -0
  146. data/tests/{drivers → deprecated/drivers}/mock/hardware_profiles_test.rb +0 -0
  147. data/tests/deprecated/drivers/mock/images_test.rb +197 -0
  148. data/tests/deprecated/drivers/mock/instances_test.rb +343 -0
  149. data/tests/deprecated/drivers/mock/keys_test.rb +161 -0
  150. data/tests/deprecated/drivers/mock/realms_test.rb +132 -0
  151. data/tests/deprecated/drivers/mock/storage_snapshots_test.rb +114 -0
  152. data/tests/deprecated/drivers/mock/storage_volumes_test.rb +122 -0
  153. data/tests/{drivers → deprecated/drivers}/openstack/api_test.rb +0 -0
  154. data/tests/{drivers → deprecated/drivers}/openstack/common.rb +0 -0
  155. data/tests/{drivers → deprecated/drivers}/openstack/hardware_profiles_test.rb +0 -0
  156. data/tests/{drivers → deprecated/drivers}/openstack/images_test.rb +0 -0
  157. data/tests/{drivers → deprecated/drivers}/openstack/instances_test.rb +0 -0
  158. data/tests/{drivers → deprecated/drivers}/openstack/realms_test.rb +0 -0
  159. data/tests/{drivers → deprecated/drivers}/rackspace/api_test.rb +0 -0
  160. data/tests/{drivers → deprecated/drivers}/rackspace/buckets_test.rb +0 -0
  161. data/tests/{drivers → deprecated/drivers}/rackspace/common.rb +0 -0
  162. data/tests/{drivers → deprecated/drivers}/rackspace/hardware_profiles_test.rb +0 -0
  163. data/tests/{drivers → deprecated/drivers}/rackspace/images_test.rb +0 -0
  164. data/tests/{drivers → deprecated/drivers}/rackspace/instances_test.rb +0 -0
  165. data/tests/{drivers → deprecated/drivers}/rackspace/realms_test.rb +0 -0
  166. data/tests/{drivers → deprecated/drivers}/rhevm/api_test.rb +0 -0
  167. data/tests/deprecated/drivers/rhevm/common.rb +21 -0
  168. data/tests/{drivers → deprecated/drivers}/rhevm/hardware_profiles_test.rb +0 -0
  169. data/tests/deprecated/drivers/rhevm/images_test.rb +48 -0
  170. data/tests/{drivers → deprecated/drivers}/rhevm/instances_test.rb +0 -0
  171. data/tests/deprecated/drivers/rhevm/realms_test.rb +40 -0
  172. data/tests/{minitest_common.rb → deprecated/minitest_common.rb} +0 -0
  173. data/tests/{minitest_common_api_test.rb → deprecated/minitest_common_api_test.rb} +0 -0
  174. data/tests/{rabbit_test.rb → deprecated/rabbit_test.rb} +0 -0
  175. data/tests/drivers/base/base_driver_test.rb +124 -0
  176. data/tests/{api → drivers/base}/library_test.rb +2 -8
  177. data/tests/drivers/ec2/common.rb +23 -15
  178. data/tests/drivers/ec2/images_test.rb +30 -211
  179. data/tests/drivers/ec2/instance_test.rb +104 -0
  180. data/tests/drivers/ec2/keys_test.rb +32 -161
  181. data/tests/drivers/ec2/realms_test.rb +26 -128
  182. data/tests/drivers/ec2/storage_snapshots_test.rb +54 -0
  183. data/tests/drivers/mock/images_test.rb +37 -179
  184. data/tests/drivers/mock/instances_test.rb +103 -340
  185. data/tests/drivers/mock/keys_test.rb +30 -145
  186. data/tests/drivers/mock/realms_test.rb +23 -118
  187. data/tests/drivers/mock/storage_snapshots_test.rb +23 -100
  188. data/tests/drivers/mock/storage_volumes_test.rb +41 -104
  189. data/tests/drivers/models/address_test.rb +18 -0
  190. data/tests/drivers/models/base_test.rb +33 -0
  191. data/tests/drivers/models/blob_test.rb +18 -0
  192. data/tests/drivers/models/hardware_profile_test.rb +52 -0
  193. data/tests/drivers/models/instance_address_test.rb +24 -0
  194. data/tests/drivers/models/instance_profile_test.rb +21 -0
  195. data/tests/drivers/models/instance_test.rb +29 -0
  196. data/tests/drivers/models/keys_test.rb +25 -0
  197. data/tests/drivers/models/metrics_test.rb +20 -0
  198. data/tests/drivers/rhevm/common.rb +15 -15
  199. data/tests/drivers/rhevm/images_test.rb +61 -36
  200. data/tests/drivers/rhevm/instance_test.rb +104 -0
  201. data/tests/drivers/rhevm/provider_test.rb +48 -0
  202. data/tests/drivers/rhevm/realms_test.rb +40 -37
  203. data/tests/ec2/common.rb +24 -0
  204. data/tests/ec2/query_parser_test.rb +98 -0
  205. data/tests/ec2/server_test.rb +45 -0
  206. data/tests/helpers/core_ext/array_test.rb +24 -0
  207. data/tests/helpers/core_ext/hash_test.rb +42 -0
  208. data/tests/helpers/core_ext/integer_test.rb +19 -0
  209. data/tests/helpers/core_ext/string_test.rb +74 -0
  210. data/tests/test_helper.rb +66 -0
  211. data/views/api/show.html.haml +1 -2
  212. data/views/api/show.xml.haml +1 -2
  213. data/views/blobs/show.xml.haml +1 -2
  214. data/views/keys/new.html.haml +9 -2
  215. data/views/load_balancers/new.html.haml +35 -34
  216. data/views/metrics/index.html.haml +1 -1
  217. data/views/metrics/show.html.haml +2 -2
  218. data/views/metrics/show.xml.haml +6 -2
  219. data/views/storage_volumes/attach.html.haml +1 -1
  220. data/views/storage_volumes/show.html.haml +1 -1
  221. metadata +853 -544
  222. data/lib/sinatra/accept_media_types.rb +0 -154
@@ -16,6 +16,12 @@
16
16
 
17
17
  module Deltacloud
18
18
 
19
+ require_relative '../core_ext.rb'
20
+ require_relative './exceptions.rb'
21
+ require_relative './features.rb'
22
+ require_relative '../models/hardware_profile.rb'
23
+ require_relative '../models/state_machine.rb'
24
+
19
25
  class BaseDriver
20
26
 
21
27
  include ExceptionHandler
@@ -33,12 +39,6 @@ module Deltacloud
33
39
  @features ||= {}
34
40
  end
35
41
 
36
- def self.features_for(entity)
37
- features.inject([]) do |result, item|
38
- result << item[entity] if item.has_key? entity
39
- result
40
- end
41
- end
42
42
 
43
43
  def self.feature(collection, feature_name)
44
44
  return if has_feature?(collection, feature_name)
@@ -75,7 +75,7 @@ module Deltacloud
75
75
  return if hw_profile
76
76
  hw_profile = ::Deltacloud::HardwareProfile.new( name, &block )
77
77
  @hardware_profiles << hw_profile
78
- hw_params = hw_profile.params
78
+ hw_profile.params
79
79
  # FIXME: Features
80
80
  #unless hw_params.empty?
81
81
  # feature :instances, :hardware_profiles do
@@ -145,7 +145,6 @@ module Deltacloud
145
145
 
146
146
  def instance_actions_for(state)
147
147
  actions = []
148
- state_key = state.downcase.to_sym
149
148
  states = instance_state_machine.states()
150
149
  current_state = states.find{|e| e.name == state.underscore.to_sym }
151
150
  if ( current_state )
@@ -157,7 +156,11 @@ module Deltacloud
157
156
 
158
157
  def has_capability?(method)
159
158
  method = (RUBY_VERSION =~ /^1\.9/) ? method : method.to_s
160
- (self.class.instance_methods - self.class.superclass.instance_methods).include? method
159
+ # Prevent has_capability fail when driver is inherited from another
160
+ # driver, like Eucalyptus
161
+ superclass_methods = self.class.superclass.name == 'Deltacloud::BaseDriver' ?
162
+ self.class.superclass.instance_methods : []
163
+ (self.class.instance_methods - superclass_methods).include? method
161
164
  end
162
165
 
163
166
  ## Capabilities
@@ -257,14 +260,6 @@ module Deltacloud
257
260
  end
258
261
  end
259
262
 
260
- def supported_collections
261
- DEFAULT_COLLECTIONS
262
- end
263
-
264
- def has_collection?(collection)
265
- supported_collections.include?(collection)
266
- end
267
-
268
263
  def catched_exceptions_list
269
264
  { :error => [], :auth => [], :glob => [] }
270
265
  end
@@ -142,8 +142,13 @@ module Deltacloud
142
142
  profiles = hardware_profiles(nil)
143
143
  if opts[:id]
144
144
  safely do
145
- img_arr = ec2.describe_images([opts[:id]]).collect do |image|
146
- convert_image(image, profiles)
145
+ begin
146
+ img_arr = ec2.describe_images([opts[:id]]).collect do |image|
147
+ convert_image(image, profiles)
148
+ end
149
+ rescue => e
150
+ raise e unless e.message =~ /Invalid id/ or e.message =~ /does not exist/
151
+ img_arr = []
147
152
  end
148
153
  end
149
154
  return img_arr
@@ -163,8 +168,13 @@ module Deltacloud
163
168
  realms = []
164
169
  safely do
165
170
  if opts[:id] and !opts[:id].empty?
166
- ec2.describe_availability_zones([opts[:id]]).collect do |realm|
167
- realms << convert_realm(realm) unless realm.empty?
171
+ begin
172
+ ec2.describe_availability_zones([opts[:id]]).collect do |realm|
173
+ realms << convert_realm(realm) unless realm.empty?
174
+ end
175
+ rescue => e
176
+ raise e unless e.message =~ /Invalid availability zone/
177
+ realms = []
168
178
  end
169
179
  else
170
180
  ec2.describe_availability_zones.collect do |realm|
@@ -195,10 +205,14 @@ module Deltacloud
195
205
 
196
206
  def instance(credentials, opts={})
197
207
  ec2 = new_client(credentials)
198
- inst_arr = []
199
208
  safely do
200
- ec2_inst = ec2.describe_instances([opts[:id]]).first
201
- raise "Instance #{opts[:id]} NotFound" if ec2_inst.nil?
209
+ begin
210
+ ec2_inst = ec2.describe_instances([opts[:id]]).first
211
+ rescue => e
212
+ raise e unless e.message =~ /Invalid id/ or e.message =~ /NotFound/
213
+ ec2_inst = nil
214
+ end
215
+ return if ec2_inst.nil?
202
216
  instance = convert_instance(ec2_inst)
203
217
  return nil unless instance
204
218
  if ec2_inst[:aws_platform] == 'windows'
@@ -329,8 +343,13 @@ module Deltacloud
329
343
  ec2 = new_client(credentials)
330
344
  opts ||= {}
331
345
  safely do
332
- ec2.describe_key_pairs(opts[:id] ? [opts[:id]] : nil).collect do |key|
333
- convert_key(key)
346
+ begin
347
+ ec2.describe_key_pairs(opts[:id] ? [opts[:id]] : nil).collect do |key|
348
+ convert_key(key)
349
+ end
350
+ rescue => e
351
+ raise e unless e.message =~ /does not exist/
352
+ []
334
353
  end
335
354
  end
336
355
  end
@@ -378,7 +397,7 @@ module Deltacloud
378
397
  :instance_port => opts['listener_instance_port'],
379
398
  :protocol => opts['listener_protocol']}]
380
399
  )
381
- return load_balancer(credentials, opts['name'])
400
+ return load_balancer(credentials, :id => opts['name'])
382
401
  end
383
402
  end
384
403
 
@@ -440,6 +459,7 @@ module Deltacloud
440
459
 
441
460
  def delete_bucket(credentials, name, opts={})
442
461
  s3_client = new_client(credentials, :s3)
462
+ s3_bucket, s3_client = get_bucket_with_endpoint(s3_client, credentials, name)
443
463
  safely do
444
464
  s3_client.interface.delete_bucket(name)
445
465
  end
@@ -524,7 +544,7 @@ module Deltacloud
524
544
 
525
545
  def blob_data(credentials, bucket_id, blob_id, opts={})
526
546
  s3_client = new_client(credentials, :s3)
527
- bucket, s3_client = get_bucket_with_endpoint(s3_client, credentials, bucket_id)
547
+ s3_client = get_bucket_with_endpoint(s3_client, credentials, bucket_id)[1]
528
548
  safely do
529
549
  s3_client.interface.get(bucket_id, blob_id) do |chunk|
530
550
  yield chunk
@@ -563,7 +583,7 @@ module Deltacloud
563
583
 
564
584
  def storage_volumes(credentials, opts={})
565
585
  ec2 = new_client( credentials )
566
- volume_list = (opts and opts[:id]) ? opts[:id] : nil
586
+ volume_list = (opts and opts[:id]) ? [opts[:id]] : []
567
587
  safely do
568
588
  ec2.describe_volumes(volume_list).collect do |volume|
569
589
  convert_volume(volume)
@@ -588,7 +608,7 @@ module Deltacloud
588
608
  unless ec2.delete_volume(opts[:id])
589
609
  raise Deltacloud::BackendError.new(500, "StorageVolume", "Cannot delete storage volume")
590
610
  end
591
- storage_volume(credentials, opts[:id])
611
+ storage_volume(credentials, :id => opts[:id])
592
612
  end
593
613
  end
594
614
 
@@ -608,11 +628,19 @@ module Deltacloud
608
628
 
609
629
  def storage_snapshots(credentials, opts={})
610
630
  ec2 = new_client(credentials)
611
- snapshot_list = (opts and opts[:id]) ? opts[:id] : []
631
+ snapshot_list = opts[:id] ? [opts[:id]] : []
612
632
  safely do
633
+ begin
613
634
  ec2.describe_snapshots(snapshot_list).collect do |snapshot|
614
635
  convert_snapshot(snapshot)
615
636
  end
637
+ rescue => e
638
+ if e.message =~ /NotFound/
639
+ []
640
+ else
641
+ raise e
642
+ end
643
+ end
616
644
  end
617
645
  end
618
646
 
@@ -756,8 +784,8 @@ module Deltacloud
756
784
 
757
785
  def providers(credentials, opts={})
758
786
  ec2 = new_client(credentials)
759
- providers = ec2.describe_regions.map{|r| Provider.new( {:id=>r, :name=>r,
760
- :url=>"#{ENV['API_HOST']}:#{ENV['API_PORT']}#{Deltacloud[ENV['API_FRONTEND'] || :deltacloud].root_url}\;provider=#{r}" }) }
787
+ @providers ||= ec2.describe_regions.map{|r| Provider.new( {:id=>r, :name=>r,
788
+ :url=>"#{ENV['API_HOST']}:#{ENV['API_PORT']}#{Deltacloud.default_frontend.root_url}\;provider=#{r}" }) }
761
789
  end
762
790
 
763
791
  def configured_providers
@@ -769,7 +797,7 @@ module Deltacloud
769
797
  realms(credentials) && true
770
798
  rescue => e
771
799
  if e.class.name =~ /AuthFailure/
772
- retval = false
800
+ false
773
801
  else
774
802
  safely { raise e }
775
803
  end
@@ -787,7 +815,7 @@ module Deltacloud
787
815
  klass.new(credentials.user, credentials.password, {
788
816
  :server => endpoint || endpoint_for_service(type),
789
817
  :connection_mode => :per_thread,
790
- :logger => ENV['RACK_ENV'] == 'test' ? Logger.new('/dev/null') : Logger.new(STDOUT)
818
+ :logger => ENV['RACK_ENV'] == 'test' ? Logger.new(StringIO.new) : Logger.new(STDOUT)
791
819
  })
792
820
  end
793
821
 
@@ -808,7 +836,7 @@ module Deltacloud
808
836
 
809
837
  def get_bucket_with_endpoint(s3_client, credentials, s3_bucket_name)
810
838
  s3_bucket = s3_client.bucket(s3_bucket_name)
811
- endpoint_for_bucket = Deltacloud::Drivers::driver_config[:ec2][:entrypoints]["s3"]["#{s3_bucket.location}"]
839
+ endpoint_for_bucket = Deltacloud::Drivers::driver_config[:ec2][:entrypoints]["s3"]["#{s3_bucket.location}"] || "s3.amazonaws.com"
812
840
  if (s3_client.interface.params[:server] != endpoint_for_bucket)
813
841
  s3_client = new_client(credentials, :s3, endpoint_for_bucket)
814
842
  s3_bucket = s3_client.bucket(s3_bucket_name)
@@ -934,8 +962,8 @@ module Deltacloud
934
962
 
935
963
  def convert_load_balancer(credentials, loadbalancer)
936
964
  realms = []
937
- balancer_realms = loadbalancer[:availability_zones].each do |zone|
938
- realms << realm(credentials, zone)
965
+ loadbalancer[:availability_zones].each do |zone|
966
+ realms << realm(credentials, :id => zone)
939
967
  end
940
968
  balancer = LoadBalancer.new({
941
969
  :id => loadbalancer[:name],
@@ -965,7 +993,7 @@ module Deltacloud
965
993
  end
966
994
  end
967
995
  #sources_string is @group,297467797945,test@address,ipv4,10.1.1.1,24 etc
968
- id_string = "#{user_id}~#{protocol}~#{from_port}~#{to_port}~#{sources_string.chomp!(",")}"
996
+ "#{user_id}~#{protocol}~#{from_port}~#{to_port}~#{sources_string.chomp!(",")}"
969
997
  #sources_string.slice(0,sources_string.length-1)}"
970
998
  end
971
999
 
@@ -71,7 +71,7 @@ module Deltacloud
71
71
  end
72
72
 
73
73
  def default_image_owner
74
- "self"
74
+ "self"
75
75
  end
76
76
 
77
77
  def default_image_type
@@ -37,6 +37,13 @@ module Deltacloud
37
37
  end
38
38
  end
39
39
 
40
+ class ForbiddenError < DeltacloudException
41
+ def initialize(e, message=nil)
42
+ message ||= e.message
43
+ super(403, e.class.name, message, e.backtrace)
44
+ end
45
+ end
46
+
40
47
  class UnknownMediaTypeError < DeltacloudException
41
48
  def initialize(e, message=nil)
42
49
  message ||= e.message
@@ -136,6 +143,7 @@ module Deltacloud
136
143
  return @handler if @handler
137
144
  case @status
138
145
  when 401 then Deltacloud::ExceptionHandler::AuthenticationFailure.new(e, @message)
146
+ when 403 then Deltacloud::ExceptionHandler::ForbiddenError.new(e, @message)
139
147
  when 404 then Deltacloud::ExceptionHandler::ObjectNotFound.new(e, @message)
140
148
  when 406 then Deltacloud::ExceptionHandler::UnknownMediaTypeError.new(e, @message)
141
149
  when 405 then Deltacloud::ExceptionHandler::MethodNotAllowed.new(e, @message)
@@ -176,8 +184,10 @@ module Deltacloud
176
184
  Deltacloud::ExceptionHandler::exceptions.each do |exdef|
177
185
  if exdef.match?($!)
178
186
  new_exception = exdef.handler($!)
179
- m = new_exception.message.nil? ? $!.message : new_exception.message
180
- $stderr.send(report_method, "#{[$!.class.to_s, m].join(':')}\n#{$!.backtrace[0..10].join("\n")}")
187
+ m = (new_exception && !new_exception.message.nil?) ? new_exception.message : $!.message
188
+ unless ENV['RACK_ENV'] == 'test'
189
+ $stderr.send(report_method, "#{[$!.class.to_s, m].join(':')}\n#{$!.backtrace[0..10].join("\n")}")
190
+ end
181
191
  raise exdef.handler($!) unless new_exception.nil?
182
192
  end
183
193
  end
@@ -148,6 +148,14 @@ module Deltacloud
148
148
  param :sandbox, :string, :optional
149
149
  end
150
150
  end
151
+
152
+ feature :import_key, :for => :keys do
153
+ description "Allow importing existing public key for creation of new key on provider"
154
+ operation :create do
155
+ param :public_key, :string, :optional
156
+ end
157
+ end
158
+
151
159
  end
152
160
 
153
161
  end
@@ -29,13 +29,16 @@ module Deltacloud
29
29
 
30
30
  class FgcpClient
31
31
 
32
- def initialize(cert, key, endpoint = nil, version = '2011-01-31', locale = 'en')
32
+ def initialize(cert, key, region = nil, version = '2011-01-31', locale = 'en')
33
33
  @version = version
34
34
  @locale = locale
35
- cert.subject.to_s =~ /\b[Cc]=(\w\w)\b/
36
- country = $1.downcase
37
- endpoint = Deltacloud::Drivers::driver_config[:fgcp][:entrypoints]['default'][country] unless endpoint
38
- raise "API endpoint not found for region #{country}" if endpoint.nil?
35
+ if region.nil?
36
+ cert.subject.to_s =~ /\b[Cc]=(\w\w)\b/
37
+ region = $1.downcase
38
+ end
39
+ # first 'jp' region is now 'jp-east'
40
+ region = 'jp-east' if region == 'jp'
41
+ endpoint = Deltacloud::Drivers::driver_config[:fgcp][:entrypoints]['default'][region] || region
39
42
 
40
43
  #proxy settings:
41
44
  http_proxy = ENV['http_proxy']
@@ -87,6 +90,10 @@ class FgcpClient
87
90
  request('GetVSYSConfiguration', {'vsysId' => vsys_id})
88
91
  end
89
92
 
93
+ def list_vservers(vsys_id)
94
+ request('ListVServer', {'vsysId' => vsys_id})
95
+ end
96
+
90
97
  def start_vserver(vserver_id)
91
98
  request('StartVServer', {'vsysId' => extract_vsys_id(vserver_id), 'vserverId' => vserver_id})
92
99
  end
@@ -284,6 +291,15 @@ eoidxml
284
291
  request('DestroyVSYS', {'vsysId' => vsys_id})
285
292
  end
286
293
 
294
+ def get_performance_information(vserver_id, interval, data_type=nil)
295
+ @version = '2012-02-18'
296
+ if data_type.nil?
297
+ request('GetPerformanceInformation', {'vsysId' => extract_vsys_id(vserver_id), 'serverId' => vserver_id, 'interval' => interval})
298
+ else
299
+ request('GetPerformanceInformation', {'vsysId' => extract_vsys_id(vserver_id), 'serverId' => vserver_id, 'dataType' => data_type, 'interval' => interval})
300
+ end
301
+ end
302
+
287
303
  #extract vsysId from vserverId, efmId or networkId
288
304
  def extract_vsys_id(id)
289
305
  /^(\w+-\w+)\b.*/ =~ id
@@ -307,7 +323,6 @@ eoidxml
307
323
  begin
308
324
  if attachment.nil?
309
325
  @uri.query = encode_params(params)
310
-
311
326
  resp = @service.request_get(@uri.request_uri, @headers)
312
327
  else
313
328
  #multipart post
@@ -32,6 +32,7 @@ class FgcpDriver < Deltacloud::BaseDriver
32
32
  end
33
33
 
34
34
  feature :instances, :user_name
35
+ feature :instances, :metrics
35
36
  feature :images, :user_name
36
37
  feature :images, :user_description
37
38
 
@@ -89,9 +90,6 @@ class FgcpDriver < Deltacloud::BaseDriver
89
90
  end
90
91
  end
91
92
  end
92
- #TODO: is there a way to sort them by arch and memory?
93
- #current order is as returned by API which is not a natural order
94
- # @hardware_profiles.sort_by{|e| [e.architecture, e.memory]}
95
93
  filter_hardware_profiles(@hardware_profiles, opts)
96
94
  end
97
95
 
@@ -198,6 +196,7 @@ class FgcpDriver < Deltacloud::BaseDriver
198
196
  )
199
197
  elsif xml = client.list_vsys['vsyss']
200
198
 
199
+ return [] if xml.nil?
201
200
  xml[0]['vsys'].each do |vsys|
202
201
 
203
202
  realms << Realm::new(
@@ -256,6 +255,7 @@ class FgcpDriver < Deltacloud::BaseDriver
256
255
  end
257
256
  elsif xml = client.list_vsys['vsyss']
258
257
 
258
+ return [] if xml.nil?
259
259
  xml[0]['vsys'].each do |vsys|
260
260
 
261
261
  # use get_vsys_configuration (instead of get_vserver_configuration) to retrieve all vservers in one call
@@ -428,12 +428,13 @@ class FgcpDriver < Deltacloud::BaseDriver
428
428
  :instance_id => vdisk['attachedTo'].nil? ? nil : vdisk['attachedTo'][0],
429
429
  :state => state,
430
430
  :actions => actions,
431
- # alining with rhevm, which returns 'system' or 'data'
431
+ # aligning with rhevm, which returns 'system' or 'data'
432
432
  :kind => determine_storage_type(opts[:id]),
433
433
  :realm_id => client.extract_vsys_id(opts[:id])
434
434
  )
435
435
  elsif xml = client.list_vsys['vsyss']
436
436
 
437
+ return [] if xml.nil?
437
438
  xml[0]['vsys'].each do |vsys|
438
439
 
439
440
  vdisks = client.list_vdisk(vsys['vsysId'][0])['vdisks'][0]
@@ -449,7 +450,7 @@ class FgcpDriver < Deltacloud::BaseDriver
449
450
  :capacity => vdisk['size'][0],
450
451
  :instance_id => vdisk['attachedTo'].nil? ? nil : vdisk['attachedTo'][0],
451
452
  :realm_id => client.extract_vsys_id(vdisk['vdiskId'][0]),
452
- # alining with rhevm, which returns 'system' or 'data'
453
+ # aligning with rhevm, which returns 'system' or 'data'
453
454
  :kind => determine_storage_type(vdisk['vdiskId'][0]),
454
455
  :state => vdisk['attachedTo'].nil? ? nil : 'IN-USE'
455
456
  )
@@ -490,7 +491,7 @@ class FgcpDriver < Deltacloud::BaseDriver
490
491
  :realm_id => client.extract_vsys_id(opts[:realm_id]),
491
492
  :instance_id => nil,
492
493
  :state => 'DEPLOYING',
493
- # alining with rhevm, which returns 'system' or 'data'
494
+ # aligning with rhevm, which returns 'system' or 'data'
494
495
  :kind => 'data',
495
496
  :actions => []
496
497
  )
@@ -545,15 +546,13 @@ class FgcpDriver < Deltacloud::BaseDriver
545
546
  end
546
547
  elsif xml = client.list_vsys['vsyss']
547
548
 
549
+ return [] if xml.nil?
548
550
  xml[0]['vsys'].each do |vsys|
549
551
 
550
552
  vdisks = client.list_vdisk(vsys['vsysId'][0])['vdisks'][0]
551
553
  if vdisks['vdisk']
552
554
  vdisks['vdisk'].each do |vdisk|
553
555
 
554
- #TODO: skipping system disks for now to improve performance
555
- if vdisk['vdiskId'][0] =~ /^.*-D-\d\d\d\d/
556
-
557
556
  backups = client.list_vdisk_backup(vdisk['vdiskId'][0])
558
557
  if backups['backups'] and backups['backups'][0]['backup']
559
558
  backups['backups'][0]['backup'].each do |backup|
@@ -566,7 +565,6 @@ if vdisk['vdiskId'][0] =~ /^.*-D-\d\d\d\d/
566
565
  )
567
566
  end
568
567
  end
569
- end
570
568
  end
571
569
  end
572
570
  end
@@ -689,7 +687,7 @@ end
689
687
  client = new_client(credentials)
690
688
  opts ||= {}
691
689
  if opts[:realm_id]
692
- # just in case a network realm was passed
690
+ # just in case a network realm was passed in
693
691
  opts[:realm_id] = client.extract_vsys_id(opts[:realm_id])
694
692
  else
695
693
  # get first vsys
@@ -699,7 +697,7 @@ end
699
697
 
700
698
  client.allocate_public_ip(opts[:realm_id])
701
699
  end
702
- #TODO: new address not returned immediately!
700
+ # new address not returned immediately!
703
701
  Address.new(:id => 'PENDING-xxx.xxx.xxx.xxx')
704
702
  end
705
703
 
@@ -710,9 +708,9 @@ end
710
708
  if opts[:realm_id]
711
709
  opts[:realm_id] = client.extract_vsys_id(opts[:realm_id])
712
710
  else
713
- xml = client.list_public_ips
714
- if xml['publicips']
715
- xml['publicips'][0]['publicip'].find do |ip|
711
+ xml = client.list_public_ips['publicips']
712
+ if xml
713
+ xml[0]['publicip'].find do |ip|
716
714
  opts[:realm_id] = ip['vsysId'][0] if opts[:id] == ip['address'][0]
717
715
  end
718
716
  end
@@ -894,15 +892,16 @@ eofwpxml
894
892
  :rules => rules
895
893
  })
896
894
  else
897
- xml = client.list_vsys
898
- return [] if xml['vsyss'].nil?
895
+ xml = client.list_vsys['vsyss']
896
+ return [] if xml.nil?
899
897
 
900
- firewalls = xml['vsyss'][0]['vsys'].collect do |vsys|
898
+ firewalls = xml[0]['vsys'].collect do |vsys|
901
899
 
902
900
  Firewall.new({
903
901
  :id => vsys['vsysId'][0] + '-S-0001',
904
902
  :name => fw_name,
905
903
  :description => "#{vsys['vsysName'][0]} [#{vsys['baseDescriptor'][0]}]",
904
+ :rules => [],
906
905
  :owner_id => vsys['creator'][0]
907
906
  })
908
907
  end
@@ -1013,10 +1012,10 @@ eofwopxml
1013
1012
  balancers = []
1014
1013
  safely do
1015
1014
  client = new_client(credentials)
1016
- xml = client.list_vsys
1017
- return [] if xml['vsyss'].nil?
1015
+ xml = client.list_vsys['vsyss']
1016
+ return [] if xml.nil?
1018
1017
 
1019
- xml['vsyss'][0]['vsys'].each do |vsys|
1018
+ xml[0]['vsys'].each do |vsys|
1020
1019
 
1021
1020
  # use get_vsys_configuration (instead of list_efm) to retrieve all SLBs incl. realms in one call
1022
1021
  vsys_config = client.get_vsys_configuration(vsys['vsysId'][0])
@@ -1137,33 +1136,138 @@ eofwopxml
1137
1136
  end
1138
1137
  end
1139
1138
 
1139
+ def metrics(credentials, opts={})
1140
+ opts ||= {}
1141
+ metrics_arr = []
1142
+ safely do
1143
+ client = new_client(credentials)
1144
+ realms = []
1145
+
1146
+ # first check for cases of id or realm_id specified
1147
+ if opts[:id]
1148
+ metrics_arr << Metric.new(
1149
+ :id => opts[:id],
1150
+ :entity => client.get_vserver_attributes(opts[:id])['vserver'][0]['vserverName'][0]
1151
+ )
1152
+ elsif opts[:realm_id]
1153
+ # if realm is set, list vservers in that realm (vsys/network ID), else list from all vsys
1154
+ realms << opts[:realm_id]
1155
+ else
1156
+
1157
+ # list all vsys
1158
+ xml = client.list_vsys['vsyss']
1159
+ realms = xml[0]['vsys'].collect { |vsys| vsys['vsysId'][0] } if xml
1160
+ end
1161
+
1162
+ # list all vservers
1163
+ realms.each do |realm_id|
1164
+
1165
+ xml = client.list_vservers(client.extract_vsys_id(realm_id))['vservers']
1166
+
1167
+ if xml and xml[0]['vserver']
1168
+
1169
+ xml[0]['vserver'].each do |vserver|
1170
+
1171
+ # should check whether vserver is actually in opts[:realm_id] if network segment?
1172
+ metrics_arr << Metric.new(
1173
+ :id => vserver['vserverId'][0],
1174
+ :entity => vserver['vserverName'][0]
1175
+ )
1176
+ end
1177
+ end
1178
+ end
1179
+
1180
+ # add metric names to metrics
1181
+ metrics_arr.each do |metric|
1182
+ @@METRIC_NAMES.each do |name|
1183
+ metric.add_property(name)
1184
+ end
1185
+ metric.properties.sort! {|a,b| a.name <=> b.name}
1186
+ end
1187
+ end
1188
+ metrics_arr
1189
+ end
1190
+
1191
+ def metric(credentials, opts={})
1192
+ safely do
1193
+ client = new_client(credentials)
1194
+ perf = client.get_performance_information(opts[:id], 'hour')
1195
+
1196
+ metric = Metric.new(
1197
+ :id => opts[:id],
1198
+ :entity => perf['serverName'][0],
1199
+ :properties => []
1200
+ )
1201
+ # if instance hasn't been running for an hour, no info will be returned
1202
+ unless perf['performanceinfos'].nil? or perf['performanceinfos'][0].nil? or perf['performanceinfos'][0]['performanceinfo'].nil?
1203
+
1204
+ perf['performanceinfos'][0]['performanceinfo'].each do |sample|
1205
+
1206
+ timestamp = Time.at(sample['recordTime'][0].to_i / 1000)
1207
+ sample.each do |measure|
1208
+
1209
+ measure_name = measure[0]
1210
+ unless measure_name == 'recordTime'
1211
+
1212
+ unit = metric_unit_for(measure_name)
1213
+ average = (unit == 'Percent') ? measure[1][0].to_f * 100 : measure[1][0]
1214
+
1215
+ properties = metric.add_property(measure_name).properties
1216
+ property = properties.find { |p| p.name == measure_name }
1217
+ property.values ||= []
1218
+ property.values << {
1219
+ :average => average,
1220
+ :timestamp => timestamp,
1221
+ :unit => unit
1222
+ }
1223
+ end
1224
+ end
1225
+ metric.properties.sort! {|a,b| a.name <=> b.name}
1226
+ end
1227
+ end
1228
+ metric
1229
+ end
1230
+ end
1231
+
1140
1232
  ######################################################################
1141
1233
  # Providers
1142
1234
  ######################################################################
1235
+ # output of this method is used to list regions (id, url) under /api/drivers/fgcp
1143
1236
  def providers(credentials, opts={})
1144
- cert, key = convert_credentials(credentials)
1145
- cert.subject.to_s =~ /\b[Cc]=(\w\w)\b/
1146
- country = $1.downcase
1147
- endpoint = Deltacloud::Drivers::driver_config[:fgcp][:entrypoints]['default'][country]
1148
- [
1237
+ configured_providers.collect do |region|
1149
1238
  Provider.new(
1150
- :id => "fgcp-#{country}",
1151
- :name => "Fujitsu Global Cloud Platform - #{country.upcase}",
1152
- :url => endpoint
1239
+ :id => "fgcp-#{region}",
1240
+ :name => "Fujitsu Global Cloud Platform - #{region.upcase}",
1241
+ :url => Deltacloud::Drivers::driver_config[:fgcp][:entrypoints]['default'][region]
1153
1242
  )
1154
- ]
1243
+ end
1155
1244
  end
1156
1245
 
1157
- # following code enables region drop-down box on GUI. No need as retrieving region from cert (subject c)
1158
- # def configured_providers
1159
- # Deltacloud::Drivers::driver_config[:fgcp][:entrypoints]['default'].keys
1160
- # end
1246
+ # following method enables region drop-down box on GUI
1247
+ def configured_providers
1248
+ Deltacloud::Drivers::driver_config[:fgcp][:entrypoints]['default'].keys.sort
1249
+ end
1161
1250
 
1162
1251
  exceptions do
1252
+
1253
+ on /ALREADY_STARTED/ do
1254
+ status 405
1255
+ end
1256
+
1257
+ # trying to start a running vserver, etc.
1258
+ on /ILLEGAL_STATE/ do
1259
+ status 405
1260
+ end
1261
+
1163
1262
  on /AuthFailure/ do
1164
1263
  status 401
1165
1264
  end
1166
1265
 
1266
+ # User not found: using certificate with wrong region
1267
+ on /User not found in selectData./ do
1268
+ status 401
1269
+ end
1270
+
1167
1271
  # if user doesn't have privileges to view or operate a particular resource
1168
1272
  on /User doesn.t have the right of access./ do
1169
1273
  status 400
@@ -1184,6 +1288,11 @@ eofwopxml
1184
1288
  status 404
1185
1289
  end
1186
1290
 
1291
+ # trying an operation that is not supported (yet) by the target region
1292
+ on /NOTFOUND: API to the Version/ do
1293
+ status 501 # Not Implemented
1294
+ end
1295
+
1187
1296
  # destroying a running SLB, etc.
1188
1297
  on /ALREADY_STARTED/ do
1189
1298
  status 502 #?
@@ -1215,18 +1324,12 @@ eofwopxml
1215
1324
  end
1216
1325
 
1217
1326
  def convert_credentials(credentials)
1218
- #username could be 'dkoper'
1219
- #load dkoper/UserCert.p12 from cert dir
1220
1327
  begin
1221
- #p File::join(CERT_DIR, credentials.user, 'UserCert.p12')
1222
1328
  cert_file = File.open(File::join(CERT_DIR, credentials.user, 'UserCert.p12'), 'rb')
1223
1329
  rescue Errno::ENOENT => e # file not found
1224
1330
  raise "AuthFailure: No certificate registered under name \'#{credentials.user}\'"
1225
1331
  # raise Deltacloud::ExceptionHandler::AuthenticationFailure.new(e, "No certificate registered under name #{credentials.user}")
1226
1332
  end
1227
- #TODO: check that cert's cn is indeed the username?
1228
- #cert.subject=/C=AU/O=Fujitsu Limited/CN=diesk_fast
1229
- #raise AuthError(?) if not
1230
1333
 
1231
1334
  begin
1232
1335
  pkcs12 = OpenSSL::PKCS12.new(cert_file, credentials.password)
@@ -1245,7 +1348,7 @@ eofwopxml
1245
1348
  else
1246
1349
  # vserver
1247
1350
  state = @@INSTANCE_STATE_MAP[client.get_vserver_status(vserver['vserverId'][0])['vserverStatus'][0]]
1248
- create_image = (state == /STOPPED|UNEXPECTED_STOP/)
1351
+ create_image = (state =~ /STOPPED|UNEXPECTED_STOP/)
1249
1352
  end
1250
1353
 
1251
1354
  {
@@ -1324,21 +1427,6 @@ eofwopxml
1324
1427
 
1325
1428
  # storage volumes
1326
1429
  storage_volumes = []
1327
- # system volume
1328
- if server == 'vserver'
1329
- storage_volumes << StorageVolume.new(
1330
- :id => vserver['vserverId'][0],
1331
- :name => vserver['vserverName'][0],
1332
- #:device => '', # no API to retrieve from
1333
- # :capacity => '10',# or '40', need to check with image (vserver['diskimageId'][0],)
1334
- :realm_id => realm_id,
1335
- :instance_id => vserver['vserverId'][0],
1336
- :state => 'IN-USE',
1337
- # alining with rhevm, which returns 'system' or 'data'
1338
- :kind => 'system',
1339
- :actions => []
1340
- )
1341
- end
1342
1430
  # additional volumes
1343
1431
  if vserver['vdisks'] and vserver['vdisks'][0]['vdisk']
1344
1432
  vserver['vdisks'][0]['vdisk'].each do |vdisk|
@@ -1352,7 +1440,7 @@ eofwopxml
1352
1440
  :realm_id => client.extract_vsys_id(realm_id),
1353
1441
  :instance_id => vserver['vserverId'][0],
1354
1442
  :state => 'IN-USE',
1355
- # alining with rhevm, which returns 'system' or 'data'
1443
+ # aligning with rhevm, which returns 'system' or 'data'
1356
1444
  :kind => 'data',
1357
1445
  :actions => actions
1358
1446
  )
@@ -1411,6 +1499,30 @@ eofwopxml
1411
1499
  client.get_efm_configuration("#{vsys_id}-S-0001", 'FW_NAT_RULE')
1412
1500
  end
1413
1501
 
1502
+ def metric_unit_for(name)
1503
+ case name
1504
+ when /Utilization/ then 'Percent'
1505
+ when /Byte/ then 'Bytes'
1506
+ when /Sector/ then 'Count'
1507
+ when /Count/ then 'Count'
1508
+ when /Packet/ then 'Count'
1509
+ else 'None'
1510
+ end
1511
+ end
1512
+
1513
+ # FGCP instance states mapped to DeltaCloud
1514
+ @@METRIC_NAMES = [
1515
+ 'cpuUtilization',
1516
+ 'diskReadRequestCount',
1517
+ 'diskReadSector',
1518
+ 'diskWriteRequestCount',
1519
+ 'diskWriteSector',
1520
+ 'nicInputByte',
1521
+ 'nicInputPacket',
1522
+ 'nicOutputByte',
1523
+ 'nicOutputPacket'
1524
+ ]
1525
+
1414
1526
  # FGCP instance states mapped to DeltaCloud
1415
1527
  @@INSTANCE_STATE_MAP = {
1416
1528
  'DEPLOYING' => 'PENDING',