deltacloud-core 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. data/Rakefile +40 -28
  2. data/bin/deltacloud-db-upgrade +24 -0
  3. data/bin/deltacloudd +20 -9
  4. data/config.ru +12 -53
  5. data/db/migrations/1_add_realm_to_machine_template.rb +23 -0
  6. data/deltacloud-core.gemspec +11 -5
  7. data/lib/cimi/collections.rb +4 -31
  8. data/lib/cimi/collections/address_templates.rb +2 -5
  9. data/lib/cimi/collections/addresses.rb +2 -5
  10. data/lib/cimi/collections/base.rb +18 -6
  11. data/lib/cimi/collections/credentials.rb +2 -5
  12. data/lib/cimi/collections/machine_images.rb +2 -1
  13. data/lib/cimi/collections/machine_templates.rb +2 -5
  14. data/lib/cimi/collections/machines.rb +6 -9
  15. data/lib/cimi/collections/network_ports.rb +3 -3
  16. data/lib/cimi/collections/networks.rb +5 -8
  17. data/lib/cimi/collections/system_templates.rb +72 -0
  18. data/lib/cimi/collections/systems.rb +194 -0
  19. data/lib/cimi/collections/volume_configurations.rb +1 -1
  20. data/lib/cimi/collections/volume_images.rb +2 -1
  21. data/lib/cimi/collections/volume_templates.rb +3 -2
  22. data/lib/cimi/collections/volumes.rb +2 -2
  23. data/lib/cimi/dependencies.rb +0 -2
  24. data/lib/cimi/helpers/cimi_helper.rb +12 -57
  25. data/lib/cimi/helpers/database_helper.rb +0 -4
  26. data/lib/cimi/models.rb +25 -14
  27. data/lib/cimi/models/address.rb +4 -31
  28. data/lib/cimi/models/address_create.rb +51 -0
  29. data/lib/cimi/models/address_template.rb +8 -52
  30. data/lib/cimi/models/address_template_create.rb +44 -0
  31. data/lib/cimi/models/base.rb +44 -6
  32. data/lib/cimi/models/cloud_entry_point.rb +1 -1
  33. data/lib/cimi/models/credential.rb +1 -1
  34. data/lib/cimi/models/credential_create.rb +46 -0
  35. data/lib/cimi/models/credential_template.rb +24 -0
  36. data/lib/cimi/models/machine.rb +1 -71
  37. data/lib/cimi/models/machine_configuration.rb +3 -3
  38. data/lib/cimi/models/machine_create.rb +49 -0
  39. data/lib/cimi/models/machine_image.rb +2 -25
  40. data/lib/cimi/models/machine_image_create.rb +41 -0
  41. data/lib/cimi/models/machine_template.rb +14 -34
  42. data/lib/cimi/models/machine_template_create.rb +33 -0
  43. data/lib/cimi/models/network.rb +0 -38
  44. data/lib/cimi/models/network_create.rb +43 -0
  45. data/lib/cimi/models/network_port.rb +17 -17
  46. data/lib/cimi/models/network_template.rb +2 -3
  47. data/lib/cimi/models/resource.rb +22 -3
  48. data/lib/cimi/models/schema.rb +94 -8
  49. data/lib/cimi/models/system.rb +67 -0
  50. data/lib/cimi/models/system_template.rb +63 -0
  51. data/lib/cimi/models/volume.rb +2 -42
  52. data/lib/cimi/models/volume_configuration.rb +4 -4
  53. data/lib/cimi/models/volume_create.rb +58 -0
  54. data/lib/cimi/models/volume_image.rb +8 -17
  55. data/lib/cimi/models/volume_image_create.rb +47 -0
  56. data/lib/cimi/models/volume_template.rb +6 -19
  57. data/lib/cimi/models/volume_template_create.rb +33 -0
  58. data/lib/db.rb +14 -22
  59. data/lib/db/volume_template.rb +1 -1
  60. data/lib/deltacloud/api.rb +6 -5
  61. data/lib/deltacloud/collections.rb +4 -27
  62. data/lib/deltacloud/collections/base.rb +4 -0
  63. data/lib/deltacloud/collections/images.rb +1 -1
  64. data/lib/deltacloud/collections/instances.rb +2 -2
  65. data/lib/deltacloud/core_ext/array.rb +1 -0
  66. data/lib/deltacloud/core_ext/integer.rb +13 -9
  67. data/lib/deltacloud/core_ext/string.rb +45 -28
  68. data/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb +0 -9
  69. data/lib/deltacloud/drivers/base_driver.rb +45 -16
  70. data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +78 -8
  71. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +13 -9
  72. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +44 -0
  73. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +164 -90
  74. data/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +74 -0
  75. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +3 -3
  76. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +3 -3
  77. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +3 -3
  78. data/lib/deltacloud/drivers/mock/mock_client.rb +17 -1
  79. data/lib/deltacloud/drivers/mock/mock_driver.rb +161 -204
  80. data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +80 -0
  81. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -1
  82. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +61 -68
  83. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +0 -9
  84. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +11 -6
  85. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +0 -8
  86. data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +11 -4
  87. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +0 -12
  88. data/lib/deltacloud/helpers/collection_helper.rb +106 -0
  89. data/lib/deltacloud/helpers/deltacloud_helper.rb +12 -8
  90. data/lib/deltacloud/models/address.rb +19 -17
  91. data/lib/deltacloud/models/base_model.rb +29 -26
  92. data/lib/deltacloud/models/blob.rb +22 -20
  93. data/lib/deltacloud/models/bucket.rb +21 -16
  94. data/lib/deltacloud/models/firewall.rb +18 -16
  95. data/lib/deltacloud/models/firewall_rule.rb +22 -20
  96. data/lib/deltacloud/models/image.rb +29 -28
  97. data/lib/deltacloud/models/instance.rb +92 -94
  98. data/lib/deltacloud/models/instance_address.rb +42 -40
  99. data/lib/deltacloud/models/instance_profile.rb +28 -26
  100. data/lib/deltacloud/models/key.rb +47 -45
  101. data/lib/deltacloud/models/load_balancer.rb +32 -31
  102. data/lib/deltacloud/models/metric.rb +76 -29
  103. data/lib/deltacloud/models/provider.rb +15 -13
  104. data/lib/deltacloud/models/realm.rb +15 -21
  105. data/lib/deltacloud/models/storage_snapshot.rb +23 -19
  106. data/lib/deltacloud/models/storage_volume.rb +35 -34
  107. data/lib/deltacloud/version.rb +1 -1
  108. data/lib/deltacloud_rack.rb +22 -0
  109. data/lib/initialize.rb +28 -0
  110. data/lib/initializers/database_initialize.rb +76 -0
  111. data/lib/initializers/frontend_initialize.rb +42 -0
  112. data/lib/initializers/mock_initialize.rb +33 -0
  113. data/lib/sinatra/rack_logger.rb +35 -24
  114. data/tests/cimi/collections/cloud_entry_point_test.rb +1 -7
  115. data/tests/cimi/collections/machine_images_test.rb +2 -2
  116. data/tests/cimi/collections/machine_templates_test.rb +75 -0
  117. data/tests/cimi/collections/machines_test.rb +2 -2
  118. data/tests/cimi/collections/system_templates_test.rb +41 -0
  119. data/tests/cimi/collections/systems_test.rb +50 -0
  120. data/tests/cimi/db/database_helper_test.rb +17 -25
  121. data/tests/cimi/db/db_helper.rb +1 -12
  122. data/tests/cimi/db/entity_test.rb +7 -8
  123. data/tests/cimi/model/machine_create_spec.rb +44 -0
  124. data/tests/cimi/model/machine_template_spec.rb +29 -0
  125. data/tests/cimi/model/resource_spec.rb +40 -0
  126. data/tests/cimi/model/schema_spec.rb +37 -0
  127. data/tests/cimi/spec_helper.rb +3 -0
  128. data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
  129. data/tests/deltacloud/collections/drivers_collection_test.rb +2 -2
  130. data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +2 -2
  131. data/tests/deltacloud/collections/images_collection_test.rb +2 -2
  132. data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
  133. data/tests/deltacloud/collections/instances_collection_test.rb +6 -3
  134. data/tests/deltacloud/collections/keys_collection_test.rb +2 -2
  135. data/tests/deltacloud/collections/realms_collection_test.rb +2 -2
  136. data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +2 -2
  137. data/tests/deltacloud/collections/storage_volumes_collection_test.rb +2 -2
  138. data/tests/deltacloud/collections_test.rb +5 -5
  139. data/tests/deltacloud/common.rb +2 -13
  140. data/tests/deltacloud/launcher_test.rb +3 -3
  141. data/tests/deltacloud/rack_test.rb +2 -2
  142. data/tests/deltacloud/server_test.rb +1 -1
  143. data/tests/drivers/base/base_driver_test.rb +5 -5
  144. data/tests/drivers/base/common.rb +2 -12
  145. data/tests/drivers/ec2/buckets_test.rb +1 -1
  146. data/tests/drivers/ec2/images_test.rb +2 -2
  147. data/tests/drivers/ec2/instance_test.rb +6 -6
  148. data/tests/drivers/ec2/keys_test.rb +3 -3
  149. data/tests/drivers/ec2/realms_test.rb +2 -2
  150. data/tests/drivers/ec2/storage_snapshots_test.rb +1 -1
  151. data/tests/drivers/fgcp/common.rb +32 -0
  152. data/tests/drivers/fgcp/firewall_test.rb +70 -0
  153. data/tests/drivers/fgcp/hardware_profiles_test.rb +61 -0
  154. data/tests/drivers/fgcp/images_test.rb +46 -0
  155. data/tests/drivers/fgcp/provider_test.rb +27 -0
  156. data/tests/drivers/fgcp/realms_test.rb +53 -0
  157. data/tests/drivers/fgcp/storage_volumes_test.rb +58 -0
  158. data/tests/drivers/gogrid/images_test.rb +2 -2
  159. data/tests/drivers/gogrid/instances_test.rb +2 -2
  160. data/tests/drivers/gogrid/realms_test.rb +2 -2
  161. data/tests/drivers/mock/images_test.rb +4 -4
  162. data/tests/drivers/mock/instances_test.rb +9 -9
  163. data/tests/drivers/mock/keys_test.rb +3 -3
  164. data/tests/drivers/mock/realms_test.rb +2 -2
  165. data/tests/drivers/mock/storage_snapshots_test.rb +2 -2
  166. data/tests/drivers/mock/storage_volumes_test.rb +4 -4
  167. data/tests/drivers/models/instance_test.rb +2 -2
  168. data/tests/drivers/openstack/images_test.rb +2 -2
  169. data/tests/drivers/openstack/instances_test.rb +2 -3
  170. data/tests/drivers/openstack/keys_test.rb +1 -1
  171. data/tests/drivers/openstack/realms_test.rb +2 -11
  172. data/tests/drivers/rhevm/common.rb +33 -12
  173. data/tests/drivers/rhevm/images_test.rb +20 -12
  174. data/tests/drivers/rhevm/instance_test.rb +62 -46
  175. data/tests/drivers/rhevm/provider_test.rb +12 -6
  176. data/tests/drivers/rhevm/realms_test.rb +15 -9
  177. data/tests/ec2/query_parser_test.rb +1 -1
  178. data/tests/test_helper.rb +68 -12
  179. data/views/addresses/show.html.haml +1 -1
  180. data/views/buckets/show.html.haml +1 -1
  181. data/views/errors/{500.html.haml → common.html.haml} +0 -0
  182. data/views/errors/common.xml.haml +17 -0
  183. data/views/firewalls/index.xml.haml +2 -2
  184. data/views/firewalls/new.html.haml +2 -2
  185. data/views/images/show.html.haml +1 -1
  186. data/views/instances/run_command.html.haml +1 -1
  187. data/views/instances/show.html.haml +3 -3
  188. data/views/keys/index.html.haml +1 -0
  189. data/views/keys/show.html.haml +8 -4
  190. data/views/keys/show.xml.haml +3 -2
  191. data/views/load_balancers/new.html.haml +1 -1
  192. data/views/load_balancers/show.html.haml +2 -2
  193. data/views/metrics/show.html.haml +1 -1
  194. data/views/realms/index.html.haml +0 -2
  195. data/views/realms/show.html.haml +0 -4
  196. data/views/realms/show.xml.haml +0 -3
  197. data/views/storage_snapshots/index.html.haml +1 -1
  198. data/views/storage_snapshots/new.html.haml +1 -1
  199. data/views/storage_volumes/new.html.haml +2 -2
  200. data/views/storage_volumes/show.html.haml +3 -3
  201. metadata +90 -41
  202. data/views/errors/400.html.haml +0 -41
  203. data/views/errors/400.xml.haml +0 -3
  204. data/views/errors/401.html.haml +0 -26
  205. data/views/errors/401.xml.haml +0 -3
  206. data/views/errors/403.html.haml +0 -42
  207. data/views/errors/403.xml.haml +0 -9
  208. data/views/errors/404.html.haml +0 -28
  209. data/views/errors/404.xml.haml +0 -3
  210. data/views/errors/405.html.haml +0 -29
  211. data/views/errors/405.xml.haml +0 -5
  212. data/views/errors/409.html.haml +0 -47
  213. data/views/errors/409.xml.haml +0 -11
  214. data/views/errors/500.xml.haml +0 -13
  215. data/views/errors/501.html.haml +0 -44
  216. data/views/errors/501.xml.haml +0 -1
  217. data/views/errors/502.html.haml +0 -44
  218. data/views/errors/502.xml.haml +0 -1
  219. data/views/errors/504.html.haml +0 -43
  220. data/views/errors/504.xml.haml +0 -1
