deltacloud-core 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (294) hide show
  1. data/NOTICE +1 -1
  2. data/Rakefile +63 -21
  3. data/bin/deltacloudd +10 -6
  4. data/config.ru +62 -6
  5. data/config/drivers/ec2.yaml +8 -0
  6. data/config/drivers/fgcp.yaml +13 -0
  7. data/deltacloud-core.gemspec +10 -2
  8. data/lib/cimi/collections.rb +58 -0
  9. data/lib/cimi/collections/address_templates.rb +49 -0
  10. data/lib/cimi/collections/addresses.rb +74 -0
  11. data/lib/cimi/collections/cloud_entry_point.rb +37 -0
  12. data/lib/{deltacloud/helpers/conversion_helper.rb → cimi/collections/entity_metadata.rb} +24 -16
  13. data/lib/cimi/collections/machine_admins.rb +74 -0
  14. data/lib/cimi/collections/machine_configurations.rb +49 -0
  15. data/lib/cimi/collections/machine_images.rb +50 -0
  16. data/lib/cimi/collections/machines.rb +157 -0
  17. data/lib/cimi/collections/network_configurations.rb +47 -0
  18. data/lib/cimi/collections/network_templates.rb +48 -0
  19. data/lib/cimi/collections/networks.rb +125 -0
  20. data/lib/cimi/collections/routing_group_templates.rb +47 -0
  21. data/lib/cimi/collections/routing_groups.rb +48 -0
  22. data/lib/cimi/collections/volume_configurations.rb +48 -0
  23. data/lib/cimi/collections/volume_images.rb +50 -0
  24. data/lib/cimi/collections/volumes.rb +80 -0
  25. data/lib/cimi/collections/vsp_configurations.rb +48 -0
  26. data/lib/cimi/collections/vsp_templates.rb +50 -0
  27. data/lib/cimi/collections/vsps.rb +108 -0
  28. data/lib/cimi/dependencies.rb +1 -0
  29. data/lib/cimi/helpers.rb +116 -0
  30. data/lib/cimi/helpers/cimi_helper.rb +6 -2
  31. data/lib/cimi/models.rb +72 -0
  32. data/lib/cimi/{model → models}/action.rb +1 -1
  33. data/lib/cimi/models/address.rb +72 -0
  34. data/lib/cimi/models/address_collection.rb +34 -0
  35. data/lib/cimi/models/address_template.rb +54 -0
  36. data/lib/cimi/models/address_template_collection.rb +34 -0
  37. data/lib/cimi/{model → models}/base.rb +2 -2
  38. data/lib/cimi/{model → models}/cloud_entry_point.rb +3 -5
  39. data/lib/cimi/{model → models}/entity_metadata.rb +7 -6
  40. data/lib/cimi/{model → models}/entity_metadata_collection.rb +2 -2
  41. data/lib/cimi/{model → models}/errors.rb +8 -0
  42. data/lib/cimi/{model → models}/machine.rb +10 -10
  43. data/lib/cimi/{model → models}/machine_admin.rb +1 -1
  44. data/lib/cimi/{model → models}/machine_admin_collection.rb +2 -2
  45. data/lib/cimi/{model → models}/machine_collection.rb +2 -2
  46. data/lib/cimi/{model → models}/machine_configuration.rb +9 -6
  47. data/lib/cimi/{model → models}/machine_configuration_collection.rb +2 -2
  48. data/lib/cimi/{model → models}/machine_image.rb +1 -1
  49. data/lib/cimi/{model → models}/machine_image_collection.rb +2 -2
  50. data/lib/cimi/{model → models}/machine_template.rb +0 -0
  51. data/lib/cimi/{model → models}/machine_template_collection.rb +2 -2
  52. data/lib/cimi/models/network.rb +109 -0
  53. data/lib/cimi/{model → models}/network_collection.rb +2 -2
  54. data/lib/cimi/{model → models}/network_configuration.rb +3 -4
  55. data/lib/cimi/{model → models}/network_configuration_collection.rb +2 -2
  56. data/lib/cimi/models/network_template.rb +36 -0
  57. data/lib/cimi/models/network_template_collection.rb +35 -0
  58. data/lib/cimi/models/routing_group.rb +34 -0
  59. data/lib/cimi/models/routing_group_collection.rb +34 -0
  60. data/lib/cimi/models/routing_group_template.rb +34 -0
  61. data/lib/cimi/models/routing_group_template_collection.rb +35 -0
  62. data/lib/cimi/{model → models}/schema.rb +0 -0
  63. data/lib/cimi/{model → models}/volume.rb +4 -4
  64. data/lib/cimi/{model → models}/volume_collection.rb +2 -2
  65. data/lib/cimi/{model → models}/volume_configuration.rb +1 -1
  66. data/lib/cimi/{model → models}/volume_configuration_collection.rb +2 -2
  67. data/lib/cimi/{model → models}/volume_image.rb +1 -1
  68. data/lib/cimi/{model → models}/volume_image_collection.rb +2 -2
  69. data/lib/cimi/{model → models}/volume_template.rb +0 -0
  70. data/lib/cimi/{model → models}/volume_template_collection.rb +2 -2
  71. data/lib/cimi/models/vsp.rb +102 -0
  72. data/lib/cimi/models/vsp_collection.rb +34 -0
  73. data/lib/cimi/models/vsp_configuration.rb +40 -0
  74. data/lib/cimi/models/vsp_configuration_collection.rb +34 -0
  75. data/lib/cimi/models/vsp_template.rb +34 -0
  76. data/lib/cimi/models/vsp_template_collection.rb +34 -0
  77. data/lib/cimi/server.rb +27 -549
  78. data/lib/deltacloud/api.rb +79 -0
  79. data/lib/deltacloud/collections.rb +54 -0
  80. data/lib/deltacloud/collections/addresses.rb +91 -0
  81. data/lib/deltacloud/collections/buckets.rb +273 -0
  82. data/lib/deltacloud/collections/drivers.rb +51 -0
  83. data/lib/deltacloud/collections/firewalls.rb +116 -0
  84. data/lib/deltacloud/collections/hardware_profiles.rb +29 -0
  85. data/lib/deltacloud/collections/images.rb +73 -0
  86. data/lib/deltacloud/collections/instance_states.rb +59 -0
  87. data/lib/deltacloud/collections/instances.rb +113 -0
  88. data/lib/deltacloud/collections/keys.rb +61 -0
  89. data/lib/deltacloud/collections/load_balancers.rb +102 -0
  90. data/lib/deltacloud/collections/metrics.rb +28 -0
  91. data/lib/deltacloud/collections/realms.rb +28 -0
  92. data/lib/deltacloud/collections/storage_snapshots.rb +51 -0
  93. data/lib/deltacloud/collections/storage_volumes.rb +99 -0
  94. data/lib/deltacloud/core_ext.rb +14 -6
  95. data/lib/deltacloud/core_ext/string.rb +17 -5
  96. data/lib/deltacloud/drivers.rb +6 -42
  97. data/lib/deltacloud/drivers/azure/azure_driver.rb +0 -4
  98. data/lib/deltacloud/{base_driver → drivers}/base_driver.rb +56 -18
  99. data/lib/deltacloud/drivers/condor/condor_driver.rb +1 -8
  100. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +142 -33
  101. data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +2 -6
  102. data/lib/deltacloud/{base_driver → drivers}/exceptions.rb +25 -2
  103. data/lib/deltacloud/drivers/features.rb +154 -0
  104. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +387 -0
  105. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +1435 -0
  106. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +8 -11
  107. data/lib/deltacloud/drivers/google/google_driver.rb +2 -5
  108. data/lib/deltacloud/drivers/mock/data/keys/test-key.yml +28 -0
  109. data/lib/deltacloud/drivers/mock/mock_client.rb +2 -2
  110. data/lib/deltacloud/drivers/mock/mock_driver.rb +58 -40
  111. data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +145 -0
  112. data/lib/deltacloud/drivers/opennebula/cloud_client.rb +107 -73
  113. data/lib/deltacloud/drivers/opennebula/occi_client.rb +285 -145
  114. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +189 -126
  115. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +427 -8
  116. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +7 -9
  117. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +48 -66
  118. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +44 -51
  119. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +7 -8
  120. data/lib/deltacloud/drivers/sbc/sbc_client.rb +1 -1
  121. data/lib/deltacloud/drivers/sbc/sbc_driver.rb +3 -3
  122. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +8 -8
  123. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +39 -13
  124. data/lib/deltacloud/drivers/vsphere/vsphere_filemanager.rb +1 -0
  125. data/lib/deltacloud/helpers.rb +79 -7
  126. data/lib/{sinatra/lazy_auth.rb → deltacloud/helpers/auth_helper.rb} +5 -9
  127. data/lib/deltacloud/helpers/{blob_stream.rb → blob_stream_helper.rb} +7 -7
  128. data/lib/deltacloud/helpers/deltacloud_helper.rb +286 -0
  129. data/lib/deltacloud/helpers/driver_helper.rb +58 -0
  130. data/lib/deltacloud/helpers/rabbit_helper.rb +34 -0
  131. data/lib/{sinatra/url_for.rb → deltacloud/helpers/url_helper.rb} +31 -9
  132. data/lib/deltacloud/models.rb +19 -17
  133. data/lib/deltacloud/models/bucket.rb +4 -0
  134. data/lib/deltacloud/{hardware_profile.rb → models/hardware_profile.rb} +4 -2
  135. data/lib/deltacloud/models/image.rb +1 -0
  136. data/lib/deltacloud/models/instance.rb +4 -2
  137. data/lib/deltacloud/models/instance_address.rb +4 -0
  138. data/lib/deltacloud/models/key.rb +4 -0
  139. data/lib/deltacloud/models/metric.rb +40 -0
  140. data/lib/deltacloud/{state_machine.rb → models/state_machine.rb} +18 -1
  141. data/lib/deltacloud/server.rb +41 -1222
  142. data/lib/deltacloud_rack.rb +79 -0
  143. data/lib/{cimi/model/network_template.rb → ec2/helpers.rb} +7 -10
  144. data/lib/{deltacloud/backend_capability.rb → ec2/helpers/errors.rb} +24 -29
  145. data/lib/ec2/helpers/result.rb +31 -0
  146. data/lib/ec2/query_parser.rb +152 -0
  147. data/lib/ec2/server.rb +70 -0
  148. data/lib/{deltacloud.rb → sinatra.rb} +7 -12
  149. data/lib/sinatra/rack_accept.rb +13 -7
  150. data/lib/sinatra/rack_driver_select.rb +1 -1
  151. data/lib/sinatra/rack_matrix_params.rb +1 -3
  152. data/public/images/metric.png +0 -0
  153. data/public/javascripts/jquery.mobile-1.0.1.min.js +177 -0
  154. data/public/stylesheets/jquery.mobile-1.0.1.min.css +2 -0
  155. data/public/stylesheets/new.css +10 -0
  156. data/support/fedora/deltacloud-core.spec +1 -1
  157. data/tests/api/common.rb +1 -0
  158. data/tests/api/driver_test.rb +79 -0
  159. data/tests/api/library_test.rb +48 -0
  160. data/tests/cimi/features/step_definitions/common_steps.rb +2 -2
  161. data/tests/cimi/features/step_definitions/machines_steps.rb +5 -4
  162. data/tests/cimi/features/step_definitions/volumes_steps.rb +8 -8
  163. data/tests/cimi/features/support/env.rb +33 -11
  164. data/tests/common.rb +7 -8
  165. data/tests/drivers/ec2/api_test.rb +19 -0
  166. data/tests/drivers/ec2/common.rb +23 -0
  167. data/tests/drivers/ec2/drivers_test.rb +120 -0
  168. data/tests/drivers/ec2/hardware_profiles_test.rb +224 -0
  169. data/tests/drivers/ec2/images_test.rb +230 -0
  170. data/tests/drivers/ec2/instances_test.rb +356 -0
  171. data/tests/drivers/ec2/keys_test.rb +181 -0
  172. data/tests/drivers/ec2/realms_test.rb +146 -0
  173. data/tests/drivers/fgcp/api_test.rb +47 -0
  174. data/tests/drivers/fgcp/hardware_profiles_test.rb +54 -0
  175. data/tests/drivers/fgcp/realms_test.rb +42 -0
  176. data/tests/drivers/{rackspace → fgcp}/setup.rb +5 -6
  177. data/tests/drivers/google/api_test.rb +10 -26
  178. data/tests/drivers/google/buckets_test.rb +79 -95
  179. data/tests/drivers/google/common.rb +54 -0
  180. data/tests/drivers/mock/api_test.rb +4 -127
  181. data/tests/drivers/mock/buckets_test.rb +195 -0
  182. data/tests/drivers/mock/common.rb +7 -0
  183. data/tests/drivers/mock/drivers_test.rb +123 -0
  184. data/tests/drivers/mock/hardware_profiles_test.rb +190 -100
  185. data/tests/drivers/mock/images_test.rb +162 -103
  186. data/tests/drivers/mock/instances_test.rb +310 -220
  187. data/tests/drivers/mock/keys_test.rb +161 -0
  188. data/tests/drivers/mock/realms_test.rb +109 -70
  189. data/tests/drivers/mock/storage_snapshots_test.rb +114 -0
  190. data/tests/drivers/mock/storage_volumes_test.rb +122 -0
  191. data/tests/drivers/openstack/api_test.rb +8 -3
  192. data/tests/drivers/openstack/common.rb +21 -0
  193. data/tests/drivers/openstack/hardware_profiles_test.rb +20 -9
  194. data/tests/drivers/openstack/images_test.rb +11 -5
  195. data/tests/drivers/openstack/instances_test.rb +61 -16
  196. data/tests/drivers/openstack/realms_test.rb +11 -7
  197. data/tests/drivers/rackspace/api_test.rb +7 -2
  198. data/tests/drivers/rackspace/buckets_test.rb +7 -2
  199. data/tests/drivers/rackspace/common.rb +16 -0
  200. data/tests/drivers/rackspace/hardware_profiles_test.rb +7 -2
  201. data/tests/drivers/rackspace/images_test.rb +7 -2
  202. data/tests/drivers/rackspace/instances_test.rb +10 -5
  203. data/tests/drivers/rackspace/realms_test.rb +7 -2
  204. data/tests/drivers/rhevm/api_test.rb +12 -6
  205. data/tests/drivers/rhevm/{setup.rb → common.rb} +8 -1
  206. data/tests/drivers/rhevm/hardware_profiles_test.rb +7 -2
  207. data/tests/drivers/rhevm/images_test.rb +8 -2
  208. data/tests/drivers/rhevm/instances_test.rb +7 -2
  209. data/tests/drivers/rhevm/realms_test.rb +7 -2
  210. data/tests/minitest_common.rb +58 -0
  211. data/tests/minitest_common_api_test.rb +115 -0
  212. data/views/addresses/associate.html.haml +1 -1
  213. data/views/addresses/index.html.haml +1 -1
  214. data/views/addresses/show.html.haml +2 -3
  215. data/views/api/show.html.haml +22 -9
  216. data/views/api/show.xml.haml +8 -7
  217. data/views/blobs/show.xml.haml +7 -4
  218. data/views/buckets/new.html.haml +2 -2
  219. data/views/cimi/errors/401.xml.haml +1 -1
  220. data/views/error.html.haml +3 -3
  221. data/views/errors/400.html.haml +1 -1
  222. data/views/errors/400.xml.haml +1 -2
  223. data/views/errors/401.html.haml +8 -7
  224. data/views/errors/401.xml.haml +1 -1
  225. data/views/errors/404.xml.haml +1 -0
  226. data/views/errors/500.xml.haml +4 -2
  227. data/views/{cimi/errors/403.html.haml → errors/501.html.haml} +4 -2
  228. data/views/errors/501.xml.haml +1 -0
  229. data/views/errors/502.xml.haml +1 -7
  230. data/views/{cimi/errors/500.html.haml → errors/504.html.haml} +0 -0
  231. data/views/errors/504.xml.haml +1 -0
  232. data/views/firewalls/new.html.haml +2 -2
  233. data/views/firewalls/new_rule.html.haml +1 -1
  234. data/views/firewalls/show.html.haml +1 -1
  235. data/views/hardware_profiles/index.html.haml +3 -1
  236. data/views/hardware_profiles/index.xml.haml +2 -2
  237. data/views/hardware_profiles/show.html.haml +3 -3
  238. data/views/hardware_profiles/show.xml.haml +3 -3
  239. data/views/images/show.html.haml +5 -0
  240. data/views/images/show.xml.haml +6 -1
  241. data/views/instance_states/show.html.haml +1 -1
  242. data/views/instances/index.html.haml +1 -1
  243. data/views/instances/new.html.haml +54 -39
  244. data/views/instances/run_command.html.haml +24 -15
  245. data/views/instances/show.html.haml +7 -3
  246. data/views/instances/show.xml.haml +2 -2
  247. data/views/keys/show.xml.haml +1 -0
  248. data/views/layout.html.haml +5 -9
  249. data/views/load_balancers/show.html.haml +12 -6
  250. data/views/metrics/index.html.haml +13 -0
  251. data/views/metrics/index.xml.haml +5 -0
  252. data/views/metrics/show.html.haml +23 -0
  253. data/views/metrics/show.xml.haml +9 -0
  254. data/views/realms/show.xml.haml +2 -1
  255. data/views/root/index.html.haml +1 -1
  256. data/views/storage_snapshots/show.html.haml +1 -1
  257. data/views/storage_snapshots/show.xml.haml +1 -0
  258. data/views/storage_volumes/attach.html.haml +1 -2
  259. data/views/storage_volumes/index.html.haml +1 -1
  260. data/views/storage_volumes/new.html.haml +22 -16
  261. data/views/storage_volumes/show.html.haml +10 -4
  262. data/views/storage_volumes/show.xml.haml +3 -4
  263. metadata +547 -519
  264. data/DISCLAIMER +0 -8
  265. data/lib/cimi/model.rb +0 -52
  266. data/lib/cimi/model/network.rb +0 -69
  267. data/lib/deltacloud/base_driver.rb +0 -18
  268. data/lib/deltacloud/base_driver/features.rb +0 -262
  269. data/lib/deltacloud/base_driver/mock_driver.rb +0 -78
  270. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +0 -186
  271. data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +0 -521
  272. data/lib/deltacloud/helpers/application_helper.rb +0 -267
  273. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +0 -50
  274. data/lib/deltacloud/helpers/json_helper.rb +0 -31
  275. data/lib/deltacloud/method_serializer.rb +0 -83
  276. data/lib/deltacloud/validation.rb +0 -107
  277. data/lib/sinatra/rabbit.rb +0 -441
  278. data/lib/sinatra/rack_runtime.rb +0 -47
  279. data/lib/sinatra/rack_syslog.rb +0 -86
  280. data/lib/sinatra/sinatra_verbose.rb +0 -73
  281. data/lib/sinatra/static_assets.rb +0 -99
  282. data/public/javascripts/jquery.mobile-1.0rc1.min.js +0 -170
  283. data/public/stylesheets/jquery.mobile-1.0rc1.min.css +0 -12
  284. data/tests/drivers/google/setup.rb +0 -38
  285. data/tests/drivers/mock/instance_states_test.rb +0 -71
  286. data/tests/drivers/mock/setup.rb +0 -3
  287. data/tests/drivers/mock/url_for_test.rb +0 -67
  288. data/tests/drivers/openstack/setup.rb +0 -20
  289. data/views/cimi/errors/400.html.haml +0 -41
  290. data/views/cimi/errors/401.html.haml +0 -41
  291. data/views/cimi/errors/404.html.haml +0 -29
  292. data/views/cimi/errors/405.html.haml +0 -29
  293. data/views/cimi/errors/502.html.haml +0 -43
  294. data/views/cimi/errors/backend_capability_failure.html.haml +0 -29
