libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From quent...@apache.org
Subject [1/3] libcloud git commit: Add restore and resize/scale to Cloudstack compute driver
Date Thu, 25 Jan 2018 06:56:09 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk fd1162844 -> 91257d533


Add restore and resize/scale to Cloudstack compute driver

Signed-off-by: Quentin Pradet <quentinp@apache.org>


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

Branch: refs/heads/trunk
Commit: f38a9e30847bcfa8e806d4bd402e26a5248567f6
Parents: fd11628
Author: otherpirate <mauro_murari@hotmail.com>
Authored: Tue Jan 23 17:17:50 2018 -0200
Committer: Quentin Pradet <quentinp@apache.org>
Committed: Thu Jan 25 10:46:33 2018 +0400

----------------------------------------------------------------------
 libcloud/common/cloudstack.py                   |  5 +-
 libcloud/compute/drivers/cloudstack.py          | 53 ++++++++++++++++++++
 .../cloudstack/queryAsyncJobResult_88776.json   |  1 +
 .../cloudstack/queryAsyncJobResult_88777.json   |  1 +
 .../restoreVirtualMachine_default.json          |  1 +
 .../cloudstack/scaleVirtualMachine_default.json |  1 +
 libcloud/test/compute/test_cloudstack.py        | 18 ++++++-
 7 files changed, 78 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f38a9e30/libcloud/common/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/common/cloudstack.py b/libcloud/common/cloudstack.py
index ee16dfd..1cb63fe 100644
--- a/libcloud/common/cloudstack.py
+++ b/libcloud/common/cloudstack.py
@@ -162,12 +162,15 @@ class CloudStackConnection(ConnectionUserAndKey, PollingConnection):
         if (command == 'revokesecuritygroupingress' and
                 'revokesecuritygroupingressresponse' not in result.object):
             command = command
+        elif (command == 'restorevirtualmachine' and
+                'restorevmresponse' in result.object):
+            command = "restorevmresponse"
         else:
             command = command + 'response'
 
         if command not in result.object:
             raise MalformedResponseError(
-                "Unknown response format",
+                "Unknown response format {}".format(command),
                 body=result.body,
                 driver=self.driver)
         result = result.object[command]

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f38a9e30/libcloud/compute/drivers/cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/cloudstack.py b/libcloud/compute/drivers/cloudstack.py
index a97758c..1fd0ab2 100644
--- a/libcloud/compute/drivers/cloudstack.py
+++ b/libcloud/compute/drivers/cloudstack.py
@@ -486,6 +486,18 @@ class CloudStackNode(Node):
         """
         return self.driver.ex_delete_port_forwarding_rule(node=self, rule=rule)
 
+    def ex_restore(self, template=None):
+        """
+        Restore virtual machine
+        """
+        return self.driver.ex_restore(node=self, template=template)
+
+    def ex_change_node_size(self, offering):
+        """
+        Change virtual machine offering/size
+        """
+        return self.driver.ex_change_node_size(node=self, offering=offering)
+
     def ex_start(self):
         """
         Starts a stopped virtual machine.
@@ -1693,6 +1705,47 @@ class CloudStackNodeDriver(CloudStackDriverMixIn, NodeDriver):
                             method='GET')
         return True
 
