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
@@ -22,7 +22,7 @@ module CIMI::Collections
22
22
  description "list all resources of the cloud"
23
23
  control do
24
24
  if params[:force_auth]
25
- return [401, 'Authentication failed'] unless driver.valid_credentials?(credentials)
25
+ halt 401 unless driver.valid_credentials?(credentials)
26
26
  end
27
27
  entry_point = CIMI::Model::CloudEntryPoint.create(self)
28
28
  respond_to do |format|
data/lib/cimi/models.rb CHANGED
@@ -17,13 +17,7 @@ module CIMI
17
17
  module Model; end
18
18
  end
19
19
 
20
- unless Kernel.respond_to?(:require_relative)
21
- module Kernel
22
- def require_relative(path)
23
- require File.join(File.dirname(caller[0]), path.to_str)
24
- end
25
- end
26
- end
20
+ require 'require_relative' if RUBY_VERSION < '1.9'
27
21
 
28
22
  require_relative './models/schema'
29
23
  require_relative './models/base'
@@ -199,10 +199,7 @@ class CIMI::Model::Base
199
199
  #
200
200
  text :id, :name, :description, :created
201
201
 
202
- # FIXME: this doesn't match with JSON
203
- hash :property, :content => :value do
204
- scalar :name
205
- end
202
+ hash :property
206
203
 
207
204
  def self.act_as_root_entity(name=nil)
208
205
  if name
@@ -15,15 +15,26 @@
15
15
 
16
16
  class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
17
17
 
18
+ text :base_uri, :xml_name => "baseURI", :json_name => "baseURI"
18
19
  array :entity_metadata do
19
20
  scalar :href
20
21
  end
21
22
 
23
+ DELTACLOUD_MAPPINGS = { "MachineImages" => "images",
24
+ "MachineConfigurations" => "hardware_profiles",
25
+ "Machines" => "instances",
26
+ "Volumes" => "storage_volumes",
27
+ "MachineAdmins" => "keys",
28
+ "VolumeImages" => "storage_snapshots",
29
+ }
30
+
31
+
22
32
  def self.create(context)
23
33
  self.new(entities(context).merge({
24
34
  :name => context.driver.name,
25
35
  :description => "Cloud Entry Point for the Deltacloud #{context.driver.name} driver",
26
36
  :id => context.cloudEntryPoint_url,
37
+ :base_uri => context.root_url,
27
38
  :created => Time.now,
28
39
  :entity_metadata => CIMI::Model::EntityMetadata.all_uri(context)
29
40
  }))
@@ -32,6 +43,9 @@ class CIMI::Model::CloudEntryPoint < CIMI::Model::Base
32
43
  # Return an Hash of the CIMI root entities used in CloudEntryPoint
33
44
  def self.entities(context)
34
45
  CIMI::Model.root_entities.inject({}) do |result, entity|
46
+ if DELTACLOUD_MAPPINGS[entity]
47
+ next result unless context.driver.respond_to?(DELTACLOUD_MAPPINGS[entity])
48
+ end
35
49
  result[entity.underscore] = { :href => context.send(:"#{entity.underscore}_url") }
36
50
  result
37
51
  end
@@ -132,7 +132,6 @@ class CIMI::Model::Machine < CIMI::Model::Base
132
132
  end
133
133
 
134
134
  private
135
-
136
135
  def self.from_instance(instance, context)
137
136
  cpu = memory = disks = (instance.instance_profile.id == "opaque")? "n/a" : nil
