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)
-
add_item
(item)[source]¶ Add the given
Item
element to this OVFItem.Parameters: item (xml.etree.ElementTree.Element) – XML Item
elementRaises: 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
.
-
generate_items
()[source]¶ Get a list of Item XML elements derived from this object’s data.
Return type: list[xml.etree.ElementTree.Element]
-
get
(tag)[source]¶ Get the dict associated with the given XML tag, if any.
Parameters: tag (str) – XML tag to look up Return type: dict Returns: 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 Return type: list
-
get_nonintersecting_set_list
()[source]¶ Identify the minimal non-intersecting set of profiles.
Returns: 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 of strings) – set of profile names, or None
Returns: Value string or list, or
None
-
has_profile
(profile)[source]¶ Check if this Item exists under the given profile.
Parameters: profile (str) – Profile name Return type: boolean
-
property_profiles
(name, value)[source]¶ Get set of profiles associated with a property name and value.
-
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[str]) – If
None
, set for all profiles currently known to this item, else set only for the given list of profiles. - overwrite (boolean) – 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
isTrue
-
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 self-repair is impossible.
-
value_add_wildcards
(name, value, profiles)[source]¶ Add wildcard placeholders to a string that may need updating.
-
ATTRIB_KEY_SUFFIX
= ' {Item attribute}'¶
-
ELEMENT_KEY_SUFFIX
= ' {custom element}'¶
-
properties
= None¶ Dict of dicts. properties[name][value] = (profile1, profile2).
-
property_names
¶ List of names of all properties known to this OVFItem.
- a dict of