[lxc-devel] [pylxd/master] Adjust in the function snapshot.all()

shazaum on Github lxc-bot at linuxcontainers.org
Tue Sep 26 13:58:37 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 397 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170926/b5b8807b/attachment.bin>
-------------- next part --------------
From 94aec45579145bcaeee3bd60ef793db00a6ba41d Mon Sep 17 00:00:00 2001
From: Renato dos Santos <shazaum at gmail.com>
Date: Tue, 26 Sep 2017 10:40:38 -0300
Subject: [PATCH] Ajuste na funcao snapshot.all()

---
 pylxd/client.py           |  1 +
 pylxd/models/container.py | 17 +++++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)
 mode change 100644 => 100755 pylxd/client.py
 mode change 100644 => 100755 pylxd/models/container.py

diff --git a/pylxd/client.py b/pylxd/client.py
old mode 100644
new mode 100755
index d4fb2a7..9560482
--- a/pylxd/client.py
+++ b/pylxd/client.py
@@ -237,6 +237,7 @@ def __init__(
         self.networks = managers.NetworkManager(self)
         self.operations = managers.OperationManager(self)
         self.profiles = managers.ProfileManager(self)
+        self.snapshot = managers.SnapshotManager(self)
 
     @property
     def trusted(self):
diff --git a/pylxd/models/container.py b/pylxd/models/container.py
old mode 100644
new mode 100755
index 415ea37..dd59b0d
--- a/pylxd/models/container.py
+++ b/pylxd/models/container.py
@@ -384,13 +384,18 @@ def get(cls, client, container, name):
         return snapshot
 
     @classmethod
-    def all(cls, client, container):
-        response = client.api.containers[container.name].snapshots.get()
 
-        return [cls(
-                client, name=snapshot.split('/')[-1],
-                container=container)
-                for snapshot in response.json()['metadata']]
+    def all(cls, client):
+        response = client.api.containers.get()
+        containers = []
+        for url in response.json()['metadata']:
+            name = url.split('/')[3]
+            name = client.api.containers[name].snapshots.get().json()['metadata']
+            if [] != name:
+                name = name[0].split('/')[-1]
+                containers.append(cls(client, name=name))
+
+        return containers
 
     @classmethod
     def create(cls, client, container, name, stateful=False, wait=False):


More information about the lxc-devel mailing list