@@ -35,16 +35,20 @@ module Deltacloud
35
35
  module Ec2
36
36
  class Ec2Driver < Deltacloud::BaseDriver
37
37
 
38
- feature :instances, :user_data
39
- feature :instances, :authentication_key
40
- feature :instances, :firewalls
41
- feature :instances, :instance_count
42
- feature :instances, :metrics
43
- feature :images, :owner_id
44
- feature :images, :image_name
45
- feature :images, :image_description
38
+ feature :instances,
39
+ :user_data,
40
+ :authentication_key,
41
+ :firewalls,
42
+ :instance_count,
43
+ :metrics,
44
+ :attach_snapshot
45
+
46
+ feature :images,
47
+ :owner_id,
48
+ :image_name,
49
+ :image_description
50
+
46
51
  feature :buckets, :bucket_location
47
- feature :instances, :attach_snapshot
48
52
 
49
53
  DEFAULT_REGION = 'us-east-1'
50
54
 
@@ -274,6 +274,44 @@ eoidxml
274
274
  request('DestroyVDiskBackup', {'vsysId' => vsys_id, 'backupId' => backup_id})
275
275
  end
276
276
 
277
+ def get_vdisk_backup_copy_key(vsys_id, backup_id)
278
+ @version = '2012-07-20'
279
+ request('GetVDiskBackupCopyKey', {'vsysId' => vsys_id, 'backupId' => backup_id})
280
+ end
281
+
282
+ def set_vdisk_backup_copy_key(vsys_id, backup_id, contracts)
283
+ @version = '2012-07-20'
284
+ contracts_xml = <<-"eoctxml"
285
+ <?xml version="1.0" encoding ="UTF-8"?>
286
+ <Request>
287
+ <contracts>
288
+ <contract>
289
+ #{contracts.collect { |c| " <number>#{c}</number>" }.join("\n")}
290
+ </contract>
291
+ </contracts>
292
+ </Request>
293
+ eoctxml
294
+ request('SetVDiskBackupCopyKey',
295
+ {
296
+ 'vsysId' => vsys_id,
297
+ 'backupId' => backup_id
298
+ },
299
+ contracts_xml,
300
+ 'contractsXMLFilePath'
301
+ )
302
+ end
303
+
304
+ def external_restore_vdisk(src_vsys_id, src_backup_id, dst_vsys_id, dst_vdisk_id, key)
305
+ @version = '2012-07-20'
306
+ request('ExternalRestoreVDisk', {
307
+ 'srcVsysId' => src_vsys_id,
308
+ 'srcBackupId' => src_backup_id,
309
+ 'dstVsysId' => dst_vsys_id,
310
+ 'dstVdiskId' => dst_vdisk_id,
311
+ 'key' => key}
312
+ )
313
+ end
314
+
277
315
  def list_public_ips(vsys_id=nil)
