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
             return None
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
     def _write(self, key, value):
48
     def _write(self, key, value):
41
         self._client.write(self._prefix + key, value)
49
         self._client.write(self._prefix + key, value)
42
 
50
 
93
 
101
 
94
     def get_label(self, label):
102
     def get_label(self, label):
95
         """Gets a map of container names to values for the given label."""
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
     def _notify_update(self):
112
     def _notify_update(self):

Loading…
Cancel
Save