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
@@ -73,7 +73,7 @@ module Deltacloud::Drivers::Vsphere
73
73
 
74
74
  # Images are virtual machines with 'template' flag set to be true.
75
75
  # Thus we're getting them using find_vm and list_virtual_machines
76
- def images(credentials, opts=nil)
76
+ def images(credentials, opts={})
77
77
  cloud = new_client(credentials)
78
78
  img_arr = []
79
79
  profiles = hardware_profiles(credentials)
@@ -123,7 +123,7 @@ module Deltacloud::Drivers::Vsphere
123
123
  end
124
124
 
125
125
  # List all datacenters managed by the vSphere or vCenter entrypoint.
126
- def realms(credentials, opts=nil)
126
+ def realms(credentials, opts={})
127
127
  vsphere = new_client(credentials)
128
128
  safely do
129
129
  if opts and opts[:id]
@@ -140,7 +140,7 @@ module Deltacloud::Drivers::Vsphere
140
140
 
141
141
  # List all running instances, across all datacenters. DeltaCloud API does
142
142
  # not yet support filtering instances by realm.
143
- def instances(credentials, opts=nil)
143
+ def instances(credentials, opts={})
144
144
  cloud = new_client(credentials)
145
145
  inst_arr, machine_vms, pending_vms = [], [], []
146
146
  safely do
@@ -212,7 +212,7 @@ module Deltacloud::Drivers::Vsphere
212
212
  end
213
213
 
214
214
 
215
- def create_instance(credentials, image_id, opts)
215
+ def create_instance(credentials, image_id, opts={})
216
216
  vsphere = new_client(credentials)
217
217
  safely do
218
218
  if opts[:hwp_cpu]
@@ -66,6 +66,10 @@ module Deltacloud::Collections
66
66
 
67
67
  after do
68
68
  headers 'Server' => 'Apache-Deltacloud/' + settings.version
69
+ headers 'X-Deltacloud-Driver' => driver_name
70
+ if provider_name
71
+ headers 'X-Deltacloud-Provider' => provider_name
72
+ end
69
73
  end
70
74
 
71
75
  def self.new_route_for(route, &block)
@@ -79,10 +83,6 @@ module Deltacloud::Collections
79
83
  end
80
84
  end
81
85
 
82
- def self.check_capability(opts={})
83
- Sinatra::Rabbit.set :check_capability, opts[:for]
84
- end
85
-
86
86
  def self.check_features(opts={})
87
87
  Sinatra::Rabbit.set :check_features, opts[:for]
88
88
  end
@@ -25,10 +25,7 @@ begin
25
25
  AsyncResponse = [-1, {}, []].freeze
26
26
  def self.call(context, credentials, params)
27
27
  body = DeferrableBody.new