138
137
  self.new(
@@ -159,10 +158,10 @@ class CIMI::Model::Machine < CIMI::Model::Base
159
158
  end
160
159
 
161
160
  def self.convert_instance_properties(instance, context)
162
- properties = []
163
- properties << { :name => :machine_image, :value => context.machine_image_url(instance.image_id) }
161
+ properties = {}
162
+ properties["machine_image"] = context.machine_image_url(instance.image_id)
164
163
  if instance.respond_to? :keyname
165
- properties << { :name => :machine_admin, :value => context.machine_admin_url(instance.keyname) }
164
+ properties["machine_admin"] = context.machine_admin_url(instance.keyname)
166
165
  end
167
166
  properties
168
167
  end
@@ -187,6 +186,7 @@ class CIMI::Model::Machine < CIMI::Model::Base
187
186
 
188
187
  def self.convert_instance_storage(profile, context)
189
188
  machine_conf = CIMI::Model::MachineConfiguration.find(profile.name, context)
189
+ return nil unless machine_conf.disks
190
190
  storage_override = profile.overrides.find { |p, v| p == :storage }
191
191
  [
192
192
  { :capacity => {
@@ -25,6 +25,7 @@ class CIMI::Model::MachineAdmin < CIMI::Model::Base
25
25
 
26
26
  def self.find(id, context)
27
27
  if id == :all
28
+ return [] unless context.driver.respond_to?(:keys)
28
29
  keys = context.driver.keys(context.credentials)
29
30
  keys.map { |key| from_key(key, context) }
30
31
  else
@@ -52,16 +52,16 @@ class CIMI::Model::MachineConfiguration < CIMI::Model::Base
52
52
  # We accept just profiles with all properties set
53
53
  return unless profile.memory or profile.cpu or profile.storage
54
54
  memory = profile.memory.value || profile.memory.default
55
- cpu = profile.cpu.value || profile.cpu.default
56
- storage = profile.storage.value || profile.storage.default
55
+ cpu = (profile.cpu ? (profile.cpu.value || profile.cpu.default) : nil )
56
+ storage = (profile.storage ? (profile.storage.value || profile.storage.default) : nil )
57
57
  machine_hash = {
58
58
  :name => profile.name,
59
59
  :description => "Machine Configuration with #{memory} #{profile.memory.unit} "+
60
60
  "of memory and #{cpu} CPU",
61
- :cpu => cpu,
61
+ :cpu => ( cpu if cpu ) ,
62
62
  :created => Time.now.to_s, # FIXME: DC hardware_profile has no mention about created_at
63
63
  :memory => { :quantity => profile.memory.value || profile.memory.default, :units => profile.memory.unit },
64
- :disks => [ { :capacity => { :quantity => profile.storage.value || profile.storage.default, :units => profile.storage.unit } } ],
64
+ :disks => ( [ { :capacity => { :quantity => profile.storage.value || profile.storage.default, :units => profile.storage.unit } } ] if storage ),
65
65
  :id => context.machine_configuration_url(profile.name)
66
66
  }
67
67
  self.new(machine_hash)
@@ -25,8 +25,8 @@ class CIMI::Model::Schema
25
25
 
26
26
  def initialize(name, opts = {})
27
27
  @name = name
28
- @xml_name = (opts[:xml_name] || name).to_s.camelize(true)
29
- @json_name = (opts[:json_name] || name).to_s.camelize(true)
28
+ @xml_name = opts[:xml_name] || name.to_s.camelize(true)
29
+ @json_name = opts[:json_name] || name.to_s.camelize(true)
30
30
  end
31
31
 
32
32
  def from_xml(xml, model)
@@ -144,10 +144,12 @@ class CIMI::Model::Schema
144
144
  end
145
145
 
146
146
  class Array < Attribute
147
- # For an array :things, we collect all <thing/> elements (XmlSimple
147
+ # For an array :funThings, we collect all <funThing/> elements (XmlSimple
148
148
  # actually does the collecting)
149
149
  def initialize(name, opts = {}, &block)
150
- opts[:xml_name] = name.to_s.singularize unless opts[:xml_name]
150
+ unless opts[:xml_name]
151
+ opts[:xml_name] = name.to_s.singularize.camelize.uncapitalize
152
+ end
151
153
  super(name, opts)
152
154
  @struct = Struct.new(name, opts, &block)
153
155
  end
@@ -176,27 +178,28 @@ class CIMI::Model::Schema
176
178
  def initialize(name, opts = {}, &block)
177
179
  opts[:json_name] = name.to_s.pluralize unless opts[:json_name]
178
180
  super(name, opts)
179
- @struct = Struct.new(name, opts, &block)
180
181
  end
181
182
 
182
183
  def from_xml(xml, model)
183
- model[name] = (xml[xml_name] || []).map { |elt| @struct.convert_from_xml(elt) }
184
+ model[name] = (xml[xml_name] || []).inject({}) do |result, item|
185
+ result[item["name"]] = item["content"]
186
+ result
187
+ end
184
188
  end
185
189
 
186
190
  def from_json(json, model)
187
- model[name] = (json[json_name] || {}).inject([]) do |result,item|
188
- result << @struct.convert_from_json({ 'name' => item[0], 'value' => item[1] })
189
- end
191
+ model[name] = json[json_name] || {}
190
192
  end
191
193
 
192
194
  def to_xml(model, xml)
193
- ary = (model[name] || []).map { |elt| @struct.convert_to_xml(elt) }
195
+ ary = (model[name] || {}).map { |k, v| { "name" => k, "content" => v } }
194
196
  xml[xml_name] = ary unless ary.empty?
195
197
  end
196
198
 
197
199
  def to_json(model, json)
198
- ary = (model[name] || []).map { |elt| @struct.convert_to_json(elt) }
199
- json[json_name] = ary.inject({}) { |result, item| result[item['name']] = item['value']; result } unless ary.empty?
200
+ if model[name] && ! model[name].empty?
201
+ json[json_name] = model[name]
202
+ end
200
203
  end
201
204
  end
202
205
 
@@ -262,8 +265,8 @@ class CIMI::Model::Schema
262
265
  add_attributes!([name, opts], Struct, &block)
263
266
  end
264
267
 
265
- def hash(name, opts={}, &block)
266
- add_attributes!([name, opts], Hash, &block)
268
+ def hash(name)
269
+ add_attributes!([name, {}], Hash)
267
270
  end
268
271
  end
269
272
 
@@ -25,7 +25,7 @@ class CIMI::Model::VolumeImage < CIMI::Model::Base
25
25
  def self.find(id, context)
26
26
  storage_snapshots = []
27
27
  opts = ( id==:all ) ? {} : { :id=>id }
28
- storage_snapshots = self.driver.storage_snapshots(context.credentials, opts)
28
+ storage_snapshots = context.driver.storage_snapshots(context.credentials, opts)
29
29
  storage_snapshots.collect!{ |snapshot| from_storage_snapshot(snapshot, context) }
30
30
  return storage_snapshots.first unless storage_snapshots.length > 1
31
31
  return storage_snapshots
data/lib/cimi/server.rb CHANGED
@@ -31,7 +31,7 @@ module CIMI
31
31
  class API < Collections::Base
32
32
 
33
33
  # Enable logging
34
- use Rack::CommonLogger
34
+ use Deltacloud[:cimi].logger
35
35
  use Rack::Date
36
36
  use Rack::ETag
37
37
  use Rack::MatrixParams
@@ -16,14 +16,58 @@
16
16
  require 'rubygems'
17
17
  require 'ostruct'
18
18
 
19
- load File.join(File.dirname(__FILE__), 'core_ext.rb')
19
+ require 'require_relative' if RUBY_VERSION < '1.9'
20
+
21
+ require_relative 'core_ext'
20
22
  require_relative 'models'
21
23
  require_relative 'drivers'
22
24
  require_relative 'helpers/driver_helper'
23
25
 
26
+ module TestPoller
27
+ # This method will pool the resource until condition is true
28
+ # Will raise 'Timeout' when it reach retry count
29
+ #
30
+ # default opts[:retries] => 10
31
+ # default opts[:time_between_retry] => 10 (seconds)
32
+ # default opts[:timeout] => 60 (seconds) -> single request timeout
33
+ #
34
+ # opts[:before] => Proc -> executed 'before' making each request
35
+ # opts[:after] => Proc -> executed 'after' making each request
36
+ #
37
+ def wait_for!(driver, opts={}, &block)
38
+ opts[:retries] ||= 10
39
+ opts[:time_between_retry] ||= 10
40
+ opts[:timeout] ||= 60
41
+ opts[:method] ||= self.class.name.downcase.to_sym
42
+ opts[:retries].downto(0) do |r|
43
+ result = begin
44
+ timeout(opts[:timeout]) do
45
+ if opts[:before]
46
+ new_instance = opts[:before].call(r) { driver.send(opts[:method], :id => self.id) }
47
+ else
48
+ new_instance = driver.send(opts[:method], :id => self.id)
49
+ end
50
+ ((yield new_instance) == true) ? new_instance : false
51
+ end
52
+ rescue Timeout::Error
53
+ false
54
+ ensure
55
+ opts[:after].call(r) if opts[:after]
56
+ end
57
+ return result unless result == false
58
+ sleep(opts[:time_between_retry])
59
+ end
60
+ raise Timeout::Error
61
+ end
62
+ end
63
+
64
+ class Instance; include TestPoller; end
65
+ class Image; include TestPoller; end
66
+ class StorageSnapshot; include TestPoller; end
67
+
24
68
  module Deltacloud
25
69
 
26
- API_VERSION = '1.0.0'
70
+ API_VERSION = '1.0.2'
27
71
 
28
72
  def self.drivers
29
73
  Drivers.driver_config
@@ -57,7 +101,15 @@ module Deltacloud
57
101
  end
58
102
 
59
103
  def providers
60
- Deltacloud.drivers[current_driver.to_sym]
104
+ if backend.respond_to? :providers
105
+ backend.providers(@credentials)
106
+ else
107
+ Deltacloud.drivers[current_driver.to_sym]
108
+ end
109
+ end
110
+
111
+ def provider(opts={})
112
+ providers.find { |p| p.id == opts[:id] }
61
113
  end
62
114
 
63
115
  def method_missing(name, *args)
@@ -16,7 +16,7 @@
16
16
  module Deltacloud::Collections
17
17
  class Addresses < Base
18
18
 
19
- check_capability :for => lambda { |m| driver.respond_to? m }
19
+ set :capability, lambda { |m| driver.respond_to? m }
20
20
 
21
21
  get route_for('/addresses/:id/associate') do
22
22
  @address = driver.address(credentials, params )
@@ -18,7 +18,8 @@ module Deltacloud::Collections
18
18
 
19
19
  include Deltacloud::Features
20
20
 
21
- check_capability :for => lambda { |m| driver.respond_to? m }
21
+ set :capability, lambda { |m| driver.respond_to? m }
22
+
22
23
  check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
23
24
 
24
25
  new_route_for :buckets
@@ -48,7 +49,7 @@ module Deltacloud::Collections
48
49
  end
49
50
  end
50
51
 
51
- put route_for ("/buckets/:bucket/:blob") do
52
+ put route_for("/buckets/:bucket/:blob") do
52
53
  if(env["BLOB_SUCCESS"]) #ie got a 200ok after putting blob
53
54
  content_type = env["CONTENT_TYPE"]
54
55
  content_type ||= ""
@@ -57,7 +58,7 @@ module Deltacloud::Collections
57
58
  respond_to do |format|
58
59
  format.xml { haml :"blobs/show" }
59
60
  format.html { haml :"blobs/show" }
60
- format.json { convert_to_json(:blob, @blob) }
61
+ format.json { xml_to_json 'blobs/show' }
61
62
  end
62
63
  elsif(env["BLOB_FAIL"])
63
64
  report_error(500) #OK?
@@ -76,7 +77,7 @@ module Deltacloud::Collections
76
77
  respond_to do |format|
77
78
  format.xml { haml :"blobs/show" }
78
79
  format.html { haml :"blobs/show" }
79
- format.json { convert_to_json(:blob, @blob) }
80
+ format.json { xml_to_json 'blobs/show' }
80
81
  end
81
82
  end
82
83
  end
@@ -95,7 +96,7 @@ module Deltacloud::Collections
95
96
  response['Location'] = bucket_url(@bucket.id)
96
97
  respond_to do |format|
97
98
  format.xml { haml :"buckets/show" }
98
- format.json { convert_to_json(:bucket, @bucket) }
99
+ format.json { xml_to_json('buckets/show') }
99
100
  format.html do
100
101
  redirect bucket_url(@bucket.id) if @bucket and @bucket.id
101
102
  redirect buckets_url
@@ -125,7 +126,7 @@ module Deltacloud::Collections
125
126
  respond_to do |format|
126
127
  format.xml { haml :"blobs/show" }
127
128
  format.html { haml :"blobs/show" }
128
- format.json { convert_to_json(:blob, @blob) }
129
+ format.json { xml_to_json 'blobs/show' }
129
130
  end
130
131
  else
131
132
  report_error(404)
@@ -154,10 +155,11 @@ module Deltacloud::Collections
154
155
  end
155
156
  end
156
157
  @blob = driver.create_blob(credentials, bucket_id, blob_id, blob_data, user_meta)
158
+ status 201
157
159
  respond_to do |format|
158
160
  format.xml { haml :"blobs/show" }
159
161
  format.html { haml :"blobs/show"}
160
- format.json {convert_to_json(:blob, @blob)}
162
+ format.json { xml_to_json 'blobs/show' }
161
163
  end
162
164
  end
163
165
  end
@@ -187,7 +189,7 @@ module Deltacloud::Collections
187
189
  respond_to do |format|
188
190
  format.xml { haml :"blobs/show" }
189
191
  format.html { haml :"blobs/show" }
190
- format.json { convert_to_json(:blob, @blob) }
192
+ format.json { xml_to_json 'blobs/show' }
191
193
  end
192
194
  elsif(env["BLOB_FAIL"])
193
195
  report_error(500) #OK?
@@ -206,7 +208,7 @@ module Deltacloud::Collections
206
208
  respond_to do |format|
207
209
  format.xml { haml :"blobs/show" }
208
210
  format.html { haml :"blobs/show" }
209
- format.json { convert_to_json(:blob, @blob) }
211
+ format.json { xml_to_json 'blobs/show' }
210
212
  end
211
213
  end
212
214
  end
@@ -256,7 +258,7 @@ module Deltacloud::Collections
256
258
  @blob = driver.blob(credentials, { :id => params[:blob_id], 'bucket' => params[:id]})
257
259
  if @blob
258
260
  params['content_length'] = @blob.content_length
259
- params['content_type'] = @blob.content_type
261
+ params['content_type'] = (@blob.content_type.nil? || @blob.content_type == "")? "application/octet-stream" : @blob.content_type
260
262
  params['content_disposition'] = "attachment; filename=#{@blob.id}"
261
263
  BlobStream.call(self, credentials, params)
262
264
  else
@@ -16,7 +16,8 @@
16
16
  module Deltacloud::Collections
17
17
  class Firewalls < Base
18
18
 
19
- check_capability :for => lambda { |m| driver.respond_to? m }
19
+ set :capability, lambda { |m| driver.respond_to? m }
20
+
20
21
  check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
21
22
 
22
23
  get route_for('/firewalls/:id/new_rule') do
@@ -16,7 +16,7 @@
16
16
  module Deltacloud::Collections
17
17
  class HardwareProfiles < Base
18
18
 
19
- check_capability :for => lambda { |m| !driver.class.send(m).empty? }
19
+ set :capability, lambda { |m| !driver.class.send(m).empty? }
20
20
 
21
21
  collection :hardware_profiles do
22
22
 
@@ -18,12 +18,12 @@ module Deltacloud::Collections
18
18
 
19
19
  include Deltacloud::Features
20
20
 
21
- check_capability :for => lambda { |m| driver.respond_to? m }
22
21
  check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
22
+ set :capability, lambda { |m| driver.respond_to? m }
23
23
 
24
24
  new_route_for :images do
25
+ halt 404 unless params[:instance_id]
25
26
  @instance = Instance.new( :id => params[:instance_id] )
26
- status 404 unless @instance
27
27
  end
28
28
 
29
29
  collection :images do