class documentation

class OVFReader(object):

View In Hierarchy

Reader class for OVF files.

Method __init__ Initialiaze the reader - load the .ovf file to XML parser.
Method GetBackendData Provides backend information - vcpus, memory, auto balancing options.
Method GetDisksNames Provides list of file names for the disks used by the instance.
Method GetDiskTemplate Returns disk template from .ovf file
Method GetHypervisorData Provides hypervisor information - hypervisor name and options.
Method GetInstanceName Provides information about instance name.
Method GetNetworkData Provides data about the network in the OVF instance.
Method GetOSData Provides operating system information - os name and options.
Method GetTagsData Provides tags information for instance.
Method GetVersionData Provides version number read from .ovf file
Method VerifyManifest Verifies manifest for the OVF package, if one is given.
Instance Variable files_list list of files in the OVF package
Instance Variable input_dir directory in which the .ovf file resides
Instance Variable schema_name name of the .ovf file
Instance Variable tree XML tree of the .ovf file
Static Method _GetDictParameters Reads text in all children and creates the dictionary from the contents.
Method _GetAttributes Get specified attribute from all nodes accessible using given path.
Method _GetElementMatchingAttr Searches for element on a path that matches certain attribute value.
Method _GetElementMatchingText Searches for element on a path that matches certain text value.
def __init__(self, input_path):

Initialiaze the reader - load the .ovf file to XML parser.

It is assumed that names of manifesto (.mf), certificate (.cert) and ovf files are the same. In order to account any other files as part of the ovf package, they have to be explicitly mentioned in the Resources section of the .ovf file.

Parameters
input_path:stringabsolute path to the .ovf file
Raises
errors.OpPrereqErrorwhen .ovf file is not a proper XML file or some of the files mentioned in Resources section do not exist
def GetBackendData(self):

Provides backend information - vcpus, memory, auto balancing options.

Returns
dictdictionary containing options for vcpus, memory and auto balance settings
def GetDisksNames(self):

Provides list of file names for the disks used by the instance.

Returns
listlist of file names, as referenced in .ovf file
def GetDiskTemplate(self):

Returns disk template from .ovf file

Returns
string or Nonename of the template
def GetHypervisorData(self):

Provides hypervisor information - hypervisor name and options.

Returns
dictdictionary containing name of the used hypervisor and all the specified options
def GetInstanceName(self):

Provides information about instance name.

Returns
stringinstance name string
def GetNetworkData(self):

Provides data about the network in the OVF instance.

The method gathers the data about networks used by OVF instance. It assumes that 'name' tag means something - in essence, if it contains one of the words 'bridged' or 'routed' then that will be the mode of this network in Ganeti. The information about the network can be either in GanetiSection or VirtualHardwareSection.

Returns
dictdictionary containing all the network information
def GetOSData(self):

Provides operating system information - os name and options.

Returns
dictdictionary containing name and options for the chosen OS
def GetTagsData(self):

Provides tags information for instance.

Returns
string or Nonestring of comma-separated tags for the instance
def GetVersionData(self):

Provides version number read from .ovf file

Returns
stringstring containing the version number
def VerifyManifest(self):

Verifies manifest for the OVF package, if one is given.

Raises
errors.OpPrereqErrorif SHA1 checksums do not match
files_list: list =

list of files in the OVF package

input_dir: string =

directory in which the .ovf file resides

schema_name: string =

name of the .ovf file

tree: ET.ElementTree =

XML tree of the .ovf file

@staticmethod
def _GetDictParameters(root, schema):

Reads text in all children and creates the dictionary from the contents.

Parameters
root:ET.ElementTree or Nonefather of the nodes we want to collect data about
schema:stringschema name to be removed from the tag
Returns
dictdictionary containing tags and their text contents, tags have their schema fragment removed or empty dictionary, when root is None
def _GetAttributes(self, path, attribute):

Get specified attribute from all nodes accessible using given path.

Function follows the path from root node to the desired tags using path, then reads the apropriate attribute values.

Parameters
path:stringpath of nodes to visit
attribute:stringattribute for which we gather the information
Returns
listfor each accessible tag with the attribute value set, value of the attribute
def _GetElementMatchingAttr(self, path, match_attr):

Searches for element on a path that matches certain attribute value.

Function follows the path from root node to the desired tags using path, then searches for the first one matching the attribute value.

Parameters
path:stringpath of nodes to visit
match_attr:tuplepair (attribute, value) for which we search
Returns
ET.ElementTree or Nonefirst element matching match_attr or None if nothing matches
def _GetElementMatchingText(self, path, match_text):

Searches for element on a path that matches certain text value.

Function follows the path from root node to the desired tags using path, then searches for the first one matching the text value.

Parameters
path:stringpath of nodes to visit
match_text:tuplepair (node, text) for which we search
Returns
ET.ElementTree or Nonefirst element matching match_text or None if nothing matches