278
316
  if vsys_id.nil?
279
317
  request('ListPublicIP')
@@ -321,6 +359,12 @@ eoidxml
321
359
  $1
322
360
  end
323
361
 
362
+ #extract contract id from vserverId, efmId or networkId
363
+ def extract_contract_id(id)
364
+ /^(\w+)-\w+\b.*/ =~ id
365
+ $1
366
+ end
367
+
324
368
  private
325
369
 
326
370
  # params hash is of the form :vserverId => 'ABC123', etc.
@@ -17,6 +17,7 @@
17
17
 
18
18
  require_relative 'fgcp_client'
19
19
  require_relative '../../runner'
20
+ require_relative 'fgcp_driver_cimi_methods'
20
21
  require 'openssl'
21
22
  require 'xmlsimple'
22
23
 
@@ -109,8 +110,11 @@ class FgcpDriver < Deltacloud::BaseDriver
109
110
  if xml['diskimages'] # not likely to not be so, but just in case
110
111
  xml['diskimages'][0]['diskimage'].each do |img|
111
112
 
112
- # 32bit CentOS/RHEL images are refused on hwps > 16GB (i.e. w_high, quad_high)
113
+ # This will determine image architecture using OS name.
114
+ # Usually the OS name includes '64bit' or '32bit'. If not,
115
+ # it will fall back to 64 bit.
113
116
  os_arch = img['osName'][0].to_s =~ /.*32.?bit.*/ ? 'i386' : 'x86_64'
