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
@@ -409,7 +409,7 @@ class GogridDriver < Deltacloud::BaseDriver
409
409
 
410
410
  def convert_image(gg_image, owner_id=nil)
411
411
  Image.new( {
412
- :id=>gg_image['id'],
412
+ :id=>gg_image['id'].to_s,
413
413
  :name => "#{gg_image['friendlyName']}",
414
414
  :description=> convert_description(gg_image).to_s,
415
415
  :owner_id=>gg_image['owner']['name'].to_s,
@@ -19,6 +19,8 @@
19
19
 
20
20
  module Deltacloud::Drivers::Mock
21
21
 
22
+ require 'fileutils'
23
+
22
24
  class Client
23
25
  def initialize(storage_root)
24
26
  @storage_root = storage_root
@@ -17,8 +17,10 @@
17
17
  require 'yaml'
18
18
  require 'base64'
19
19
  require 'etc'
20
+
20
21
  require_relative 'mock_client'
21
22
  require_relative 'mock_driver_cimi_methods'
23
+ require_relative '../../runner'
22
24
 
23
25
  module Deltacloud::Drivers::Mock
24
26
 
@@ -45,7 +47,7 @@ module Deltacloud::Drivers::Mock
45
47
  end
46
48
 
47
49
  define_hardware_profile('m1-large') do
48
- cpu (1..6)
50
+ cpu (1..6)
49
51
  memory ( 7680.. 15*1024), :default => 10 * 1024
50
52
  storage [ 850, 1024 ]
51
53
  architecture 'x86_64'
@@ -76,6 +78,7 @@ module Deltacloud::Drivers::Mock
76
78
  feature :instances, :user_name
77
79
  feature :instances, :user_data
78
80
  feature :instances, :authentication_key
81
+ feature :instances, :metrics
79
82
  feature :images, :user_name
80
83
  feature :images, :user_description
81
84
 
@@ -90,7 +93,7 @@ module Deltacloud::Drivers::Mock
90
93
  @client = Client.new(storage_root)
91
94
  end
92
95
 
93
- def realms(credentials, opts=nil)
96
+ def realms(credentials, opts={})
94
97
  check_credentials( credentials )
95
98
  results = []
96
99
  safely do
@@ -100,7 +103,6 @@ module Deltacloud::Drivers::Mock
100
103
  raise "NotImplementedTest" if opts and opts[:id] == "501"
101
104
  raise "ProviderErrorTest" if opts and opts[:id] == "502"
102
105
  raise "ProviderTimeoutTest" if opts and opts[:id] == "504"
103
- return REALMS if ( opts.nil? )
104
106
  results = REALMS
105
107
  end
106
108
  results = filter_on( results, :id, opts )
@@ -188,6 +190,7 @@ module Deltacloud::Drivers::Mock
188
190
  end
189
191
 
190
192
  hwp = find_hardware_profile(credentials, opts[:hwp_id], image_id)
193
+ hwp ||= find_hardware_profile(credentials, 'm1-small', image_id)
191
194
 
192
195
  name = opts[:name] || "i-#{Time.now.to_i}"
193
196
 
@@ -257,9 +260,8 @@ module Deltacloud::Drivers::Mock
257
260
  volumes
258
261
  end
259
262
 
260
- def create_storage_volume(credentials, opts=nil)
263
+ def create_storage_volume(credentials, opts={})
261
264
  check_credentials(credentials)
262
- opts ||= {}
263
265
  opts[:capacity] ||= "1"
264
266
  id = "Volume#{Time.now.to_i}"
265
267
  volume = {
@@ -273,13 +275,13 @@ module Deltacloud::Drivers::Mock
273
275
  StorageVolume.new(volume)
274
276
  end
275
277
 
276
- def destroy_storage_volume(credentials, opts=nil)
278
+ def destroy_storage_volume(credentials, opts={})
277
279
  check_credentials(credentials)
278
280
  @client.destroy(:storage_volumes, opts[:id])
279
281
  end
280
282
 
281
283
  #opts: {:id=,:instance_id,:device}
282
- def attach_storage_volume(credentials, opts)
284
+ def attach_storage_volume(credentials, opts={})
283
285
  check_credentials(credentials)
284
286
  attach_volume_instance(opts[:id], opts[:device], opts[:instance_id])
285
287
  end
@@ -319,9 +321,10 @@ module Deltacloud::Drivers::Mock
319
321
  :fingerprint => Key::generate_mock_fingerprint,
320
322
  :pem_rsa_key => Key::generate_mock_pem
321
323
  }
322
-
323
- raise "KeyExist" if @client.load(:keys, key_hash[:id])
324
- @client.store(:keys, key_hash)
324
+ safely do
325
+ raise "KeyExist" if @client.load(:keys, key_hash[:id])
326
+ @client.store(:keys, key_hash)
327
+ end
325
328
  return Key.new(key_hash)
326
329
  end
327
330
 
@@ -387,6 +390,8 @@ module Deltacloud::Drivers::Mock
387
390
  def blob_data(credentials, bucket_id, blob_id, opts = {})
388
391
  check_credentials(credentials)
389
392
  if blob = @client.load(:blobs, blob_id)
393
+ #give event machine a chance
394
+ sleep 1
390
395
  blob[:content].split('').each {|part| yield part}
391
396
  end
392
397
  end
@@ -401,12 +406,23 @@ module Deltacloud::Drivers::Mock
401
406
  :id => blob_id,
402
407
  :name => blob_id,
403
408
  :bucket => bucket_id,
404
- :content_length => blob_data[:tempfile].length,
405
- :content_type => blob_data[:type],
406
409
  :last_modified => Time.now,
407
410
  :user_metadata => BlobHelper::rename_metadata_headers(blob_meta, ''),
408
- :content => blob_data[:tempfile].read
409
411
  }
412
+ if blob_data.kind_of? Hash
413
+ blob_data[:tempfile].rewind
414
+ blob.merge!({
415
+ :content_length => blob_data[:tempfile].length,
416
+ :content_type => blob_data[:type],
417
+ :content => blob_data[:tempfile].read
418
+ })
419
+ elsif blob_data.kind_of? String
420
+ blob.merge!({
421
+ :content_length => blob_data.size,
422
+ :content_type => 'text/plain',
423
+ :content => blob_data
424
+ })
425
+ end
410
426
  @client.store(:blobs, blob)
411
427
  Blob.new(blob)
412
428
  end
@@ -447,6 +463,54 @@ module Deltacloud::Drivers::Mock
447
463
  end
448
464
  end
449
465
 
466
+ #--
467
+ # Metrics
468
+ #--
469
+ def metrics(credentials, opts={})
470
+ check_credentials( credentials )
471
+ instances = @client.build_all(Instance)
472
+ instances = filter_on( instances, :id, opts )
473
+
474
+ metrics_arr = instances.collect do |instance|
475
+ Metric.new(
476
+ :id => instance.id,
477
+ :entity => instance.name
478
+ )
479
+ end
480
+
481
+ # add metric names to metrics
482
+ metrics_arr.each do |metric|
483
+ @@METRIC_NAMES.each do |name|
484
+ metric.add_property(name)
485
+ end
486
+ metric.properties.sort! {|a,b| a.name <=> b.name}
487
+ end
488
+ metrics_arr
489
+ end
490
+
491
+ def metric(credentials, opts={})
492
+ metric = metrics(credentials, opts).first
493
+
494
+ metric.properties.each do |property|
495
+
496
+ property.values = (0..5).collect do |i|
497
+
498
+ unit = metric_unit_for(property.name)
499
+ average = (property.name == 'cpuUtilization') ? (rand * 1000).to_i / 10.0 : rand(1000)
500
+ max = (property.name == 'cpuUtilization') ? (1000 + 10 * average).to_i / 20.0 : average * (i + 1)
501
+ min = (property.name == 'cpuUtilization') ? (2.5 * average).to_i / 10.0 : (average / 4).to_i
502
+ {
503
+ :minimum => min,
504
+ :maximum => max,
505
+ :average => average,
506
+ :timestamp => Time.now - i * 60,
507
+ :unit => unit
508
+ }
509
+ end
510
+ end
511
+ metric
512
+ end
513
+
450
514
  def valid_credentials?(credentials)
451
515
  begin
452
516
  check_credentials(credentials)
@@ -492,6 +556,30 @@ module Deltacloud::Drivers::Mock
492
556
  StorageVolume.new(volume)
493
557
  end
494
558
 
559
+ def metric_unit_for(name)
560
+ case name
561
+ when /Utilization/ then 'Percent'
562
+ when /Byte/ then 'Bytes'
563
+ when /Sector/ then 'Count'
564
+ when /Count/ then 'Count'
565
+ when /Packet/ then 'Count'
566
+ else 'None'
567
+ end
568
+ end
569
+
570
+ # names copied from FGCP driver
571
+ @@METRIC_NAMES = [
572
+ 'cpuUtilization',
573
+ 'diskReadRequestCount',
574
+ 'diskReadSector',
575
+ 'diskWriteRequestCount',
576
+ 'diskWriteSector',
577
+ 'nicInputByte',
578
+ 'nicInputPacket',
579
+ 'nicOutputByte',
580
+ 'nicOutputPacket'
581
+ ]
582
+
495
583
  exceptions do
496
584
 
497
585
  on /AuthFailure/ do
@@ -83,8 +83,8 @@ module OCCIClient
83
83
  ######################################################################
84
84
  # Retieves the pool of Virtual Machines
85
85
  ######################################################################
86
- def get_vms
87
- get('/compute')
86
+ def get_vms(verbose=false)
87
+ get('/compute', verbose)
88
88
  end
89
89
 
90
90
  ######################################################################
@@ -196,8 +196,8 @@ module OCCIClient
196
196
  ######################################################################
197
197
  # Retieves the pool of Images owned by the user
198
198
  ######################################################################
199
- def get_images
200
- get('/storage')
199
+ def get_images(verbose=false)
200
+ get('/storage', verbose)
201
201
  end
202
202
 
203
203
 
@@ -275,10 +275,16 @@ module OCCIClient
275
275
 
276
276
  private
277
277
 
278
- def get(path)
278
+ def get(path, verbose=false)
279
279
  url = URI.parse(@endpoint+path)
280
+
281
+ params = []
282
+ params << "verbose=true" if verbose
283
+ params << "#{url.query}" if url.query
284
+
280
285
  path = url.path
281
- path << "?#{url.query}" if url.query
286
+ path << "?#{params.join('&')}"
287
+
282
288
  req = Net::HTTP::Get.new(path)
283
289
 
284
290
  do_request(url, req)
@@ -45,10 +45,10 @@ class OpennebulaDriver < Deltacloud::BaseDriver
45
45
  @hardware_profiles = REXML::Document.new(xml).root.elements.map {|d|
46
46
  elem = d.elements
47
47
  ::Deltacloud::HardwareProfile.new(elem['NAME'].text) {
48
- cpu elem['CPU']
49
- memory elem['MEMORY']
50
- storage elem['STORAGE']
51
- architecture elem['ARCHITECTURE']
48
+ cpu elem['CPU'].text if elem['CPU']
49
+ memory elem['MEMORY'].text if elem['MEMORY']
50
+ storage elem['STORAGE'].text if elem['STORAGE']
51
+ architecture elem['ARCHITECTURE'].text if elem['ARCHITECTURE']
52
52
  }
53
53
  }
54
54
  end
@@ -84,13 +84,11 @@ class OpennebulaDriver < Deltacloud::BaseDriver
84
84
  def images(credentials, opts=nil)
85
85
  occi_client = new_client(credentials)
86
86
 
87
- xml = treat_response(occi_client.get_images)
87
+ xml = treat_response(occi_client.get_images(true))
88
88
 
89
89
  # TBD Add extended info in the pool
90
90
  images = REXML::Document.new(xml).root.elements.map do |d|
91
- im_id = d.attributes['href'].split("/").last
92
- storage = treat_response(occi_client.get_image(im_id))
93
- convert_image(storage, credentials)
91
+ convert_image(d, credentials)
94
92
  end
95
93
  end
96
94
 
@@ -156,13 +154,10 @@ class OpennebulaDriver < Deltacloud::BaseDriver
156
154
  def instances(credentials, opts=nil)
157
155
  occi_client = new_client(credentials)
158
156
 
159
- xml = treat_response(occi_client.get_vms)
160
-
157
+ xml = treat_response(occi_client.get_vms(true))
161
158
  # TBD Add extended info in the pool
162
159
  instances = REXML::Document.new(xml).root.elements.map do |d|
163
- vm_id = d.attributes['href'].split("/").last
164
- computexml = treat_response(occi_client.get_vm(vm_id))
165
- convert_instance(computexml, credentials)
160
+ convert_instance(d, credentials)
166
161
  end
167
162
 
168
163
  instances = filter_on( instances, :state, opts )
@@ -221,7 +216,7 @@ class OpennebulaDriver < Deltacloud::BaseDriver
221
216
 
222
217
 
223
218
  def convert_image(diskxml, credentials)
224
- storage = REXML::Document.new(diskxml).root.elements
219
+ storage = REXML::Document.new(diskxml.to_s).root.elements
225
220
 
226
221
  # TBD Add Image STATE, OWNER
227
222
  Image.new( {
@@ -235,10 +230,8 @@ class OpennebulaDriver < Deltacloud::BaseDriver
235
230
  } )
236
231
  end
237
232
 
238
-
239
233
  def convert_instance(computexml, credentials)
240
- compute = REXML::Document.new(computexml)
241
- computehash = compute.root.elements
234
+ computehash = REXML::Document.new(computexml.to_s).root.elements
242
235
 
243
236
  network = []
244
237
  computehash.each('NIC/IP') {|ip| network<<InstanceAddress.new(ip.text, :type => :ipv4)}
@@ -247,7 +240,6 @@ class OpennebulaDriver < Deltacloud::BaseDriver
247
240
  if computehash['DISK/STORAGE']
248
241
  image_id = computehash['DISK/STORAGE'].attributes['href'].split("/").last
249
242
  end
250
-
251
243
  Instance.new( {
252
244
  :id=>computehash['ID'].text,
253
245
  :owner_id=>credentials.user,
@@ -23,9 +23,11 @@ module Deltacloud
23
23
  class OpenstackDriver < Deltacloud::BaseDriver
24
24
 
25
25
  feature :instances, :user_name
26
+ feature :instances, :authentication_key
26
27
  feature :instances, :authentication_password
27
28
  feature :instances, :user_files
28
29
  feature :images, :user_name
30
+ feature :keys, :import_key
29
31
 
30
32
  define_instance_states do
31
33
  start.to( :pending ) .on( :create )
@@ -142,6 +144,9 @@ module Deltacloud
142
144
  if opts[:password] && opts[:password].length > 0
143
145
  params[:adminPass]=opts[:password]
144
146
  end
147
+ if opts[:keyname] && opts[:keyname].length > 0
148
+ params[:key_name]=opts[:keyname]
149
+ end
145
150
  safely do
146
151
  server = os.create_server(params)
147
152
  result = convert_from_server(server, os.connection.authuser)
@@ -285,6 +290,30 @@ module Deltacloud
285
290
  return http, request
286
291
  end
287
292
 
293
+ def keys(credentials, opts={})
294
+ os = new_client(credentials)
295
+ keys = []
296
+ safely do
297
+ os.keypairs.values.each{|key| keys << convert_key(key)}
298
+ end
299
+ filter_on(keys, :id, opts)
300
+ end
301
+
302
+ def create_key(credentials, opts={})
303
+ os = new_client(credentials)
304
+ safely do
305
+ params = (opts[:public_key] and opts[:public_key].length > 0)? {:name=>opts[:key_name], :public_key=> opts[:public_key]} : {:name=>opts[:key_name]}
306
+ convert_key(os.create_keypair(params))
307
+ end
308
+ end
309
+
310
+ def destroy_key(credentials, opts={})
311
+ os = new_client(credentials)
312
+ safely do
313
+ os.delete_keypair(opts[:id])
314
+ end
315
+ end
316
+
288
317
  private
289
318
 
290
319
  #for v2 authentication credentials.name == "username+tenant_name"
@@ -362,7 +391,8 @@ private
362
391
  :public_addresses => convert_server_addresses(server, :public),
363
392
  :private_addresses => convert_server_addresses(server, :private),
364
393
  :username => 'root',
365
- :password => password
394
+ :password => password,
395
+ :keyname => server.send(op, :key_name)
366
396
  )
367
397
  inst.actions = instance_actions_for(inst.state)
368
398
  inst.create_image = 'RUNNING'.eql?(inst.state)
@@ -411,6 +441,17 @@ private
411
441
  :user_metadata => blob_meta })
