[lxc-devel] [pylxd/master] Operation work
rockstar on Github
lxc-bot at linuxcontainers.org
Tue Jun 7 17:24:16 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 567 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160607/28b39fc4/attachment.bin>
-------------- next part --------------
From 3dd710a10bb821b4627ae93e6db65e0d5019b551 Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Tue, 7 Jun 2016 11:18:39 -0600
Subject: [PATCH 1/2] Use Operation
---
pylxd/mixin.py | 7 +++----
pylxd/operation.py | 5 +++--
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/pylxd/mixin.py b/pylxd/mixin.py
index 5bd8960..324e0ca 100644
--- a/pylxd/mixin.py
+++ b/pylxd/mixin.py
@@ -11,17 +11,16 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
+from pylxd.operation import Operation
class Waitable(object):
def get_operation(self, operation_id):
- if operation_id.startswith('/'):
- operation_id = operation_id.split('/')[-1]
- return self._client.operations.get(operation_id)
+ return Operation.get(self._client, operation_id)
def wait_for_operation(self, operation_id):
- operation = self.get_operation(operation_id)
+ operation = Operation.get(self._client, operation_id)
operation.wait()
return operation
diff --git a/pylxd/operation.py b/pylxd/operation.py
index 47a067c..5ec9ea0 100644
--- a/pylxd/operation.py
+++ b/pylxd/operation.py
@@ -26,14 +26,15 @@ class Operation(object):
@classmethod
def wait_for_operation(cls, client, operation_id):
"""Get an operation and wait for it to complete."""
- if operation_id.startswith('/'):
- operation_id = operation_id.split('/')[-1]
operation = cls.get(client, operation_id)
operation.wait()
+ return operation
@classmethod
def get(cls, client, operation_id):
"""Get an operation."""
+ if operation_id.startswith('/'):
+ operation_id = operation_id.split('/')[-1]
response = client.api.operations[operation_id].get()
return cls(_client=client, **response.json()['metadata'])
From 824c5a420a5f09423f988004b1a96bc717715874 Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul.hummer at canonical.com>
Date: Tue, 7 Jun 2016 11:22:20 -0600
Subject: [PATCH 2/2] Remove Waitable.get_operation
---
pylxd/mixin.py | 3 ---
1 file changed, 3 deletions(-)
diff --git a/pylxd/mixin.py b/pylxd/mixin.py
index 324e0ca..d940758 100644
--- a/pylxd/mixin.py
+++ b/pylxd/mixin.py
@@ -16,9 +16,6 @@
class Waitable(object):
- def get_operation(self, operation_id):
- return Operation.get(self._client, operation_id)
-
def wait_for_operation(self, operation_id):
operation = Operation.get(self._client, operation_id)
operation.wait()
More information about the lxc-devel
mailing list