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
@@ -14,7 +14,6 @@
14
14
  # License for the specific language governing permissions and limitations
15
15
  # under the License.
16
16
 
17
- require 'deltacloud/base_driver'
18
17
  require 'deltacloud/drivers/gogrid/gogrid_client'
19
18
 
20
19
  class Instance
@@ -33,13 +32,16 @@ module Deltacloud
33
32
 
34
33
  class GogridDriver < Deltacloud::BaseDriver
35
34
 
36
- feature :instances, :authentication_password
37
- feature :instances, :sandboxing
38
35
  feature :instances, :user_name do
39
- constraint :max_length, 20
36
+ { :max_length => 20 }
40
37
  end
41
38
 
42
- USER_NAME_MAX = feature(:instances, :user_name).constraints[:max_length]
39
+ feature :instances, :authentication_password
40
+ feature :instances, :sandboxing
41
+
42
+ define_hardware_profile 'default'
43
+
44
+ USER_NAME_MAX = constraints(:collection => :instances, :feature => :user_name)[:max_length]
43
45
 
44
46
  def hardware_profiles(credentials, opts={})
45
47
  client = new_client(credentials)
@@ -61,11 +63,6 @@ class GogridDriver < Deltacloud::BaseDriver
61
63
  @hardware_profiles
62
64
  end
63
65
 
64
- def supported_collections
65
- DEFAULT_COLLECTIONS.reject! { |c| [ :storage_volumes, :storage_snapshots ].include?(c) }
66
- DEFAULT_COLLECTIONS + [ :keys, :load_balancers ]
67
- end
68
-
69
66
  def images(credentials, opts=nil)
70
67
  imgs = []
71
68
  if opts and opts[:id]
@@ -148,7 +145,7 @@ class GogridDriver < Deltacloud::BaseDriver
148
145
  }
149
146
  param[:credentials].merge!({ :password => opts[:password]}) if opts[:password].length>0
150
147
  param[:port] = opts[:port] || '22'
151
- param[:ip] = target.public_addresses
148
+ param[:ip] = opts[:ip] || target.public_addresses.first.address
152
149
  Deltacloud::Runner.execute(opts[:cmd], param)
153
150
  end
154
151
 
@@ -21,9 +21,6 @@ module Deltacloud
21
21
 
22
22
  class GoogleDriver < Deltacloud::BaseDriver
23
23
 
24
- def supported_collections; [:buckets]
25
- end
26
-
27
24
  feature :buckets, :bucket_location
28
25
 
29
26
  #--
@@ -197,8 +194,8 @@ class GoogleDriver < Deltacloud::BaseDriver
197
194
 
198
195
  def valid_credentials?(credentials)
199
196
  begin
200
- new_client(credentials)
201
- rescue
197
+ new_client(credentials).get_service && true
198
+ rescue => e
202
199
  return false
203
200
  end
204
201
  return true
