summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-06-05 17:34:29 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-06-05 17:34:34 -0400
commit42e619c585de45e5e4e16ae3746efb7db9f90b1e (patch)
treedfdf1905a4bf586bba321d6ab562343cf1ebc28a /tools
parentc6e7bfed9b6563b0c567997f063a8259ec548519 (diff)
downloadbcfg2-42e619c585de45e5e4e16ae3746efb7db9f90b1e.tar.gz
bcfg2-42e619c585de45e5e4e16ae3746efb7db9f90b1e.tar.bz2
bcfg2-42e619c585de45e5e4e16ae3746efb7db9f90b1e.zip
re-rationalized service modes to make them more consistent and granular
Diffstat (limited to 'tools')
-rwxr-xr-xtools/upgrade/1.3/service_modes.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/upgrade/1.3/service_modes.py b/tools/upgrade/1.3/service_modes.py
new file mode 100755
index 000000000..b658fb51e
--- /dev/null
+++ b/tools/upgrade/1.3/service_modes.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import glob
+import lxml.etree
+import Bcfg2.Options
+
+def main():
+ opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY)
+ setup = Bcfg2.Options.OptionParser(opts)
+ setup.parse(sys.argv[1:])
+
+ for bfile in glob.glob(os.path.join(setup['repo'], "Bundler", "*")):
+ bdata = lxml.etree.parse(bfile)
+ changed = False
+ for svc in bdata.xpath("//Service|//BoundService"):
+ if "mode" not in svc.attrib:
+ continue
+ mode = svc.get("mode")
+ del svc.attrib["mode"]
+ if mode not in ["default", "supervised", "interactive_only",
+ "manual"]:
+ print("Unrecognized mode on Service:%s: %s. Assuming default" %
+ (svc.get("name"), mode))
+ mode = "default"
+ if mode == "default" or mode == "supervised":
+ svc.set("restart", "true")
+ svc.set("install", "true")
+ elif mode == "interactive_only":
+ svc.set("restart", "interactive")
+ svc.set("install", "true")
+ elif mode == "manual":
+ svc.set("restart", "false")
+ svc.set("install", "false")
+ changed = True
+ if changed:
+ print("Writing %s" % bfile)
+ try:
+ open(bfile, "w").write(lxml.etree.tostring(bdata))
+ except IOError:
+ err = sys.exc_info()[1]
+ print("Could not write %s: %s" % (bfile, err))
+
+if __name__ == '__main__':
+ sys.exit(main())