ruby_vcloud_sdk 0.5.1 → 0.6.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 (29) hide show
  1. data/README.md +182 -3
  2. data/lib/ruby_vcloud_sdk/catalog.rb +18 -13
  3. data/lib/ruby_vcloud_sdk/client.rb +10 -1
  4. data/lib/ruby_vcloud_sdk/connection/connection.rb +1 -1
  5. data/lib/ruby_vcloud_sdk/disk.rb +1 -13
  6. data/lib/ruby_vcloud_sdk/infrastructure.rb +11 -1
  7. data/lib/ruby_vcloud_sdk/internal_disk.rb +12 -0
  8. data/lib/ruby_vcloud_sdk/network.rb +8 -3
  9. data/lib/ruby_vcloud_sdk/right_record.rb +12 -0
  10. data/lib/ruby_vcloud_sdk/vapp.rb +85 -0
  11. data/lib/ruby_vcloud_sdk/vdc.rb +61 -41
  12. data/lib/ruby_vcloud_sdk/vm.rb +233 -0
  13. data/lib/ruby_vcloud_sdk/xml/constants.rb +10 -0
  14. data/lib/ruby_vcloud_sdk/xml/wrapper.rb +10 -1
  15. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/disk.rb +1 -1
  16. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/ip_ranges.rb +16 -0
  17. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/ip_scope.rb +4 -0
  18. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/network_config_section.rb +4 -6
  19. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/org_vdc_network.rb +0 -4
  20. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/product_section.rb +35 -0
  21. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/product_section_list.rb +14 -0
  22. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/query_result_records.rb +4 -0
  23. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/virtual_hardware_section.rb +6 -4
  24. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb +31 -47
  25. data/lib/ruby_vcloud_sdk/xml/wrapper_classes.rb +2 -0
  26. data/lib/ruby_vcloud_sdk/xml/xml_templates/NetworkConfig.xml +1 -6
  27. data/lib/ruby_vcloud_sdk/xml/xml_templates/ProductSectionList.xml +8 -1
  28. metadata +29 -13
  29. checksums.yaml +0 -7
@@ -15,23 +15,15 @@ module VCloudSdk
15
15
  include Infrastructure
16
16
 
17
17
  extend Forwardable
18
- def_delegators :@vdc_xml_obj,
18
+ def_delegators :entity_xml,
19
19
  :name, :upload_link, :upload_media_link,
20
20
  :instantiate_vapp_template_link
21
21
 
22
- BUS_TYPE = {
23
- "scsi" => Xml::HARDWARE_TYPE[:SCSI_CONTROLLER]
24
- }
22
+ public :find_network_by_name
25
23
 
26
- BUS_SUB_TYPE = {
27
- "lsilogic" => Xml::BUS_SUB_TYPE[:LSILOGIC]
28
- }
29
-
30
- private_constant :BUS_TYPE, :BUS_SUB_TYPE
31
-
32
- def initialize(session, vdc_xml_obj)
24
+ def initialize(session, link)
33
25
  @session = session
34
- @vdc_xml_obj = vdc_xml_obj
26
+ @link = link
35
27
  end
36
28
 
37
29
  def storage_profiles
@@ -57,19 +49,19 @@ module VCloudSdk
57
49
  end
58
50
 
59
51
  def vapps
60
- @vdc_xml_obj.vapps.map do |vapp_link|
52
+ entity_xml.vapps.map do |vapp_link|
61
53
  VCloudSdk::VApp.new(@session, vapp_link)
62
54
  end
63
55
  end
64
56
 
65
57
  def list_vapps
66
- @vdc_xml_obj.vapps.map do |vapp_link|
58
+ entity_xml.vapps.map do |vapp_link|
67
59
  vapp_link.name
68
60
  end
69
61
  end
70
62
 
71
63
  def find_vapp_by_name(name)
72
- @vdc_xml_obj.vapps.each do |vapp_link|
64
+ entity_xml.vapps.each do |vapp_link|
73
65
  if vapp_link.name == name
74
66
  return VCloudSdk::VApp.new(@session, vapp_link)
75
67
  end
@@ -79,8 +71,8 @@ module VCloudSdk
79
71
  end
80
72
 
81
73
  def resources