@@ -19,8 +19,7 @@
19
19
  # https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/d-complete-vcloud-express-api-document.aspx
20
20
  #
21
21
  # 02 May 2010
22
- #
23
- require 'deltacloud/base_driver'
22
+
24
23
  require 'fog'
25
24
  require 'excon'
26
25
  require 'nokogiri'
@@ -30,12 +29,11 @@ module Deltacloud
30
29
  module Terremark
31
30
 
32
31
  class TerremarkDriver < Deltacloud::BaseDriver
33
-
34
32
  feature :instances, :user_name do
35
- constraint :max_length, 15
33
+ { :max_length => 50 }
36
34
  end
37
35
 
38
- USER_NAME_MAX = feature(:instances, :user_name).constraints[:max_length]
36
+ USER_NAME_MAX = constraints(:collection => :instances, :feature => :user_name)[:max_length]
39
37
 
40
38
  #--
41
39
  # Vapp State Map... for use with convert_instance (get an integer back from terremark)
@@ -118,8 +116,8 @@ VAPP_STATE_MAP = { "0" => "PENDING", "1" => "PENDING", "2" => "STOPPED", "4"
118
116
  pending.to(:stopped) .automatically
119
117
  stopped.to(:running) .on( :start )
120
118
  running.to(:running) .on( :reboot )
121
- running.to(:shutting_down) .on( :stop )
122
- shutting_down.to(:stopped) .automatically
119
+ running.to(:stopping) .on( :stop )
120
+ stopping.to(:stopped) .automatically
123
121
  stopped.to(:finish) .on( :destroy )
124
122
  end
125
123
 
@@ -141,7 +139,9 @@ VAPP_STATE_MAP = { "0" => "PENDING", "1" => "PENDING", "2" => "STOPPED", "4"
141
139
  end
142
140
  unless ( (terremark_hwp.include?(:cpu, opts[:hwp_cpu].to_i)) &&
143
141
  (terremark_hwp.include?(:memory, opts[:hwp_memory].to_i)) ) then
144
- raise Deltacloud::Validation::Failure.new(Deltacloud::Validation::Param.new(["cpu"]), "Error with cpu and/or memory values. you said cpu->#{opts[:hwp_cpu]} and mem->#{opts[:hwp_memory]}")
142
+ raise Deltacloud::ExceptionHandler::ValidationFailure.new(
143
+ StandardError.new("Error with cpu and/or memory values. you said cpu->#{opts[:hwp_cpu]} and mem->#{opts[:hwp_memory]}")
144
+ )
145
145
  end
146
146
  vapp_opts['cpus'] = opts[:hwp_cpu]
147
147
  vapp_opts['memory'] = opts[:hwp_memory]
@@ -14,18 +14,17 @@
14
14
  # under the License.
15
15
  #
16
16
 
17
- require 'deltacloud/base_driver'
18
17
  require 'rbvmomi'
19
18
  require 'deltacloud/drivers/vsphere/vsphere_client'
20
19
 
21
- module Deltacloud::Drivers::VSphere
20
+ module Deltacloud::Drivers::Vsphere
22
21
 
23
22
  MAPPER_STORAGE_ROOT = File::join("/var/tmp", "deltacloud-vsphere-#{ENV["USER"]}")
24
23
 
25
- class VSphereDriver < Deltacloud::BaseDriver
24
+ class VsphereDriver < Deltacloud::BaseDriver
26
25
 
27
26
  include Deltacloud::Drivers::VSphere::Helper
28
- include Deltacloud::Drivers::VSphere::FileManager
27
+ include VSphere::FileManager
29
28
 
30
29
  # You can use 'user_iso' feature to set 'user_iso' parameter when creating
31
30
  # a new instance where this parameter can hold gzipped CDROM iso which will
@@ -34,6 +33,8 @@ module Deltacloud::Drivers::VSphere
34
33
  feature :instances, :user_data
35
34
  feature :instances, :user_name
36
35
 
36
+ define_hardware_profile('default')
37
+
37
38
  # There is just one hardware profile where memory is measured using maximum
38
39
  # memory available on ESX for virtual machines and CPU using maximum free
39
40
  # CPU cores in ESX.
@@ -64,8 +65,8 @@ module Deltacloud::Drivers::VSphere
64
65
  pending.to(:stopped) .automatically
65
66
  stopped.to(:running) .on( :start )
66
67
  running.to(:running) .on( :reboot )
67
- running.to(:shutting_down) .on( :stop )
68
- shutting_down.to(:stopped) .automatically
68
+ running.to(:stopping) .on( :stop )
69
+ stopping.to(:stopped) .automatically
69
70
  stopped.to(:finish) .on( :destroy )
70
71
  end
71
72
 
@@ -75,7 +76,7 @@ module Deltacloud::Drivers::VSphere
75
76
  def images(credentials, opts=nil)
76
77
  cloud = new_client(credentials)
77
78
  img_arr = []
78
-
79
+ profiles = hardware_profiles(credentials)
79
80
  # Skip traversing through all instances in all datacenters when ID
80
81
  # attribute is set
81
82
  safely do
@@ -104,7 +105,8 @@ module Deltacloud::Drivers::VSphere
104
105
  :architecture => image_architecture,
105
106
  :owner_id => credentials.user,
106
107
  :description => properties[:full_name],
107
- :state => image_state
108
+ :state => image_state,
109
+ :hardware_profiles => profiles
108
110
  )
109
111
  end
110
112
  end
@@ -117,7 +119,7 @@ module Deltacloud::Drivers::VSphere
117
119
  safely do
118
120
  find_vm(credentials, opts[:id])[:instance].MarkAsTemplate
119
121
  end
120
- images(credentials, :id => opts[:id])
122
+ image(credentials, :id => opts[:id])
121
123
  end
122
124
 
123
125
  # List all datacenters managed by the vSphere or vCenter entrypoint.
@@ -350,11 +352,20 @@ module Deltacloud::Drivers::VSphere
350
352
  status 401
351
353
  end
352
354
 
355
+ on /nodename nor servname provided/ do
356
+ status 502
357
+ end
358
+
353
359
  on /ERROR/ do
354
360
  status 500
355
361
  end
356
362
 
357
- on /RbVmomi::Fault/ do
363
+ on /(RbVmomi::Fault|ToolsUnavailable)/ do
364
+ status 502
365
+ end
366
+
367
+ on /Undefined namespace prefix/ do
368
+ message 'VSphere Internal Error'
358
369
  status 502
359
370
  end
360
371
 
@@ -362,6 +373,18 @@ module Deltacloud::Drivers::VSphere
362
373
  status 502
363
374
  end
364
375
 
376
+ on /Requested datastore does not exists or misconfigured/ do
377
+ status 502
378
+ end
379
+
380
+ on /Connection timed out/ do
381
+ status 504
382
+ end
383
+
384
+ on /execution expired/ do
385
+ status 504
386
+ end
387
+
365
388
  on /Invalid/ do
366
389
  status 400
367
390
  end
@@ -370,10 +393,13 @@ module Deltacloud::Drivers::VSphere
370
393
 
371
394
  def valid_credentials?(credentials)
372
395
  begin
373
- RbVmomi::VIM.connect(:host => host_endpoint, :user => credentials.user, :password => credentials.password, :insecure => true)
374
- return true
375
- rescue
396
+ RbVmomi::VIM.connect(:host => host_endpoint, :user => credentials.user, :password => credentials.password, :insecure => true) && true
397
+ rescue RbVmomi::Fault::InvalidLogin
376
398
  return false
399
+ rescue => e
400
+ safely do
401
+ raise e
402
+ end
377
403
  end
378
404
  end
379
405
 
@@ -164,6 +164,7 @@ module VSphere
164
164
  # return the url like https://<server_address>/folder/<path>/<file_name>?<query_infos>
165
165
 
166
166
  def buildUrl(datastore,file="")
167
+ raise "Requested datastore does not exists or misconfigured" unless datastore.respond_to?(:'_connection')
167
168
  uri=URI::HTTPS::build(:host=>datastore._connection.http.address)
168
169
  uri.path= ["/folder",DIRECTORY_PATH,file].join("/") if file
169
170
  query={:dcPath => datastore.send(:datacenter).name, :dsName => datastore.name }
@@ -1,4 +1,3 @@
1
- #
2
1
  # Licensed to the Apache Software Foundation (ASF) under one or more
3
2
  # contributor license agreements. See the NOTICE file distributed with
4
3
  # this work for additional information regarding copyright ownership. The
@@ -14,10 +13,83 @@
14
13
  # License for the specific language governing permissions and limitations
15
14
  # under the License.
16
15
 
17
- require 'deltacloud/helpers/application_helper'
18
- require 'deltacloud/helpers/json_helper'
19
- require 'deltacloud/helpers/conversion_helper'
20
- require 'deltacloud/helpers/hardware_profiles_helper'
21
- require 'deltacloud/helpers/blob_stream'
16
+ require_relative 'helpers/driver_helper'
17
+ require_relative 'helpers/auth_helper'
18
+ require_relative 'helpers/url_helper'
19
+ require_relative 'helpers/deltacloud_helper'
20
+ require_relative 'helpers/rabbit_helper'
21
+ require_relative 'helpers/blob_stream_helper'
22
+
23
+ module Deltacloud::Collections
24
+ class Base < Sinatra::Base
25
+
26
+ include Sinatra::Rabbit
27
+ extend Deltacloud::Helpers::Drivers
28
+ include Sinatra::Rabbit::Features
29
+
30
+ helpers Deltacloud::Helpers::Drivers
31
+ helpers Sinatra::AuthHelper
32
+ helpers Sinatra::UrlForHelper
33
+ helpers Rack::RespondTo::Helpers
34
+ helpers Deltacloud::Helpers::Application
35
+
36
+ register Rack::RespondTo
37
+
38
+ enable :xhtml
39
+ enable :dump_errors
40
+ enable :show_errors
41
+ enable :method_override
42
+ disable :show_exceptions
43
+
44
+ set :config, Deltacloud[:deltacloud]
45
+ set :root_url, config.root_url
46
+ set :root_path, config.root_url
47
+ set :version, config.version
48
+ set :root, File.join(File.dirname(__FILE__), '..', '..')
49
+ set :views, root + '/views'
50
+ set :public_folder, root + '/public'
51
+
52
+ Sinatra::Rabbit.set :root_path, "#{config.root_url}/"
53
+
54
+ error do
55
+ report_error
56
+ end
57
+
58
+ error Deltacloud::ExceptionHandler::ValidationFailure do
59
+ report_error
60
+ end
61
+
62
+ before do
63
+ # Respond with 400, If we don't get a http Host header,
64
+ halt 400, "Unable to find HTTP Host header" if @env['HTTP_HOST'] == nil
65
+ end
66
+
67
+ after do
68
+ headers 'Server' => 'Apache-Deltacloud/' + settings.version
69
+ end
70
+
71
+ def self.new_route_for(route, &block)
72
+ get route_for('/' + route.to_s + '/new') do
73
+ instance_eval(&block) if block_given?
74
+ respond_to do |format|
75
+ format.html do
76
+ haml :"#{route}/new"
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ def self.check_capability(opts={})
83
+ Sinatra::Rabbit.set :check_capability, opts[:for]
84
+ end
85
+
86
+ def self.check_features(opts={})
87
+ Sinatra::Rabbit.set :check_features, opts[:for]
88
+ end
89
+
90
+ def self.route_for(url)
91
+ "#{settings.root_url}#{url}"
92
+ end
22
93
 
23
- helpers ApplicationHelper, ConversionHelper, HardwareProfilesHelper, JSONHelper
94
+ end
95
+ end
@@ -14,12 +14,11 @@
14
14
  # License for the specific language governing permissions and limitations
15
15
  # under the License.
16
16
 
17
- require 'sinatra/base'
18
-
19
17
  # Lazy Basic HTTP authentication. Authentication is only forced when the
20
18
  # credentials are actually needed.
19
+
21
20
  module Sinatra
22
- module LazyAuth
21
+ module AuthHelper
23
22
  class LazyCredentials
24
23
  def initialize(app)
25
24
  @app = app
@@ -49,9 +48,7 @@ module Sinatra
49
48
  end
50
49
  unless provided?
51
50
  auth = Rack::Auth::Basic::Request.new(@app.request.env)
52
- unless auth.provided? && auth.basic? && auth.credentials
53
- @app.authorize!
54
- end
51
+ @app.authorize! unless auth.provided? && auth.basic? && auth.credentials
55
52
  @user = auth.credentials[0]
56
53
  @password = auth.credentials[1]
57
54
  @provided = true
@@ -61,9 +58,9 @@ module Sinatra
61
58
  end
62
59
 
63
60
  def authorize!
64
- r = "#{driver_symbol}-deltacloud@#{HOSTNAME}"
61
+ r = "#{Thread.current[:driver]}-deltacloud@#{ENV['HOSTNAME']}"
65
62
  response['WWW-Authenticate'] = %(Basic realm="#{r}")
66
- throw(:halt, [401, "Not authorized\n"])
63
+ throw(:halt, [401, report_error(401)])
67
64
  end
68
65
 
69
66
  # Request the current user's credentials. Actual credentials are only
@@ -73,5 +70,4 @@ module Sinatra
73
70
  end
74
71
  end
75
72
 
76
- helpers LazyAuth
77
73
  end
@@ -14,6 +14,7 @@
14
14
  # under the License.
15
15
 
16
16
  include Deltacloud
17
+
17
18
  begin
18
19
  require 'eventmachine'
19
20
  #--
@@ -22,20 +23,20 @@ begin
22
23
  #--
23
24
  class BlobStream
24
25
  AsyncResponse = [-1, {}, []].freeze
25
- def self.call(env, credentials, params)
26
- body = DeferrableBody.new
26
+ def self.call(context, credentials, params)
27
+ body = DeferrableBody.new
27
28
  #Get the headers out asap. Don't specify a content-type let
28
29
  #the client guess and if they can't they SHOULD default to
29
30
  #'application/octet-stream' anyway as per:
30
31
  #http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.2.1
31
- EM.next_tick { env['async.callback'].call [200, {
32
+ EM.next_tick { context.env['async.callback'].call [200, {
32
33
  'Content-Type' => "#{params['content_type']}",
33
34
  'Content-Disposition' => params["content_disposition"],
34
35
  'Content-Length' => "#{params['content_length']}"}, body]
35
36
  }
36
37
  #call the driver from here. the driver method yields for every chunk
37
38
  #of blob it receives. Then use body.call to write that chunk as received.
38
- driver.blob_data(credentials, params[:bucket], params[:blob], params) {|chunk| body.call ["#{chunk}"]} #close blob_data block
39
+ context.driver.blob_data(credentials, params[:id], params[:blob_id], params) {|chunk| body.call ["#{chunk}"]} #close blob_data block
39
40
  body.succeed
40
41
  AsyncResponse # Tell Thin to not close connection & work other requests
41
42
  end
@@ -148,7 +149,6 @@ require 'base64'
148
149
  class BlobStreamIO
149
150
 
150
151
  attr_accessor :size, :provider, :sock
151
-
152
152
  def initialize(request)
153
153
  @client_request = request
154
154
  @size = 0
@@ -158,7 +158,7 @@ class BlobStreamIO
158
158
  #deal with blob_metadata: (X-Deltacloud-Blobmeta-name: value)
159
159
  user_meta = BlobHelper::extract_blob_metadata_hash(request.env)
160
160
  @content_length = request.env['CONTENT_LENGTH']
161
- @http, provider_request = driver.blob_stream_connection({:user=>user,
161
+ @http, provider_request = Deltacloud::API.driver.blob_stream_connection({:user=>user,
162
162
  :password=>password, :bucket=>bucket, :blob=>blob, :metadata=> user_meta,
163
163
  :content_type=>content_type, :content_length=>@content_length })
164
164
  @content_length = @content_length.to_i #for comparison of size in '<< (data)'
@@ -187,7 +187,7 @@ class BlobStreamIO
187
187
  def self.is_put_blob(request = nil)
188
188
  path = request.env['PATH_INFO']
189
189
  method = request.env['REQUEST_METHOD']
190
- if ( path =~ /^#{Regexp.escape(settings.root_url)}\/buckets/ && method == 'PUT' )
190
+ if ( path =~ /^#{Regexp.escape(Deltacloud::API.settings.root_url)}\/buckets/ && method == 'PUT' )
191
191
  return true
192
192
  else
193
193
  return false
@@ -0,0 +1,286 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership. The
4
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+
16
+ module Deltacloud::Helpers
17
+ module Application
18
+
19
+ require 'benchmark'
20
+
21
+ def auth_feature_name
22
+ return 'key' if driver.class.has_feature?(:instances, :authentication_key)
23
+ return 'password' if driver.class.has_feature?(:instances, :authentication_password)
24
+ end
25
+
26
+ def instance_action_method(action)
27
+ action_method(action, Sinatra::Rabbit::InstancesCollection)
28
+ end
29
+
30
+ def action_method(action, collection)
31
+ http_method = collection.operation(action).http_method
32
+ http_method || Sinatra::Rabbit::BaseCollection.http_method_for(action)
33
+ end
34
+
35
+ def filter_all(model)
36
+ filter = {}
37
+ filter.merge!(:id => params[:id]) if params[:id]
38
+ filter.merge!(:architecture => params[:architecture]) if params[:architecture]
39
+ filter.merge!(:owner_id => params[:owner_id]) if params[:owner_id]
40
+ filter.merge!(:state => params[:state]) if params[:state]
41
+ filter = {} if filter.keys.size.eql?(0)
42
+ singular = model.to_s.singularize.to_sym
43
+ begin
44
+ @benchmark = Benchmark.measure do
45
+ @elements = driver.send(model.to_sym, credentials, filter)
46
+ end
47
+ rescue
48
+ @exception = $!
49
+ end
50
+ if @elements
51
+ headers['X-Backend-Runtime'] = @benchmark.real.to_s
52
+ instance_variable_set(:"@#{model}", @elements)
53
+ respond_to do |format|
54
+ format.html { haml :"#{model}/index" }
55
+ format.xml { haml :"#{model}/index" }
56
+ format.json { @media_type=:xml; to_json(haml(:"#{model}/index")) }
57
+ end
58
+ else
59
+ report_error(@exception.respond_to?(:code) ? @exception.code : 500)
60
+ end
61
+ end
62
+
63
+ def xml_to_json(model)
64
+ @media_type = :xml
65
+ to_json(haml(:"#{model}"))
66
+ end
67
+
68
+ def to_json(xml)
69
+ Crack::XML.parse(xml).to_json
70
+ end
71
+
72
+ def show(model)
73
+ @benchmark = Benchmark.measure do
74
+ @element = driver.send(model, credentials, { :id => params[:id]} )
75
+ end
76
+ headers['X-Backend-Runtime'] = @benchmark.real.to_s
77
+ instance_variable_set("@#{model}", @element)
78
+ if @element
79
+ respond_to do |format|
80
+ format.html { haml :"#{model.to_s.pluralize}/show" }
81
+ format.xml { haml :"#{model.to_s.pluralize}/show" }
82
+ format.json { @media_type=:xml; to_json(haml(:"#{model.to_s.pluralize}/show")) }
83
+ end
84
+ else
85
+ report_error(404)
86
+ end
87
+ end
88
+
89
+ def report_error(code=nil)
90
+ @error, @code = (request.env['sinatra.error'] || @exception), code
91
+ @code = 500 if not @code and not @error.class.method_defined? :code
92
+ response.status = @code || @error.code
93
+ respond_to do |format|
94
+ format.xml { haml :"errors/#{@code || @error.code}", :layout => false }
95
+ format.html { haml :"errors/#{@code || @error.code}", :layout => :error }
96
+ end
97
+ end
98
+
99
+ def instance_action(name)
100
+ original_instance = driver.instance(credentials, :id => params[:id])
101
+
102
+ # If original instance doesn't include called action
103
+ # return with 405 error (Method is not Allowed)
104
+ unless driver.instance_actions_for(original_instance.state).include?(name.to_sym)
105
+ return report_error(405)
106
+ end
107
+
108
+ @benchmark = Benchmark.measure do
109
+ @instance = driver.send(:"#{name}_instance", credentials, params[:id])
110
+ end
111
+
112
+ headers['X-Backend-Runtime'] = @benchmark.real.to_s
113
+
114
+ if name == :destroy
115
+ response = respond_to do |format|
116
+ format.html { redirect(instances_url) }
117
+ end
118
+ halt 204, response
119
+ end
120
+
121
+ unless @instance.class == Instance
122
+ redirect instance_url(params[:id])
123
+ else
124
+ response = respond_to do |format|
125
+ format.xml { haml :"instances/show" }
126
+ format.html { haml :"instances/show" }
127
+ format.json { xml_to_json("instances/show") }
128
+ end
129
+ halt 202, response
130
+ end
131
+ end
132
+
133
+ def cdata(text = nil, &block)
134
+ text ||= capture_haml(&block)
135
+ "<![CDATA[#{text.strip}]]>"
136
+ end
137
+
138
+ def render_cdata(text)
139
+ "<![CDATA[#{text.strip}]]>"
140
+ end
141
+
142
+ def link_to_action(action, url, method)
143
+ capture_haml do
144
+ haml_tag :form, :method => :post, :action => url, :class => [:link, method], :'data-ajax' => 'false' do
145
+ haml_tag :input, :type => :hidden, :name => '_method', :value => method
146
+ haml_tag :button, :type => :submit, :'data-ajax' => 'false', :'data-inline' => "true" do
147
+ haml_concat action
148
+ end
149
+ end
150
+ end
151
+ end
152
+
153
+ def link_to_format(format)
154
+ return unless request.env['REQUEST_URI']
155
+ uri = request.env['REQUEST_URI']
156
+ return if uri.include?('format=')
157
+ uri += uri.include?('?') ? "&format=#{format}" : "?format=#{format}"
158
+ capture_haml do
159
+ haml_tag :a, :href => uri, :'data-ajax' => 'false', :'data-icon' => 'grid' do
160
+ haml_concat format.to_s.upcase
161
+ end
162
+ end
163
+ end
164
+
165
+ def image_for_state(state)
166
+ state_img = "stopped" if (state!='RUNNING' or state!='PENDING')
167
+ capture_haml do
168
+ haml_tag :img, :src => "/images/#{state}" % state.downcase, :title => state
169
+ end
170
+ end
171
+
172
+ # Reverse the entrypoints hash for a driver from drivers.yaml; note that
173
+ # +d+ is a hash, not an actual driver object
174
+ def driver_provider(d)
175
+ result = {}
176
+ if d[:entrypoints]
177
+ d[:entrypoints].each do |kind, details|
178
+ details.each do |prov, url|
179
+ result[prov] ||= {}
180
+ result[prov][kind] = url
181
+ end
182
+ end
183
+ end
184
+ result
185
+ end
186
+
187
+ def header(title, opts={}, &block)
188
+ opts[:theme] ||= 'b'
189
+ opts[:back] ||= 'true'
190
+ capture_haml do
191
+ haml_tag :div, :'data-role' => :header, :'data-theme' => opts[:theme], :'data-add-back-btn' => opts[:back] do
192
+ haml_tag :a, :'data-rel' => :back do
193
+ haml_concat "Back"
194
+ end if opts[:back] == 'true'
195
+ haml_tag :h1 do
196
+ haml_concat title
197
+ end
198
+ block.call if block_given?
199
+ end
200
+ end
201
+ end
202
+
203
+ def subheader(title, opts={})
204
+ opts[:theme] ||= 'a'
205
+ capture_haml do
206
+ haml_tag :div, :'data-role' => :header, :'data-theme' => opts[:theme] do
207
+ haml_tag :p, :class => 'inner-right' do
208
+ haml_concat title
209
+ end
210
+ end
211
+ end
212
+ end
213
+
214
+ def translate_error_code(code)
215
+ case code
216
+ when 400; { :message => "Bad Request" }
217
+ when 401; { :message => "Unauthorized" }
218
+ when 403; { :message => "Forbidden" }
219
+ when 404; { :message => "Not Found" }
220
+ when 405; { :message => "Method Not Allowed" }
221
+ when 406; { :message => "Not Acceptable" }
222
+ when 500; { :message => "Internal Server Error" }
223
+ when 502; { :message => "Backend Server Error" }
224
+ when 504; { :message => "Gateway Timeout" }
225
+ when 501; { :message => "Not Supported" }
226
+ end
227
+ end
228
+
229
+ NEW_BLOB_FORM_ID = 'new_blob_form_d15cfd90' unless defined?(NEW_BLOB_FORM_ID)
230
+
231
+ def new_blob_form_url(bucket)
232
+ bucket_url(@bucket.name) + "/" + NEW_BLOB_FORM_ID
233
+ end
234
+
235
+ def format_hardware_property(prop)
236
+ return "&empty;" unless prop
237
+ u = hardware_property_unit(prop)
238
+ case prop.kind
239
+ when :range
240
+ "#{prop.first} #{u} - #{prop.last} #{u} (default: #{prop.default} #{u})"
241
+ when :enum
242
+ prop.values.collect{ |v| "#{v} #{u}"}.join(', ') + " (default: #{prop.default} #{u})"
243
+ else
244
+ "#{prop.value} #{u}"
245
+ end
246
+ end
247
+
248
+ def format_instance_profile(ip)
249
+ o = ip.overrides.collect do |p, v|
250
+ u = hardware_property_unit(p)
251
+ "#{p} = #{v} #{u}"
252
+ end
253
+ if o.empty?
254
+ nil
255
+ else
256
+ "with #{o.join(", ")}"
257
+ end
258
+ end
259
+
260
+ def order_hardware_profiles(profiles)
261
+ #have to deal with opaque hardware profiles
262
+ uncomparables = profiles.select{|x| x.cpu.nil? or x.memory.nil? }
263
+ if uncomparables.empty?
264
+ profiles.sort_by{|a| [a.cpu.default, a.memory.default] }
265
+ else
266
+ (profiles - uncomparables).sort_by{|a| [a.cpu.default, a.memory.default] } + uncomparables
267
+ end
268
+ end
269
+
270
+ def additional_features_for?(collection_name, apart_from = [])
271
+ features_arr = (driver.class.features[collection_name.to_sym] || [] ) - apart_from
272
+ not features_arr.empty?
273
+ end
274
+
275
+ private
276
+ def hardware_property_unit(prop)
277
+ u = ::Deltacloud::HardwareProfile::unit(prop)
278
+ u = "" if ["label", "count"].include?(u)
279
+ u = "vcpus" if prop == :cpu
280
+ u
281
+ end
282
+
283
+
284
+
285
+ end
286
+ end