[lxc-devel] [pylxd/master] Change Operation calls to use the manager methods on client

rockstar on Github lxc-bot at linuxcontainers.org
Thu Nov 24 19:07:03 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 325 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161124/8235ceea/attachment.bin>
-------------- next part --------------
From c8cc790c987d9b73675cce1c52fa6da0688d2938 Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Thu, 24 Nov 2016 12:01:15 -0700
Subject: [PATCH] Change Operation calls to use the manager methods on client

---
 pylxd/models/_model.py    | 10 ++++------
 pylxd/models/container.py | 25 ++++++++++++-------------
 pylxd/models/image.py     |  7 ++-----
 3 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/pylxd/models/_model.py b/pylxd/models/_model.py
index 7307a0d..ed3c88e 100644
--- a/pylxd/models/_model.py
+++ b/pylxd/models/_model.py
@@ -15,8 +15,6 @@
 
 import six
 
-from pylxd.models.operation import Operation
-
 
 class Attribute(object):
     """A metadata class for model attributes."""
@@ -170,8 +168,8 @@ def save(self, wait=False):
         response = self.api.put(json=marshalled)
 
         if response.json()['type'] == 'async' and wait:
-            Operation.wait_for_operation(
-                self.client, response.json()['operation'])
+            self.client.operations.wait_for_operation(
+                response.json()['operation'])
         self.__dirty__.clear()
 
     def delete(self, wait=False):
@@ -179,8 +177,8 @@ def delete(self, wait=False):
         response = self.api.delete()
 
         if response.json()['type'] == 'async' and wait:
-            Operation.wait_for_operation(
-                self.client, response.json()['operation'])
+            self.client.operations.wait_for_operation(
+                response.json()['operation'])
         self.client = None
 
     def marshall(self):
diff --git a/pylxd/models/container.py b/pylxd/models/container.py
index 27552f8..b27edc6 100644
--- a/pylxd/models/container.py
+++ b/pylxd/models/container.py
@@ -26,7 +26,6 @@
 
 from pylxd import managers
 from pylxd.models import _model as model
-from pylxd.models.operation import Operation
 
 
 class ContainerState(object):
@@ -121,7 +120,7 @@ def create(cls, client, config, wait=False):
         response = client.api.containers.post(json=config)
 
         if wait:
-            Operation.wait_for_operation(client, response.json()['operation'])
+            client.operations.wait_for_operation(response.json()['operation'])
         return cls(client, name=config['name'])
 
     def __init__(self, *args, **kwargs):
@@ -135,8 +134,8 @@ def rename(self, name, wait=False):
         response = self.api.post(json={'name': name})
 
         if wait:
-            Operation.wait_for_operation(
-                self.client, response.json()['operation'])
+            self.client.operations.wait_for_operation(
+                response.json()['operation'])
         self.name = name
 
     def _set_state(self, state, timeout=30, force=True, wait=False):
@@ -146,8 +145,8 @@ def _set_state(self, state, timeout=30, force=True, wait=False):
             'force': force
         })
         if wait:
-            Operation.wait_for_operation(
-                self.client, response.json()['operation'])
+            self.client.operations.wait_for_operation(
+                response.json()['operation'])
             if 'status' in self.__dirty__:
                 del self.__dirty__[self.__dirty__.index('status')]
             self.sync()
@@ -301,8 +300,8 @@ def publish(self, public=False, wait=False):
 
         response = self.client.api.images.post(json=data)
         if wait:
-            operation = Operation.wait_for_operation(
-                self.client, response.json()['operation'])
+            operation = self.client.operations.wait_for_operation(
+                response.json()['operation'])
 
             return self.client.images.get(operation.metadata['fingerprint'])
 
@@ -385,15 +384,15 @@ def create(cls, client, container, name, stateful=False, wait=False):
 
         snapshot = cls(client, container=container, name=name)
         if wait:
-            Operation.wait_for_operation(client, response.json()['operation'])
+            client.operations.wait_for_operation(response.json()['operation'])
         return snapshot
 
     def rename(self, new_name, wait=False):
         """Rename a snapshot."""
         response = self.api.post(json={'name': new_name})
         if wait:
-            Operation.wait_for_operation(
-                self.client, response.json()['operation'])
+            self.client.operations.wait_for_operation(
+                response.json()['operation'])
         self.name = new_name
 
     def publish(self, public=False, wait=False):
@@ -416,6 +415,6 @@ def publish(self, public=False, wait=False):
 
         response = self.client.api.images.post(json=data)
         if wait:
-            operation = Operation.wait_for_operation(
-                self.client, response.json()['operation'])
+            operation = self.client.operations.wait_for_operation(
+                response.json()['operation'])
             return self.client.images.get(operation.metadata['fingerprint'])
diff --git a/pylxd/models/image.py b/pylxd/models/image.py
index ac1c4fa..4cb8753 100644
--- a/pylxd/models/image.py
+++ b/pylxd/models/image.py
@@ -19,7 +19,6 @@
 import six
 
 from pylxd.models import _model as model
-from pylxd.models.operation import Operation
 
 
 def _image_create_from_config(client, config, wait=False):
@@ -29,10 +28,8 @@ def _image_create_from_config(client, config, wait=False):
     """
     response = client.api.images.post(json=config)
     if wait:
-        Operation.wait_for_operation(client, response.json()['operation'])
-
-        return Operation.get(client, response.json()['operation'])
-
+        return client.operations.wait_for_operation(
+            response.json()['operation'])
     return response.json()['operation']
 
 


More information about the lxc-devel mailing list