annotate service/arduinoNode/pushConfig.py @ 1139:db955e7943af

arduinonode reads config from etcd. use pushConfig.py to inform all nodes Ignore-this: 3155d873bb30ca82b48ace7531a550e5 darcs-hash:0b2be13fbb4dc2571bb1bb8ac97f6a1350f36e77
author drewp <drewp@bigasterisk.com>
date Sat, 03 Mar 2018 17:53:37 -0800
parents 08615804ee0e
children 13b2a61650c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1138
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
1 from __future__ import division
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
2
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
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
5 from twisted.python.filepath import FilePath
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
6
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1138
diff changeset
7 etcd = etcd3.client(host='bang6')
1138
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
8
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1138
diff changeset
9 def main():
1138
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
10 prefix = b'arduino/'
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1138
diff changeset
11 existing = set(md.key for v, md in etcd.get_prefix(prefix))
1138
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
12 written = set()
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
13 root = FilePath('config')
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
14 for f in root.walk():
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
15 if f.isfile() and f.path.endswith('.n3'):
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
16 n3 = f.getContent()
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
17 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
18 etcd.put(key, n3)
1138
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
19 written.add(key)
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
20 print 'wrote %s' % key
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
21 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
22 etcd.delete(k)
1138
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
23 print 'removed %s' % k
08615804ee0e twisted pushConfig
drewp <drewp@bigasterisk.com>
parents:
diff changeset
24
1139
db955e7943af arduinonode reads config from etcd. use pushConfig.py to inform all nodes
drewp <drewp@bigasterisk.com>
parents: 1138
diff changeset
25 main()