28
- #Get the headers out asap. Don't specify a content-type let
29
- #the client guess and if they can't they SHOULD default to
30
- #'application/octet-stream' anyway as per:
31
- #http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.2.1
28
+ #Get the headers out asap.
32
29
  EM.next_tick { context.env['async.callback'].call [200, {
33
30
  'Content-Type' => "#{params['content_type']}",
34
31
  'Content-Disposition' => params["content_disposition"],
@@ -36,9 +33,9 @@ begin
36
33
  }
37
34
  #call the driver from here. the driver method yields for every chunk
38
35
  #of blob it receives. Then use body.call to write that chunk as received.
39
- context.driver.blob_data(credentials, params[:id], params[:blob_id], params) {|chunk| body.call ["#{chunk}"]} #close blob_data block
36
+ context.driver.blob_data(credentials, params[:id], params[:blob_id], params) {|chunk| body.call [chunk]} #close blob_data block
40
37
  body.succeed
41
- AsyncResponse # Tell Thin to not close connection & work other requests
38
+ AsyncResponse.dup # Tell Thin to not close connection & work other requests
42
39
  end
43
40
  end
44
41
 
@@ -54,6 +51,7 @@ begin
54
51
  def each(&blk)
55
52
  @body_callback = blk
56
53
  end
54
+
57
55
  end
58
56
  rescue LoadError => e
59
57
  # EventMachine isn't available, disable blob streaming
@@ -18,6 +18,22 @@ module Deltacloud::Helpers
18
18
 
19
19
  require 'benchmark'
20
20
 
21
+ def supported_collections
22
+ collection_arr = []
23
+ Deltacloud::Collections.deltacloud_modules.each do |m|
24
+ m.collections.each do |c|
25
+ # Get the required capability for the :index operation (like 'realms' or 'instance_state_machine')
26
+ index_operation_capability = c.operation(:index).required_capability
27
+ # Then use this capability to check if the 'capability' lambda defined
28
+ # for the Sinatra::Base class evaluate to 'true'
29
+ next if m.settings.respond_to?(:capability) and !m.settings.capability(index_operation_capability)
30
+ yield c if block_given?
31
+ collection_arr << c
32
+ end
33
+ end
34
+ collection_arr
35
+ end
36
+
21
37
  def auth_feature_name
22
38
  return 'key' if driver.class.has_feature?(:instances, :authentication_key)
23
39
  return 'password' if driver.class.has_feature?(:instances, :authentication_password)
@@ -136,7 +152,7 @@ module Deltacloud::Helpers
136
152
  end
137
153
 
138
154
  def render_cdata(text)
139
- "<![CDATA[#{text.strip}]]>"
155
+ "<![CDATA[#{text.strip}]]>" unless text.nil?
140
156
  end
141
157
 
142
158
  def link_to_action(action, url, method)
@@ -22,7 +22,11 @@ module Deltacloud::Helpers
22
22
  end
23
23
 
24
24
  def driver_name
25
- Thread.current[:driver] ||= ENV['API_DRIVER']
25
+ Thread.current[:driver] ||= Deltacloud.default_frontend.default_driver.to_s
26
+ end
27
+
28
+ def provider_name
29
+ Thread.current[:provider] || ENV['API_PROVIDER']
26
30
  end
27
31
 
28
32
  def driver_class_name
@@ -38,14 +42,14 @@ module Deltacloud::Helpers
38
42
  m = Deltacloud::Drivers.const_get(driver_class_name)
39
43
  m.const_get(driver_class_name + "Driver").new
40
44
  rescue NameError
41
- raise "[ERROR] The driver class name is not defined as #{driver_class_name}Driver"
45
+ nil
42
46
  end
43
47
  end
44
48
 
45
49
  def driver
46
50
  $:.unshift File.join(File.dirname(__FILE__), '..', '..')
47
51
  begin
48
- require_relative driver_source_name
52
+ require_relative(driver_source_name) unless driver_class
49
53
  driver_class
50
54
  rescue LoadError => e
51
55
  raise "[ERROR] The driver '#{driver_name}' is unknown or not installed (#{driver_source_name})\n" +
@@ -35,9 +35,9 @@ module Sinatra
35
35
  t = $1
36
36
  if t.match(/^(stop|reboot|start|attach|detach)_/)
37
37
  action = $1
38
- api_url_for(t.pluralize.split('_').last + '/' + args.first + '/' + action, :full)
38
+ api_url_for(t.pluralize.split('_').last + '/' + args.first.to_s + '/' + action, :full)
39
39
  elsif t.match(/^(destroy|update)_/)
40
- api_url_for(t.pluralize.split('_').last + '/' + args.first, :full)
40
+ api_url_for(t.pluralize.split('_').last + '/' + args.first.to_s, :full)
41
41
  else
42
42
  api_url_for(t.pluralize, :full) + '/' + "#{args.first}"
43
43
  end
@@ -79,7 +79,7 @@ module Sinatra
79
79
  def url_for url_fragment, mode=:path_only
80
80
  case mode
81
81
  when :path_only
82
- base = request.script_name.empty? ? Deltacloud[ENV['API_FRONTEND'] || :deltacloud].root_url : request.script_name
82
+ base = request.script_name.empty? ? Deltacloud.default_frontend.root_url : request.script_name
83
83
  when :full
84
84
  scheme = request.scheme
85
85
  port = request.port
@@ -96,7 +96,7 @@ module Sinatra
96
96
  else
97
97
  port = ":#{port}"
98
98
  end
99
- base = "#{scheme}://#{request_host}#{port}#{request.script_name.empty? ? Deltacloud[ENV['API_FRONTEND'] || :deltacloud].root_url : request.script_name}"
99
+ base = "#{scheme}://#{request_host}#{port}#{request.script_name.empty? ? settings.config.root_url : request.script_name}"
100
100
  else
101
101
  raise TypeError, "Unknown url_for mode #{mode}"
102
102
  end
@@ -22,7 +22,7 @@ class Address < BaseModel
22
22
  end
23
23
 
24
24
  def associated?
25
- true unless self.instance_id.nil?
25
+ !self.instance_id.nil?
26
26
  end
27
27
 
28
28
  end
@@ -44,18 +44,4 @@ class BaseModel
44
44
  @id
45
45
  end
46
46
 
47
- def to_hash
48
- out = {}
49
- self.attributes.each do |attribute|
50
- if self.send(:"#{attribute}")
51
- out.merge!({ attribute => self.send(:"#{attribute}") } )
52
- end
53
- end
54
- out
55
- end
56
-
57
- def to_json(*a)
58
- self.to_hash.to_json(*a)
59
- end
60
-
61
47
  end
@@ -20,18 +20,8 @@ class Bucket < BaseModel
20
20
  attr_accessor :size
21
21
  attr_accessor :blob_list
22
22
 
23
- alias :to_hash_original :to_hash
24
-
25
23
  def blob_list
26
24
  @blob_list || []
27
25
  end
28
26
 
29
- def to_hash
30
- h = self.to_hash_original
31
- unless blob_list.nil?
32
- h[:blob_list] = self.blob_list.collect { |blob| { :id => blob,
33
- :href => "#{settings.root_url}/buckets/#{self.id}/#{blob}"}}
34
- end
35
- return h
36
- end
37
27
  end
@@ -154,35 +154,14 @@ module Deltacloud
154
154
  end
155
155
 
156
156
  def default?(prop, v)
157
- p = @properties[prop.to_sym]
158
- p && p.default.to_s == v
159
- end
160
-
161
- def to_hash
162
- props = []
163
- self.each_property do |p|
164
- if p.kind.eql? :fixed
165
- props << { :kind => p.kind, :value => p.value, :name => p.name, :unit => p.unit }
166
- else
167
- param = { :operation => "create", :method => "post", :name => p.name }
168
- if p.kind.eql? :range
169
- param[:range] = { :first => p.first, :last => p.last }
170
- elsif p.kind.eql? :enum
171
- param[:enum] = p.values.collect { |v| { :entry => v } }
172
- end
173
- param
174
- props << { :kind => p.kind, :value => p.default, :name => p.name, :unit => p.unit, :param => param }
175
- end
176
- end
177
- {
178
- :id => self.name,
179
- :properties => props
180
- }
157
+ property(prop) && property(prop).default.to_s == v
181
158
  end
182
159
 
183
160
  def include?(prop, v)
184
- p = @properties[prop]
185
- p.nil? || p.include?(v)
161
+ return false unless p = property(prop)
162
+ return true if p.kind == :range and (p.first..p.last).include?(v)
163
+ return true if p.kind == :enum and p.values.include?(v)
164
+ false
186
165
  end
187
166
 
188
167
  def params
@@ -24,16 +24,4 @@ class Image < BaseModel
24
24
  attr_accessor :state
25
25
  attr_accessor :hardware_profiles
26
26
 
27
- alias :to_hash_original :to_hash
28
-
29
- def to_hash
30
- h = self.to_hash_original
31
- h.merge({
32
- :actions => [ :create_instance => {
33
- :method => 'post',
34
- :href => "#{settings.root_url}/instances;image_id=#{self.id}"
35
- }]
36
- })
37
- end
38
-
39
27
  end
@@ -14,8 +14,12 @@
14
14
  # License for the specific language governing permissions and limitations
15
15
  # under the License.
16
16
 
17
+ require 'timeout'
18
+
17
19
  class Instance < BaseModel
18
20
 
21
+ include Timeout
22
+
19
23
  attr_accessor :owner_id
20
24
  attr_accessor :image_id
21
25
  attr_accessor :name
@@ -42,10 +46,6 @@ class Instance < BaseModel
42
46
  self.create_image
43
47
  end
44
48
 
45
- def to_s
46
- name
47
- end
48
-
49
49
  def hardware_profile
50
50
  instance_profile
51
51
  end
@@ -62,8 +62,8 @@ class Instance < BaseModel
62
62
  end
63
63
 
64
64
  def method_missing(name, *args)
65
- if name =~ /is_(\w+)\?/
66
- return true if self.state.downcase.eql?($1)
65
+ if name.to_s =~ /is_(\w+)\?/
66
+ self.state.downcase.eql?($1)
67
67
  else
68
68
  raise NoMethodError.new(name.to_s)
69
69
  end
@@ -73,20 +73,4 @@ class Instance < BaseModel
73
73
  return true unless authn_error.nil?
74
74
  end
75
75
 
76
- alias :to_hash_original :to_hash
77
-
78
- def to_hash
79
- h = self.to_hash_original
80
- h[:public_addresses] = h[:public_addresses].collect do |address|
81
- { :address => { :type => address.address_type, :value => address } }
82
- end
83
- h[:actions] = self.actions.collect do |action|
84
- { :"#{action}" => {
85
- :method => collections[:instances].operations[action.to_sym].method,
86
- :href => collections[:instances].operations[action.to_sym].path.gsub(':id', self.id)
87
- }}
88
- end
89
- h
90
- end
91
-
92
76
  end
@@ -28,11 +28,11 @@ class Key < BaseModel
28
28
  end
29
29
 
30
30
  def is_password?
31
- true if @credential_type.eql?(:password)
31
+ @credential_type.eql?(:password)
32
32
  end
33
33
 
34
34
  def is_key?
35
- true if @credential_type.eql?(:key)
35
+ @credential_type.eql?(:key)
36
36
  end
37
37
 
38
38
  # Mock fingerprint generator
@@ -19,7 +19,7 @@ class Metric < BaseModel
19
19
  attr_accessor :properties
20
20
 
21
21
  def unknown?
22
- true if self.entity == :unknown
22
+ self.entity == :unknown
23
23
  end
24
24
 
25
25
  def add_property(name, values=nil)
@@ -22,4 +22,8 @@ class StorageSnapshot < BaseModel
22
22
  attr_accessor :storage_volume_id
23
23
  attr_accessor :created
24
24
 
25
+ def is_completed?
26
+ state == 'completed'
27
+ end
28
+
25
29
  end
@@ -31,7 +31,9 @@ module Deltacloud
31
31
  class API < Collections::Base
32
32
 
33
33
  # Enable logging
34
- use Rack::CommonLogger
34
+ # NOTE: Jruby use different logging mechanism not complatible with our
35
+ # logger.
36
+ use Deltacloud[:deltacloud].logger unless RUBY_PLATFORM == 'java'
35
37
  use Rack::Date
36
38
  use Rack::ETag
37
39
  use Rack::MatrixParams
@@ -55,13 +57,17 @@ module Deltacloud
55
57
  end
56
58
  end
57
59
 
60
+ options Deltacloud.config[:deltacloud].root_url + '/?' do
61
+ headers 'Allow' => supported_collections { |c| c.collection_name }.join(',')
62
+ end
63
+
58
64
  post Deltacloud.config[:deltacloud].root_url + '/?' do
59
65
  param_driver, param_provider = params["driver"], params["provider"]
60
66
  if param_driver
61
67
  redirect "#{Deltacloud.config[:deltacloud].root_url}\;driver=#{param_driver}", 301
62
68
  elsif param_provider && param_provider != "default"
63
69
  #FIXME NEEDS A BETTER WAY OF GRABBING CURRENT DRIVER FROM MATRIX PARAMS...
64
- current_matrix_driver = env["HTTP_REFERER"].match(/\;(driver)=(\w*).*$/i)
70
+ current_matrix_driver = env['HTTP_REFERER'] ? env["HTTP_REFERER"].match(/\;(driver)=(\w*).*$/i) : nil
65
71
  if current_matrix_driver
66
72
  redirect "#{Deltacloud.config[:deltacloud].root_url}\;driver=#{$2}\;provider=#{param_provider}", 301
67
73
  else
@@ -13,15 +13,10 @@
13
13
  # License for the specific language governing permissions and limitations
14
14
  # under the License.
15
15
 
16
- unless Kernel.respond_to?(:require_relative)
17
- module Kernel
18
- def require_relative(path)
19
- require File.join(File.dirname(caller[0]), path.to_str)
20
- end
21
- end
22
- end
16
+ require 'require_relative' if RUBY_VERSION < '1.9'
23
17
 
24
18
  require_relative './deltacloud/core_ext'
19
+ require_relative './sinatra/rack_logger'
25
20
 
26
21
  module Deltacloud
27
22
 
@@ -31,7 +26,7 @@ module Deltacloud
31
26
 
32
27
  def self.configure(frontend=:deltacloud, &block)
33
28
  frontend = frontend.to_sym
34
- config[frontend] = Server.new(&block)
29
+ config[frontend] ||= Server.new(frontend, &block)
35
30
  self
36
31
  end
37
32
 
@@ -41,20 +36,37 @@ module Deltacloud
41
36
 
42
37
  def self.require_frontend!(frontend=:deltacloud)
43
38
  frontend = frontend.to_sym
44
- require File.join(File.dirname(__FILE__), frontend.to_s, 'server.rb')
39
+ return false if frontend_required?(frontend)
40
+ require_relative File.join(frontend.to_s, 'server.rb')
45
41
  Deltacloud[frontend].klass eval('::'+Deltacloud[frontend].klass)
46
42
  end
47
43
 
44
+ def self.frontend_required?(frontend)
45
+ true unless Deltacloud[frontend].klass.kind_of? String
46
+ end
47
+
48
+ def self.default_frontend(frontend=nil)
49
+ @default_frontend = frontend unless frontend.nil?
50
+ raise "Could not determine default API frontend" if @default_frontend.nil? and !config[:deltacloud]
51
+ @default_frontend || config[:deltacloud]
52
+ end
53
+
48
54
  class Server
49
55
 
56
+ attr_reader :name
50
57
  attr_reader :root_url
51
58
  attr_reader :version
52
59
  attr_reader :klass
60
+ attr_reader :logger
61
+ attr_reader :default_driver
53
62
 
54
- def initialize(opts={}, &block)
63
+ def initialize(frontend, opts={}, &block)
64
+ @name=frontend.to_sym
55
65
  @root_url = opts[:root_url]
56
66
  @version = opts[:version]
57
67
  @klass = opts[:klass]
68
+ @logger = opts[:logger] || Rack::DeltacloudLogger
69
+ @default_driver = opts[:default_driver] || :mock
58
70
  instance_eval(&block)
59
71
  end
60
72
 
@@ -74,6 +86,24 @@ module Deltacloud
74
86
  @klass = k
75
87
  end
76
88
 
89
+ def default_driver(drv=nil)
90
+ return @default_driver if drv.nil?
91
+ @default_driver = drv
92
+ end
93
+
94
+ def logger(logger=nil)
95
+ return @logger if logger.nil?
96
+ @logger = logger
97
+ end
98
+
99
+ def require!
100
+ Deltacloud.require_frontend!(@name)
101
+ end
102
+
103
+ def default_frontend!
104
+ Deltacloud.default_frontend(self)
105
+ end
106
+
77
107
  end
78
108
 
79
109
  end