ovfparse 0.0.81 → 0.0.91

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 (3) hide show
  1. data/README +2 -2
  2. data/lib/ovfparse/vmpackage.rb +24 -8
  3. metadata +4 -4
data/README CHANGED
@@ -39,7 +39,7 @@ puts vmRepo.fetch #shows all the packages available at the repo
39
39
  # use factory method to get correct package type
40
40
  package = VmPackage.create("http://ambrosia/repo/someOVF.ovf")
41
41
  # retrieve package
42
- package.get
42
+ package.fetch
43
43
  # spit out package xml
44
44
  puts package.xml
45
45
 
@@ -49,7 +49,7 @@ puts package.xml
49
49
  # use factory method to get correct package type
50
50
  package = VmPackage.create("http://ambrosia/repo/someOVF.ovf")
51
51
  # retrieve package
52
- package.get
52
+ package.fetch
53
53
  # spit out specific xml section
54
54
  puts package.ProductSection
55
55
 
@@ -38,14 +38,14 @@ class VmPackage
38
38
  {'full_name' => 'ovf:password', 'node_ref' => 'password', 'attribute_ref' => 'password'},
39
39
  {'full_name' => 'ovf:required', 'node_ref' => 'required', 'attribute_ref' => 'required'},
40
40
  {'full_name' => 'ovf:type', 'node_ref' => 'type', 'attribute_ref' => 'value_basetype'},
41
- {'full_name' => 'cops:valueType', 'node_ref' => 'valueType', 'attribute_ref' => 'valueType'},
42
- {'full_name' => 'cops:uuid', 'node_ref' => 'uuid', 'attribute_ref' => 'uuid'} ]
41
+ {'full_name' => 'cops:valueType', 'node_ref' => 'valueType', 'attribute_ref' => 'valueType'}, # @todo refactor to cops extension module
42
+ {'full_name' => 'cops:uuid', 'node_ref' => 'uuid', 'attribute_ref' => 'uuid'} ] # @todo refactor to cops extension module
43
43
 
44
44
  # List of elements in an OVF property that we will extract / set
45
45
  PROPERTY_ELEMENTS = [ {'full_name' => 'ovf:Label', 'node_ref' => 'Label', 'element_ref' => 'name', 'required' => false},
46
46
  {'full_name' => 'ovf:Description', 'node_ref' => 'Description', 'element_ref' => 'description', 'required' => false},
47
- {'full_name' => 'cops:Example', 'node_ref' => 'cops:Example', 'element_ref' => 'example', 'required' => true},
48
- {'full_name' => 'cops:NoneType', 'node_ref' => 'cops:NoneType', 'element_ref' => 'nonetype', 'required' => true} ]
47
+ {'full_name' => 'cops:Example', 'node_ref' => 'cops:Example', 'element_ref' => 'example', 'required' => true}, # @todo refactor to cops extension module
48
+ {'full_name' => 'cops:NoneType', 'node_ref' => 'cops:NoneType', 'element_ref' => 'nonetype', 'required' => true} ] # @todo refactor to cops extension module
49
49
 
50
50
  OVF_NAMESPACE = {'ovf' => 'http://schemas.dmtf.org/ovf/envelope/1'}
51
51
 
@@ -172,11 +172,13 @@ class VmPackage
172
172
  return xml.xpath('ovf:Envelope/ovf:VirtualSystem/ovf:OperatingSystemSection')[0]['id']
173
173
  end
174
174
 
175
+ # @todo refactor to cops extension module
175
176
  def getVmPatchLevel
176
177
  patchNode = xml.xpath('ovf:Envelope/ovf:VirtualSystem/ovf:OperatingSystemSection/ovf:Description')[0]
177
178
  return patchNode.nil? ? '' : patchNode.text
178
179
  end
179
180
 
181
+ # @todo refactor to cops extension module, specifically, patch level
180
182
  def getVmAttributes
