fog-vcloud-director 0.1.10 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +4 -240
  4. data/.rubocop_local.yml +1 -0
  5. data/.travis.yml +5 -10
  6. data/README.md +3 -0
  7. data/docs/examples-vm-reconfigure.md +39 -0
  8. data/docs/vm-to-reconfigure.xml +373 -0
  9. data/fog-vcloud-director.gemspec +4 -1
  10. data/lib/fog/vcloud_director.rb +14 -1
  11. data/lib/fog/vcloud_director/compute.rb +34 -8
  12. data/lib/fog/vcloud_director/core.rb +0 -3
  13. data/lib/fog/vcloud_director/generators/compute/org_vdc_network.rb +1 -1
  14. data/lib/fog/vcloud_director/generators/compute/reconfigure_vm.rb +110 -0
  15. data/lib/fog/vcloud_director/generators/compute/vapp.rb +0 -1
  16. data/lib/fog/vcloud_director/models/compute/catalog.rb +0 -2
  17. data/lib/fog/vcloud_director/models/compute/catalog_item.rb +0 -2
  18. data/lib/fog/vcloud_director/models/compute/catalog_items.rb +0 -1
  19. data/lib/fog/vcloud_director/models/compute/catalogs.rb +0 -1
  20. data/lib/fog/vcloud_director/models/compute/custom_field.rb +0 -2
  21. data/lib/fog/vcloud_director/models/compute/disk.rb +1 -2
  22. data/lib/fog/vcloud_director/models/compute/disks.rb +0 -1
  23. data/lib/fog/vcloud_director/models/compute/media.rb +0 -2
  24. data/lib/fog/vcloud_director/models/compute/medias.rb +0 -1
  25. data/lib/fog/vcloud_director/models/compute/network.rb +0 -2
  26. data/lib/fog/vcloud_director/models/compute/networks.rb +0 -1
  27. data/lib/fog/vcloud_director/models/compute/organization.rb +0 -2
  28. data/lib/fog/vcloud_director/models/compute/organizations.rb +0 -1
  29. data/lib/fog/vcloud_director/models/compute/tag.rb +1 -2
  30. data/lib/fog/vcloud_director/models/compute/tags.rb +0 -1
  31. data/lib/fog/vcloud_director/models/compute/task.rb +0 -2
  32. data/lib/fog/vcloud_director/models/compute/tasks.rb +0 -1
  33. data/lib/fog/vcloud_director/models/compute/template_vm.rb +0 -1
  34. data/lib/fog/vcloud_director/models/compute/template_vms.rb +2 -3
  35. data/lib/fog/vcloud_director/models/compute/vapp.rb +25 -8
  36. data/lib/fog/vcloud_director/models/compute/vapp_template.rb +0 -2
  37. data/lib/fog/vcloud_director/models/compute/vapp_templates.rb +0 -1
  38. data/lib/fog/vcloud_director/models/compute/vapps.rb +0 -1
  39. data/lib/fog/vcloud_director/models/compute/vdc.rb +0 -2
  40. data/lib/fog/vcloud_director/models/compute/vdcs.rb +0 -1
  41. data/lib/fog/vcloud_director/models/compute/vm.rb +10 -30
  42. data/lib/fog/vcloud_director/models/compute/vm_customization.rb +0 -2
  43. data/lib/fog/vcloud_director/models/compute/vm_customizations.rb +0 -1
  44. data/lib/fog/vcloud_director/models/compute/vm_network.rb +0 -2
  45. data/lib/fog/vcloud_director/models/compute/vm_networks.rb +0 -1
  46. data/lib/fog/vcloud_director/models/compute/vms.rb +1 -2
  47. data/lib/fog/vcloud_director/parsers/compute/vapp.rb +93 -0
  48. data/lib/fog/vcloud_director/parsers/compute/vm.rb +3 -62
  49. data/lib/fog/vcloud_director/parsers/compute/vm_parser_helper.rb +47 -0
  50. data/lib/fog/vcloud_director/parsers/compute/vms.rb +2 -23
  51. data/lib/fog/vcloud_director/query.rb +0 -1
  52. data/lib/fog/vcloud_director/requests/compute/delete_vapp.rb +1 -1
  53. data/lib/fog/vcloud_director/requests/compute/get_lease_settings_section_vapp.rb +1 -1
  54. data/lib/fog/vcloud_director/requests/compute/get_template_vm.rb +1 -47
  55. data/lib/fog/vcloud_director/requests/compute/get_template_vms.rb +0 -13
  56. data/lib/fog/vcloud_director/requests/compute/get_vapp.rb +4 -3
  57. data/lib/fog/vcloud_director/requests/compute/get_vapp_metadata.rb +1 -1
  58. data/lib/fog/vcloud_director/requests/compute/get_vapp_owner.rb +1 -1
  59. data/lib/fog/vcloud_director/requests/compute/get_vm.rb +0 -46
  60. data/lib/fog/vcloud_director/requests/compute/instantiate_vapp_template.rb +1 -1
  61. data/lib/fog/vcloud_director/requests/compute/post_power_on_vapp.rb +2 -2
  62. data/lib/fog/vcloud_director/requests/compute/post_reconfigure_vm.rb +4 -84
  63. data/lib/fog/vcloud_director/requests/compute/post_update_vapp_metadata.rb +1 -1
  64. data/lib/fog/vcloud_director/requests/compute/put_cpu.rb +1 -1
  65. data/lib/fog/vcloud_director/requests/compute/put_memory.rb +1 -1
  66. data/lib/fog/vcloud_director/requests/compute/put_metadata_value.rb +1 -1
  67. data/lib/fog/vcloud_director/requests/compute/put_network_connection_system_section_vapp.rb +1 -1
  68. data/lib/fog/vcloud_director/requests/compute/put_vm.rb +1 -1
  69. data/lib/fog/vcloud_director/version.rb +1 -1
  70. data/spec/common_assertions.rb +42 -0
  71. data/spec/fixtures/vm.xml +419 -0
  72. data/spec/secrets.yaml.templ +3 -0
  73. data/spec/spec_helper.rb +5 -5
  74. data/spec/vcloud_director/generators/compute/compose_common_spec.rb +1 -6
  75. data/spec/vcloud_director/generators/compute/compose_vapp_spec.rb +67 -0
  76. data/spec/vcloud_director/generators/compute/create_snapshot_spec.rb +4 -0
  77. data/spec/vcloud_director/generators/compute/customization_spec.rb +4 -0
  78. data/spec/vcloud_director/generators/compute/disks_spec.rb +4 -0
  79. data/spec/vcloud_director/generators/compute/edge_gateway_service_configuration_spec.rb +4 -0
  80. data/spec/vcloud_director/generators/compute/instantiate_vapp_template_params_spec.rb +1 -4
  81. data/spec/vcloud_director/generators/compute/metadata_spec.rb +4 -0
  82. data/spec/vcloud_director/generators/compute/org_vdc_network_spec.rb +4 -0
  83. data/spec/vcloud_director/generators/compute/recompose_vapp_spec.rb +4 -0
  84. data/spec/vcloud_director/generators/compute/reconfigure_vm_spec.rb +117 -0
  85. data/spec/vcloud_director/generators/compute/vapp_spec.rb +4 -0
  86. data/spec/vcloud_director/generators/compute/vm_network_spec.rb +4 -0
  87. data/spec/vcloud_director/generators/compute/vm_spec.rb +4 -0
  88. data/spec/vcloud_director/models/compute/basic_spec.rb +44 -0
  89. data/spec/vcloud_director/models/compute/vapps_spec.rb +104 -0
  90. data/spec/vcloud_director/models/compute/vms_spec.rb +54 -0
  91. data/spec/vcloud_director/parsers/compute/disks_spec.rb +4 -0
  92. data/spec/vcloud_director/parsers/compute/metadata_spec.rb +4 -0
  93. data/spec/vcloud_director/parsers/compute/network_spec.rb +4 -0
  94. data/spec/vcloud_director/parsers/compute/vm_customization_spec.rb +4 -0
  95. data/spec/vcloud_director/parsers/compute/vm_network_spec.rb +4 -0
  96. data/spec/vcloud_director/parsers/compute/vm_parser_helper_spec.rb +4 -0
  97. data/spec/vcloud_director/parsers/compute/vm_spec.rb +4 -0
  98. data/spec/vcloud_director/parsers/compute/vms_by_metadata_spec.rb +4 -0
  99. data/spec/vcloud_director/parsers/compute/vms_spec.rb +4 -0
  100. data/spec/vcloud_director/requests/compute/basic_spec.rb +212 -0
  101. data/spec/vcloud_director/requests/compute/get_vapp_spec.rb +11 -0
  102. data/spec/vcloud_director/requests/compute/get_vdc_spec.rb +10 -0
  103. data/spec/vcloud_director/requests/compute/instantiate_vapp_template_spec.rb +1 -3
  104. data/spec/vcloud_director/requests/compute/post_reconfigure_vm_spec.rb +26 -0
  105. data/spec/vcr_cassettes/authentication.yml +48 -0
  106. data/spec/vcr_cassettes/get_vapp.yml +937 -0
  107. data/spec/vcr_cassettes/get_vapps-expired.yml +918 -0
  108. data/spec/vcr_cassettes/get_vapps-novms.yml +215 -0
  109. data/spec/vcr_cassettes/get_vapps.yml +118 -0
  110. data/spec/vcr_cassettes/get_vdc.yml +118 -0
  111. data/spec/vcr_cassettes/get_vm.yml +398 -0
  112. data/spec/vcr_cassettes/post_reconfigure_vm-virtual_hardware.yml +445 -0
  113. data/spec/vcr_spec_helper.rb +34 -0
  114. data/tasks/test.rake +3 -10
  115. metadata +129 -5
  116. data/lib/fog/vcloud_director/requests/compute/get_vms.rb +0 -41
  117. data/spec/vcloud_director/spec_helper.rb +0 -13
