COT.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.

Functions

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.

Parameters:
add_item(item)[source]

Add the given Item element to this OVFItem.

Parameters:

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

Raises:
  • 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.

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

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.

Parameters:
  • name (str) – Property name.
  • default (object) – Default value to return if there are no matches
Returns:

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

generate_items()[source]

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

Returns:list – Generated list of XML Item elements
get(tag)[source]

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_all_values(tag)[source]

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.
get_nonintersecting_set_list()[source]

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.

Parameters:
  • tag (str) – Tag to retrieve value for
  • profiles (set) – set of profile names, or None
Returns:

Value string or list, or None

Raises:

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

has_profile(profile)[source]

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.

Parameters:
  • name (str) – Property name.
  • value (object) – Property value of interest.
Returns:

set – Profile strings associated with this name/value.

property_values(name)[source]

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.

Parameters:
  • 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.

Parameters:
  • 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.
Raises:

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

validate()[source]

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 ElementName or Description references the VirtualQuantity, Connection, or ResourceSubType, replace that reference with a placeholder that we can regenerate at output time. That way, if the VirtualQuantity or ResourceSubType changes, these can change too.

Parameters:
  • name (str) – Property name
  • value (str) – Value to add wildcards to.
  • profiles (list) – Profiles to which this (name, value) applies.
Returns:

str – The updated value string with wildcards added.

value_replace_wildcards(name, value, profiles)[source]

Replace wildcards with actual values.

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

str – The updated value string, with wildcards replaced.

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

Device hardware subtype such as ‘virtio’ or ‘lsilogic’.

hardware_type

Device hardware type such as ‘ide’ or ‘memory’.

instance_id

Device instance ID.

properties = None

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

property_names

List of names of all properties known to this OVFItem.

list_union(*lists)[source]

Get union of lists.

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

Examples

>>> 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']