117
+ # 32bit CentOS/RHEL images are refused on hwps > 16GB (i.e. w_high, quad_high)
114
118
  os_centos_rhel = img['osName'][0] =~ /(CentOS|Red Hat).*/
115
119
  allowed_hwps = hwps.select do |hwp|
116
120
  hwp.memory.default.to_i < 16000 or os_arch == 'x86_64' or not os_centos_rhel
@@ -122,9 +126,6 @@ class FgcpDriver < Deltacloud::BaseDriver
122
126
  :description => img['description'][0].to_s,
123
127
  :owner_id => img['registrant'][0].to_s, # or 'creatorName'?
124
128
  :state => 'AVAILABLE', #server keeps no particular state. If it's listed, it's available for use.
125
- # This will determine image architecture using OS name.
126
- # Usually the OS name includes '64bit' or '32bit'. If not,
127
- # it will fall back to 64 bit.
128
129
  :architecture => os_arch,
129
130
  :hardware_profiles => allowed_hwps
130
131
  ) if opts[:id].nil? or opts[:id] == img['diskimageId'][0]
@@ -183,7 +184,13 @@ class FgcpDriver < Deltacloud::BaseDriver
183
184
 
184
185
  # determine id belongs to system or network
185
186
  vsys_id = client.extract_vsys_id(opts[:id])
186
- vsys = client.get_vsys_attributes(vsys_id)['vsys'][0]
187
+ begin
188
+ vsys = client.get_vsys_attributes(vsys_id)['vsys'][0]
189
+ rescue Exception => ex
190
+ return [] if ex.message =~ /VALIDATION_ERROR.*A wrong value is set/
191
+ raise
192
+ end
193
+
187
194
  realm_name = vsys['vsysName'][0]
