pyvcloud
pyvcloud copied to clipboard
vapp is not updating existing guest properties of the VM or VAPP
I was working on a solution to dynamic create the VM, VAPP etc using pyvcloud API. But I had issue to update the guest properties(Product section) in the VM.
When I looked into the code of vdc/vapp.py for the method of update_product_section then I found the issue that after getting the existing key , itwas removed rather to update that property.
In my project, I have written a new method function to handle the scenario.
Problematic code:
properties = product_section.xpath('ovf:Property', namespaces=NSMAP) for prop in properties: id = prop.get('{' + NSMAP['ovf'] + '}key') if key == id: **prop.getparent().remove(prop)** product_section.append(property) is_updated = True break
Correct code:
` properties = product_section.xpath("ovf:Property", namespaces=NSMAP) if properties: prop = self.find_key(properties, key) if prop is not None: prop.set("{" + NSMAP["ovf"] + "}value", str(value)) prop.Value.set("{" + NSMAP["ovf"] + "}value", str(value))
A utility function: def find_key(self, properties, key):
for prop in properties:
id = prop.get("{" + NSMAP["ovf"] + "}key")
if key == id:
return prop
return`