Mercurial > code > home > repos > homeauto
annotate service/arduinoNode/pushConfig.py @ 1426:c3c2418d138c
fix pushconfig host lookup
Ignore-this: d53a114fdfb3bd3bf355a0c7293a1c7b
darcs-hash:6306237a7df35fffb57f27c31a971107608f979e
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Wed, 07 Aug 2019 21:06:46 -0700 |
parents | 672a3d830e7f |
children | 6b80a6c58907 |
rev | line source |
---|---|
1138 | 1 from __future__ import division |
1148 | 2 import sys |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
3 import etcd3 |
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
4 |
1138 | 5 from twisted.python.filepath import FilePath |
6 | |
1426 | 7 etcd = etcd3.client(host='bang', port=9022) |
1138 | 8 |
1148 | 9 prefix, = sys.argv[1:] |
10 | |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
11 def main(): |
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
12 existing = set(md.key for v, md in etcd.get_prefix(prefix)) |
1138 | 13 written = set() |
14 root = FilePath('config') | |
1259
672a3d830e7f
arduinoNode: build updates, stats support, etc
drewp <drewp@bigasterisk.com>
parents:
1148
diff
changeset
|
15 print 'reading at %s' % root |
1138 | 16 for f in root.walk(): |
17 if f.isfile() and f.path.endswith('.n3'): | |
18 n3 = f.getContent() | |
19 key = prefix + b'/'.join(f.segmentsFrom(root)) | |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
20 etcd.put(key, n3) |
1138 | 21 written.add(key) |
22 print 'wrote %s' % key | |
23 for k in existing - written: | |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
24 etcd.delete(k) |
1138 | 25 print 'removed %s' % k |
26 | |
1139
db955e7943af
arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents:
1138
diff
changeset
|
27 main() |