summaryrefslogtreecommitdiffstats
path: root/tools/upgrade
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-04-23 14:50:09 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-04-23 14:50:09 -0400
commit46a47b4120b3d892b8149a5e181e4d976ad87f99 (patch)
treef2697f233fc7f5ad5022864222a5ca87715a651b /tools/upgrade
parente1f99d1d5045e0511db42debb30aa97da2018796 (diff)
parent3d06f311274d6b942ee89d8cdb13b2ecc99af1b0 (diff)
downloadbcfg2-46a47b4120b3d892b8149a5e181e4d976ad87f99.tar.gz
bcfg2-46a47b4120b3d892b8149a5e181e4d976ad87f99.tar.bz2
bcfg2-46a47b4120b3d892b8149a5e181e4d976ad87f99.zip
Merge branch '1.4.x'
Conflicts: debian/bcfg2-server.install doc/server/plugins/grouping/metadata.txt src/lib/Bcfg2/Client/Client.py src/lib/Bcfg2/Client/Tools/Portage.py src/lib/Bcfg2/Client/Tools/RcUpdate.py src/lib/Bcfg2/Client/Tools/YUM24.py src/lib/Bcfg2/Client/Tools/__init__.py src/lib/Bcfg2/Client/Tools/launchd.py src/lib/Bcfg2/Options.py src/lib/Bcfg2/Server/Core.py src/lib/Bcfg2/Server/Plugin/helpers.py src/lib/Bcfg2/Server/Plugins/Metadata.py src/lib/Bcfg2/Server/models.py src/lib/Bcfg2/Utils.py src/sbin/bcfg2-info src/sbin/bcfg2-test testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py testsuite/Testsrc/test_code_checks.py
Diffstat (limited to 'tools/upgrade')
-rw-r--r--tools/upgrade/1.4/README6
-rwxr-xr-xtools/upgrade/1.4/migrate_decisions.py82
2 files changed, 88 insertions, 0 deletions
diff --git a/tools/upgrade/1.4/README b/tools/upgrade/1.4/README
new file mode 100644
index 000000000..b6ff8d8c8
--- /dev/null
+++ b/tools/upgrade/1.4/README
@@ -0,0 +1,6 @@
+This directory contains scripts to help with upgrading from Bcfg2 1.3
+to 1.4.
+
+migrate_decisions.py
+ - Convert old group- and host-specific whitelist and blacklist
+ files into structured XML
diff --git a/tools/upgrade/1.4/migrate_decisions.py b/tools/upgrade/1.4/migrate_decisions.py
new file mode 100755
index 000000000..f7072783a
--- /dev/null
+++ b/tools/upgrade/1.4/migrate_decisions.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+
+import os
+import re
+import sys
+import glob
+import lxml.etree
+import Bcfg2.Options
+from Bcfg2.Server import XMLParser
+
+
+SPECIFIC = re.compile(r'.*\/(white|black)list'
+ r'(\.(H_(?P<host>.*)|G\d+_(?P<group>.*)))?$')
+
+
+def convert(files, xdata):
+ hosts = []
+ groups = []
+ for oldfile in files:
+ spec = SPECIFIC.match(oldfile)
+ if spec and spec.group('host'):
+ hosts.append(spec.group('host'))
+ elif spec and spec.group('group'):
+ groups.append(spec.group('group'))
+
+ for oldfile in files:
+ print("Converting %s" % oldfile)
+ spec = SPECIFIC.match(oldfile)
+ if not spec:
+ print("Skipping unknown file %s" % oldfile)
+ continue
+
+ parent = xdata
+ if spec.group('host'):
+ for host in hosts:
+ if host != spec.group('host'):
+ parent = lxml.etree.SubElement(parent, "Client",
+ name=host, negate="true")
+ parent = lxml.etree.SubElement(parent, "Client",
+ name=spec.group('host'))
+ elif spec.group('group'):
+ for host in hosts:
+ parent = lxml.etree.SubElement(parent, "Client",
+ name=host, negate="true")
+ for group in groups:
+ if group != spec.group('group'):
+ parent = lxml.etree.SubElement(parent, "Group",
+ name=group, negate="true")
+ parent = lxml.etree.SubElement(parent, "Group",
+ name=spec.group('group'))
+ parent.append(lxml.etree.Comment("Converted from %s" % oldfile))
+ olddata = lxml.etree.parse(oldfile, parser=Bcfg2.Server.XMLParser)
+ for decision in olddata.xpath('//Decision'):
+ parent.append(decision)
+ return xdata
+
+
+def main():
+ opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY,
+ configfile=Bcfg2.Options.CFILE)
+ setup = Bcfg2.Options.load_option_parser(opts)
+ setup.parse(sys.argv[1:])
+
+ datadir = os.path.join(setup['repo'], 'Decisions')
+ whitelist = lxml.etree.Element("Decisions")
+ blacklist = lxml.etree.Element("Decisions")
+ if os.path.exists(datadir):
+ convert(glob.glob(os.path.join(datadir, 'whitelist*')),
+ whitelist)
+ convert(glob.glob(os.path.join(datadir, 'blacklist*')),
+ blacklist)
+
+ print("Writing %s" % os.path.join(datadir, "whitelist.xml"))
+ open(os.path.join(datadir, "whitelist.xml"),
+ 'w').write(lxml.etree.tostring(whitelist, pretty_print=True))
+ print("Writing %s" % os.path.join(datadir, "blacklist.xml"))
+ open(os.path.join(datadir, "blacklist.xml"),
+ 'w').write(lxml.etree.tostring(blacklist, pretty_print=True))
+
+
+if __name__ == '__main__':
+ sys.exit(main())