412
442
  end
413
443
 
444
+ def convert_key(key)
445
+ Key.new(
446
+ :id => key[:name],
447
+ :fingerprint => key[:fingerprint],
448
+ :credential_type => :key,
449
+ :pem_rsa_key => key[:private_key], # only available once, on create_key
450
+ :state => "AVAILABLE"
451
+ )
452
+ end
453
+
454
+
414
455
  #IN: path1='server_path1'. content1='contents1', path2='server_path2', content2='contents2' etc
415
456
  #OUT:{local_path=>server_path, local_path1=>server_path2 etc}
416
457
  def extract_personality(opts)
@@ -457,6 +498,10 @@ private
457
498
  status 500
458
499
  end
459
500
 
501
+ on /OpenStack::Exception::NotImplemented/ do
502
+ status 501
503
+ end
504
+
460
505
  end
461
506
 
462
507
 
@@ -85,8 +85,13 @@ class RhevmDriver < Deltacloud::BaseDriver
85
85
  client = new_client(credentials)
86
86
  img_arr = []
87
87
  safely do
88
- if (!opts.nil? && opts[:id])
89
- img_arr << convert_image(client, client.template(opts[:id]))
88
+ if opts[:id]
89
+ begin
90
+ img_arr << convert_image(client, client.template(opts[:id]))
91
+ rescue OVIRT::OvirtException => e
92
+ raise e unless e.message =~ /Resource Not Found/
93
+ img_arr = []
94
+ end
90
95
  else