@@ -0,0 +1,28 @@
1
+ ---
2
+ :credential_type: :key
3
+ :fingerprint: 5e:ce:b6:dc:59:3b:5c:93:f8:2e:9d:20:ce:60:ca:f5:0b:8a:66:93
4
+ :pem_rsa_key: |-
5
+ -----BEGIN RSA PRIVATE KEY-----
6
+ P9mRXOY7p2SmMzTGA6dwKxUp1NB8LNCIJ7sMGgAljsf=ToAi9qn9myx0EQJkE8FZ8FigUIMHS/T
7
+ 8EwP7Ayjztb8dczbC6sb/Ep2UWcegNUVHimyHstaEaO/3dCaFwLJ/kw=laAfLQAVj4sIr8EHDTg
8
+ /BFkgmwTAYlS/ybkEfO9J7AJlY6/agwYzDWp+VGAD9rMsl2EkkbkWdoTX4Aob9RqyHaFi2m1AAw
9
+ 2nhhqYpa1W4H=PJvyBcsXT3JynowSI8rTvo41oVwgSzv7YofGP0yV7BePm5pXZUUP2ZMByxbAUv
10
+ jvYRN/cMHbC6RW1ezR3uehCKdKFRXLTkoivoGj4ugrKgOwQP0HWI2orx/NW+6vYBxyCKiTJPZcK
11
+ x4BlRrlgvPST/7eaFv7/5Pqc3jWcp+bRC0qyYqQT9iq3gGNoc4ABFTI7zCeZ3p9tK8oje5fWo5m
12
+ 54P32hVGeBjfqT/MrEYbY5gbJU6LejCj7x6Ozlp4iHQtrYNhiZ0iP0W3nRhVFQHamKx9aoBXyeg
13
+ LLGxBOr+TfaeeBXRkXiaMuWoyPSzUQwWmaJhm0sjHf7e/iKiUggZkOHQ/eF9MWI4M+4wvyepfS0
14
+ 5vl2Ql/2rXv+Mx+c4cx1fjBhRrMPcGKmHGjNMjPyamTrlqueFRJYP45AYABP2U2AsNxoPfEG0qu
15
+ ki3DJOeC5x/03nODd=hQLzfdiQ3Yyt0GMw1EQN96cPaRtnjr3U4/ngxt0Fi6o7Z8E2+Uh5t4n8D
16
+ h0exXCOlOi9BDsJJz677mga/=5Sin/4Cw8=D8O1FHrWoA4ZQbWFE71F=/29PM90RHJf2bjgk2WF
17
+ piltKwVfGAxPOTcpmf=J+V3NHgT/EawMPHuEmwgNvx6smDBUgJaw0QYX/XG5xuiQ7HTkffJN6Cm
18
+ 6D4WCJPZUvO1r+v=T9v7Qu4j9ue/l2WwVZuvQsVD67jpzq2R72EHna6rcwwyMcdAlwikP9nzJIL
19
+ Ale7hQAWHIEeAvAxtwxEMSfTkuLQcD=i0ORysmInDxdORw4ue2YThj2Id/jmUy6IiEqMYeVpiRq
20
+ 6spq2ukt=+HHn6aBcYWbsD=e8/wOk0X0=ixZ0HF+xqYgsiiAk==rA4QEgrf+5djbIRZk1wegeIO
21
+ po/HZdF4qk32cKBjrrel2AzxfZeGxWNX7ObAE4HACXi3eSdcnm1fIHsoSC+1eDqFkfAIve3Dj/a
22
+ afZxrda6zzp3g6IPcHAqleCn7XNcS0v5tk4Fag8Wr5Wq7IipRfixAs+GESGiyugeRvZWN2mtDOL
23
+ CGHGGAbpvplw2vjdryVyj7P6bVcwLNgl0t1ufZBaGRBpyontJ1/UQQMew7e2lW=EZr/GxHke8HN
24
+ X5vIw9ssx8=LL00fxAuX9SRdcrtVyTYGXORXe9NnldXjBXmLPgwqJAjoBTjTBQxzrQOtdla=/yw
25
+ MsDlFWumPz1HAFw7R5zS2VCHrwkLDm=h7k3y+fUvYOx6IYf+MmevANuJT+2qY6s/ilTBNDYq6jJ
26
+ 8LYpsBo4XpQm1ZleFCIyRldHfmaC5EMxkVQVqCV7X9I6JgzDEetUre25LQTpDa31M=ucVHNWlT+
27
+ 6rjiLETNeMTWGcuIkLPe/PElmp4llKeFi6g2=E2AKeSDzNycr5eXHEnBuKfEnENXXo6n-----END RSA PRIVATE KEY-----
28
+ :id: test-key
@@ -26,7 +26,7 @@ module Deltacloud::Drivers::Mock
26
26
 
27
27
  if ! File::directory?(@storage_root)
28
28
  FileUtils::rm_rf(@storage_root)
29
- FileUtils::mkdir_p(@storage_root)
29
+ FileUtils::mkdir_p(@storage_root, :mode => 0750)
30
30
  data = Dir[File::join(File::dirname(__FILE__), "data", "*")]
