COT.vm_description.ovf.item module

Module for working with individual hardware elements in an OVF.

Represents all variations of a given hardware Item amongst different hardware configuration profiles.


list_union Get union of lists.

Classes and Exceptions

OVFItem Helper class for OVF.
OVFItemDataError Data to be added to an OVFItem conflicts with existing data.
exception OVFItemDataError[source]

Bases: exceptions.Exception

Data to be added to an OVFItem conflicts with existing data.

class OVFItem(ovf, item=None)[source]

Bases: object

Helper class for OVF.

Represents all variations of a given hardware Item amongst different hardware configuration profiles.

In essence, it is:

  • a dict of Item properties (indexed by element name)
  • each of which is a dict of sets of profiles (indexed by element value)
__init__(ovf, item=None)[source]

Create a new OVFItem with contents based on the given Item element.


Add the given Item element to this OVFItem.


item (xml.etree.ElementTree.Element) -- XML Item element

  • ValueUnsupportedError -- if the item is not a recognized Item variant.
  • OVFItemDataError -- if the new Item conflicts with existing data already in the OVFItem.
add_profile(new_profile, from_item=None)[source]

Add a new profile to this item.

  • new_profile (str) -- Profile name to add
  • from_item (OVFItem) -- Item to inherit properties from. If unset, this defaults to self.

RuntimeError -- If unable to determine what value to inherit for a particular property.

all_profiles(name, default=None)[source]

Superset of all profiles for which this name has a value.

  • name (str) -- Property name.
  • default (object) -- Default value to return if there are no matches

Set of profile strings, or the given default if no matches.


Get a list of Item XML elements derived from this object's data.

Returns:list -- Generated list of XML Item elements

Get the dict associated with the given XML tag, if any.

Parameters:tag (str) -- XML tag to look up
Returns:dict -- Dictionary of values associated with this tag (TODO?)

Get the list of all value strings for the given tag.

Parameters:tag (str) -- Tag to retrieve value for
Returns:list -- List of value strings.

Identify the minimal non-intersecting set of profiles.

Returns:list -- List of profile-set strings.
get_value(tag, profiles=None)[source]

Get the value for the given tag under the given profiles.

If the tag does not exist under these profiles, or the tag values differ across the profiles, returns None.

  • tag (str) -- Tag to retrieve value for
  • profiles (set) -- set of profile names, or None

Value string or list, or None


OVFItemDataError -- if value_replace_wildcards() failed to remove any wildcards from the internally stored value.


Check if this Item exists under the given profile.

Parameters:profile (str) -- Profile name
Returns:bool -- True if the item exists in this profile, False if not.
property_profiles(name, value)[source]

Get set of profiles associated with a property name and value.

  • name (str) -- Property name.
  • value (object) -- Property value of interest.

set -- Profile strings associated with this name/value.


Get list of values known for a given property name.

Parameters:name (str) -- Property name.
Returns:list -- List of values
remove_profile(profile, split_default=True)[source]

Remove all trace of the given profile from this item.

  • profile (str) -- Profile name to remove
  • split_default (bool) -- If False, do not split out 'default' profile items to specifically exclude this profile. Used when the profile being removed will no longer exist anywhere and so 'default' will continue to exclude this profile.
set_property(name, value, profiles=None, overwrite=True)[source]

Store the value and profiles associated with it for the given name.

  • name (str) -- Property name
  • value (str) -- Value associated with name
  • profiles (list) -- If None, set for all profiles currently known to this item, else set only for the given list of profiles.
  • overwrite (bool) -- Whether to permit overwriting of existing value set in this item.

OVFItemDataError -- if a value is already defined and would be overwritten, unless overwrite is True


Verify that the OVFItem describes a valid set of items.

Also clean up any oddities (like a property value assigned to 'all profiles' and also redundantly to a specific profile).

Raises:RuntimeError -- if validation fails and COT doesn't know how to automatically repair the error(s) identified.
value_add_wildcards(name, value, profiles)[source]

Add wildcard placeholders to a string that may need updating.

If the Description references the ElementName, or the ElementName or Description references the VirtualQuantity, Connection, or ResourceSubType, replace such references with a placeholder that we can regenerate at output time. That way, if any of the linked items change, these strings can change too.

  • name (str) -- Property name
  • value (str) -- Value to add wildcards to.
  • profiles (list) -- Profiles to which this (name, value) applies.

str -- The updated value string with wildcards added.

value_replace_wildcards(name, value, profiles)[source]

Replace wildcards with actual values.

  • name (str) -- Property name
  • value (str) -- Value to replace wildcards from.
  • profiles (list) -- Profiles to which this (name, value) applies.

str -- The updated value string, with wildcards replaced.

ATTRIB_KEY_SUFFIX = ' {Item attribute}'
ELEMENT_KEY_SUFFIX = ' {custom element}'

Device hardware subtype such as 'virtio' or 'lsilogic'.


Device hardware type such as 'ide' or 'memory'.


Device instance ID.

properties = None

Dict of dicts. properties[name][value] = (profile1, profile2).


List of names of all properties known to this OVFItem.


Get union of lists.

Parameters:lists (list) -- List of lists to unify.
Returns:list -- All distinct values across the given lists.


>>> list_union([1, 2, 3], [0, 4], [1, 5])
[1, 2, 3, 0, 4, 5]
>>> list_union(['foo'], ['bar'], ['bar', 'foo'])
['foo', 'bar']
>>> list_union(['bar', 'foo'], ['foo'], ['bar'])
['bar', 'foo']