@@ -26,6 +26,9 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rake"
27
27
  spec.add_development_dependency "shindo"
28
28
  spec.add_development_dependency "minitest"
29
+ spec.add_development_dependency "mocha"
29
30
  spec.add_development_dependency "vcr"
30
- spec.add_development_dependency "rubocop"
31
+ spec.add_development_dependency "webmock"
32
+ spec.add_development_dependency "rubocop", "~>0.52.1"
33
+ spec.add_development_dependency "pronto-rubocop"
31
34
  end
@@ -1,2 +1,15 @@
1
- require 'fog/vcloud_director/compute'
1
+ require 'pp'
2
2
  require 'securerandom'
3
+
4
+ require 'fog/core'
5
+ require 'fog/core/model'
6
+ require 'fog/core/collection'
7
+ require 'fog/xml'
8
+ require 'fog/vcloud_director/core'
9
+ require 'fog/vcloud_director/query'
10
+ require 'fog/vcloud_director/compute'
11
+
12
+ Dir[File.join(File.dirname(__FILE__), 'vcloud_director', 'generators', '**', '*.rb')].each {|file| require file }
13
+ Dir[File.join(File.dirname(__FILE__), 'vcloud_director', 'models', '**', '*.rb')].each {|file| require file }
14
+ Dir[File.join(File.dirname(__FILE__), 'vcloud_director', 'parsers', '**', '*.rb')].each {|file| require file }
15
+ Dir[File.join(File.dirname(__FILE__), 'vcloud_director', 'requests', '**', '*.rb')].each {|file| require file }
@@ -1,6 +1,3 @@
1
- require 'fog/vcloud_director/core'
2
- require 'fog/vcloud_director/query'
3
-
4
1
  class VcloudDirectorParser < Fog::Parsers::Base
