From ejcasler@us.ibm.com Thu Aug 14 17:06:18 2008 Date: Thu, 14 Aug 2008 14:05:39 -0700 From: Eric Casler To: ssmoser@linux.vnet.ibm.com Subject: [PATCH] Added getParentAttribute - returns element's specified attritbute value getParentAttribute returns a lambda function that takes one argument the child node, such that getParentAttribute('ovf:id')() would return the id of the VirtualSystem that contained the passed in element. Signed-off-by: Eric Casler --- py/ovf/Ovf.py | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/py/ovf/Ovf.py b/py/ovf/Ovf.py index 73038b6..41798a9 100644 --- a/py/ovf/Ovf.py +++ b/py/ovf/Ovf.py @@ -128,6 +128,23 @@ def getElements(ovfNode, tagName, *criteria): return elements +def getParentAttribute(attrName): + """ + Return value for given attribute of the parent of given XML DOM Element. + XML DOM Element passed into returned lambda function. + + e.g. getParentAttribute('ovf:id')() + + @note: lambda arg(xmlElement): type - DOM Element + + @param attrName: attribute name + @type attrName: String + + @return: function that returns parent attribute value + @rtype: lambda function + """ + return lambda xmlElement: xmlElement.parentNode.getAttribute(attrName) + def getContentEntities(ovfNode, ovfId=None): """ Returns a list of OVF Entities, optionally restricted by id. -- 1.5.4.3