188
195
  limit = '[System]'
189
196
  if opts[:id] != vsys_id # network id specified
@@ -210,18 +217,24 @@ class FgcpDriver < Deltacloud::BaseDriver
210
217
  :limit => '[System]',
211
218
  :state => 'AVAILABLE' # map to state of FW/VSYS (reconfiguring = unavailable)?
212
219
  )
213
- # then retrieve and add list of network segments
214
- client.get_vsys_configuration(vsys['vsysId'][0])['vsys'][0]['vnets'][0]['vnet'].each do |vnet|
215
-
216
- vnet['networkId'][0] =~ /^.*\b(\w+)$/
217
- realm_name = vsys['vsysName'][0].to_s + ' [' + $1 + ']' # vsys name or vsys name + network [DMZ/SECURE1/SECURE2]
218
- realms << Realm::new(
219
- :id => vnet['networkId'][0], # vsysId or networkId
220
- :name => realm_name,
221
- #:limit => :unlimited,
222
- :limit => '[Network]',
223
- :state => 'AVAILABLE' # map to state of FW/VSYS (reconfiguring = unavailable)?
224
- )
220
+ begin
221
+ # then retrieve and add list of network segments
222
+ client.get_vsys_configuration(vsys['vsysId'][0])['vsys'][0]['vnets'][0]['vnet'].each do |vnet|
223
+
224
+ vnet['networkId'][0] =~ /^.*\b(\w+)$/
225
+ realm_name = vsys['vsysName'][0].to_s + ' [' + $1 + ']' # vsys name or vsys name + network [DMZ/SECURE1/SECURE2]
226
+ realms << Realm::new(
227
+ :id => vnet['networkId'][0], # vsysId or networkId
228
+ :name => realm_name,
229
+ #:limit => :unlimited,
230
+ :limit => '[Network]',
231
+ :state => 'AVAILABLE' # map to state of FW/VSYS (reconfiguring = unavailable)?
232
+ )
233
+ end
234
+ rescue Exception => ex # cater for case where vsys was just destroyed since list_vsys call
235
+ raise ex if not ex.message =~ /RESOURCE_NOT_FOUND.*/
236
+ # remove earlier added vsys
237
+ realms.pop
225
238
  end
226
239
  end
227
240
  end
@@ -266,20 +279,24 @@ class FgcpDriver < Deltacloud::BaseDriver
266
279
  xml[0]['vsys'].each do |vsys|
267
280
 
268
281
  # use get_vsys_configuration (instead of get_vserver_configuration) to retrieve all vservers in one call
269
- vsys_config = client.get_vsys_configuration(vsys['vsysId'][0])
270
- vsys_config['vsys'][0]['vservers'][0]['vserver'].each do |vserver|
271
-
272
- # skip firewalls - they probably don't belong here and their new type ('firewall' instead of
273
- # 'economy') causes errors when trying to map to available profiles)
274
- unless determine_server_type(vserver) == 'FW'
275
- # to keep the response time of this method acceptable, retrieve state
276
- # only if required because state is filtered on
277
- state_data = opts[:state] ? instance_state_data(vserver, client) : nil
278
- # filter on state
279
- if opts[:state].nil? or opts[:state] == state_data[:state]
280
- instances << convert_to_instance(client, vserver, state_data)
282
+ begin
283
+ vsys_config = client.get_vsys_configuration(vsys['vsysId'][0])
284
+ vsys_config['vsys'][0]['vservers'][0]['vserver'].each do |vserver|
285
+
286
+ # skip firewalls - they probably don't belong here and their new type ('firewall' instead of
287
+ # 'economy') causes errors when trying to map to available profiles)
288
+ unless determine_server_type(vserver) == 'FW'
289
+ # to keep the response time of this method acceptable, retrieve state
290
+ # only if required because state is filtered on
291
+ state_data = opts[:state] ? instance_state_data(vserver, client) : nil
292
+ # filter on state
293
+ if opts[:state].nil? or opts[:state] == state_data[:state]
294
+ instances << convert_to_instance(client, vserver, state_data)
295
+ end
281
296
  end
282
297
  end
298
+ rescue Exception => ex # cater for case where vsys was just destroyed since list_vsys call
299
+ raise ex if not ex.message =~ /RESOURCE_NOT_FOUND.*/
283
300
  end
284
301
  end
285
302
  end
@@ -452,7 +469,10 @@ class FgcpDriver < Deltacloud::BaseDriver
452
469
  begin
453
470
  vdisk = client.get_vdisk_attributes(opts[:id])['vdisk'][0]
454
471
  rescue Exception => ex
472
+ # vdisk doesn't exist
455
473
  return [] if ex.message =~ /VALIDATION_ERROR.*t exist./
474
+ # vsys_id extracted from :id doesn't exist
475
+ return [] if ex.message =~ /VALIDATION_ERROR.*A wrong value is set/
456
476
  raise
457
477
  end