5
2
  def extract_attributes(attributes_xml)
6
3
  attributes = {}
@@ -44,6 +41,8 @@ module Fog
44
41
  class DuplicateName < Fog::VcloudDirector::Errors::DuplicateName; end
45
42
  class TaskError < Fog::VcloudDirector::Errors::TaskError; end
46
43
 
44
+ class PreProcessingError < Fog::Errors::Error; end
45
+
47
46
  requires :vcloud_director_username, :vcloud_director_password, :vcloud_director_host
48
47
  recognizes :vcloud_director_api_version, :vcloud_director_show_progress, :path, :vcloud_token, :port
49
48
 
@@ -196,7 +195,6 @@ module Fog
196
195
  request :get_vm_disks
197
196
  request :get_vm_network
198
197
  request :get_vm_pending_question
199
- request :get_vms
200
198
  request :get_vms_by_metadata
201
199
  request :get_vms_disk_attached_to
202
200
  request :get_vms_in_lease_from_query
@@ -322,19 +320,33 @@ module Fog
322
320
  end
323
321
 
324
322
  def get_by_name(item_name)
325
- item_found = item_list.find {|item| item[:name] == item_name}
323
+ item_found = _item_list.find { |item| item[:name] == item_name }
326
324
  return nil unless item_found
327
325
  get(item_found[:id])