181
183
  return {
182
184
  'name' => getVmName,
@@ -212,7 +214,8 @@ class VmPackage
212
214
  return networks
213
215
  end
214
216
 
215
- # What a long strange trip it's been.
217
+ # @todo refactor to cops extension module
218
+ # cpe and cops namespaces are not general purpose
216
219
  def getVmProducts
217
220
  products = Array.new
218
221
  xml.root.add_namespace('cops', 'http://cops.mitre.org/1.1')
@@ -253,6 +256,7 @@ class VmPackage
253
256
 
254
257
  valueOptionsArray = Array.new
255
258
 
259
+ # @todo refactor to cops extension module
256
260
  node = propertyNode.xpath('cops:ValueOptions')[0]
257
261
  if(!node.nil?)
258
262
  if (!node['selection'].nil?)
@@ -271,6 +275,7 @@ class VmPackage
271
275
 
272
276
  property['valueoptions'] = valueOptionsArray.join("\n")
273
277
 
278
+ # @todo refactor to cops extension module
274
279
  actions = Array.new
275
280
  node = propertyNode.xpath('cops:Action')[0]
276
281
  if(!node.nil?)
@@ -333,6 +338,8 @@ class VmPackage
333
338
  xml.xpath('ovf:Envelope/ovf:VirtualSystem/ovf:OperatingSystemSection')[0]['ovf:id'] = newValue.to_s
334
339
  end
335
340
 
341
+ # @todo refactor to cops extension module
342
+ # currently we're using description field for vmpatchlevel
336
343
  def setVmPatchLevel(newValue)
337
344
  osNode = xml.xpath('ovf:Envelope/ovf:VirtualSystem/ovf:OperatingSystemSection')[0]
338
345
  descNode = osNode.xpath('ovf:Description')[0] || osNode.add_child(xml.create_element('Description', {}))
@@ -453,6 +460,7 @@ class VmPackage
453
460
  productNode.add_child(xml.create_element('Icon', {'ovf:fileRef' => productNode['class'] + '_icon'}))
454
461
  xml.xpath('ovf:Envelope/ovf:References')[0].add_child(xml.create_element('File', {'ovf:id' => productNode['class'] + '_icon', 'ovf:href' => new_icon}))
455
462
  else
463
+ productNode.add_child(iconNode)
456
464
  (xml.xpath('ovf:Envelope/ovf:References/ovf:File').detect { |fileNode| fileNode['id'] == iconNode['fileRef']})['ovf:href'] = new_icon
457
465
  end
458
466
  end
@@ -465,7 +473,7 @@ class VmPackage
465
473
  if((updated_value == '' || updated_value.nil?) && !element_node.nil?)
466
474
  element_node.unlink
467
475
  elsif(updated_value != '' && !updated_value.nil?)
468
- element_node = element_node || parent_node.add_child(xml.create_element(element_details['node_ref'], updated_value))
476
+ element_node = element_node.nil? ? parent_node.add_child(xml.create_element(element_details['node_ref'], updated_value)) : parent_node.add_child(element_node)
469
477
  element_node.content = updated_value
470
478
  if(element_details['required'])
471
479
  element_node['ovf:required'] = 'false'
@@ -485,6 +493,7 @@ class VmPackage
485
493
  virtualSystem = xml.xpath('ovf:Envelope/ovf:VirtualSystem')[0]
486
494
  productNodes = virtualSystem.xpath('ovf:ProductSection')
487
495
 
496
+ # @todo refactor to cops extension module, notice the "coat_properties"...
488
497
  # Removing old ones that don't exist anymore, updating ones that do
489
498
  productNodes.each { |productNode|
490
499
  updated_product = products.detect { |product| productNode['class'] == product.product_class }
@@ -510,6 +519,7 @@ class VmPackage
510
519
  }
511
520
  end
512
521
 
522
+ # @todo refactor to cops extension module, notice the "coat_properties"...
513
523
  def setProperties(product, properties)
514
524
  propertyNodes = product.xpath('ovf:Property')
515
525
 
@@ -518,6 +528,7 @@ class VmPackage
518
528
  if(updated_property.nil?)
519
529
  propertyNode.unlink
520
530
  else
531
+ product.add_child(propertyNode)
521
532
  setAttributes(updated_property, propertyNode, PROPERTY_ATTRIBUTES)
522
533
  setElements(updated_property, propertyNode, PROPERTY_ELEMENTS)
523
534
  setValueOptions(propertyNode, updated_property)
@@ -538,13 +549,14 @@ class VmPackage
538
549
  }
