浏览代码

Add pydoc strings

master
Chris Smith 8 年前
父节点
当前提交
ea5253ca93
共有 1 个文件被更改,包括 20 次插入0 次删除
  1. 20
    0
      etcdlib.py

+ 20
- 0
etcdlib.py 查看文件

1
 #!/usr/bin/env python3
1
 #!/usr/bin/env python3
2
+"""Library to connect to etcd and manage docker service information."""
2
 
3
 
3
 import time
4
 import time
4
 import etcd
5
 import etcd
5
 
6
 
6
 
7
 
7
 class Connection:
8
 class Connection:
9
+    """A high-level connection to etcd.
8
 
10
 
11
+    Manages a connection to etcd, and provides high-level methods for
12
+    interacting with service records and related meta-data.
13
+
14
+    Args:
15
+        host (str): Hostname to connect to etcd on.
16
+        port (int): Port to connect to etcd on.
17
+        prefix (str): Etcd node under which the service information is stored.
18
+    """
9
 
19
 
10
     def __init__(self, host, port, prefix):
20
     def __init__(self, host, port, prefix):
11
         self._client = etcd.Client(host=host, port=port)
21
         self._client = etcd.Client(host=host, port=port)
49
 
59
 
50
 
60
 
51
     def wipe(self):
61
     def wipe(self):
62
+        """Deletes all service entries and related structures in etcd."""
52
         self._delete('')
63
         self._delete('')
53
 
64
 
54
 
65
 
55
     def add_containers(self, new_containers):
66
     def add_containers(self, new_containers):
67
+        """Writes the new containers' information to etcd."""
56
         for container in new_containers:
68
         for container in new_containers:
57
             name = container['name']
69
             name = container['name']
58
             print('Adding container %s' % name)
70
             print('Adding container %s' % name)
66
 
78
 
67
 
79
 
68
     def remove_containers(self, old_containers):
80
     def remove_containers(self, old_containers):
81
+        """Deletes the containers' entries from etcd."""
69
         for container in old_containers:
82
         for container in old_containers:
70
             name = container['name']
83
             name = container['name']
71
             print('Removing container %s' % name)
84
             print('Removing container %s' % name)
79
 
92
 
80
 
93
 
81
     def get_label(self, label):
94
     def get_label(self, label):
95
+        """Gets a map of container names to values for the given label."""
82
         node = self._read_recursive('/labels/%s' % label)
96
         node = self._read_recursive('/labels/%s' % label)
83
         if node:
97
         if node:
84
             return {child.key.split('/')[-1]: child.value for child in node.children}
98
             return {child.key.split('/')[-1]: child.value for child in node.children}
92
 
106
 
93
 
107
 
94
     def wait_for_update(self):
108
     def wait_for_update(self):
109
+        """Waits for an update to occur.
110
+
111
+        When writing entries to etcd, a special _updated key is set to the
112
+        current unix timestamp. This method watches that key until it is
113
+        changed, blocking execution.
114
+        """
95
         original_time = self._read('/_updated')
115
         original_time = self._read('/_updated')
96
         new_time = original_time
116
         new_time = original_time
97
 
117
 

正在加载...
取消
保存