+    def ex_restore(self, node, template=None):
+        """
+        Restore virtual machine
+
+        :param node: Node to restore
+        :type node: :class:`CloudStackNode`
+
+        :param template: Optional new template
+        :type  template: :class:`NodeImage`
+
+        :rtype ``str``
+        """
+        params = {'virtualmachineid': node.id}
+        if template:
+            params['templateid'] = template.id
+
+        res = self._async_request(command='restoreVirtualMachine',
+                                  params=params,
+                                  method='GET')
+        return res['virtualmachine']['templateid']
+
+    def ex_change_node_size(self, node, offering):
+        """
+        Change offering/size of a virtual machine
+
+        :param node: Node to change size
+        :type node: :class:`CloudStackNode`
+
+        :param offering: The new offering
+        :type  offering: :class:`NodeSize`
+
+        :rtype ``str``
+        """
+        res = self._async_request(command='scaleVirtualMachine',
+                                  params={
+                                      'id': node.id,
+                                      'serviceofferingid': offering.id
+                                  },
+                                  method='GET')
+        return res['virtualmachine']['serviceofferingid']
+
     def ex_start(self, node):
         """
         Starts/Resumes a stopped virtual machine

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f38a9e30/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_88776.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_88776.json b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_88776.json
new file mode 100644
index 0000000..a01c3a3
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_88776.json
@@ -0,0 +1 @@
+{ "queryasyncjobresultresponse": {"jobprocstatus": 0, "jobstatus": 1, "jobresult": {"virtualmachine":
{"serviceofferingid": "eee-fff-ggg-hhh"}}}}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f38a9e30/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_88777.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_88777.json b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_88777.json
new file mode 100644
index 0000000..8e0685e
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/queryAsyncJobResult_88777.json
@@ -0,0 +1 @@
+{ "queryasyncjobresultresponse": {"jobprocstatus": 0, "jobstatus": 1, "jobresult": {"virtualmachine":
{"templateid": "aaa-bbb-ccc-ddd"}}}}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f38a9e30/libcloud/test/compute/fixtures/cloudstack/restoreVirtualMachine_default.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/restoreVirtualMachine_default.json
b/libcloud/test/compute/fixtures/cloudstack/restoreVirtualMachine_default.json
new file mode 100644
index 0000000..0586809
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/restoreVirtualMachine_default.json
@@ -0,0 +1 @@
+{ "restorevirtualmachineresponse" : { "jobid" : 88777} }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f38a9e30/libcloud/test/compute/fixtures/cloudstack/scaleVirtualMachine_default.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/cloudstack/scaleVirtualMachine_default.json b/libcloud/test/compute/fixtures/cloudstack/scaleVirtualMachine_default.json
new file mode 100644
index 0000000..bdab77b
--- /dev/null
+++ b/libcloud/test/compute/fixtures/cloudstack/scaleVirtualMachine_default.json
@@ -0,0 +1 @@
+{ "scalevirtualmachineresponse" : { "jobid" : 88776} }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f38a9e30/libcloud/test/compute/test_cloudstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_cloudstack.py b/libcloud/test/compute/test_cloudstack.py
index 356cd94..78b1a95 100644
--- a/libcloud/test/compute/test_cloudstack.py
+++ b/libcloud/test/compute/test_cloudstack.py
@@ -25,7 +25,7 @@ try:
 except ImportError:
     import json
 
-from libcloud.compute.base import NodeLocation
+from libcloud.compute.base import NodeLocation, NodeSize, NodeImage
 from libcloud.common.types import ProviderError
 from libcloud.compute.drivers.cloudstack import CloudStackNodeDriver, \
     CloudStackAffinityGroupType
@@ -1276,6 +1276,22 @@ class CloudStackTestCase(CloudStackCommonTestCase, unittest.TestCase):
         except Exception:
             self.fail('url provided but driver raised an exception')
 
+    def test_restore(self):
+        template = NodeImage("aaa-bbb-ccc-ddd", "fake-img", None)
+
+        node = self.driver.list_nodes()[0]
+        res = node.ex_restore(template=template)
+
+        self.assertEqual(res, template.id)
+
+    def test_change_offerings(self):
+        offering = NodeSize("eee-fff-ggg-hhh", "fake-size", 1, 4, 5, 0.1, None)
+
+        node = self.driver.list_nodes()[0]
+        res = node.ex_change_node_size(offering=offering)
+
+        self.assertEqual(res, offering.id)
+
 
 class CloudStackMockHttp(MockHttp, unittest.TestCase):
     fixtures = ComputeFileFixtures('cloudstack')


Mime
View raw message