summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-06-27 10:36:17 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-06-27 10:42:32 -0400
commitcd14868d4db8eaa7e9421e1d5fe8653294ac1e38 (patch)
tree52ad2955c9d81a979d5242262a0209eafd3a12d4 /tools
parent02783685f003b740b2ced28566833a46d3da07f1 (diff)
downloadbcfg2-cd14868d4db8eaa7e9421e1d5fe8653294ac1e38.tar.gz
bcfg2-cd14868d4db8eaa7e9421e1d5fe8653294ac1e38.tar.bz2
bcfg2-cd14868d4db8eaa7e9421e1d5fe8653294ac1e38.zip
Options: migrated tools to new parser
Diffstat (limited to 'tools')
-rwxr-xr-xtools/bcfg2_local.py44
-rwxr-xr-xtools/posixusers_baseline.py94
-rwxr-xr-xtools/selinux_baseline.py33
-rwxr-xr-x[-rw-r--r--]tools/upgrade/1.1/posixunified.py13
-rwxr-xr-xtools/upgrade/1.2/nagiosgen-convert.py15
-rwxr-xr-xtools/upgrade/1.2/packages-convert.py15
-rwxr-xr-xtools/upgrade/1.3/migrate_configs.py51
-rwxr-xr-xtools/upgrade/1.3/migrate_dbstats.py20
-rwxr-xr-xtools/upgrade/1.3/migrate_info.py26
-rwxr-xr-xtools/upgrade/1.3/migrate_perms_to_mode.py17
-rwxr-xr-xtools/upgrade/1.3/service_modes.py12
-rw-r--r--tools/upgrade/1.4/README3
-rwxr-xr-xtools/upgrade/1.4/convert_bundles.py32
-rwxr-xr-xtools/upgrade/1.4/migrate_decisions.py12
14 files changed, 193 insertions, 194 deletions
diff --git a/tools/bcfg2_local.py b/tools/bcfg2_local.py
index 8c164e52e..5022f7064 100755
--- a/tools/bcfg2_local.py
+++ b/tools/bcfg2_local.py
@@ -6,19 +6,19 @@ the server core, then uses that to get probes, run them, and so on."""
import sys
import socket
import Bcfg2.Options
-from Bcfg2.Client.Client import Client
-from Bcfg2.Server.Core import BaseCore
+from Bcfg2.Client import Client
+from Bcfg2.Server.Core import Core
-class LocalCore(BaseCore):
+class LocalCore(Core):
""" Local server core similar to the one started by bcfg2-info """
- def __init__(self, setup):
- saved = (setup['syslog'], setup['logging'])
- setup['syslog'] = False
- setup['logging'] = None
- Bcfg2.Server.Core.BaseCore.__init__(self, setup=setup)
- setup['syslog'], setup['logging'] = saved
+ def __init__(self):
+ #saved = (setup['syslog'], setup['logging'])
+ #setup['syslog'] = False
+ #setup['logging'] = None
+ Bcfg2.Server.Core.BaseCore.__init__(self)
+ #setup['syslog'], setup['logging'] = saved
self.load_plugins()
self.fam.handle_events_in_interval(0.1)
@@ -57,26 +57,22 @@ class LocalClient(Client):
""" A version of the Client class that uses LocalProxy instead of
an XML-RPC proxy to make its calls """
- def __init__(self, setup, proxy):
- Client.__init__(self, setup)
+ def __init__(self, proxy):
+ Client.__init__(self)
self._proxy = proxy
def main():
- optinfo = Bcfg2.Options.CLIENT_COMMON_OPTIONS
- optinfo.update(Bcfg2.Options.SERVER_COMMON_OPTIONS)
- if 'bundle_quick' in optinfo:
- # CLIENT_BUNDLEQUICK option uses -Q, just like the server repo
- # option. the server repo is more important for this
- # application.
- optinfo['bundle_quick'] = Bcfg2.Options.Option('bundlequick',
- default=False)
- setup = Bcfg2.Options.OptionParser(optinfo)
- setup.parse(sys.argv[1:])
-
- core = LocalCore(setup)
+ parser = Bcfg2.Options.Parser(
+ description="Run a Bcfg2 client against a local repository without a "
+ "server",
+ conflict_handler="resolve",
+ components=[LocalCore, LocalProxy, LocalClient])
+ parser.parse()
+
+ core = LocalCore()
try:
- LocalClient(setup, LocalProxy(core)).run()
+ LocalClient(LocalProxy(core)).run()
finally:
core.shutdown()
diff --git a/tools/posixusers_baseline.py b/tools/posixusers_baseline.py
index c45e54f1a..1f89c7cb6 100755
--- a/tools/posixusers_baseline.py
+++ b/tools/posixusers_baseline.py
@@ -2,72 +2,46 @@
import grp
import sys
-import logging
import lxml.etree
import Bcfg2.Logger
+import Bcfg2.Options
from Bcfg2.Client.Tools.POSIXUsers import POSIXUsers
-from Bcfg2.Options import OptionParser, Option, get_bool, CLIENT_COMMON_OPTIONS
-def get_setup():
- optinfo = CLIENT_COMMON_OPTIONS
- optinfo['nouids'] = Option("Do not include UID numbers for users",
- default=False,
- cmd='--no-uids',
- long_arg=True,
- cook=get_bool)
- optinfo['nogids'] = Option("Do not include GID numbers for groups",
- default=False,
- cmd='--no-gids',
- long_arg=True,
- cook=get_bool)
- setup = OptionParser(optinfo)
- setup.parse(sys.argv[1:])
+class CLI(object):
+ options = [
+ Bcfg2.Options.BooleanOption(
+ "--no-uids", help="Do not include UID numbers for users"),
+ Bcfg2.Options.BooleanOption(
+ "--no-gids", help="Do not include GID numbers for groups")]
- if setup['args']:
- print("posixuser_[baseline.py takes no arguments, only options")
- print(setup.buildHelpMessage())
- raise SystemExit(1)
- level = 30
- if setup['verbose']:
- level = 20
- if setup['debug']:
- level = 0
- Bcfg2.Logger.setup_logging('posixusers_baseline.py',
- to_syslog=False,
- level=level,
- to_file=setup['logging'])
- return setup
-
-
-def main():
- setup = get_setup()
- if setup['file']:
- config = lxml.etree.parse(setup['file']).getroot()
- else:
+ def __init__(self):
+ Bcfg2.Options.get_parser(
+ description="Generate a bundle with a baseline of POSIX users and "
+ "groups",
+ components=[self, POSIXUsers]).parse()
config = lxml.etree.Element("Configuration")
- users = POSIXUsers(logging.getLogger('posixusers_baseline.py'),
- setup, config)
-
- baseline = lxml.etree.Element("Bundle", name="posixusers_baseline")
- for entry in users.FindExtra():
- data = users.existing[entry.tag][entry.get("name")]
- for attr, idx in users.attr_mapping[entry.tag].items():
- if (entry.get(attr) or
- (attr == 'uid' and setup['nouids']) or
- (attr == 'gid' and setup['nogids'])):
- continue
- entry.set(attr, str(data[idx]))
- if entry.tag == 'POSIXUser':
- entry.set("group", grp.getgrgid(data[3])[0])
- for group in users.user_supplementary_groups(entry):
- memberof = lxml.etree.SubElement(entry, "MemberOf",
- group=group[0])
-
- entry.tag = "Bound" + entry.tag
- baseline.append(entry)
-
- print(lxml.etree.tostring(baseline, pretty_print=True))
+ self.users = POSIXUsers(config)
+
+ def run(self):
+ baseline = lxml.etree.Element("Bundle", name="posixusers_baseline")
+ for entry in self.users.FindExtra():
+ data = self.users.existing[entry.tag][entry.get("name")]
+ for attr, idx in self.users.attr_mapping[entry.tag].items():
+ if (entry.get(attr) or
+ (attr == 'uid' and Bcfg2.Options.setup.no_uids) or
+ (attr == 'gid' and Bcfg2.Options.setup.no_gids)):
+ continue
+ entry.set(attr, str(data[idx]))
+ if entry.tag == 'POSIXUser':
+ entry.set("group", grp.getgrgid(data[3])[0])
+ for group in self.users.user_supplementary_groups(entry):
+ lxml.etree.SubElement(entry, "MemberOf", group=group[0])
+
+ entry.tag = "Bound" + entry.tag
+ baseline.append(entry)
+
+ print(lxml.etree.tostring(baseline, pretty_print=True))
if __name__ == "__main__":
- sys.exit(main())
+ sys.exit(CLI().run())
diff --git a/tools/selinux_baseline.py b/tools/selinux_baseline.py
index 507a16f43..ad2a40426 100755
--- a/tools/selinux_baseline.py
+++ b/tools/selinux_baseline.py
@@ -1,41 +1,18 @@
#!/usr/bin/env python
import sys
-import logging
import lxml.etree
-
import Bcfg2.Logger
import Bcfg2.Options
-from Bcfg2.Client.Tools.SELinux import *
-
-LOGGER = None
-
-def get_setup():
- global LOGGER
- optinfo = Bcfg2.Options.CLIENT_COMMON_OPTIONS
- setup = Bcfg2.Options.OptionParser(optinfo)
- setup.parse(sys.argv[1:])
+from Bcfg2.Client.Tools.SELinux import SELinux
- if setup['args']:
- print("selinux_baseline.py takes no arguments, only options")
- print(setup.buildHelpMessage())
- raise SystemExit(1)
- level = 30
- if setup['verbose']:
- level = 20
- if setup['debug']:
- level = 0
- Bcfg2.Logger.setup_logging('selinux_base',
- to_syslog=False,
- level=level,
- to_file=setup['logging'])
- LOGGER = logging.getLogger('bcfg2')
- return setup
def main():
- setup = get_setup()
+ Bcfg2.Options.get_parser(
+ description="Get a baseline bundle of SELinux entries",
+ components=[SELinux]).parse()
config = lxml.etree.Element("Configuration")
- selinux = SELinux(LOGGER, setup, config)
+ selinux = SELinux(config)
baseline = lxml.etree.Element("Bundle", name="selinux_baseline")
for etype, handler in selinux.handlers.items():
diff --git a/tools/upgrade/1.1/posixunified.py b/tools/upgrade/1.1/posixunified.py
index 8eb4ed734..b6ce7bc90 100644..100755
--- a/tools/upgrade/1.1/posixunified.py
+++ b/tools/upgrade/1.1/posixunified.py
@@ -17,12 +17,13 @@ NOTE: This script takes a conservative approach when it comes to
"""
if __name__ == '__main__':
- opts = {
- 'repo': Bcfg2.Options.SERVER_REPOSITORY,
- }
- setup = Bcfg2.Options.OptionParser(opts)
- setup.parse(sys.argv[1:])
- repo = setup['repo']
+ parser = Bcfg2.Options.get_parser(
+ description="Migrate from Bcfg2 1.0-style POSIX entries to 1.1-style "
+ "unified Path entries")
+ parser.add_options([Bcfg2.Options.Common.repository])
+ parser.parse()
+
+ repo = Bcfg2.Options.setup.repository
unifiedposixrules = "%s/Rules/unified-rules.xml" % repo
rulesroot = lxml.etree.Element("Rules")
diff --git a/tools/upgrade/1.2/nagiosgen-convert.py b/tools/upgrade/1.2/nagiosgen-convert.py
index 2c2142735..eb10cd4ea 100755
--- a/tools/upgrade/1.2/nagiosgen-convert.py
+++ b/tools/upgrade/1.2/nagiosgen-convert.py
@@ -7,10 +7,13 @@ import lxml.etree
import Bcfg2.Options
def main():
- opts = {'repo': Bcfg2.Options.SERVER_REPOSITORY}
- setup = Bcfg2.Options.OptionParser(opts)
- setup.parse(sys.argv[1:])
- repo = setup['repo']
+ parser = Bcfg2.Options.get_parser(
+ description="Migrate from Bcfg2 1.1-style Properties-based NagiosGen "
+ "configuration to standalone 1.2-style")
+ parser.add_options([Bcfg2.Options.Common.repository])
+ parser.parse()
+
+ repo = Bcfg2.Options.setup.repository
oldconfigfile = os.path.join(repo, 'Properties', 'NagiosGen.xml')
newconfigpath = os.path.join(repo, 'NagiosGen')
newconfigfile = os.path.join(newconfigpath, 'config.xml')
@@ -32,11 +35,11 @@ def main():
if host.tag == lxml.etree.Comment:
# skip comments
continue
-
+
if host.tag == 'default':
print("default tag will not be converted; use a suitable Group tag instead")
continue
-
+
newhost = lxml.etree.Element("Client", name=host.tag)
for opt in host:
newopt = lxml.etree.Element("Option", name=opt.tag)
diff --git a/tools/upgrade/1.2/packages-convert.py b/tools/upgrade/1.2/packages-convert.py
index d65ce90a2..eb1f2f7de 100755
--- a/tools/upgrade/1.2/packages-convert.py
+++ b/tools/upgrade/1.2/packages-convert.py
@@ -30,10 +30,13 @@ def place_source(xdata, source, groups):
return xdata
def main():
- opts = {'repo': Bcfg2.Options.SERVER_REPOSITORY}
- setup = Bcfg2.Options.OptionParser(opts)
- setup.parse(sys.argv[1:])
- repo = setup['repo']
+ parser = Bcfg2.Options.get_parser(
+ description="Migrate from Bcfg2 1.1-style Packages configuration to "
+ "1.2-style")
+ parser.add_options([Bcfg2.Options.Common.repository])
+ parser.parse()
+
+ repo = Bcfg2.Options.setup.repository
configpath = os.path.join(repo, 'Packages')
oldconfigfile = os.path.join(configpath, 'config.xml')
newconfigfile = os.path.join(configpath, 'packages.conf')
@@ -78,7 +81,7 @@ def main():
if el.tag == lxml.etree.Comment or el.tag == 'Config':
# skip comments and Config
continue
-
+
if el.tag == XI + 'include':
oldsources.append(os.path.join(configpath, el.get('href')))
newsource.append(el)
@@ -98,7 +101,7 @@ def main():
newel.set(tag.lower(), el.find(tag).text)
except AttributeError:
pass
-
+
for child in el.getchildren():
if child.tag in ['Component', 'Blacklist', 'Whitelist', 'Arch']:
newel.append(child)
diff --git a/tools/upgrade/1.3/migrate_configs.py b/tools/upgrade/1.3/migrate_configs.py
index b7adb2528..9fa362acf 100755
--- a/tools/upgrade/1.3/migrate_configs.py
+++ b/tools/upgrade/1.3/migrate_configs.py
@@ -16,13 +16,13 @@ def copy_section(src_file, tgt_cfg, section, newsection=None):
tgt_cfg.add_section(newsection)
except ConfigParser.DuplicateSectionError:
print("[%s] section already exists in %s, adding options" %
- (newsection, setup['cfile']))
+ (newsection, Bcfg2.Options.setup.config))
for opt in cfg.options(section):
val = cfg.get(section, opt)
if tgt_cfg.has_option(newsection, opt):
print("%s in [%s] already populated in %s, skipping" %
- (opt, newsection, setup['cfile']))
- print(" %s: %s" % (setup['cfile'],
+ (opt, newsection, Bcfg2.Options.setup.config))
+ print(" %s: %s" % (Bcfg2.Options.setup.config,
tgt_cfg.get(newsection, opt)))
print(" %s: %s" % (src_file, val))
else:
@@ -30,47 +30,50 @@ def copy_section(src_file, tgt_cfg, section, newsection=None):
tgt_cfg.set(newsection, opt, val)
def main():
- opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY,
- configfile=Bcfg2.Options.CFILE)
- setup = Bcfg2.Options.OptionParser(opts)
- setup.parse(sys.argv[1:])
+ parser = Bcfg2.Options.get_parser(
+ description="Migrate from Bcfg2 1.2 per-plugin config files to 1.3 "
+ "unified config file")
+ parser.add_options([Bcfg2.Options.Common.repository])
+ parser.parse()
+ repo = Bcfg2.Options.setup.repository
+ cfp = ConfigParser.ConfigParser()
+ cfp.read(Bcfg2.Options.setup.config)
# files that you should remove manually
remove = []
# move rules config out of rules.conf and into bcfg2.conf
- rules_conf = os.path.join(setup['repo'], 'Rules', 'rules.conf')
+ rules_conf = os.path.join(repo, 'Rules', 'rules.conf')
if os.path.exists(rules_conf):
remove.append(rules_conf)
- copy_section(rules_conf, setup.cfp, "rules")
-
+ copy_section(rules_conf, cfp, "rules")
+
# move packages config out of packages.conf and into bcfg2.conf
- pkgs_conf = os.path.join(setup['repo'], 'Packages', 'packages.conf')
+ pkgs_conf = os.path.join(repo, 'Packages', 'packages.conf')
if os.path.exists(pkgs_conf):
remove.append(pkgs_conf)
- copy_section(pkgs_conf, setup.cfp, "global", newsection="packages")
+ copy_section(pkgs_conf, cfp, "global", newsection="packages")
for section in ["apt", "yum", "pulp"]:
- copy_section(pkgs_conf, setup.cfp, section,
+ copy_section(pkgs_conf, cfp, section,
newsection="packages:" + section)
# move reports database config into [database] section
- if setup.cfp.has_section("statistics"):
- if not setup.cfp.has_section("database"):
- setup.cfp.add_section("database")
- for opt in setup.cfp.options("statistics"):
+ if cfp.has_section("statistics"):
+ if not cfp.has_section("database"):
+ cfp.add_section("database")
+ for opt in cfp.options("statistics"):
if opt.startswith("database_"):
newopt = opt[9:]
- if setup.cfp.has_option("database", newopt):
+ if cfp.has_option("database", newopt):
print("%s in [database] already populated, skipping" %
newopt)
else:
- setup.cfp.set("database", newopt,
- setup.cfp.get("statistics", opt))
- setup.cfp.remove_option("statistics", opt)
+ cfp.set("database", newopt, cfp.get("statistics", opt))
+ cfp.remove_option("statistics", opt)
- print("Writing %s" % setup['configfile'])
+ print("Writing %s" % Bcfg2.Options.setup.config)
try:
- setup.cfp.write(open(setup['configfile'], "w"))
+ cfp.write(open(Bcfg2.Options.setup.config, "w"))
if len(remove):
print("Settings were migrated, but you must remove these files "
"manually:")
@@ -78,7 +81,7 @@ def main():
print(" %s" % path)
except IOError:
err = sys.exc_info()[1]
- print("Could not write %s: %s" % (setup['configfile'], err))
+ print("Could not write %s: %s" % (Bcfg2.Options.setup.config, err))
if __name__ == '__main__':
sys.exit(main())
diff --git a/tools/upgrade/1.3/migrate_dbstats.py b/tools/upgrade/1.3/migrate_dbstats.py
index 07def2ac8..f52ccab08 100755
--- a/tools/upgrade/1.3/migrate_dbstats.py
+++ b/tools/upgrade/1.3/migrate_dbstats.py
@@ -9,10 +9,9 @@ import logging
import time
import Bcfg2.Logger
import Bcfg2.Options
-from django.core.cache import cache
from django.db import connection, transaction, backend
-from Bcfg2.Server.Admin.Reports import Reports
+from Bcfg2.Server.Admin import UpdateReports
from Bcfg2.Reporting import models as new_models
from Bcfg2.Reporting.utils import BatchFetch
from Bcfg2.Server.Reports.reports import models as legacy_models
@@ -281,17 +280,10 @@ def _restructure():
if __name__ == '__main__':
- Bcfg2.Logger.setup_logging('bcfg2-report-collector',
- to_console=logging.INFO,
- level=logging.INFO)
-
- optinfo = dict()
- optinfo.update(Bcfg2.Options.CLI_COMMON_OPTIONS)
- optinfo.update(Bcfg2.Options.SERVER_COMMON_OPTIONS)
- setup = Bcfg2.Options.OptionParser(optinfo)
- setup.parse(sys.argv[1:])
-
- #sync!
- Reports(setup).__call__(['update'])
+ parser = Bcfg2.Options.get_parser(
+ description="Migrate from Bcfg2 1.2 DBStats plugin to 1.3 Reporting "
+ "subsystem",
+ components=[UpdateReports])
+ UpdateReports().run(Bcfg2.Options.setup)
_restructure()
diff --git a/tools/upgrade/1.3/migrate_info.py b/tools/upgrade/1.3/migrate_info.py
index 3ccbf0285..7f3bb9a29 100755
--- a/tools/upgrade/1.3/migrate_info.py
+++ b/tools/upgrade/1.3/migrate_info.py
@@ -5,7 +5,16 @@ import re
import sys
import lxml.etree
import Bcfg2.Options
-from Bcfg2.Server.Plugin import INFO_REGEX
+
+INFO_REGEX = re.compile(r'owner:\s*(?P<owner>\S+)|' +
+ r'group:\s*(?P<group>\S+)|' +
+ r'mode:\s*(?P<mode>\w+)|' +
+ r'secontext:\s*(?P<secontext>\S+)|' +
+ r'paranoid:\s*(?P<paranoid>\S+)|' +
+ r'sensitive:\s*(?P<sensitive>\S+)|' +
+ r'encoding:\s*(?P<encoding>\S+)|' +
+ r'important:\s*(?P<important>\S+)|' +
+ r'mtime:\s*(?P<mtime>\w+)')
PERMS_REGEX = re.compile(r'perms:\s*(?P<perms>\w+)')
@@ -32,16 +41,17 @@ def convert(info_file):
def main():
- opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY,
- configfile=Bcfg2.Options.CFILE,
- plugins=Bcfg2.Options.SERVER_PLUGINS)
- setup = Bcfg2.Options.OptionParser(opts)
- setup.parse(sys.argv[1:])
+ parser = Bcfg2.Options.get_parser(
+ description="Migrate from Bcfg2 1.2 info/:info files to 1.3 info.xml")
+ parser.add_options([Bcfg2.Options.Common.repository,
+ Bcfg2.Options.Common.plugins])
+ parser.parse()
- for plugin in setup['plugins']:
+ for plugin in Bcfg2.Options.setup.plugins:
if plugin not in ['SSLCA', 'Cfg', 'TGenshi', 'TCheetah', 'SSHbase']:
continue
- for root, dirs, files in os.walk(os.path.join(setup['repo'], plugin)):
+ datastore = os.path.join(Bcfg2.Options.setup.repository, plugin)
+ for root, dirs, files in os.walk(datastore):
for fname in files:
if fname in [":info", "info"]:
convert(os.path.join(root, fname))
diff --git a/tools/upgrade/1.3/migrate_perms_to_mode.py b/tools/upgrade/1.3/migrate_perms_to_mode.py
index 18abffec2..786df0de6 100755
--- a/tools/upgrade/1.3/migrate_perms_to_mode.py
+++ b/tools/upgrade/1.3/migrate_perms_to_mode.py
@@ -54,16 +54,17 @@ def convertstructure(structfile):
def main():
- opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY,
- configfile=Bcfg2.Options.CFILE,
- plugins=Bcfg2.Options.SERVER_PLUGINS)
- setup = Bcfg2.Options.OptionParser(opts)
- setup.parse(sys.argv[1:])
- repo = setup['repo']
+ parser = Bcfg2.Options.get_parser(
+ description="Migrate from Bcfg2 1.2 'perms' attribute to 1.3 'mode' "
+ "attribute")
+ parser.add_options([Bcfg2.Options.Common.repository,
+ Bcfg2.Options.Common.plugins])
+ parser.parse()
+ repo = Bcfg2.Options.setup.repository
- for plugin in setup['plugins']:
+ for plugin in Bcfg2.Options.setup.plugins:
if plugin in ['Base', 'Bundler', 'Rules']:
- for root, dirs, files in os.walk(os.path.join(repo, plugin)):
+ for root, _, files in os.walk(os.path.join(repo, plugin)):
for fname in files:
convertstructure(os.path.join(root, fname))
if plugin not in ['Cfg', 'TGenshi', 'TCheetah', 'SSHbase', 'SSLCA']:
diff --git a/tools/upgrade/1.3/service_modes.py b/tools/upgrade/1.3/service_modes.py
index 0c458c3a9..d8e3c9e6f 100755
--- a/tools/upgrade/1.3/service_modes.py
+++ b/tools/upgrade/1.3/service_modes.py
@@ -6,14 +6,18 @@ 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:])
+ parser = Bcfg2.Options.get_parser(
+ description="Migrate from Bcfg2 1.2 Service modes to 1.3-style "
+ "granular Service specification")
+ parser.add_options([Bcfg2.Options.Common.repository])
+ parser.parse()
files = []
for plugin in ['Bundler', 'Rules', 'Default']:
- files.extend(glob.glob(os.path.join(setup['repo'], plugin, "*")))
+ files.extend(glob.glob(os.path.join(Bcfg2.Options.setup.repository,
+ plugin, "*")))
for bfile in files:
bdata = lxml.etree.parse(bfile)
diff --git a/tools/upgrade/1.4/README b/tools/upgrade/1.4/README
index b6ff8d8c8..58786966b 100644
--- a/tools/upgrade/1.4/README
+++ b/tools/upgrade/1.4/README
@@ -4,3 +4,6 @@ to 1.4.
migrate_decisions.py
- Convert old group- and host-specific whitelist and blacklist
files into structured XML
+
+remove_bundle_names.py
+ - Remove deprecated explicit bundle names
diff --git a/tools/upgrade/1.4/convert_bundles.py b/tools/upgrade/1.4/convert_bundles.py
new file mode 100755
index 000000000..b9cb483f2
--- /dev/null
+++ b/tools/upgrade/1.4/convert_bundles.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+import os
+import sys
+import lxml.etree
+import Bcfg2.Options
+
+
+def main():
+ parser = Bcfg2.Options.get_parser("Tool to remove bundle names")
+ parser.add_options([Bcfg2.Options.Common.repository])
+ parser.parse()
+
+ bundler_dir = os.path.join(Bcfg2.Options.setup.repository, "Bundler")
+ if os.path.exists(bundler_dir):
+ for root, _, files in os.walk(bundler_dir):
+ for fname in files:
+ bpath = os.path.join(root, fname)
+ newpath = bpath
+ if newpath.endswith(".genshi"):
+ newpath = newpath[:-6] + "xml"
+ print("Converting %s to %s" % (bpath, newpath))
+ else:
+ print("Converting %s" % bpath)
+ xroot = lxml.etree.parse(bpath)
+ xdata = xroot.getroot()
+ if 'name' in xdata.attrib:
+ del xdata.attrib['name']
+ xroot.write(bpath)
+
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/tools/upgrade/1.4/migrate_decisions.py b/tools/upgrade/1.4/migrate_decisions.py
index f7072783a..d0915f202 100755
--- a/tools/upgrade/1.4/migrate_decisions.py
+++ b/tools/upgrade/1.4/migrate_decisions.py
@@ -6,7 +6,6 @@ import sys
import glob
import lxml.etree
import Bcfg2.Options
-from Bcfg2.Server import XMLParser
SPECIFIC = re.compile(r'.*\/(white|black)list'
@@ -56,12 +55,13 @@ def convert(files, 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:])
+ parser = Bcfg2.Options.get_parser(
+ description="Migrate from Bcfg2 1.3 Decisions list format to 1.4 "
+ "format")
+ parser.add_options([Bcfg2.Options.Common.repository])
+ parser.parse()
- datadir = os.path.join(setup['repo'], 'Decisions')
+ datadir = os.path.join(Bcfg2.Options.setup.repository, 'Decisions')
whitelist = lxml.etree.Element("Decisions")
blacklist = lxml.etree.Element("Decisions")
if os.path.exists(datadir):