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.
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.ExceptionData to be added to an
OVFItemconflicts with existing data.
-
class
OVFItem(ovf, item=None)[source]¶ Bases:
objectHelper class for
OVF.Represents all variations of a given hardware
Itemamongst different hardware configuration profiles.In essence, it is:
- a dict of
Itemproperties (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: - ovf (OVF) -- OVF instance that owns the Item (optional)
- item (xml.etree.ElementTree.Element) -- 'Item' element (optional)
-
add_item(item)[source]¶ Add the given
Itemelement to this OVFItem.Parameters: item (xml.etree.ElementTree.Element) -- XML
ItemelementRaises: ValueUnsupportedError-- if theitemis 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: 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: 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: Returns: Value string or list, or
NoneRaises: OVFItemDataError-- ifvalue_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: 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:
-
set_property(name, value, profiles=None, overwrite=True)[source]¶ Store the value and profiles associated with it for the given name.
Parameters: Raises: OVFItemDataError-- if a value is already defined and would be overwritten, unlessoverwriteisTrue
-
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 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.
Parameters: Returns: str -- The updated value string with wildcards added.
See also
-
value_replace_wildcards(name, value, profiles)[source]¶ Replace wildcards with actual values.
Parameters: Returns: str -- The updated value string, with wildcards replaced.
See also
-
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.
- a dict of
-
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']