Giuseppe Lavagetto has uploaded a new change for review.
https://gerrit.wikimedia.org/r/220536
Change subject: confctl: allow regex expression and a global "all"
......................................................................
confctl: allow regex expression and a global "all"
Change-Id: I377d5476d16c8df416bfca58f750f99c643f8a8e
---
M conftool/__init__.py
M conftool/cli/tool.py
2 files changed, 42 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/software/conftool
refs/changes/36/220536/1
diff --git a/conftool/__init__.py b/conftool/__init__.py
index 93456f7..9a28331 100644
--- a/conftool/__init__.py
+++ b/conftool/__init__.py
@@ -88,7 +88,7 @@
try:
setattr(self, key, validator(values[key]))
except Exception as e:
- _log.error("Value for key %s is invalid: %s",
+ _log.info("Value for key %s is invalid: %s",
key, e)
if set_defaults:
val = self.get_default(key)
diff --git a/conftool/cli/tool.py b/conftool/cli/tool.py
index 31e9fad..9de0462 100644
--- a/conftool/cli/tool.py
+++ b/conftool/cli/tool.py
@@ -8,8 +8,31 @@
from conftool.drivers import BackendError
# TODO: auto import these somehow
from conftool import service, node
+import re
object_types = {"node": node.Node, "service": service.Service}
+
+
+def host_list(self, name, cur_dir):
+ if name == "all":
+ leaves = KVObject.backend.driver.ls(cur_dir)
+ if act == "get":
+ print json.dumps(dict(leaves))
+ else:
+ for objname in leaves.keys():
+ yield objname
+ elif not name.startswith('re:'):
+ yield name
+ else:
+ regex = host.replace('re:', '', 1)
+ try:
+ r = re.compile(regex)
+ except:
+ _log.critical("Invalid regexp: %s", regex)
+ sys.exit(1)
+ for objname in KVObject.backend.driver.ls(cur_dir).keys():
+ if r.match(objname):
+ yield objname
def main(cmdline=None):
@@ -59,26 +82,24 @@
sys.exit(1)
for unit in args.action:
- try:
- act, name = unit
- if act == 'get' and name == "all":
- cur_dir = cls.dir(*tags)
- print json.dumps(dict(KVObject.backend.driver.ls(cur_dir)))
- return
- # Oh python I <3 you...
- arguments = list(tags)
- arguments.append(name)
- obj = cls(*arguments)
- a = action.Action(obj, act)
- msg = a.run()
- except action.ActionError as e:
- _log.error("Invalid action, reason: %s", str(e))
- except BackendError as e:
- _log.error("Failure writing to the kvstore: %s", str(e))
- except Exception as e:
- _log.error("Generic action failure: %s", str(e))
- else:
- print(msg)
+ act, n = unit
+ cur_dir = cls.dir(*tags)
+ for name in host_list(n, cur_dir, act):
+ try:
+ # Oh python I <3 you...
+ arguments = list(tags)
+ arguments.append(name)
+ obj = cls(*arguments)
+ a = action.Action(obj, act)
+ msg = a.run()
+ except action.ActionError as e:
+ _log.error("Invalid action, reason: %s", str(e))
+ except BackendError as e:
+ _log.error("Failure writing to the kvstore: %s", str(e))
+ except Exception as e:
+ _log.error("Generic action failure: %s", str(e))
+ else:
+ print(msg)
if __name__ == '__main__':
--
To view, visit https://gerrit.wikimedia.org/r/220536
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I377d5476d16c8df416bfca58f750f99c643f8a8e
Gerrit-PatchSet: 1
Gerrit-Project: operations/software/conftool
Gerrit-Branch: master
Gerrit-Owner: Giuseppe Lavagetto <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits