Only include 'snapshots' in extra field if vCloud >5.5
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/9ce9190b Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/9ce9190b Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/9ce9190b Branch: refs/heads/trunk Commit: 9ce9190b50fbad8659691fbc02b71a06da596f29 Parents: 8e5a773 Author: Juan Font Alonso <juanfontalo...@gmail.com> Authored: Wed Dec 16 17:16:12 2015 +0100 Committer: anthony-shaw <anthony.p.s...@gmail.com> Committed: Mon Feb 15 09:44:49 2016 +1100 ---------------------------------------------------------------------- libcloud/compute/drivers/vcloud.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/9ce9190b/libcloud/compute/drivers/vcloud.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/drivers/vcloud.py b/libcloud/compute/drivers/vcloud.py index db1148c..b345aea 100644 --- a/libcloud/compute/drivers/vcloud.py +++ b/libcloud/compute/drivers/vcloud.py @@ -1997,14 +1997,17 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver): return isinstance(node_or_image, Node) def _to_node(self, node_elm): - # Parse snapshots and VMs as extra fields - snapshots = [] - for snapshot_elem in node_elm.findall(fixxpath(node_elm, 'SnapshotSection/Snapshot')): - snapshots.append({ - "created": snapshot_elem.get("created"), - "poweredOn": snapshot_elem.get("poweredOn"), - "size": snapshot_elem.get("size"), - }) + # Parse snapshots and VMs as extra + if node_elm.find(fixxpath(node_elm, "SnapshotSection")) is None: + snapshots = None + else: + snapshots = [] + for snapshot_elem in node_elm.findall(fixxpath(node_elm, 'SnapshotSection/Snapshot')): + snapshots.append({ + "created": snapshot_elem.get("created"), + "poweredOn": snapshot_elem.get("poweredOn"), + "size": snapshot_elem.get("size"), + }) vms = [] for vm_elem in node_elm.findall(fixxpath(node_elm, 'Children/Vm')): @@ -2056,13 +2059,17 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver): 'application/vnd.vmware.vcloud.vdc+xml') vdc = next(vdc for vdc in self.vdcs if vdc.id == vdc_id) + extra = {'vdc': vdc.name, 'vms': vms} + if snapshots is not None: + extra['snapshots'] = snapshots + node = Node(id=node_elm.get('href'), name=node_elm.get('name'), state=self.NODE_STATE_MAP[node_elm.get('status')], public_ips=public_ips, private_ips=private_ips, driver=self.connection.driver, - extra={'vdc': vdc.name, 'vms': vms, 'snapshots': snapshots}) + extra=extra) return node def _to_vdc(self, vdc_elm):