458
478
  state = client.get_vdisk_status(opts[:id])['vdiskStatus'][0]
@@ -489,24 +509,28 @@ class FgcpDriver < Deltacloud::BaseDriver
489
509
  return [] if xml.nil?
490
510
  xml[0]['vsys'].each do |vsys|
491
511
 
492
- vdisks = client.list_vdisk(vsys['vsysId'][0])['vdisks'][0]
493
-
494
- if vdisks['vdisk']
495
- vdisks['vdisk'].each do |vdisk|
496
-
497
- #state requires an additional call per volume. Only set if attached.
498
- #exclude system disks as they are not detachable?
499
- volumes << StorageVolume.new(
500
- :id => vdisk['vdiskId'][0],
501
- :name => vdisk['vdiskName'][0],
502
- :capacity => vdisk['size'][0],
503
- :instance_id => vdisk['attachedTo'].nil? ? nil : vdisk['attachedTo'][0],
504
- :realm_id => client.extract_vsys_id(vdisk['vdiskId'][0]),
505
- # aligning with rhevm, which returns 'system' or 'data'
506
- :kind => determine_storage_type(vdisk['vdiskId'][0]),
507
- :state => vdisk['attachedTo'].nil? ? 'AVAILABLE' : 'IN-USE'
508
- )
512
+ begin
513
+ vdisks = client.list_vdisk(vsys['vsysId'][0])['vdisks'][0]
514
+
515
+ if vdisks['vdisk']
516
+ vdisks['vdisk'].each do |vdisk|
517
+
518
+ #state requires an additional call per volume. Only set if attached.
519
+ #exclude system disks as they are not detachable?
520
+ volumes << StorageVolume.new(
521
+ :id => vdisk['vdiskId'][0],
522
+ :name => vdisk['vdiskName'][0],
523
+ :capacity => vdisk['size'][0],
524
+ :instance_id => vdisk['attachedTo'].nil? ? nil : vdisk['attachedTo'][0],
525
+ :realm_id => client.extract_vsys_id(vdisk['vdiskId'][0]),
526
+ # aligning with rhevm, which returns 'system' or 'data'
527
+ :kind => determine_storage_type(vdisk['vdiskId'][0]),
528
+ :state => vdisk['attachedTo'].nil? ? 'AVAILABLE' : 'IN-USE'
529
+ )
530
+ end
509
531
  end
532
+ rescue Exception => ex # cater for case where vsys was just destroyed since list_vsys call
533
+ raise ex if not ex.message =~ /RESOURCE_NOT_FOUND.*/
510
534
  end
511
535
  end
512
536
  end
@@ -533,7 +557,43 @@ class FgcpDriver < Deltacloud::BaseDriver
533
557
  opts[:realm_id] = xml[0]['vsys'][0]['vsysId'][0] if xml
534
558
  end
535
559
 
536
- vdisk_id = client.create_vdisk(opts[:realm_id], opts[:name], opts[:capacity])['vdiskId'][0]
560
+ if not opts[:snapshot_id]
561
+ vdisk_id = client.create_vdisk(opts[:realm_id], opts[:name], opts[:capacity])['vdiskId'][0]
562
+ else
563
+ orig_vdisk_id, backup_id = split_snapshot_id(opts[:snapshot_id])
564
+ orig_vsys_id = client.extract_vsys_id(orig_vdisk_id)
565
+ # check snapshot size
566
+ size = client.get_vdisk_attributes(orig_vdisk_id)['vdisk'][0]['size'][0]
567
+ #set and retrieve key
568
+ contract_id = client.extract_contract_id(opts[:realm_id])
569
+ client.set_vdisk_backup_copy_key(orig_vsys_id, backup_id, [contract_id])
570
+ key = client.get_vdisk_backup_copy_key(opts[:realm_id], backup_id)['keyInfo'][0]['key'][0]
571
+ # create vdisk with same size as snapshot
572
+ size = client.get_vdisk_attributes(orig_vdisk_id)['vdisk'][0]['size'][0]
573
+ vdisk_id = client.create_vdisk(opts[:realm_id], opts[:name], size)['vdiskId'][0]
574
+ # try a restore straight away. It will likely fail (as the vdisk creation has not
575
+ # completed yet), but at least the parameters will be validated straight away.
576
+ begin
577
+ client.external_restore_vdisk(orig_vsys_id, backup_id, opts[:realm_id], vdisk_id, key)
578
+ rescue Exception => ex
579
+ # ignore expected error that destination vdisk is not ready yet
580
+ raise unless ex.message =~ /ILLEGAL_STATE_DST.*/
581
+ end
582
+ #wait until creation completes in a separate thread
583
+ Thread.new {
584
+ attempts = 0
585
+ begin
586
+ sleep 10
587
+ # this fails if the destination vdisk is still being deployed
588
+ client.external_restore_vdisk(orig_vsys_id, backup_id, opts[:realm_id], vdisk_id, key)
589
+ rescue Exception => ex
590
+ raise unless attempts < 30 and ex.message =~ /ILLEGAL_STATE_DST.*/
591
+ # Deployment takes a few minutes, so keep trying for a while
592
+ attempts += 1
593
+ retry
594
+ end
595
+ }
596
+ end
537
597
 