539
550
  end
540
551
 
552
+ # @todo refactor to cops extension module
541
553
  def setValueOptions(property_node, property)
542
554
  values = property.valueoptions.split("\n")
543
555
  valueOptionsNode = property_node.xpath('cops:ValueOptions')[0]
544
556
  if(values.empty? && !valueOptionsNode.nil?)
545
557
  valueOptionsNode.unlink
546
558
  elsif(!values.empty?)
547
- valueOptionsNode = valueOptionsNode || property_node.add_child(xml.create_element('ValueOptions', {}))
559
+ valueOptionsNode = valueOptionsNode.nil? ? property_node.add_child(xml.create_element('ValueOptions', {})) : property_node.add_child(valueOptionsNode)
548
560
  valueOptionsNode.namespace = xml.root.namespace_definitions.detect{ |ns| ns.prefix == 'cops' }
549
561
  valueOptionsNode['cops:selection'] = (property.selection || 'single')
550
562
  valueOptionsNode['ovf:required'] = 'false'
@@ -559,12 +571,13 @@ class VmPackage
559
571
  end
560
572
  end
561
573
 
574
+ # @todo refactor to cops extension module
562
575
  def setActions(property, actions)
563
576
  actionsNode = property.xpath('cops:Action')[0]
564
577
  if(actions.empty? && !actionsNode.nil?)
565
578
  actionsNode.unlink
566
579
  elsif(!actions.empty?)
567
- actionsNode = actionsNode || property.add_child(xml.create_element('Action', {}))
580
+ actionsNode = actionsNode.nil? ? property.add_child(xml.create_element('Action', {})) : property.add_child(actionsNode)
568
581
  actionsNode.namespace = xml.root.namespace_definitions.detect{ |ns| ns.prefix == 'cops' }
569
582
  actionsNode['ovf:required'] = 'false'
570
583
  actionsNode.children.unlink
@@ -590,6 +603,7 @@ class VmPackage
590
603
  end
591
604
  end
592
605
 
606
+ # @todo any need to make this a general purpose "writer" ?
593
607
  def self.construct_skeleton
594
608
  builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
595
609
  xml.Envelope('xmlns' => 'http://schemas.dmtf.org/ovf/envelope/1', 'xmlns:cim' => "http://schemas.dmtf.org/wbem/wscim/1/common", 'xmlns:ovf' => "http://schemas.dmtf.org/ovf/envelope/1", 'xmlns:rasd' => "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData", 'xmlns:vmw' => "http://www.vmware.com/schema/ovf", 'xmlns:vssd' => "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance") {
@@ -632,6 +646,7 @@ class VmPackage
632
646
  }
633
647
  }
634
648
  }
649
+ # @todo make this a general purpose signature
635
650
  node = Nokogiri::XML::Comment.new(xml.doc, ' skeleton framework constructed by COAT ')
636
651
  xml.doc.children[0].add_previous_sibling(node)
637
652
  end
@@ -642,6 +657,7 @@ class VmPackage
642
657
  xml.write_xml_to(file)
643
658
  end
644
659
 
660
+ # @todo make this a general purpose signing util
645
661
  def sign
646
662
  node = Nokogiri::XML::Comment.new(xml, ' made with love by the cops ovf authoring tool. ')
647
663
  xml.children[0].add_next_sibling(node)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ovfparse
3
3
  version: !ruby/object:Gem::Version
4
- hash: 189
4
+ hash: 169
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 81
10
- version: 0.0.81
9
+ - 91
10
+ version: 0.0.91
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jim Barkley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-14 00:00:00 -04:00
18
+ date: 2011-04-01 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency