Browse Source

Add argument parsing

master
Chris Smith 8 years ago
parent
commit
856627d566
3 changed files with 23 additions and 4 deletions
  1. 1
    1
      Dockerfile
  2. 11
    1
      README.md
  3. 11
    2
      report.py

+ 1
- 1
Dockerfile View File

@@ -7,4 +7,4 @@ RUN \
7 7
     python-etcd
8 8
 
9 9
 COPY report.py /report.py
10
-CMD /report.py
10
+ENTRYPOINT ["python", "/report.py"]

+ 11
- 1
README.md View File

@@ -18,7 +18,17 @@ to volume mount the docker socket:
18 18
 docker run -d --name service-reporter \
19 19
               --restart always \
20 20
               -v /var/run/docker.sock:/var/run/docker.sock \ 
21
-              csmith/service-reporter:latest
21
+              csmith/service-reporter:latest \
22
+              --arguments
23
+```
24
+
25
+The following command line arguments are available:
26
+
27
+```
28
+  --etcd-host (default: etcd) hostname where ectd is running
29
+  --etcd-port (default: 2379) port to connect to ectd on
30
+  --etcd-prefix (default: /docker) prefix to write keys to
31
+  --name (default: docker) name of the host running docker
22 32
 ```
23 33
 
24 34
 ## Schema

+ 11
- 2
report.py View File

@@ -1,8 +1,10 @@
1 1
 #!/usr/bin/env python3
2 2
 
3 3
 from collections import defaultdict
4
+import argparse
4 5
 import docker 
5 6
 import etcd
7
+import sys
6 8
 
7 9
 
8 10
 def etcd_put(client, prefix, obj):
@@ -26,9 +28,16 @@ def get_ports(container):
26 28
   return ports
27 29
 
28 30
 
31
+parser = argparse.ArgumentParser()
32
+parser.add_argument('--name', help='Name of this docker host', default='unknown')
33
+parser.add_argument('--etcd-port', type=int, help='Port to connect to etcd on', default=2379)
34
+parser.add_argument('--etcd-host', help='Host to connect to etcd on', default='etcd')
35
+parser.add_argument('--etcd-prefix', help='Prefix to use when adding keys to etcd', default='/docker')
36
+args = parser.parse_args()
37
+
29 38
 docker_client = docker.Client(base_url='unix://var/run/docker.sock')
30
-etcd_client = etcd.Client(host='etcd', port=4001)
31
-prefix = '/docker'
39
+etcd_client = etcd.Client(host=args.etcd_host, port=args.etcd_port)
40
+prefix = args.etcd_prefix
32 41
 
33 42
 containers = {}
34 43
 label_index = defaultdict(dict) 

Loading…
Cancel
Save