328
326
  end
329
327
 
330
328
  def index
331
- load(item_list)
329
+ load(_item_list)
332
330
  end
333
331
 
334
332
  def get_everyone
335
- items = item_list.map {|item| get_by_id(item[:id])}
333
+ items = _item_list.map { |item| get_by_id(item[:id]) }
336
334
  load(items)
337
335
  end
336
+
337
+ # Use pre-fetched list of items. Particularly useful when parent's XML already contains enough information
338
+ # about child entities, hence we can parse them on parent already to reduce API requests. Some examples:
339
+ # - vApp XML contains all the information about each of its child VMs, so we can pre-fetch `vapp.vms`
340
+ # - VM XML contains all the information about customization, so we can pre-fecth `vm.guest_customization`
341
+ # - VM XML contains all the information about disks, so we can pre-fetch `vm.disks`
342
+ def with_item_list(hashes)
343
+ @items = Array(hashes)
344
+ self
345
+ end
346
+
347
+ def _item_list
348
+ @items || item_list || []
349
+ end
338
350
  end
339
351
 
340
352
  class Real
@@ -394,9 +406,23 @@ module Fog
394
406
  response.body[:href].split('/').last # returns the vapp_id if it was instantiated successfully.
395
407
  end
396
408
 
409
+ # Perform HTTP request against vCloud API.
410
+ #
411
+ # @param [Hash] params request parameters.
412
+ # - params[:parser] SAX parser class, SAX parser instance or string. String can be one of:
413
+ # - 'plaintext': returns unparsed text in response.body
414
+ # - 'xml': returns Nokogiri::XML instance in response.body
415
+ # @return [Excon::Response]
397
416
  def request(params)
398
417
  begin
399
- do_request(params)
418
+ parser_type = params[:parser]
419
+ params[:parser] = nil if parser_type.instance_of?(String)
420
+ params[:parser] = parser_type.new if parser_type.respond_to?(:new)
421
+
422
+ resp = do_request(params)
423
+
424
+ resp.body = Nokogiri::XML(resp.body) if parser_type == 'xml'
425
+ resp
400
426
  rescue EOFError
401
427
  # This error can occur if Vcloud receives a request from a network
402
428
  # it deems to be unauthorized; no HTTP response is sent, but the
@@ -1,6 +1,3 @@
1
- require 'fog/core'
2
- require 'fog/xml'
3
-
4
1
  module Fog
5
2
  module VcloudDirector
6
3
  extend Fog::Provider
@@ -11,7 +11,7 @@ module Fog
11
11
  end
12
12
 
13
13
  def generate_xml
