libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [2/6] libcloud git commit: add start_container
Date Tue, 11 Oct 2016 22:42:10 GMT
add start_container


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

Branch: refs/heads/trunk
Commit: f4b24f8dff6602f6e3b4b15f21680dba11bba21a
Parents: 23b0288
Author: Mario Loria <mario@arroyonetworks.com>
Authored: Mon Oct 10 17:47:32 2016 -0400
Committer: Mario Loria <mario@arroyonetworks.com>
Committed: Mon Oct 10 17:47:32 2016 -0400

----------------------------------------------------------------------
 libcloud/container/drivers/rancher.py   | 26 +++++++++++++++++++++++---
 libcloud/test/container/test_rancher.py |  4 ++++
 2 files changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/f4b24f8d/libcloud/container/drivers/rancher.py
----------------------------------------------------------------------
diff --git a/libcloud/container/drivers/rancher.py b/libcloud/container/drivers/rancher.py
index dbf28f2..ef3b405 100644
--- a/libcloud/container/drivers/rancher.py
+++ b/libcloud/container/drivers/rancher.py
@@ -40,11 +40,13 @@ class RancherResponse(JsonResponse):
     def parse_error(self):
         parsed = super(RancherResponse, self).parse_error()
         if 'fieldName' in parsed:
-            return "Field %s is %s: %s - %s" % (parsed['fieldName'], parsed['code'],
-                                          parsed['message'], parsed['detail'])
+            return "Field %s is %s: %s - %s" % (parsed['fieldName'],
+                                                parsed['code'],
+                                                parsed['message'],
+                                                parsed['detail'])
         else:
             return "%%s - %s" % (parsed['message'],
-                                    parsed['detail'])
+                                 parsed['detail'])
 
     def success(self):
         return self.status in VALID_RESPONSE_CODES
@@ -564,6 +566,24 @@ class RancherContainerDriver(ContainerDriver):
 
         return self._to_container(result)
 
+    def start_container(self, container):
+        """
+        Start a container
+
+        :param container: The container to be started
+        :type  container: :class:`libcloud.container.base.Container`
+
+        :return: The container refreshed with current data
+        :rtype: :class:`libcloud.container.base.Container`
+        """
+        result = self.connection.request('%s/containers/%s?action=start' %
+                                         (self.baseuri, container.id),
+                                         method='POST')
+        if result.status in VALID_RESPONSE_CODES:
+            return self.get_container(container.id)
+        else:
+            raise RancherException(result.status, 'failed to start container')
+
     def stop_container(self, container):
         """
         Stop a container

http://git-wip-us.apache.org/repos/asf/libcloud/blob/f4b24f8d/libcloud/test/container/test_rancher.py
----------------------------------------------------------------------
diff --git a/libcloud/test/container/test_rancher.py b/libcloud/test/container/test_rancher.py
index f9ddc83..9a86dea 100644
--- a/libcloud/test/container/test_rancher.py
+++ b/libcloud/test/container/test_rancher.py
@@ -157,6 +157,10 @@ class RancherContainerDriverTestCase(unittest.TestCase):
         self.assertEqual(container.extra['environment'],
                          {'STORAGE_TYPE': 'file'})
 
+    def test_start_container(self):
+        container = self.driver.get_container("1i31")
+        container.start()
+
     def test_stop_container(self):
         container = self.driver.get_container("1i31")
         container.stop()


Mime
View raw message