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
@@ -1,267 +0,0 @@
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
- # Methods added to this helper will be available to all templates in the application.
17
-
18
- require 'benchmark'
19
-
20
- module ApplicationHelper
21
-
22
- include Deltacloud
23
-
24
- def bread_crumb
25
- s = "<ul class='breadcrumb'><li class='first'><a href='#{settings.root_url}'>&#948</a></li>"
26
- url = request.path_info.split('?') #remove extra query string parameters
27
- levels = url[0].split('/') #break up url into different levels
28
- levels.each_with_index do |level, index|
29
- unless level.blank?
30
- next if "/#{level}" == settings.root_url
31
- if index == levels.size-1 || (level == levels[levels.size-2] && levels[levels.size-1].to_i > 0)
32
- s += "<li class='subsequent'>#{level.gsub(/_/, ' ')}</li>\n" unless level.to_i > 0
33
- else
34
- link = levels.slice(2, index-1).join("/")
35
- s += "<li class='subsequent'><a href=\"#{api_url_for(link)}\">#{level.gsub(/_/, ' ')}</a></li>\n"
36
- end
37
- end
38
- end
39
- s+="<li class='docs'>#{link_to_documentation}</li>"
40
- s+="</ul>"
41
- end
42
-
43
- def instance_action_method(action)
44
- action_method(action, :instances)
45
- end
46
-
47
- def action_method(action, collection)
48
- collections[collection].operations[action.to_sym].method
49
- end
50
-
51
- def driver_has_feature?(feature_name, collection_name = :instances)
52
- not driver.features(collection_name).select{ |f| f.name.eql?(feature_name) }.empty?
53
- end
54
-
55
- def driver_has_auth_features?
56
- driver_has_feature?(:authentication_password) || driver_has_feature?(:authentication_key)
57
- end
58
-
59
- def driver_auth_feature_name
60
- return 'key' if driver_has_feature?(:authentication_key)
61
- return 'password' if driver_has_feature?(:authentication_password)
62
- end
63
-
64
- def driver_has_bucket_location_feature?
65
- driver.features(:buckets).each do |feat|
66
- return true if feat.name == :bucket_location
67
- end
68
- false
69
- end
70
-
71
- def filter_all(model)
72
- filter = {}
73
- filter.merge!(:id => params[:id]) if params[:id]
74
- filter.merge!(:architecture => params[:architecture]) if params[:architecture]
75
- filter.merge!(:owner_id => params[:owner_id]) if params[:owner_id]
76
- filter.merge!(:state => params[:state]) if params[:state]
77
- filter = {} if filter.keys.size.eql?(0)
78
- singular = model.to_s.singularize.to_sym
79
- @benchmark = Benchmark.measure do
80
- @elements = driver.send(model.to_sym, credentials, filter)
81
- end
82
- headers['X-Backend-Runtime'] = @benchmark.real.to_s
83
- instance_variable_set(:"@#{model}", @elements)
84
- respond_to do |format|
85
- format.html { haml :"#{model}/index" }
86
- format.xml { haml :"#{model}/index" }
87
- format.json { convert_to_json(singular, @elements) }
88
- end
89
- end
90
-
91
- def show(model)
92
- @benchmark = Benchmark.measure do
93
- @element = driver.send(model, credentials, { :id => params[:id]} )
94
- end
95
- headers['X-Backend-Runtime'] = @benchmark.real.to_s
96
- instance_variable_set("@#{model}", @element)
97
- if @element
98
- respond_to do |format|
99
- format.html { haml :"#{model.to_s.pluralize}/show" }
100
- format.xml { haml :"#{model.to_s.pluralize}/show" }
101
- format.json { convert_to_json(model, @element) }
102
- end
103
- else
104
- report_error(404)
105
- end
106
- end
107
-
108
- def report_error(code=nil)
109
- @error, @code = request.env['sinatra.error'], code
110
- @code = 500 if not @code and not @error.class.method_defined? :code
111
- response.status = @code || @error.code
112
- respond_to do |format|
113
- format.xml { haml :"errors/#{@code || @error.code}", :layout => false }
114
- format.json { json_return_error(@error) }
115
- format.html { haml :"errors/#{@code || @error.code}", :layout => :error }
116
- end
117
- end
118
-
119
- def instance_action(name)
120
- original_instance = driver.instance(credentials, :id => params[:id])
121
-
122
- # If original instance doesn't include called action
123
- # return with 405 error (Method is not Allowed)
124
- unless driver.instance_actions_for(original_instance.state).include?(name.to_sym)
125
- return report_error(405)
126
- end
127
-
128
- @instance = driver.send(:"#{name}_instance", credentials, params["id"])
129
-
130
- if name == :destroy or @instance.class!=Instance
131
- respond_to do |format|
132
- format.xml { return 204 }
133
- format.json { return 204 }
134
- format.html { return redirect(instances_url) }
135
- end
136
- end
137
-
138
- respond_to do |format|
139
- format.xml { haml :"instances/show" }
140
- format.html { haml :"instances/show" }
141
- format.json {convert_to_json(:instance, @instance) }
142
- end
143
- end
144
-
145
- def cdata(text = nil, &block)
146
- text ||= capture_haml(&block)
147
- "<![CDATA[#{text.strip}]]>"
148
- end
149
-
150
- def render_cdata(text)
151
- "<![CDATA[#{text.strip}]]>"
152
- end
153
-
154
- def link_to_action(action, url, method)
155
- capture_haml do
156
- haml_tag :form, :method => :post, :action => url, :class => [:link, method], :'data-ajax' => 'false' do
157
- haml_tag :input, :type => :hidden, :name => '_method', :value => method
158
- haml_tag :button, :type => :submit, :'data-ajax' => 'false', :'data-inline' => "true" do
159
- haml_concat action
160
- end
161
- end
162
- end
163
- end
164
-
165
- def link_to_format(format)
166
- return '' unless request.env['REQUEST_URI']
167
- uri = request.env['REQUEST_URI']
168
- return if uri.include?('format=')
169
- if uri.include?('?')
170
- uri+="&format=#{format}"
171
- else
172
- uri+="?format=#{format}"
173
- end
174
- '<a data-ajax="false" data-icon="grid" href="%s">%s</a>' % [uri, "#{format}".upcase]
175
- end
176
-
177
- def link_to_documentation
178
- return '' unless request.env['REQUEST_URI']
179
- uri = request.env['REQUEST_URI'].dup
180
- uri.gsub!(settings.root_url,
181
- api_url_for(:docs)) unless uri.include?("docs") #i.e. if already serving under /api/docs, leave it be
182
- '<a href="%s">[ Documentation ]</a>' % uri
183
- end
184
-
185
- def action_url
186
- if [:index].include?(@operation.name)
187
- api_url_for("#{@collection.name.to_s}")
188
- elsif [:show, :stop, :start, :reboot, :attach, :detach].include?(@operation.name)
189
- api_url_for("#{@collection.name.to_s}/:id/#{@operation.name}")
190
- elsif [:destroy].include?(@operation.name)
191
- api_url_for("#{@collection.name.to_s}/:id")
192
- else
193
- api_url_for("#{@collection.name}/#{@operation.name}")
194
- end
195
- end
196
-
197
- def image_for_state(state)
198
- state_img = "stopped" if (state!='RUNNING' or state!='PENDING')
199
- "<img src='/images/#{state.downcase}.png' title='#{state}'/>"
200
- end
201
-
202
- def truncate_words(text, length = 10)
203
- return nil unless text
204
- return text if text.length<=length
205
- end_string = "...#{text[(text.length-(length/2))..text.length]}"
206
- "#{text[0..(length/2)]}#{end_string}"
207
- end
208
-
209
- # Reverse the entrypoints hash for a driver from drivers.yaml; note that
210
- # +d+ is a hash, not an actual driver object
211
- def driver_provider(d)
212
- result = {}
213
- if d[:entrypoints]
214
- d[:entrypoints].each do |kind, details|
215
- details.each do |prov, url|
216
- result[prov] ||= {}
217
- result[prov][kind] = url
218
- end
219
- end
220
- end
221
- result
222
- end
223
-
224
- def header(title, opts={}, &block)
225
- opts[:theme] ||= 'b'
226
- opts[:back] ||= 'true'
227
- capture_haml do
228
- haml_tag :div, :'data-role' => :header, :'data-theme' => opts[:theme], :'data-add-back-btn' => opts[:back] do
229
- haml_tag :a, :'data-rel' => :back do
230
- haml_concat "Back"
231
- end if opts[:back] == 'true'
232
- haml_tag :h1 do
233
- haml_concat title
234
- end
235
- block.call if block_given?
236
- end
237
- end
238
- end
239
-
240
- def subheader(title, opts={})
241
- opts[:theme] ||= 'a'
242
- capture_haml do
243
- haml_tag :div, :'data-role' => :header, :'data-theme' => opts[:theme] do
244
- haml_tag :p, :class => 'inner-right' do
245
- haml_concat title
246
- end
247
- end
248
- end
249
- end
250
-
251
- def translate_error_code(code)
252
- case code
253
- when 400; { :message => "Bad Request" }
254
- when 401; { :message => "Unauthorized" }
255
- when 403; { :message => "Forbidden" }
256
- when 404; { :message => "Not Found" }
257
- when 405; { :message => "Method Not Allowed" }
258
- when 406; { :message => "Not Acceptable" }
259
- when 500; { :message => "Internal Server Error" }
260
- when 502; { :message => "Backend Server Error" }
261
- end
262
- end
263
-
264
- def new_blob_form_url(bucket)
265
- bucket_url(@bucket.name) + "/" + NEW_BLOB_FORM_ID
266
- end
267
- end
@@ -1,50 +0,0 @@
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 HardwareProfilesHelper
17
-
18
- def format_hardware_property(prop)
19
- return "&empty;" unless prop
20
- u = hardware_property_unit(prop)
21
- case prop.kind
22
- when :range
23
- "#{prop.first} #{u} - #{prop.last} #{u} (default: #{prop.default} #{u})"
24
- when :enum
25
- prop.values.collect{ |v| "#{v} #{u}"}.join(', ') + " (default: #{prop.default} #{u})"
26
- else
27
- "#{prop.value} #{u}"
28
- end
29
- end
30
-
31
- def format_instance_profile(ip)
32
- o = ip.overrides.collect do |p, v|
33
- u = hardware_property_unit(p)
34
- "#{p} = #{v} #{u}"
35
- end
36
- if o.empty?
37
- ""
38
- else
39
- "with #{o.join(", ")}"
40
- end
41
- end
42
-
43
- private
44
- def hardware_property_unit(prop)
45
- u = ::Deltacloud::HardwareProfile::unit(prop)
46
- u = "" if ["label", "count"].include?(u)
47
- u = "vcpus" if prop == :cpu
48
- u
49
- end
50
- end
@@ -1,31 +0,0 @@
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 JSONHelper
17
-
18
- def json_features_for_entrypoint(entrypoint)
19
- features = driver.features(entrypoint.first).collect { |feature| feature.name }
20
- features.empty? ? {} : { :features => features }
21
- end
22
-
23
- def json_return_error(error)
24
- error_output=Hash.new
25
- error_output[:url] =request.env['REQUEST_URI']
26
- error_output[:status] =response.status
27
- error_output[:message]=error.message if error
28
- error_output.to_json
29
- end
30
-
31
- end
@@ -1,83 +0,0 @@
1
- #
2
- # Licensed to the Apache Software Foundation (ASF) under one or more
3
- # contributor license agreements. See the NOTICE file distributed with
4
- # this work for additional information regarding copyright ownership. The
5
- # ASF licenses this file to you under the Apache License, Version 2.0 (the
6
- # "License"); you may not use this file except in compliance with the
7
- # License. You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
- # License for the specific language governing permissions and limitations
15
- # under the License.
16
-
17
- require 'base64'
18
- require 'digest'
19
-
20
- module MethodSerializer
21
-
22
- module Cache
23
-
24
- def cache_dir
25
- storage_dir = $methods_cache_dir || File.join(File.dirname(__FILE__), 'cache')
26
- class_dir = self.class.name.split('::').last
27
- class_dir ||= self.class.name
28
- File.join(storage_dir, class_dir.downcase)
29
- end
30
-
31
- def serialize_data(method_name, args, data)
32
- File.open(cache_file_name(method_name, args), 'w') do |f|
33
- f.puts(Base64.encode64(Marshal.dump(data)))
34
- end
35
- return data
36
- end
37
-
38
- def deserialize_data(method_name, args)
39
- begin
40
- data = File.readlines(cache_file_name(method_name, args)).join
41
- Marshal.load(Base64.decode64(data))
42
- rescue Errno::ENOENT
43
- return false
44
- end
45
- end
46
-
47
- def args_hash(args)
48
- if args.class == Hash
49
- args = args.to_a.collect {|i| [i[0].to_s, i[1]]}.sort
50
- end
51
- Digest::SHA1.hexdigest(args.to_s)
52
- end
53
-
54
- def cache_file_name(method_name, args)
55
- FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir)
56
- method_name = $scenario_prefix ? "#{$scenario_prefix}_#{method_name}" : method_name
57
- File.join(cache_dir, "#{method_name}.#{args_hash(args)}")
58
- end
59
-
60
- def self.wrap_methods(c, opts={})
61
- $methods_cache_dir = opts[:cache_dir]
62
- $scenario_prefix = nil
63
- c.class_eval do
64
- cached_methods.each do |m|
65
- next if c.instance_methods(false).include?("original_#{m}")
66
- alias_method "original_#{m}".to_sym, m.to_sym
67
- define_method m.to_sym do |*args|
68
- args = args.first if args.size.eql?(1) and not args.first.class.eql?(Array)
69
- output = deserialize_data(m, args)
70
- unless output
71
- output = method("original_#{m}".to_sym).to_proc[args]
72
- return serialize_data(m, args, output)
73
- else
74
- return output
75
- end
76
- end
77
- end
78
- end
79
- end
80
-
81
- end
82
-
83
- end
@@ -1,107 +0,0 @@
1
- #
2
- # Licensed to the Apache Software Foundation (ASF) under one or more
3
- # contributor license agreements. See the NOTICE file distributed with
4
- # this work for additional information regarding copyright ownership. The
5
- # ASF licenses this file to you under the Apache License, Version 2.0 (the
6
- # "License"); you may not use this file except in compliance with the
7
- # License. You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
- # License for the specific language governing permissions and limitations
15
- # under the License.
16
-
17
- module Deltacloud::Validation
18
-
19
- class Failure < Deltacloud::ExceptionHandler::DeltacloudException
20
- attr_reader :param
21
- def initialize(e, message=nil)
22
- message ||= e.message
23
- super(400, e.class.name, message, [])
24
- end
25
- def name
26
- param.name if @param
27
- end
28
- end
29
-
30
- class Param
31
- attr_reader :name, :klass, :type, :options, :description
32
-
33
- def initialize(args)
34
- @name = args[0]
35
- @klass = args[1] || :string
36
- @type = args[2] || :optional
37
- @options = args[3] || []
38
- @description = args[4] || ''
39
- end
40
-
41
- def required?
42
- type.eql?(:required)
43
- end
44
-
45
- def optional?
46
- type.eql?(:optional)
47
- end
48
-
49
- def valid_value?(value)
50
- true if (options.kind_of?(Range) or options.kind_of?(Array)) and options.include?(value)
51
- true if options.kind_of?(String) and not options.empty?
52
- end
53
-
54
- def valid_hwp_value?(profile, value)
55
- profile.property(@name.to_s.gsub(/^hwp_/, '')).valid?(value)
56
- end
57
-
58
- def hwp_property?
59
- true if name.to_s =~ /^hwp_(cpu|memory|storage|architecture)/
60
- end
61
- end
62
-
63
- def param(*args)
64
- raise "Duplicate param #{args[0]} #{params.inspect} #{self.class.name}" if params[args[0]]
65
- p = Param.new(args)
66
- params[p.name] = p
67
- end
68
-
69
- def params
70
- @params ||= {}
71
- @params
72
- end
73
-
74
- # Add the parameters in hash +new+ to already existing parameters. If
75
- # +new+ contains a parameter with an already existing name, the old
76
- # definition is clobbered.
77
- def add_params(new)
78
- # We do not check for duplication on purpose: multiple calls
79
- # to add_params should be cumulative
80
- new.each { |p| @params[p.name] = p }
81
- end
82
-
83
- def each_param(&block)
84
- params.each_value { |p| yield p }
85
- end
86
-
87
- def validate(current_driver, all_params, values, credentials)
88
- all_params.each do |key, p|
89
- if p.required? and not values[p.name]
90
- raise Failure.new(p, "Required parameter #{p.name} not found")
91
- end
92
- next unless values[p.name]
93
- if p.hwp_property?
94
- profile = current_driver.hardware_profile(credentials, values['hwp_id'])
95
- raise Failure.new(p, "Unknown hardware profile selected #{values['hwp_id']}") unless profile
96
- unless p.valid_hwp_value?(profile, values[p.name])
97
- raise Failure.new(p, "Hardware profile property #{p.name} has invalid value #{values[p.name]}")
98
- end
99
- else
100
- if not p.options.empty? and p.valid_value?(values[p.name])
101
- raise Failure.new(p, "Parameter #{p.name} has value #{values[p.name]} which is not in #{p.options.join(", ")}")
102
- end
103
- end
104
- end
105
- end
106
-
107
- end