[lxc-devel] [pylxd/master] Add state function on container to return state with network.
aarnaud on Github
lxc-bot at linuxcontainers.org
Tue Mar 1 14:26:31 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 343 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160301/c9b1c692/attachment.bin>
-------------- next part --------------
From acfc95799c4d3c31e807b531bfa007aeb5c3ea26 Mon Sep 17 00:00:00 2001
From: Anthony ARNAUD <anthony.arnaud at niji.fr>
Date: Tue, 1 Mar 2016 15:18:34 +0100
Subject: [PATCH] Add state function on container to return state with network.
ex: container.state().network['eth0']
---
pylxd/container.py | 9 ++++++++-
pylxd/containerState.py | 19 +++++++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)
create mode 100644 pylxd/containerState.py
diff --git a/pylxd/container.py b/pylxd/container.py
index 3e2c5d9..f17e4ad 100644
--- a/pylxd/container.py
+++ b/pylxd/container.py
@@ -15,7 +15,7 @@
import six
from pylxd import mixin
-from pylxd.deprecated.container import LXDContainer # NOQA
+from pylxd.containerState import ContainerState
from pylxd.operation import Operation
@@ -121,6 +121,13 @@ def _set_state(self, state, timeout=30, force=True, wait=False):
self.wait_for_operation(response.json()['operation'])
self.reload()
+ def state(self):
+ state = ContainerState()
+ response = self._client.api.containers[self.name].state.get()
+ for key, value in response.json()['metadata'].iteritems():
+ setattr(state, key, value)
+ return state
+
def start(self, timeout=30, force=True, wait=False):
"""Start the container."""
return self._set_state(
diff --git a/pylxd/containerState.py b/pylxd/containerState.py
new file mode 100644
index 0000000..51f97cc
--- /dev/null
+++ b/pylxd/containerState.py
@@ -0,0 +1,19 @@
+# Copyright (c) 2016 Canonical Ltd
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+class ContainerState():
+
+ def __init__(self, **kwargs):
+ for key, value in kwargs.iteritems():
+ setattr(self, key, value)
More information about the lxc-devel
mailing list