annotate service/arduinoNode/pushConfig.py @ 1685:6b80a6c58907

minor changes to several services
author drewp@bigasterisk.com
date Mon, 27 Sep 2021 23:12:43 -0700
parents 048a8df60e2e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
333
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
1 from __future__ import division
343
13b2a61650c1 fix pushconfig
drewp@bigasterisk.com
parents: 334
diff changeset
2 import sys
334
bb80182195c0 arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents: 333
diff changeset
3 import etcd3
bb80182195c0 arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents: 333
diff changeset
4
333
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
5 from twisted.python.filepath import FilePath
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
6
1685
6b80a6c58907 minor changes to several services
drewp@bigasterisk.com
parents: 623
diff changeset
7 etcd = etcd3.client(host='etcd-homeauto', port=9022)
333
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
8
343
13b2a61650c1 fix pushconfig
drewp@bigasterisk.com
parents: 334
diff changeset
9 prefix, = sys.argv[1:]
13b2a61650c1 fix pushconfig
drewp@bigasterisk.com
parents: 334
diff changeset
10
334
bb80182195c0 arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents: 333
diff changeset
11 def main():
bb80182195c0 arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents: 333
diff changeset
12 existing = set(md.key for v, md in etcd.get_prefix(prefix))
333
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
13 written = set()
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
14 root = FilePath('config')
456
12f9f1838fb5 arduinoNode: build updates, stats support, etc
drewp@bigasterisk.com
parents: 343
diff changeset
15 print 'reading at %s' % root
333
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
16 for f in root.walk():
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
17 if f.isfile() and f.path.endswith('.n3'):
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
18 n3 = f.getContent()
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
19 key = prefix + b'/'.join(f.segmentsFrom(root))
334
bb80182195c0 arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents: 333
diff changeset
20 etcd.put(key, n3)
333
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
21 written.add(key)
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
22 print 'wrote %s' % key
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
23 for k in existing - written:
334
bb80182195c0 arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents: 333
diff changeset
24 etcd.delete(k)
333
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
25 print 'removed %s' % k
90b469f43944 twisted pushConfig
drewp@bigasterisk.com
parents:
diff changeset
26
334
bb80182195c0 arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp@bigasterisk.com
parents: 333
diff changeset
27 main()