31
31
  FileUtils::cp_r(data, @storage_root)
32
32
  end
@@ -35,7 +35,7 @@ module Deltacloud::Drivers::Mock
35
35
  def dir(collection)
36
36
  result = File::join(@storage_root, collection.to_s)
37
37
  unless @collections.include?(collection)
38
- FileUtils::mkdir_p(result) unless File::directory?(result)
38
+ FileUtils::mkdir_p(result, :mode => 0750) unless File::directory?(result)
39
39
  @collections << collection
40
40
  end
41
41
  result
@@ -14,27 +14,16 @@
14
14
  # License for the specific language governing permissions and limitations
15
15
  # under the License.
16
16
 
17
-
18
17
  require 'yaml'
19
18
  require 'base64'
20
19
  require 'etc'
21
- require 'deltacloud/base_driver'
22
- require 'deltacloud/drivers/mock/mock_client'
20
+ require_relative 'mock_client'
21
+ require_relative 'mock_driver_cimi_methods'
23
22
 
24
23
  module Deltacloud::Drivers::Mock
25
24
 
26
25
  class MockDriver < Deltacloud::BaseDriver
27
26
 
28
- # If the provider is set to storage, pretend to be a storage-only
29
- # driver
30
- def supported_collections
31
- if api_provider == 'storage'
32
- [:buckets]
33
- else
34
- DEFAULT_COLLECTIONS + [:buckets, :keys]
35
- end
36
- end
37
-
38
27
  ( REALMS = [
39
28
  Realm.new({
40
29
  :id=>'us',
@@ -87,6 +76,8 @@ module Deltacloud::Drivers::Mock
87
76
  feature :instances, :user_name
88
77
  feature :instances, :user_data
89
78
  feature :instances, :authentication_key
79
+ feature :images, :user_name
80
+ feature :images, :user_description
90
81
 
91
82
  def initialize
92
83
  if ENV["DELTACLOUD_MOCK_STORAGE"]
@@ -100,8 +91,18 @@ module Deltacloud::Drivers::Mock
100
91
  end
101
92
 
102
93
  def realms(credentials, opts=nil)
103
- return REALMS if ( opts.nil? )
104
- results = REALMS
94
+ check_credentials( credentials )
95
+ results = []
96
+ safely do
97
+ # This hack is used to test if client capture exceptions correctly
98
+ # To raise an exception do GET /api/realms/50[0-2]
99
+ raise "DeltacloudErrorTest" if opts and opts[:id] == "500"
100
+ raise "NotImplementedTest" if opts and opts[:id] == "501"
101
+ raise "ProviderErrorTest" if opts and opts[:id] == "502"
102
+ raise "ProviderTimeoutTest" if opts and opts[:id] == "504"
103
+ return REALMS if ( opts.nil? )
104
+ results = REALMS
105
+ end
105
106
  results = filter_on( results, :id, opts )
106
107
  results
107
108
  end
@@ -120,7 +121,8 @@ module Deltacloud::Drivers::Mock
120
121
  else
121
122
  images = filter_on( images, :owner_id, opts )
122
123
  end
123
- images.sort_by{|e| [e.owner_id,e.description]}
124
+ images = images.map { |i| (i.hardware_profiles = hardware_profiles(nil)) && i }
125
+ images.sort_by{|e| [e.owner_id, e.description]}
124
126
  end
125
127
 
126
128
  def create_image(credentials, opts={})
@@ -234,6 +236,17 @@ module Deltacloud::Drivers::Mock
234
236
  @client.destroy(:instances, id)
235
237
  end
236
238
 
239
+ # mock object to mimick Net::SSH object
240
+ class Mock_ssh
241
+ attr_accessor :command
242
+ end
243
+
244
+ def run_on_instance(credentials, opts={})
245
+ ssh = Mock_ssh.new
246
+ ssh.command = opts[:cmd]
247
+ Deltacloud::Runner::Response.new(ssh, "This is where the output would appear if this were not a mock provider")
248
+ end
249
+
237
250
  #
238
251
  # Storage Volumes
239
252
  #
@@ -248,8 +261,10 @@ module Deltacloud::Drivers::Mock
248
261
  check_credentials(credentials)
249
262
  opts ||= {}
250
263
  opts[:capacity] ||= "1"
264
+ id = "Volume#{Time.now.to_i}"
251
265
  volume = {
252
- :id => "Volume#{Time.now.to_i}",
266
+ :id => id,
267
+ :name => opts[:name] ? opts[:name] : id,
253
268
  :created => Time.now.to_s,
254
269
  :state => "AVAILABLE",
255
270
  :capacity => opts[:capacity],
@@ -351,7 +366,8 @@ module Deltacloud::Drivers::Mock
351
366
  def delete_bucket(credentials, name, opts={})
352
367
  check_credentials(credentials)
353
368
  bucket = bucket(credentials, {:id => name})
354
- raise "BucketNotEmpty" unless (bucket.size == "0")
369
+ raise 'BucketNotExist' if bucket.nil?
370
+ raise "BucketNotEmpty" unless bucket.blob_list.empty?
355
371
  @client.destroy(:buckets, bucket.id)
356
372
  end
357
373
 
@@ -371,7 +387,7 @@ module Deltacloud::Drivers::Mock
371
387
  def blob_data(credentials, bucket_id, blob_id, opts = {})
372
388
  check_credentials(credentials)
373
389
  if blob = @client.load(:blobs, blob_id)
374
- blob[:content].each {|part| yield part}
390
+ blob[:content].split('').each {|part| yield part}
375
391
  end
376
392
  end
377
393
 
@@ -411,7 +427,7 @@ module Deltacloud::Drivers::Mock
411
427
  #--
412
428
  def blob_metadata(credentials, opts={})
413
429
  check_credentials(credentials)
414
- if blob = @client.load(:blobs, params[:id])
430
+ if blob = @client.load(:blobs, opts[:id])
415
431
  blob[:user_metadata]
416
432
  else
417
433
  nil
@@ -424,7 +440,7 @@ module Deltacloud::Drivers::Mock
424
440
  def update_blob_metadata(credentials, opts={})
425
441
  check_credentials(credentials)
426
442
  safely do
427
- blob = @client.load(:blobs, params[:id])
443
+ blob = @client.load(:blobs, opts[:id])
428
444
  return false unless blob
429
445
  blob[:user_metadata] = BlobHelper::rename_metadata_headers(opts['meta_hash'], '')
430
446
  @client.store(:blobs, blob)
@@ -440,17 +456,6 @@ module Deltacloud::Drivers::Mock
440
456
  return false
441
457
  end
442
458
 
443
- def networks(credentials, opts={})
444
- check_credentials(credentials)
445
- if opts[:id].nil?
446
- networks = @client.load_all_cimi(:network).map{|net| CIMI::Model::Network.from_json(net)}
447
- networks.map{|net|convert_cimi_network(net,opts[:env])}.flatten
448
- else
449
- network = CIMI::Model::Network.from_json(@client.load_cimi(:network, opts[:id]))
450
- convert_cimi_network(network, opts[:env])
451
- end
452
- end
453
-
454
459
  private
455
460
 
456
461
  def check_credentials(credentials)
@@ -487,13 +492,6 @@ module Deltacloud::Drivers::Mock
487
492
  StorageVolume.new(volume)
488
493
  end
489
494
 
490
- def convert_cimi_network(network, context)
491
- uri=context.network_url(network.name)
492
- network.uri=uri
493
- network.operations.each{|op| op.href=uri}
494
- network
495
- end
496
-
497
495
  exceptions do
498
496
 
499
497
  on /AuthFailure/ do
@@ -511,6 +509,10 @@ module Deltacloud::Drivers::Mock
511
509
  message "Key with same name already exists"
512
510
  end
513
511
 
512
+ on /BucketNotExist/ do
513
+ status 404
514
+ end
515
+
514
516
  on /CreateImageNotSupported/ do
515
517
  status 500
516
518
  end
@@ -520,8 +522,24 @@ module Deltacloud::Drivers::Mock
520
522
  message "Could not delete a non existent blob"
521
523
  end
522
524
 
523
- on /Err/ do
525
+ on /DeltacloudErrorTest/ do
524
526
  status 500
527
+ message "DeltacloudErrorMessage"
528
+ end
529
+
530
+ on /NotImplementedTest/ do
531
+ status 501
532
+ message "NotImplementedMessage"
533
+ end
534
+
535
+ on /ProviderErrorTest/ do
536
+ status 502
537
+ message "ProviderErrorMessage"
538
+ end
539
+
540
+ on /ProviderTimeoutTest/ do
541
+ status 504
542
+ message "ProviderTimeoutMessage"
525
543
  end
526
544
 
527
545
  end
@@ -0,0 +1,145 @@
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
+ #Definition of CIMI methods for the mock driver - seperation from deltacloud
18
+ #API mock driver methods
19
+
20
+ module Deltacloud::Drivers::Mock
21
+
22
+ class MockDriver < Deltacloud::BaseDriver
23
+
24
+ def networks(credentials, opts={})
25
+ check_credentials(credentials)
26
+ if opts[:id].nil?
27
+ networks = @client.load_all_cimi(:network).map{|net| CIMI::Model::Network.from_json(net)}
28
+ networks.map{|net|convert_cimi_mock_urls(:network, net ,opts[:env])}.flatten
29
+ else
30
+ network = CIMI::Model::Network.from_json(@client.load_cimi(:network, opts[:id]))
31
+ convert_cimi_mock_urls(:network, network, opts[:env])
32
+ end
33
+ end
34
+
35
+ def network_configurations(credentials, opts={})
36
+ check_credentials(credentials)
37
+ if opts[:id].nil?
38
+ network_configs = @client.load_all_cimi(:network_configuration).map{|net_config| CIMI::Model::NetworkConfiguration.from_json(net_config)}
39
+ network_configs.map{|net_config|convert_cimi_mock_urls(:network_configuration, net_config, opts[:env])}.flatten
40
+ else
41
+ network_config = CIMI::Model::NetworkConfiguration.from_json(@client.load_cimi(:network_configuration, opts[:id]))
42
+ convert_cimi_mock_urls(:network_configuration, network_config, opts[:env])
43
+ end
44
+ end
45
+
46
+ def network_templates(credentials, opts={})
47
+ check_credentials(credentials)
48
+ if opts[:id].nil?
49
+ network_templates = @client.load_all_cimi(:network_template).map{|net_templ| CIMI::Model::NetworkTemplate.from_json(net_templ)}
50
+ network_templates.map{|net_templ|convert_cimi_mock_urls(:network_template, net_templ, opts[:env])}.flatten
51
+ else
52
+ network_template = CIMI::Model::NetworkTemplate.from_json(@client.load_cimi(:network_template, opts[:id]))
53
+ convert_cimi_mock_urls(:network_template, network_template, opts[:env])
54
+ end
55
+ end
56
+
57
+ def routing_groups(credentials, opts={})
58
+ check_credentials(credentials)
59
+ if opts[:id].nil?
60
+ routing_groups = @client.load_all_cimi(:routing_group).map{|rg| CIMI::Model::RoutingGroup.from_json(rg)}
61
+ routing_groups.map{|rg|convert_cimi_mock_urls(:routing_group, rg, opts[:env])}.flatten
62
+ else
63
+ routing_group = CIMI::Model::RoutingGroup.from_json(@client.load_cimi(:routing_group, opts[:id]))
64
+ convert_cimi_mock_urls(:routing_group, routing_group, opts[:env])
65
+ end
66
+ end
67
+
68
+ def routing_group_templates(credentials, opts={})
69
+ check_credentials(credentials)
70
+ if opts[:id].nil?
71
+ routing_group_templates = @client.load_all_cimi(:routing_group_template).map{|rg_templ| CIMI::Model::RoutingGroupTemplate.from_json(rg_templ)}
72
+ routing_group_templates.map{|rg_templ|convert_cimi_mock_urls(:routing_group_template, rg_templ, opts[:env])}.flatten
73
+ else
74
+ routing_group_template = CIMI::Model::RoutingGroupTemplate.from_json(@client.load_cimi(:routing_group_template, opts[:id]))
75
+ convert_cimi_mock_urls(:routing_group_template, routing_group_template, opts[:env])
76
+ end
77
+ end
78
+
79
+ def vsps(credentials, opts={})
80
+ check_credentials(credentials)
81
+ if opts[:id].nil?
82
+ vsps = @client.load_all_cimi(:vsp).map{|vsp| CIMI::Model::VSP.from_json(vsp)}
83
+ vsps.map{|vsp|convert_cimi_mock_urls(:vsp, vsp, opts[:env])}.flatten
84
+ else
85
+ vsp = CIMI::Model::VSP.from_json(@client.load_cimi(:vsp, opts[:id]))
86
+ convert_cimi_mock_urls(:vsp, vsp, opts[:env])
87
+ end
88
+ end
89
+
90
+ def vsp_configurations(credentials, opts={})
91
+ check_credentials(credentials)
92
+ if opts[:id].nil?
93
+ vsp_configurations = @client.load_all_cimi(:vsp_configuration).map{|vsp_config| CIMI::Model::VSPConfiguration.from_json(vsp_config)}
94
+ vsp_configurations.map{|vsp_config|convert_cimi_mock_urls(:vsp_configuration, vsp_config, opts[:env])}.flatten
95
+ else
96
+ vsp_configuration = CIMI::Model::VSPConfiguration.from_json(@client.load_cimi(:vsp_configuration, opts[:id]))
97
+ convert_cimi_mock_urls(:vsp_configuration, vsp_configuration, opts[:env])
98
+ end
99
+ end
100
+
101
+ def vsp_templates(credentials, opts={})
102
+ check_credentials(credentials)
103
+ if opts[:id].nil?
104
+ vsp_templates = @client.load_all_cimi(:vsp_template).map{|vsp_templ| CIMI::Model::VSPTemplate.from_json(vsp_templ)}
105
+ vsp_templates.map{|vsp_templ|convert_cimi_mock_urls(:vsp_template, vsp_templ, opts[:env])}.flatten
106
+ else
107
+ vsp_template = CIMI::Model::VSPTemplate.from_json(@client.load_cimi(:vsp_template, opts[:id]))
108
+ convert_cimi_mock_urls(:vsp_template, vsp_template, opts[:env])
109
+ end
110
+ end
111
+
112
+ private
113
+
114
+ def convert_cimi_mock_urls(model_name, cimi_object, context)
115
+ cimi_object.attribute_values.each do |k,v|
116
+ if ( v.is_a?(Struct) || ( v.is_a?(Array) && v.first.is_a?(Struct)))
117
+ case v
118
+ when Array
119
+ v.each do |item|
120
+ convert_struct_urls(item, k.to_s.singularize.to_sym, context)
121
+ end
122
+ else
123
+ convert_struct_urls(v, k, context)
124
+ end
125
+ end
126
+ end
127
+ object_url = context.send(:"#{model_name}_url", cimi_object.name)
128
+ cimi_object.id=object_url
129
+ cimi_object.operations.each{|op| op.href=object_url }
130
+ cimi_object
131
+ end
132
+
133
+ def convert_struct_urls(struct, cimi_name, context)
134
+ return unless (struct.respond_to?(:href) && (not struct.href.nil?) && (not cimi_name == :operation ))
135
+ obj_name = struct.href.split("/").last
136
+ if cimi_name.to_s.end_with?("config")
137
+ struct.href = context.send(:"#{cimi_name}uration_url", obj_name)
138
+ else
139
+ struct.href = context.send(:"#{cimi_name}_url", obj_name)
140
+ end
141
+ end
142
+
143
+ end
144
+
145
+ end