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 xml.etree.ElementTree and lxml.etree modules both rely on the absolute namespace URI (rather than any defined namespace prefix aliases) throughout. Thus, we can't make use of the fact that OVF descriptors of all three versions typically define the prefix "ovf" for whichever of the above URIs is appropriate. We have to use the version-appropriate namespace URI everywhere in code.

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.

__init__()[source]

Create a name helper for OVF version 0.x.

NSM = {'cim': 'http://schemas.dmtf.org/wbem/wscim/1/common', 'ovf': 'http://www.vmware.com/schema/ovf/1/envelope', 'rasd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData', 'vssd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'}

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.

__init__()[source]

Create a name helper for OVF version 1.x.

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 = {'cim': 'http://schemas.dmtf.org/wbem/wscim/1/common', 'ovf': 'http://schemas.dmtf.org/ovf/envelope/1', 'rasd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData', 'vssd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'}

Shorthand for XML namespace URIs usually seen in a version 1.x OVF.

RES_MAP = {'cdrom': '15', 'cpu': '3', 'dvd': '16', 'ethernet': '10', 'fc': '7', 'floppy': '14', 'harddisk': '17', 'ib': '9', 'ide': '5', 'iscsi': '8', 'memory': '4', 'parallel': '22', 'sata': '20', 'scsi': '6', 'serial': '21', 'usb': '23'}

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.

__init__()[source]

Create a name helper for OVF version 2.x.

NSM = {'cim': 'http://schemas.dmtf.org/wbem/wscim/1/common', 'epasd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_EthernetPortAllocationSettingData.xsd', 'ovf': 'http://schemas.dmtf.org/ovf/envelope/2', 'rasd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData', 'sasd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_StorageAllocationSettingData.xsd', 'vssd': 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'}

Shorthand for XML namespace URIs usually seen in a version 2.x OVF.

name_helper(version)[source]

Generate an instance of the correct OVFNameHelper variant class.

Parameters:version (float) -- OVF specification version to use, such as 0.9, 1.0, or 2.0
Returns:Instance of OVFNameHelper[012] as appropriate.