Browse Source

Add method to get networks for a container.

master
Chris Smith 8 years ago
parent
commit
e1898c4177
1 changed files with 14 additions and 5 deletions
  1. 14
    5
      etcdlib.py

+ 14
- 5
etcdlib.py View File

@@ -37,6 +37,14 @@ class Connection:
37 37
             return None
38 38
 
39 39
 
40
+    def _read_map(self, key):
41
+        node = self._read_recursive(key)
42
+        if node:
43
+            return {child.key.split('/')[-1]: child.value for child in node.children}
44
+        else:
45
+            return {}
46
+
47
+
40 48
     def _write(self, key, value):
41 49
         self._client.write(self._prefix + key, value)
42 50
 
@@ -93,11 +101,12 @@ class Connection:
93 101
 
94 102
     def get_label(self, label):
95 103
         """Gets a map of container names to values for the given label."""
96
-        node = self._read_recursive('/labels/%s' % label)
97
-        if node:
98
-            return {child.key.split('/')[-1]: child.value for child in node.children}
99
-        else:
100
-            return {}
104
+        return self._read_map('/labels/%s' % label)
105
+
106
+
107
+    def get_networks(self, container):
108
+        """Gets a map of network names to the specified container's IP on that network."""
109
+        return self._read_map('/containers/%s/net/addr' % container)
101 110
 
102 111
 
103 112
     def _notify_update(self):

Loading…
Cancel
Save