14
- body = Nokogiri::XML::Builder.new do
14
+ Nokogiri::XML::Builder.new do
15
15
  attrs = {
16
16
  :xmlns => 'http://www.vmware.com/vcloud/v1.5',
17
17
  :name => options[:name]
@@ -0,0 +1,110 @@
1
+ require 'fog/vcloud_director/generators/compute/compose_common'
2
+
3
+ module Fog
4
+ module Generators
5
+ module Compute
6
+ module VcloudDirector
7
+ class ReconfigureVm
8
+ extend ComposeCommon
9
+
10
+ class << self
11
+ # Generates VM reconfiguration XML.
12
+ #
13
+ # @param [Nokogiri::Xml] current DOM representing current VM configuration.
14
+ # @param [Hash] options desired configuration. Please see examples-vm-reconfigure.md for details.
15
+ #
16
+ # @return [String] xml string, a modification of `current` input, with desired configurations applied.
17
+ def generate_xml(current, options)
18
+ current.root['name'] = options[:name] if options[:name]
19
+ current.at('Description').content = options[:description] if options[:description]
20
+ if options[:hardware]
21
+ update_virtual_hardware_section(current, options[:hardware])
22
+ else
23
+ # Remove entire VirtualHardwareSection if no hardware is modified.
24
+ # https://pubs.vmware.com/vcd-80/index.jsp#com.vmware.vcloud.api.sp.doc_90/GUID-4759B018-86C2-4C91-8176-3EC73CD7122B.html
25
+ current.at('//ovf:VirtualHardwareSection').remove
26
+ end
27
+ current.to_xml
28
+ end
29
+
30
+ # Apply desired hardware modifications to the original xml.
31
+ def update_virtual_hardware_section(xml, hardware)
32
+ update_virtual_hardware_section_item_mem(xml, **hardware[:memory]) if hardware[:memory]
33
+ update_virtual_hardware_section_item_cpu(xml, **hardware[:cpu]) if hardware[:cpu]
34
+ array_wrap(hardware[:disk]).reject { |d| d[:id].nil? || d[:capacity_mb] == -1 }.each { |disk| update_virtual_hardware_section_item_hdd(xml, **disk) }
35
+ array_wrap(hardware[:disk]).select { |d| d[:id].nil? }.each { |disk| add_virtual_hardware_section_item_hdd(xml, **disk) }
36
+ array_wrap(hardware[:disk]).select { |d| d[:capacity_mb] == -1 }.each { |disk| remove_virtual_hardware_section_item_hdd(xml, id: disk[:id]) }
37
+ end
38
+
39
+ def update_virtual_hardware_section_item_cpu(xml, num_cores: nil, cores_per_socket: nil, reservation: nil, limit: nil, weight: nil)
40
+ update_virtual_hardware_section_item(xml, :type => 3) do |item|
41
+ item.at('./rasd:VirtualQuantity').content = num_cores if num_cores
42
+ item.at('./rasd:Reservation').content = reservation if reservation
43
+ item.at('./rasd:Limit').content = limit if limit
44
+ item.at('./rasd:Weight').content = weight if weight
45
+ item.at('./vmw:CoresPerSocket').content = cores_per_socket if cores_per_socket
46
+ end
47
+ end
48
+
49
+ def update_virtual_hardware_section_item_mem(xml, quantity_mb: nil, reservation: nil, limit: nil, weight: nil)
50
+ update_virtual_hardware_section_item(xml, :type => 4) do |item|
51
+ item.at('./rasd:VirtualQuantity').content = quantity_mb if quantity_mb
52
+ item.at('./rasd:Reservation').content = reservation if reservation
53
+ item.at('./rasd:Limit').content = limit if limit
54
+ item.at('./rasd:Weight').content = weight if weight
55
+ end
56
+ end
57
+
58
+ def update_virtual_hardware_section_item_hdd(xml, id:, capacity_mb: nil, address: nil, type: nil, subtype: nil)
59
+ hdd_exists = update_virtual_hardware_section_item(xml, :type => 17, :id => id) do |item|
60
+ item.at('./rasd:AddressOnParent').content = address if address
61
+ item.at('./rasd:HostResource')['ns13:capacity'] = capacity_mb if capacity_mb
62
+ item.at('./rasd:HostResource')['ns13:busType'] = type if type
63
+ item.at('./rasd:HostResource')['ns13:busSubType'] = subtype if subtype
64
+ end
65
+ raise Fog::Compute::VcloudDirector::PreProcessingError.new("Error resizing disk: disk with id '#{id}' does not exist.") unless hdd_exists
66
+ end
67
+
68
+ def remove_virtual_hardware_section_item_hdd(xml, id:)
69
+ remove_virtual_hardware_section_item(xml, :type => 17, :id => id)
70
+ end
71
+
72
+ def add_virtual_hardware_section_item_hdd(xml, **disk)
73
+ disk[:id] = rand(10_000..100_000)
74
+ add_virtual_hardware_section_item(xml) do |section|
75
+ virtual_hardware_section_item_hdd(section, **disk)
76
+ end
77
+ end
78
+
79
+ def add_virtual_hardware_section_item(xml)
80
+ virtual_hardware = xml.at('//ovf:VirtualHardwareSection')
81
+ virtual_hardware.add_namespace_definition('vcloud', 'http://www.vmware.com/vcloud/v1.5')
82
+ Nokogiri::XML::Builder.with(virtual_hardware) do |section|
83
+ yield section
84
+ end
85
+ # Move the new item to satisfy vCloud's sorting requirements.
86
+ item = virtual_hardware.at('./ovf:Item[last()]').remove
87
+ virtual_hardware.at('./ovf:Item[last()]').after(item)
88
+ end
89
+
90
+ def update_virtual_hardware_section_item(xml, type:, id: nil)
91
+ condition = "rasd:ResourceType = '#{type}'"
92
+ condition += " and rasd:InstanceID = '#{id}'" if id
93
+ if (item = xml.at("//ovf:VirtualHardwareSection/ovf:Item[#{condition}]"))
94
+ yield item
95
+ true
96
+ else
97
+ false
98
+ end
99
+ end
100
+
101
+ def remove_virtual_hardware_section_item(xml, type:, id:)
102
+ item = xml.at("//ovf:VirtualHardwareSection/ovf:Item[rasd:ResourceType = '#{type}' and rasd:InstanceID = '#{id}']")
103
+ item.remove if item
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -12,7 +12,6 @@ module Fog
12
12
  end
13
13
 
14
14
  def generate_xml
15
- attrs = @attrs
16
15
  Nokogiri::XML::Builder.new do
17
16
  VApp('xmlns' => 'http://www.vmware.com/vcloud/v1.5',
18
17
  'name' => name
@@ -1,5 +1,3 @@
1
- require 'fog/core/model'
2
-
3
1
  module Fog
4
2
  module Compute
5
3
  class VcloudDirector
@@ -1,5 +1,3 @@
1
- require 'fog/core/model'
2
-
3
1
  module Fog
4
2
  module Compute
5
3
  class VcloudDirector
@@ -1,4 +1,3 @@
1
- require 'fog/core/collection'
2
1
  require 'fog/vcloud_director/models/compute/catalog_item'
3
2
 
4
3
  module Fog
@@ -1,4 +1,3 @@
1
- require 'fog/core/collection'
2
1
  require 'fog/vcloud_director/models/compute/catalog'
3
2
  require 'fog/vcloud_director/models/compute/catalog_item'
4
3
 
@@ -1,5 +1,3 @@
1
- require 'fog/core/model'
2
-
3
1
  module Fog
4
2
  module Compute
5
3
  class VcloudDirector
@@ -1,5 +1,3 @@
1
- require 'fog/core/model'
2
-
3
1
  module Fog
4
2
  module Compute
5
3
  class VcloudDirector
@@ -17,6 +15,7 @@ module Fog
17
15
  attribute :bus_sub_type
18
16
  attribute :bus_type
19
17
 
18
+ remove_method :capacity=
20
19
  # TODO Virtual machine disk sizes may only be increased, not decreased.
21
20
  def capacity=(new_capacity)
22
21
  has_changed = ( capacity != new_capacity.to_i )
@@ -1,4 +1,3 @@
1
- require 'fog/core/collection'
2
1
  require 'fog/vcloud_director/models/compute/disk'
3
2
 
4
3
  module Fog
@@ -1,5 +1,3 @@
1
- require 'fog/core/model'
2
-
3
1
  module Fog
4
2
  module Compute
5
3
  class VcloudDirector
@@ -1,4 +1,3 @@
1
- require 'fog/core/collection'
2
1
  require 'fog/vcloud_director/models/compute/media'
3
2
 
4
3
  module Fog
@@ -1,5 +1,3 @@
1
- require 'fog/core/model'
2
-
3
1
  module Fog
4
2
  module Compute
5
3
  class VcloudDirector
@@ -1,4 +1,3 @@
1
- require 'fog/core/collection'
2
1
  require 'fog/vcloud_director/models/compute/network'
3
2
 
4
3
  module Fog
@@ -1,5 +1,3 @@
1
- require 'fog/core/model'
2
-
3
1
  module Fog
4
2
  module Compute
5
3
  class VcloudDirector
@@ -1,4 +1,3 @@
1
- require 'fog/core/collection'
2
1
  require 'fog/vcloud_director/models/compute/organization'
3
2
 
4
3
  module Fog
@@ -1,5 +1,3 @@
1
- require 'fog/core/model'
2
-
3
1
  module Fog
4
2
  module Compute
5
3
  class VcloudDirector
@@ -7,6 +5,7 @@ module Fog
7
5
  identity :id
8
6
  attribute :value
9
7
 
8
+ remove_method :value=
10
9
  def value=(new_value)
11
10
  has_changed = ( value != new_value )
12
11
  not_first_set = !value.nil?
@@ -1,4 +1,3 @@
1
- require 'fog/core/collection'
2
1
  require 'fog/vcloud_director/models/compute/tag'
3
2
 
4
3
  module Fog
@@ -1,5 +1,3 @@
1
- require 'fog/core/model'
2
-
3
1
  module Fog
4
2
  module Compute
5
3
  class VcloudDirector
@@ -1,4 +1,3 @@
1
- require 'fog/core/collection'
2
1
  require 'fog/vcloud_director/models/compute/task'
3
2
 
4
3
  module Fog
@@ -1,4 +1,3 @@
1
- require 'fog/core/model'
2
1
  require 'fog/vcloud_director/models/compute/vm_customization'
3
2
 
4
3
  module Fog
@@ -1,5 +1,4 @@
1
- require 'fog/core/collection'
2
- require 'fog/vcloud_director/models/compute/vm'
1
+ require 'fog/vcloud_director/models/compute/template_vm'
3
2
 
4
3
  module Fog
5
4
  module Compute
@@ -13,7 +12,7 @@ module Fog
13
12
  attribute :vapp_template
14
13
 
15
14
 
16
- def get_single_vm(vm_id)
15
+ def get_single_template_vm(vm_id)
17
16
  item = service.get_template_vm(vm_id).body
18
17
  return nil unless item
19
18
  new(item[:vm])
@@ -1,5 +1,3 @@
1
- require 'fog/core/model'
2
-
3
1
  module Fog
4
2
  module Compute
5
3
  class VcloudDirector
@@ -12,13 +10,32 @@ module Fog
12
10
  attribute :description, :aliases => :Description
13
11
  attribute :deployed, :type => :boolean
14
12
  attribute :status
15
- attribute :lease_settings, :aliases => :LeaseSettingsSection
16
- attribute :network_section, :aliases => :"ovf:NetworkSection", :squash => :"ovf:Network"
17
- attribute :network_config, :aliases => :NetworkConfigSection, :squash => :NetworkConfig
18
- attribute :owner, :aliases => :Owner, :squash => :User
19
- attribute :InMaintenanceMode, :type => :boolean
13
+ attribute :lease_settings
14
+ attribute :network_section
15
+ attribute :network_config
16
+ attribute :owner
17
+ attribute :maintenance, :type => :boolean
18
+
19
+ def initialize(*args, **kwargs)
20
+ # Memorize VMs because their full XML description was already included in the vApp XML description.
21
+ # Instead simple Array we rather store as Collection in order to provide common interface e.g.
22
+ # vapp.vms.all
23
+ # vapp.vms.get_by_name
24
+ if (vms = kwargs.delete(:vms))
25
+ @vms = Fog::Compute::VcloudDirector::Vms.new(
26
+ :vapp => self,
27
+ :service => kwargs[:service]
28
+ ).with_item_list(Array(vms))
29
+ end
30
+
31
+ super(*args, **kwargs)
32
+ end
33
+
34
+ def vms(force: false)
35
+ # Return memorized Collection that we parsed based on vApp XML description. This way we prevent
36
+ # additional API request to be made for each VM in a vApp.
37
+ return @vms unless @vms.nil? || force
20
38
 
21
- def vms
22
39
  requires :id
23
40
  service.vms(:vapp => self)
24
41
  end
@@ -1,5 +1,3 @@
1
- require 'fog/core/model'
2
-
3
1
  module Fog
4
2
  module Compute
5
3
  class VcloudDirector