82
- cpu = VCloudSdk::CPU.new(@vdc_xml_obj.available_cpu_cores)
83
- memory = VCloudSdk::Memory.new(@vdc_xml_obj.available_memory_mb)
74
+ cpu = VCloudSdk::CPU.new(entity_xml.available_cpu_cores)
75
+ memory = VCloudSdk::Memory.new(entity_xml.available_memory_mb)
84
76
  VCloudSdk::Resources.new(cpu, memory)
85
77
  end
86
78
 
@@ -96,19 +88,9 @@ module VCloudSdk
96
88
  end
97
89
  end
98
90
 
99
- def find_network_by_name(name)
100
- @session.org.networks.each do |network_link|
101
- if network_link.name == name
102
- return VCloudSdk::Network.new(@session, network_link)
103
- end
104
- end
105
-
106
- fail ObjectNotFoundError, "Network '#{name}' is not found"
107
- end
108
-
109
91
  def edge_gateways
110
92
  connection
111
- .get(@vdc_xml_obj.edge_gateways_link)
93
+ .get(entity_xml.edge_gateways_link)
112
94
  .edge_gateway_records
113
95
  .map do |edge_gateway_link|
114
96
  VCloudSdk::EdgeGateway.new(@session, edge_gateway_link.href)
@@ -116,19 +98,19 @@ module VCloudSdk
116
98
  end
117
99
 
118
100
  def disks
119
- @vdc_xml_obj.disks.map do |disk_link|
101
+ entity_xml.disks.map do |disk_link|
120
102
  VCloudSdk::Disk.new(@session, disk_link)
121
103
  end
122
104
  end
123
105
 
124
106
  def list_disks
125
- @vdc_xml_obj.disks.map do |disk_link|
107
+ entity_xml.disks.map do |disk_link|
126
108
  disk_link.name
127
109
  end
128
110
  end
129
111
 
130
112
  def find_disks_by_name(name)
131
- disks = @vdc_xml_obj
113
+ disks = entity_xml
132
114
  .disks
133
115
  .select { |disk_link| disk_link.name == name }
134
116
  .map { |disk_link| VCloudSdk::Disk.new(@session, disk_link.href) }
@@ -148,28 +130,28 @@ module VCloudSdk
148
130
 
149
131
  def create_disk(
150
132
  name,
151
- size_mb,
133
+ capacity,
152
134
  vm = nil,
153
135
  bus_type = "scsi",
154
136
  bus_sub_type = "lsilogic")
155
137
 
156
138
  fail(CloudError,
157
- "Invalid size in MB #{size_mb}") if size_mb <= 0
139
+ "Invalid size in MB #{capacity}") if capacity <= 0
158
140
 
159
- bus_type = BUS_TYPE[bus_type.downcase]
141
+ bus_type = Xml::BUS_TYPE_NAMES[bus_type.downcase]
160
142
  fail(CloudError,
161
143
  "Invalid bus type!") unless bus_type
162
144
 
163
- bus_sub_type = BUS_SUB_TYPE[bus_sub_type.downcase]
145
+ bus_sub_type = Xml::BUS_SUB_TYPE_NAMES[bus_sub_type.downcase]
164
146
  fail(CloudError,
165
147
  "Invalid bus sub type!") unless bus_sub_type
166
148
 
167
149
  Config
168
150
  .logger
169
- .info "Creating independent disk #{name} of #{size_mb}MB."
151
+ .info "Creating independent disk #{name} of #{capacity}MB."
170
152
 