91
96
  img_arr = client.templates.collect { |t| convert_image(client, t) }
92
97
  end
@@ -176,7 +181,7 @@ class RhevmDriver < Deltacloud::BaseDriver
176
181
  raise "Parameter name must be #{USER_NAME_MAX} characters or less" if opts[:name].length > USER_NAME_MAX
177
182
  end
178
183
  params[:name] = opts[:name]
179
- params[:template] = opts[:image_id]
184
+ params[:template] = image_id
180
185
  params[:cluster] = opts[:realm_id] if opts[:realm_id]
181
186
  params[:hwp_id] = opts[:hwp_id] if opts[:hwp_id]
182
187
  params[:memory] = (opts[:hwp_memory].to_i * 1024 * 1024) if opts[:hwp_memory]
@@ -273,19 +278,14 @@ class RhevmDriver < Deltacloud::BaseDriver
273
278
  unless state.respond_to?(:upcase)
274
279
  raise "State #{state.inspect} is not a string"
275
280
  end
276
- case state.strip.upcase
277
- when 'WAIT_FOR_LAUNCH', 'REBOOT_IN_PROGRESS', 'SAVING_STATE',
278
- 'RESTORING_STATE', 'POWERING_UP', 'IMAGE_LOCKED', 'SAVING_STATE' then
279
- 'PENDING'
280
- when 'POWERING_DOWN' then
281
- 'STOPPING'
282
- when 'UNASSIGNED', 'DOWN', 'PAUSED', 'NOT_RESPONDING', 'SUSPENDED', 'IMAGE_ILLEGAL', 'UNKNOWN' then
283
- 'STOPPED'
284
- when 'UP', 'MIGRATING_TO', 'MIGRATING_FROM'
285
- 'RUNNING'
286
- else
287
- raise "Unexpected state '#{state}'"
288
- end
281
+ state = state.gsub('\\', '').strip.upcase
282
+ return 'PENDING' if ['WAIT_FOR_LAUNCH', 'REBOOT_IN_PROGRESS', 'SAVING_STATE',
283
+ 'RESTORING_STATE', 'POWERING_UP', 'IMAGE_LOCKED', 'SAVING_STATE'].include? state
284
+ return 'STOPPING' if state == 'POWERING_DOWN'
285
+ return 'STOPPED' if ['UNASSIGNED', 'DOWN', 'PAUSED', 'NOT_RESPONDING', 'SUSPENDED',
286
+ 'IMAGE_ILLEGAL', 'UNKNOWN'].include? state
287
+ return 'RUNNING' if ['UP', 'MIGRATING_TO', 'MIGRATING_FROM'].include? state
288
+ raise "Unexpected state '#{state}'"
289
289
  end
290
290
 
291
291
  def convert_volume(volume)
@@ -308,7 +308,7 @@ class RhevmDriver < Deltacloud::BaseDriver
308
308
  :owner_id => client.credentials[:username],
309
309
  :architecture => 'x86_64', # All RHEV-M VMs are x86_64
310
310
  :hardware_profiles => hardware_profiles(nil),
311
- :state => img.status
311
+ :state => img.status.strip.upcase
312
312
  )
313
313
  end
314
314