COT.vm_description.ovf.name_helper
module¶
Module for handling the differences in XML between OVF spec versions.
Variation between OVF versions
XML can be a pain to work with, and when working with multiple OVF schema
versions (currently 3 of them – 0.9, 1.x.y, 2.0.y) it gets extra painful.
While we could use lxml
to validate inbound XML against the
appropriate schema version, even that package does not (as far as I can
determine) provide any assistance in creating XML against the appropriate
schema definition. So we have to do it ourselves.
Variation | Details and examples |
---|---|
Root namespace |
Unfortunately, the |
Element namespaces | Example: hardware details for network interfaces are
in the ResourceAllocationSettingData namespace in
versions 0.x and 1.x, but split out into a separate
EthernetPortAllocationSettingData namespace in
version 2.x. |
Element tags | Network definitions are grouped under an
ovf:Section element in version 0.x but under an
ovf:NetworkSection in versions 1.x and 2.x.
Network cards are ovf:Item elements in 0.x and
1.x, but ovf:EthernetPortItem in 2.x. |
Element attributes | In version 0.x, the different Section types are
identified by a type attribute (<ovf:Section
xsi:type="ovf:DiskSection_Type"> ) while in later
versions they are identified by tag
(<ovf:DiskSection> ) and do not have such an attribute. |
Element ordering | Most notably, the various child elements under an Item require alphabetical order in OVF 1.x and 2.x, but in 0.9 they require a different, idiosyncratic order. |
Functions
name_helper |
Generate an instance of the correct OVFNameHelper variant class. |
Classes and Exceptions
OVFNameHelper1 |
Helper class for OVF version 1.x. |
OVFNameHelper0 |
Helper class for OVF of versions prior to 1.0. |
OVFNameHelper2 |
Helper class for OVF of version 2.x. |
-
class
OVFNameHelper0
[source]¶ Bases:
COT.vm_description.ovf.name_helper.OVFNameHelper1
Helper class for
OVF
of versions prior to 1.0.Provides string constants for easier lookup of various OVF XML elements and attributes.
-
NSM
= {'vssd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData', 'rasd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData', 'ovf': 'http://www.vmware.com/schema/ovf/1/envelope', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'cim': 'http://schemas.dmtf.org/wbem/wscim/1/common'}¶ Shorthand for XML namespace URIs usually seen in a version 0.x OVF.
-
-
class
OVFNameHelper1
[source]¶ Bases:
object
Helper class for
OVF
version 1.x.Provides string constants for easier lookup of various OVF XML elements and attributes.
Version-specific subclasses below provide variant properties.
-
item_tag_for_namespace
(namespace)[source]¶ Get the Item tag for the given XML namespace.
Parameters: namespace (str) – XML namespace Returns: str – ‘Item’, ‘StorageItem’, or ‘EthernetPortItem’ as appropriate. Raises: ValueUnsupportedError
– if the namespace is unrecognized
-
namespace_for_item_tag
(tag)[source]¶ Get the XML namespace for the given item tag.
Parameters: tag (str) – Un-namespaced XML tag. Returns: str – XML namespace string, or None.
-
namespace_for_resource_type
(resource_type)[source]¶ Get the XML namespace for the given ResourceType.
Parameters: resource_type (str) – ResourceType value string. Returns: str – XML namespace string, or None.
-
NSM
= {'vssd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData', 'rasd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'ovf': 'http://schemas.dmtf.org/ovf/envelope/1', 'cim': 'http://schemas.dmtf.org/wbem/wscim/1/common'}¶ Shorthand for XML namespace URIs usually seen in a version 1.x OVF.
-
RES_MAP
= {'ib': '9', 'usb': '23', 'floppy': '14', 'dvd': '16', 'iscsi': '8', 'harddisk': '17', 'parallel': '22', 'sata': '20', 'fc': '7', 'memory': '4', 'cdrom': '15', 'ethernet': '10', 'scsi': '6', 'ide': '5', 'cpu': '3', 'serial': '21'}¶ Mapping of human-readable strings to ResourceType values.
See http://schemas.dmtf.org/wbem/cim-html/2/CIM_ResourceAllocationSettingData.html for more details.
-
-
class
OVFNameHelper2
[source]¶ Bases:
COT.vm_description.ovf.name_helper.OVFNameHelper1
Helper class for
OVF
of version 2.x. TODO.Provides string constants for easier lookup of various OVF XML elements and attributes.
-
NSM
= {'vssd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData', 'rasd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData', 'cim': 'http://schemas.dmtf.org/wbem/wscim/1/common', 'sasd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_StorageAllocationSettingData.xsd', 'ovf': 'http://schemas.dmtf.org/ovf/envelope/2', 'epasd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_EthernetPortAllocationSettingData.xsd', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'}¶ Shorthand for XML namespace URIs usually seen in a version 2.x OVF.
-