538
598
  StorageVolume.new(
539
599
  :id => vdisk_id,
@@ -608,23 +668,27 @@ class FgcpDriver < Deltacloud::BaseDriver
608
668
  return [] if xml.nil?
609
669
  xml[0]['vsys'].each do |vsys|
610
670
 
611
- vdisks = client.list_vdisk(vsys['vsysId'][0])['vdisks'][0]
612
- if vdisks['vdisk']
613
- vdisks['vdisk'].each do |vdisk|
614
-
615
- backups = client.list_vdisk_backup(vdisk['vdiskId'][0])
616
- if backups['backups'] and backups['backups'][0]['backup']
617
- backups['backups'][0]['backup'].each do |backup|
618
-
619
- snapshots << StorageSnapshot.new(
620
- :id => generate_snapshot_id(vdisk['vdiskId'][0], backup['backupId'][0]),
621
- :state => 'AVAILABLE',
622
- :storage_volume_id => vdisk['vdiskId'][0],
623
- :created => backup['backupTime'][0]
624
- )
671
+ begin
672
+ vdisks = client.list_vdisk(vsys['vsysId'][0])['vdisks'][0]
673
+ if vdisks['vdisk']
674
+ vdisks['vdisk'].each do |vdisk|
675
+
676
+ backups = client.list_vdisk_backup(vdisk['vdiskId'][0])
677
+ if backups['backups'] and backups['backups'][0]['backup']
678
+ backups['backups'][0]['backup'].each do |backup|
679
+
680
+ snapshots << StorageSnapshot.new(
681
+ :id => generate_snapshot_id(vdisk['vdiskId'][0], backup['backupId'][0]),
682
+ :state => 'AVAILABLE',
683
+ :storage_volume_id => vdisk['vdiskId'][0],
684
+ :created => backup['backupTime'][0]
685
+ )
686
+ end
625
687
  end
626
688
  end
627
689
  end
690
+ rescue Exception => ex # cater for case where vsys was just destroyed since list_vsys call
691
+ raise ex if not ex.message =~ /(RESOURCE_NOT_FOUND|ERROR).*/
628
692
  end
629
693
  end
630
694
  end
@@ -1168,31 +1232,35 @@ eofwopxml
1168
1232
  xml = client.list_vsys['vsyss']
1169
1233
  return [] if xml.nil?
1170
1234
 
1171
- xml[0]['vsys'].each do |vsys|
1235
+ begin
1236
+ xml[0]['vsys'].each do |vsys|
1172
1237
 
1173
- # use get_vsys_configuration (instead of list_efm) to retrieve all SLBs incl. realms in one call
1174
- vsys_config = client.get_vsys_configuration(vsys['vsysId'][0])
1175
- vsys_config['vsys'][0]['vservers'][0]['vserver'].each do |vserver|
1238
+ # use get_vsys_configuration (instead of list_efm) to retrieve all SLBs incl. realms in one call
1239
+ vsys_config = client.get_vsys_configuration(vsys['vsysId'][0])
1240
+ vsys_config['vsys'][0]['vservers'][0]['vserver'].each do |vserver|
1176
1241
 
1177
- if determine_server_type(vserver) == 'SLB'
1178
- vserver['vnics'][0]['vnic'][0]['networkId'][0] =~ /^.*\b(\w+)$/
1179
- realm_name = vsys['vsysId'][0] + ' [' + $1 + ']' # vsys name + network [DMZ/SECURE1/SECURE2]
1180
- realm = Realm::new(
1181
- :id => vserver['vnics'][0]['vnic'][0]['networkId'][0],
1182
- :name => realm_name,
1183
- :limit => '[Network]',
1184
- :state => 'AVAILABLE' # map to state of FW/VSYS (reconfiguring = unavailable)?
1185
- )
1186
- balancer = LoadBalancer.new({
1187
- :id => vserver['vserverId'][0],
1188
- :realms => [realm],
1189
- :listeners => [],
1190
- :instances => [],
1191
- :public_addresses => []
1192
- })
1193
- balancers << balancer
1242
+ if determine_server_type(vserver) == 'SLB'
1243
+ vserver['vnics'][0]['vnic'][0]['networkId'][0] =~ /^.*\b(\w+)$/
1244
+ realm_name = vsys['vsysId'][0] + ' [' + $1 + ']' # vsys name + network [DMZ/SECURE1/SECURE2]
1245
+ realm = Realm::new(
1246
+ :id => vserver['vnics'][0]['vnic'][0]['networkId'][0],
1247
+ :name => realm_name,
1248
+ :limit => '[Network]',
1249
+ :state => 'AVAILABLE' # map to state of FW/VSYS (reconfiguring = unavailable)?
1250
+ )
1251
+ balancer = LoadBalancer.new({
1252
+ :id => vserver['vserverId'][0],
1253
+ :realms => [realm],
1254
+ :listeners => [],
1255
+ :instances => [],
1256
+ :public_addresses => []
1257
+ })
1258
+ balancers << balancer
1259
+ end
1194
1260
  end
1195
1261
  end
1262
+ rescue Exception => ex # cater for case where vsys was just destroyed since list_vsys call
1263
+ raise ex if not ex.message =~ /(RESOURCE_NOT_FOUND).*/
1196
1264
  end
1197
1265
  end
1198
1266
  balancers
@@ -1327,18 +1395,22 @@ eofwopxml
1327
1395
  # list all vservers
1328
1396
  realms.each do |realm_id|
1329
1397
 
1330
- xml = client.list_vservers(client.extract_vsys_id(realm_id))['vservers']
1398
+ begin
1399
+ xml = client.list_vservers(client.extract_vsys_id(realm_id))['vservers']
1331
1400
 
1332
- if xml and xml[0]['vserver']
1401
+ if xml and xml[0]['vserver']
1333
1402
 
1334
- xml[0]['vserver'].each do |vserver|
1403
+ xml[0]['vserver'].each do |vserver|
1335
1404
 
1336
- # should check whether vserver is actually in opts[:realm_id] if network segment?
1337
- metrics_arr << Metric.new(
1338
- :id => vserver['vserverId'][0],
1339
- :entity => vserver['vserverName'][0]
1340
- )
1405
+ # should check whether vserver is actually in opts[:realm_id] if network segment?
1406
+ metrics_arr << Metric.new(
1407
+ :id => vserver['vserverId'][0],
1408
+ :entity => vserver['vserverName'][0]
1409
+ )
1410
+ end
1341
1411
  end
1412
+ rescue Exception => ex # cater for case where vsys was just destroyed since list_vsys call
1413
+ raise ex if not ex.message =~ /(RESOURCE_NOT_FOUND).*/
1342
1414
  end
1343
1415
  end
1344
1416
 
@@ -1558,6 +1630,8 @@ eofwopxml
1558
1630
  images['diskimages'][0]['diskimage'].each do |img|
1559
1631
  if vserver['diskimageId'][0] == img['diskimageId'][0]
1560
1632
  instance.username = img['osName'][0] =~ /Windows.*/ ? 'Administrator' : 'root'
1633
+ instance.instance_profile.storage = img['size'][0].to_s
1634
+ break
1561
1635
  end
1562
1636
  end
1563
1637
  instance.password = client.get_vserver_initial_password(vserver['vserverId'][0])['initialPassword'][0]
@@ -0,0 +1,74 @@
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 Fgcp driver - separation from deltacloud
18
+ #API Fgcp driver methods
19
+
20
+ module Deltacloud::Drivers::Fgcp
21
+
22
+ class FgcpDriver < Deltacloud::BaseDriver
23
+
24
+ #cimi features
25
+ feature :machines, :default_initial_state do
26
+ { :values => ["STOPPED"] }
27
+ end
28
+
29
+ def systems(credentials, opts={})
30
+ safely do
31
+ client = new_client(credentials)
32
+
33
+ if opts and opts[:id]
34
+ vsys_ids = [opts[:id]]
35
+ else
36
+ xml = client.list_vsys['vsyss']
37
+ return [] if xml.nil?
38
+ vsys_ids = xml[0]['vsys'].collect { |vsys| vsys['vsysId'][0] }
39
+ end
40
+
41
+ vsys_ids.collect do |vsys_id|
42
+ vsys = client.get_vsys_configuration(vsys_id)['vsys'][0]
43
+ vsys_description_el = vsys['description']
44
+ CIMI::Model::System.new(
45
+ :id => vsys['vsysId'][0],
46
+ :name => vsys['vsysName'][0],
47
+ # :machines => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/machines?realm_id=#{vsys['vsysId'][0]}",
48
+ # :volumes => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/volumes?realm_id=#{vsys['vsysId'][0]}",
49
+ # :networks => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/networks?realm_id=#{vsys['vsysId'][0]}",
50
+ # :addresses => "http://cimi.example.org/systems/#{vsys['vsysId'][0]}/addresses?realm_id=#{vsys['vsysId'][0]}",
51
+ :description => vsys_description_el ? vsys_description_el[0] : nil
52
+ )
53
+ end
54
+ end
55
+ end
56
+
57
+ def system_templates(credentials, opts={})
58
+ safely do
59
+ client = new_client(credentials)
60
+ templates = client.list_vsys_descriptor['vsysdescriptors'][0]['vsysdescriptor'].collect do |desc|
61
+ CIMI::Model::SystemTemplate.new(
62
+ :id => desc['vsysdescriptorId'][0],
63
+ :name => desc['vsysdescriptorName'][0],
64
+ :description => desc['description'][0]
65
+ )
66
+ end
67
+ templates = templates.select { |t| opts[:id] == t[:id] } if opts[:id]
68
+ templates
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end