171
- disk = connection.post(@vdc_xml_obj.add_disk_link,
172
- disk_create_params(name, size_mb, bus_type, bus_sub_type, vm),
153
+ disk = connection.post(entity_xml.add_disk_link,
154
+ disk_create_params(name, capacity, bus_type, bus_sub_type, vm),
173
155
  Xml::MEDIA_TYPE[:DISK_CREATE_PARAMS])
174
156
 
175
157
  wait_for_running_tasks(disk, "Disk #{name}")
@@ -177,10 +159,36 @@ module VCloudSdk
177
159
  VCloudSdk::Disk.new(@session, disk.href)
178
160
  end
179
161
 
162
+ def delete_disk_by_name(name)
163
+ disks = find_disks_by_name(name)
164
+ fail CloudError,
165
+ "#{disks.size} disks with name #{name} were found" if disks.size > 1
166
+
167
+ delete_single_disk(disks.first)
168
+ nil
169
+ end
170
+
171
+ def delete_all_disks_by_name(name)
172
+ disks = find_disks_by_name(name)
173
+ success = true
174
+ disks.each do |disk|
175
+ begin
176
+ delete_single_disk(disk)
177
+ rescue RuntimeError => e
178
+ success = false
179
+ Config.logger.error("Disk deletion failed with exception: #{e}")
180
+ end
181
+ end
182
+
183
+ fail CloudError,
184
+ "Failed to delete one or more of the disks with name '#{name}'. Check logs for details." unless success
185
+ nil
186
+ end
187
+
180
188
  def storage_profile_xml_node(name)
181
189
  return nil if name.nil?
182
190
 
183
- storage_profile = @vdc_xml_obj.storage_profile(name)
191
+ storage_profile = entity_xml.storage_profile(name)
184
192
  unless storage_profile
185
193
  fail ObjectNotFoundError,
186
194
  "Storage profile '#{name}' does not exist"
@@ -197,14 +205,26 @@ module VCloudSdk
197
205
  .org_vdc_storage_profile_records
198
206
  end
199
207
 
200
- def disk_create_params(name, size_mb, bus_type, bus_sub_type, vm)
208
+ def disk_create_params(name, capacity, bus_type, bus_sub_type, vm)
201
209
  Xml::WrapperFactory.create_instance("DiskCreateParams").tap do |params|
202
210
  params.name = name
203
- params.size_bytes = size_mb * 1024 * 1024 # VCD expects bytes
211
+ params.size_bytes = capacity * 1024 * 1024 # VCD expects bytes
204
212
  params.bus_type = bus_type
205
213
  params.bus_sub_type = bus_sub_type
206
214
  params.add_locality(connection.get(vm.href)) if vm # Use xml form of vm
207
215
  end
208
216
  end
217
+
218
+ def delete_single_disk(disk)
219
+ Config.logger.info "Deleting disk '#{disk.name}', link #{disk.href}"
220
+ fail CloudError,
221
+ "Disk '#{disk.name}', link #{disk.href} is attached to VM '#{disk.vm.name}'" if disk.attached?
222
+
223
+ entity_xml = connection.get(disk.href)
224
+ task = connection.delete(entity_xml.remove_link.href)
225
+ monitor_task(task)
226
+
227
+ Config.logger.info "Disk deleted successfully"
228
+ end
209
229
  end
210
230
  end
@@ -1,6 +1,7 @@
1
1
  require "forwardable"
2
2
  require_relative "infrastructure"
3
3
  require_relative "powerable"
4
+ require_relative "internal_disk"
4
5
 
5
6
  module VCloudSdk
6
7
  class VM
@@ -19,6 +20,78 @@ module VCloudSdk
19
20
  @link
20
21
  end
21
22
 
23
+ # returns size of memory in megabytes
24
+ def memory
25
+ m = entity_xml
26
+ .hardware_section
27
+ .memory
28
+ allocation_units = m.get_rasd_content(Xml::RASD_TYPES[:ALLOCATION_UNITS])
29
+ bytes = eval_memory_allocation_units(allocation_units)
30
+
31
+ virtual_quantity = m.get_rasd_content(Xml::RASD_TYPES[:VIRTUAL_QUANTITY]).to_i
32
+ memory_mb = virtual_quantity * bytes / BYTES_PER_MEGABYTE
33
+ fail CloudError,
34
+ "Size of memory is less than 1 MB." if memory_mb == 0
35
+ memory_mb
36
+ end
37
+
38
+ # sets size of memory in megabytes
39
+ def memory=(size)
40
+ fail(CloudError,
41
+ "Invalid vm memory size #{size}MB") if size <= 0
42
+
43
+ Config
44
+ .logger
45
+ .info "Changing the vm memory to #{size}MB."
46
+
47
+ payload = entity_xml
48
+ payload.change_memory(size)
49
+
50
+ task = connection.post(payload.reconfigure_link.href,
51
+ payload,
52
+ Xml::MEDIA_TYPE[:VM])
53
+ monitor_task(task)
54
+ self
55
+ end
56
+
57
+ # returns number of virtual cpus of VM
58
+ def vcpu
59
+ cpus = entity_xml
60
+ .hardware_section
61
+ .cpu
62
+ .get_rasd_content(Xml::RASD_TYPES[:VIRTUAL_QUANTITY])
63
+
64
+ fail CloudError,
65
+ "Uable to retrieve number of virtual cpus of VM #{name}" if cpus.nil?
66
+ cpus.to_i
67
+ end
68
+
69
+ # sets number of virtual cpus of VM
70
+ def vcpu=(count)
71
+ fail(CloudError,
72
+ "Invalid virtual CPU count #{count}") if count <= 0
73
+
74
+ Config
75
+ .logger
76
+ .info "Changing the virtual CPU count to #{count}."
77
+
78
+ payload = entity_xml
79
+ payload.change_cpu_count(count)
80
+
81
+ task = connection.post(payload.reconfigure_link.href,
82
+ payload,
83
+ Xml::MEDIA_TYPE[:VM])
84
+ monitor_task(task)
85
+ self
86
+ end
87
+
88
+ def list_networks
89
+ entity_xml
90
+ .network_connection_section
91
+ .network_connections
92
+ .map { |network_connection| network_connection.network }
93
+ end
94
+
22
95
  def independent_disks
23
96
  hardware_section = entity_xml.hardware_section
24
97
  disks = []
@@ -108,6 +181,115 @@ module VCloudSdk
108
181
  monitor_task(task)
109
182
  end
110
183
 
184
+ def add_nic(
185
+ network_name,
186
+ ip_addressing_mode = Xml::IP_ADDRESSING_MODE[:POOL],
187
+ ip = nil)
188
+ fail CloudError,
189
+ "Invalid IP_ADDRESSING_MODE '#{ip_addressing_mode}'" unless Xml::IP_ADDRESSING_MODE
190
+ .each_value
191
+ .any? { |m| m == ip_addressing_mode }
192
+
193
+ fail CloudError,
194
+ "IP is missing for MANUAL IP_ADDRESSING_MODE" if ip_addressing_mode == Xml::IP_ADDRESSING_MODE[:MANUAL] &&
195
+ ip.nil?
196
+
197
+ fail ObjectNotFoundError,
198
+ "Network #{network_name} is not added to parent VApp #{vapp.name}" unless vapp
199
+ .list_networks
200
+ .any? { |n| n == network_name }
201
+
202
+ payload = entity_xml
203
+ fail CloudError,
204
+ "VM #{name} is powered-on and cannot add NIC." if is_status?(payload, :POWERED_ON)
205
+
206
+ nic_index = list_networks.size # nic index begins with 0
207
+
208
+ Config.logger
209
+ .info("Adding NIC #{nic_index}, network #{network_name} using mode '#{ip_addressing_mode}' #{ip.nil? ? "" : "IP: #{ip}"}")
210
+
211
+ # Add NIC
212
+ payload
213
+ .hardware_section
214
+ .add_item(nic_params(payload.hardware_section,
215
+ nic_index,
216
+ network_name,
217
+ ip_addressing_mode,
218
+ ip))
219
+
220
+ # Connect NIC
221
+ payload
222
+ .network_connection_section
223
+ .add_item(network_connection_params(payload.network_connection_section,
224
+ nic_index,
225
+ network_name,
226
+ ip_addressing_mode,
227
+ ip))
228
+
229
+ task = connection.post(payload.reconfigure_link.href,
230
+ payload,
231
+ Xml::MEDIA_TYPE[:VM])
232
+ monitor_task(task)
233
+ end
234
+
235
+ def product_section_properties
236
+ product_section = entity_xml.product_section
237
+ return [] if product_section.nil?
238
+
239
+ product_section.properties
240
+ end
241
+
242
+ def product_section_properties=(properties)
243
+ Config.logger
244
+ .info("Updating VM #{name} production sections with properties: #{properties.pretty_inspect}")
245
+ task = connection.put(entity_xml.product_sections_link.href,
246
+ product_section_list_params(properties),
247
+ Xml::MEDIA_TYPE[:PRODUCT_SECTIONS])
248
+ monitor_task(task)
249
+ self
250
+ end
251
+
252
+ def internal_disks
253
+ hardware_section = entity_xml.hardware_section
254
+ internal_disks = []
255
+ hardware_section.hard_disks.each do |disk|
256
+ disk_link = disk.host_resource.attribute("disk")
257
+ if disk_link.nil?
258
+ internal_disks << VCloudSdk::InternalDisk.new(disk)
259
+ end
260
+ end
261
+ internal_disks
262
+ end
263
+
264
+ def create_internal_disk(
265
+ capacity,
266
+ bus_type = "scsi",
267
+ bus_sub_type = "lsilogic")
268
+
269
+ fail(CloudError,
270
+ "Invalid size in MB #{capacity}") if capacity <= 0
271
+
272
+ bus_type = Xml::BUS_TYPE_NAMES[bus_type.downcase]
273
+ fail(CloudError,
274
+ "Invalid bus type!") unless bus_type
275
+
276
+ bus_sub_type = Xml::BUS_SUB_TYPE_NAMES[bus_sub_type.downcase]
277
+ fail(CloudError,
278
+ "Invalid bus sub type!") unless bus_sub_type
279
+
280
+ Config
281
+ .logger
282
+ .info "Creating internal disk #{name} of #{capacity}MB."
283
+
284
+ payload = entity_xml
285
+ payload.add_hard_disk(capacity, bus_type, bus_sub_type)
286
+
287
+ task = connection.post(payload.reconfigure_link.href,
288
+ payload,
289
+ Xml::MEDIA_TYPE[:VM])
290
+ monitor_task(task)
291
+ end
292
+
111
293
  private
112
294
 
113
295
  def disk_attach_or_detach_params(disk)
@@ -128,5 +310,56 @@ module VCloudSdk
128
310
  params.media_href = media.href
129
311
  end
130
312
  end
313
+
314
+ def eval_memory_allocation_units(allocation_units)
315
+ # allocation_units is in the form of "byte * modifier * base ^ exponent" such as "byte * 2^20"
316
+ # "modifier", "base" and "exponent" are positive integers and optional.
317
+ # "base" and "exponent" must be present together.
318
+ # Parsing logic: remove starting "byte" and first char "*" and replace power "^" with ruby-understandable "**"
319
+ bytes = allocation_units.sub(/byte\s*(\*)?/, "").sub(/\^/, "**")
320
+ return 1 if bytes.empty? # allocation_units is "byte" without "modifier", "base" or "exponent"
321
+ fail unless bytes =~ /(\d+\s*\*)?(\d+\s*\*\*\s*\d+)?/
322
+ eval bytes
323
+ rescue
324
+ raise ApiError,
325
+ "Unexpected form of AllocationUnits of memory: '#{allocation_units}'"
326
+ end
327
+
328
+ def nic_params(section, nic_index, network_name, addressing_mode, ip)
329
+ is_primary = section.nics.empty?
330
+ item = Xml::WrapperFactory
331
+ .create_instance("Item", nil, section.doc_namespaces)
332
+
333
+ Xml::NicItemWrapper
334
+ .new(item)
335
+ .tap do |params|
336
+ params.nic_index = nic_index
337
+ params.network = network_name
338
+ params.set_ip_addressing_mode(addressing_mode, ip)
339
+ params.is_primary = is_primary
340
+ end
341
+ end
342
+
343
+ def network_connection_params(section, nic_index, network_name, addressing_mode, ip)
344
+ Xml::WrapperFactory
345
+ .create_instance("NetworkConnection", nil, section.doc_namespaces)
346
+ .tap do |params|
347
+ params.network_connection_index = nic_index
348
+ params.network = network_name
349
+ params.ip_address_allocation_mode = addressing_mode
350
+ params.ip_address = ip unless ip.nil?
351
+ params.is_connected = true
352
+ end
353
+ end
354
+
355
+ def product_section_list_params(properties)
356
+ Xml::WrapperFactory.create_instance("ProductSectionList").tap do |params|
357
+ properties.each do |property|
358
+ params.add_property(property)
359
+ end
360
+ end
361
+ end
362
+
363
+ BYTES_PER_MEGABYTE = 1_048_576 # 1048576 = 1024 * 1024 = 2^20
131
364
  end
132
365
  end
@@ -26,6 +26,8 @@ module VCloudSdk
26
26
  :CONNECTION => "Connection",
27
27
  :PARENT => "Parent",
28
28
  :ELEMENT_NAME => "ElementName",
29
+ :ALLOCATION_UNITS => "AllocationUnits",
30
+ :VIRTUAL_QUANTITY => "VirtualQuantity"
29
31
  }
30
32
 
31
33
  RESOURCE_SUB_TYPE = {
@@ -60,6 +62,14 @@ module VCloudSdk
60
62
  :BUS_TYPE => "busType"
61
63
  }
62
64
 
65
+ BUS_TYPE_NAMES = {
66
+ "scsi" => Xml::HARDWARE_TYPE[:SCSI_CONTROLLER]
67
+ }
68
+
69
+ BUS_SUB_TYPE_NAMES = {
70
+ "lsilogic" => Xml::BUS_SUB_TYPE[:LSILOGIC]
71
+ }
72
+
63
73
  TASK_STATUS = {
64
74
  :QUEUED => "queued",
65
75
  :RUNNING => "running",
@@ -99,7 +99,7 @@ module VCloudSdk
99
99
  end
100
100
 
101
101
  def href_id
102
- # Sample href: "https://10.146.21.135/api/org/a3783d64-0b9b-42d6-93cf-23bb08ec5520"
102
+ # Sample href: "https://10.147.0.0/api/org/a3783d64-0b9b-42d6-93cf-23bb08ec5520"
103
103
  URI.parse(href).path.split('/')[-1]
104
104
  end
105
105
 
@@ -316,6 +316,15 @@ module VCloudSdk
316
316
  namespace_href)
317
317
  node.namespace = ns
318
318
  end
319
+
320
+ def ovf_namespace_prefix
321
+ return @ovf_namespace_prefix if @ovf_namespace_prefix
322
+ namespace = namespace_definitions.find { |ns| ns.href == OVF }
323
+ fail VCloudSdk::CloudError,
324
+ "Namespace of href '#{OVF}' is not found" if namespace.nil?
325
+
326
+ @ovf_namespace_prefix = namespace.prefix
327
+ end
319
328
  end
320
329
  end
321
330
  end
@@ -17,7 +17,7 @@ module VCloudSdk
17
17
  @root["busSubType"] = value.to_s
18
18
  end
19
19
 
20
- def size_mb
20
+ def capacity
21
21
  @root["size"].to_i / 1024 / 1024
22
22
  end
23
23
 
@@ -4,6 +4,22 @@ module VCloudSdk
4
4
  def ranges
5
5
  get_nodes(:IpRange)
6
6
  end
7
+
8
+ def add_ranges(ranges)
9
+ ranges.each do |range|
10
+ ip_range_node = add_child("IpRange")
11
+ start_address = add_child("StartAddress",
12
+ nil,
13
+ nil,
14
+ ip_range_node)
15
+ start_address.content = range.start_address
16
+ end_address = add_child("EndAddress",
17
+ nil,
18
+ nil,
19
+ ip_range_node)
20
+ end_address.content = range.end_address
21
+ end
22
+ end
7
23
  end
8
24
  end
9
25
  end
@@ -1,6 +1,10 @@
1
1
  module VCloudSdk
2
2
  module Xml
3
3
  class IpScope < Wrapper
4
+ def ip_ranges
5
+ get_nodes(:IpRanges).first
6
+ end
7
+
4
8
  def is_inherited?
5
9
  get_nodes(:IsInherited).first.content
6
10
  end
@@ -1,6 +1,5 @@
1
1
  module VCloudSdk
2
2
  module Xml
3
-
4
3
  class NetworkConfigSection < Wrapper
5
4
  def network_configs
6
5
  get_nodes("NetworkConfig")
@@ -8,18 +7,17 @@ module VCloudSdk
8
7
 
9
8
  def add_network_config(config)
10
9
  unless config.is_a? NetworkConfig
11
- raise CloudError, "Only NetworkConfig can be added to #{self.class}"
10
+ fail CloudError, "Only NetworkConfig can be added to #{self.class}"
12
11
  end
13
12
  add_child(config)
14
13
  end
15
14
 
16
15
  def delete_network_config(net_name)
17
- net_config = network_configs.find {|n| n.network_name == net_name }
18
- raise ObjectNotFoundError,
19
- "Cannot delete network #{net_name}: not found" unless net_config
16
+ net_config = network_configs.find { |n| n.network_name == net_name }
17
+ fail ObjectNotFoundError,
18
+ "Cannot delete network #{net_name}: not found" unless net_config
20
19
  net_config.node.remove
21
20
  end
22
21
  end
23
-
24
22
  end
25
23
  end
@@ -5,10 +5,6 @@ module VCloudSdk
5
5
  get_nodes(:IpScope).first
6
6
  end
7
7
 
8
- def ip_ranges
9
- get_nodes(:IpRanges).first
10
- end
11
-
12
8
  def allocated_addresses_link
13
9
  get_nodes(XML_TYPE[:LINK],
14
10
  { type: MEDIA_TYPE[:ALLOCATED_NETWORK_IPS] },
@@ -0,0 +1,35 @@
1
+ module VCloudSdk
2
+ module Xml
3
+ class ProductSection < Wrapper
4
+ def add_property(property)
5
+ property_node = add_child("Property",
6
+ ovf_namespace_prefix,
7
+ OVF)
8
+ property_node["#{ovf_namespace_prefix}:type"] = property["type"].nil? ? "string" : property["type"]
9
+ property_node["#{ovf_namespace_prefix}:key"] = property["key"]
10
+ property_node["#{ovf_namespace_prefix}:value"] = property["value"]
11
+ property_node["#{ovf_namespace_prefix}:password"] = property["password"] if property["password"]
12
+
13
+ unless property["Label"].nil?
14
+ label_node = add_child("Label", ovf_namespace_prefix, OVF, property_node)
15
+ label_node.content = property["Label"]
16
+ end
17
+ end
18
+
19
+ def properties
20
+ get_nodes("Property", nil, true, OVF).map do |property_node|
21
+ property = {}
22
+ property["type"] = property_node.attribute("type").content
23
+ property["key"] = property_node.attribute("key").content
24
+ property["value"] = property_node.attribute("value").content
25
+ property["password"] = property_node.attribute("password").content
26
+
27
+ label_node = property_node.get_nodes("Label", nil, true, OVF).first
28
+ property["Label"] = label_node.content unless label_node.nil?
29
+
30
+ property
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ require "forwardable"
2
+
3
+ module VCloudSdk
4
+ module Xml
5
+ class ProductSectionList < Wrapper
6
+ extend Forwardable
7
+ def_delegator :production_section, :add_property
8
+
9
+ def production_section
10
+ get_nodes("ProductSection", nil, true, OVF).first
11
+ end
12
+ end
13
+ end
14
+ end
@@ -9,6 +9,10 @@ module VCloudSdk
9
9
  def edge_gateway_records
10
10
  get_nodes("EdgeGatewayRecord")
11
11
  end
12
+
13
+ def right_records
14
+ get_nodes("RightRecord")
15
+ end
12
16
  end
13
17
  end
14
18
  end
@@ -14,13 +14,15 @@ module VCloudSdk
14
14
  end
15
15
 
16
16
  def cpu
17
- hardware.find { |h| h.get_rasd_content(RASD_TYPES[:RESOURCE_TYPE]) ==
18
- HARDWARE_TYPE[:CPU] }
17
+ hardware.find do |h|
18
+ h.get_rasd_content(RASD_TYPES[:RESOURCE_TYPE]) == HARDWARE_TYPE[:CPU]
19
+ end
19
20
  end
20
21
 
21
22
  def memory
22
- hardware.find { |h| h.get_rasd_content(RASD_TYPES[:RESOURCE_TYPE]) ==
23
- HARDWARE_TYPE[:MEMORY] }
23
+ hardware.find do |h|
24
+ h.get_rasd_content(RASD_TYPES[:RESOURCE_TYPE]) == HARDWARE_TYPE[:MEMORY]
25
+ end
24
26
  end
25
27
 
26
28
  def scsi_controller