libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [2/7] libcloud git commit: Added snapshot operations for v5.5. Snapshots as extra field.
Date Sun, 14 Feb 2016 22:46:30 GMT
Added snapshot operations for v5.5. Snapshots as extra field.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/8e5a7732
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/8e5a7732
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/8e5a7732

Branch: refs/heads/trunk
Commit: 8e5a773260402083442e7e837a92475d923b75fc
Parents: 724a91a
Author: Juan Font Alonso <juanfontalonso@gmail.com>
Authored: Thu Dec 10 14:39:32 2015 +0100
Committer: anthony-shaw <anthony.p.shaw@gmail.com>
Committed: Mon Feb 15 09:44:49 2016 +1100

----------------------------------------------------------------------
 libcloud/compute/drivers/vcloud.py | 66 ++++++++++++++++++++++++++++++++-
 1 file changed, 64 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/8e5a7732/libcloud/compute/drivers/vcloud.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/vcloud.py b/libcloud/compute/drivers/vcloud.py
index 499846b..db1148c 100644
--- a/libcloud/compute/drivers/vcloud.py
+++ b/libcloud/compute/drivers/vcloud.py
@@ -1997,7 +1997,15 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
         return isinstance(node_or_image, Node)
 
     def _to_node(self, node_elm):
-        # Parse VMs as extra field
+        # 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"),
+            })
+
         vms = []
         for vm_elem in node_elm.findall(fixxpath(node_elm, 'Children/Vm')):
             public_ips = []
@@ -2054,7 +2062,7 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
                     public_ips=public_ips,
                     private_ips=private_ips,
                     driver=self.connection.driver,
-                    extra={'vdc': vdc.name, 'vms': vms})
+                    extra={'vdc': vdc.name, 'vms': vms, 'snapshots': snapshots})
         return node
 
     def _to_vdc(self, vdc_elm):
@@ -2102,3 +2110,57 @@ class VCloud_5_5_NodeDriver(VCloud_5_1_NodeDriver):
     Accept headers
     '''
     connectionCls = VCloud_5_5_Connection
+
+    def ex_create_snapshot(self, node):
+        """
+        Creates new snapshot of a virtual machine or of all the virtual machines in a vApp.
+        Prior to creation of the new snapshots, any existing user created snapshots
+        associated with the virtual machines are removed.
+
+        :param  node: node
+        :type   node: :class:`Node`
+
+        :rtype: :class:`Node`
+        """
+        snapshot_xml = ET.Element("CreateSnapshotParams",
+                                  { 'memory': 'true', 'name': 'name', 'quiesce': 'true',
+                                    'xmlns': "http://www.vmware.com/vcloud/v1.5",
+                                    'xmlns:xsi': "http://www.w3.org/2001/XMLSchema-instance"}
+                                  )
+        ET.SubElement(snapshot_xml, 'Description').text = 'Description'
+        headers = {
+            'Content-Type': 'application/vnd.vmware.vcloud.createSnapshotParams+xml'
+        }
+        return self._perform_snapshot_operation(node, "createSnapshot", snapshot_xml, headers)
+
+    def ex_remove_snapshots(self, node):
+        """
+        Removes all user created snapshots for a vApp or virtual machine.
+
+        :param  node: node
+        :type   node: :class:`Node`
+
+        :rtype: :class:`Node`
+        """
+        return self._perform_snapshot_operation(node, "removeAllSnapshots", None, None)
+
+    def ex_revert_to_snapshot(self, node):
+        """
+        Reverts a vApp or virtual machine to the current snapshot, if any.
+
+        :param  node: node
+        :type   node: :class:`Node`
+
+        :rtype: :class:`Node`
+        """
+        return self._perform_snapshot_operation(node, "revertToCurrentSnapshot", None, None)
+
+    def _perform_snapshot_operation(self, node, operation, xml_data, headers):
+        res = self.connection.request(
+            '%s/action/%s' % (get_url_path(node.id), operation),
+            data=ET.tostring(xml_data) if xml_data else None,
+            method='POST',
+            headers=headers)
+        self._wait_for_task_completion(res.object.get('href'))
+        res = self.connection.request(get_url_path(node.id))
+        return self._to_node(res.object)


Mime
View raw message