Browse Source

Handle removing

master
Chris Smith 8 years ago
parent
commit
5c4d6b7c45
2 changed files with 20 additions and 2 deletions
  1. 3
    1
      README.md
  2. 17
    1
      report.py

+ 3
- 1
README.md View File

31
   --name (default: unknown) name of the host running docker
31
   --name (default: unknown) name of the host running docker
32
 ```
32
 ```
33
 
33
 
34
+The script will update etcd as soon as it launches, and then
35
+monitor for docker events and apply the relevant updates.
36
+
34
 ## Schema
37
 ## Schema
35
 
38
 
36
 The script stores values relating to containers, labels, hosts and
39
 The script stores values relating to containers, labels, hosts and
65
 
68
 
66
 * The docker node is deleted when the script starts, so you can't run multiple
69
 * The docker node is deleted when the script starts, so you can't run multiple
67
   copies on multiple hosts
70
   copies on multiple hosts
68
-* Containers that are stopped aren't removed
69
 * There's no way to get notified when the script has finished, rather than
71
 * There's no way to get notified when the script has finished, rather than
70
   mid-update
72
   mid-update
71
 
73
 

+ 17
- 1
report.py View File

35
   etcd_put(etcd_client, prefix + '/hosts', host_index)
35
   etcd_put(etcd_client, prefix + '/hosts', host_index)
36
 
36
 
37
 
37
 
38
+def remove_containers(old_containers):
39
+  global containers, host_index, label_index, network_index
40
+  for container in old_containers:
41
+    name = container['name']
42
+    del containers[name]
43
+    etcd_client.delete(prefix + '/containers/' + name, recursive=True)
44
+
45
+    for k, v in container['labels'].items():
46
+      del label_index[k][name]
47
+      etcd_client.delete(prefix + '/labels/' + k + '/' + name)
48
+    for k, v in container['net']['addr'].items():
49
+      del network_index[k][name]
50
+      etcd_client.delete(prefix + '/networks/' + k + '/' + name)
51
+    etcd_client.delete(prefix + '/hosts/' + host + '/' + name)
52
+
53
+
38
 parser = argparse.ArgumentParser()
54
 parser = argparse.ArgumentParser()
39
 parser.add_argument('--name', help='Name of this docker host', default='unknown')
55
 parser.add_argument('--name', help='Name of this docker host', default='unknown')
40
 parser.add_argument('--etcd-port', type=int, help='Port to connect to etcd on', default=2379)
56
 parser.add_argument('--etcd-port', type=int, help='Port to connect to etcd on', default=2379)
42
 parser.add_argument('--etcd-prefix', help='Prefix to use when adding keys to etcd', default='/docker')
58
 parser.add_argument('--etcd-prefix', help='Prefix to use when adding keys to etcd', default='/docker')
43
 args = parser.parse_args()
59
 args = parser.parse_args()
44
 
60
 
45
-monitor = Monitor(args.name, add_containers, lambda x: None) 
61
+monitor = Monitor(args.name, add_containers, remove_containers)
46
 etcd_client = etcd.Client(host=args.etcd_host, port=args.etcd_port)
62
 etcd_client = etcd.Client(host=args.etcd_host, port=args.etcd_port)
47
 prefix = args.etcd_prefix
63
 prefix = args.etcd_prefix
48
 host = args.name
64
 host = args.name

Loading…
Cancel
Save