diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-08-08 13:35:20 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-08-08 13:35:20 -0400 |
commit | 73c61dd6c0c464f06637db750484417bc8bbb6de (patch) | |
tree | 01381b324b6e0a44ebe49660752f31a4abca648a /tools/upgrade/1.3/migrate_configs.py | |
parent | e1e194a573b3803fa7f45a646bbb36b2f164a3e1 (diff) | |
parent | cd14868d4db8eaa7e9421e1d5fe8653294ac1e38 (diff) | |
download | bcfg2-73c61dd6c0c464f06637db750484417bc8bbb6de.tar.gz bcfg2-73c61dd6c0c464f06637db750484417bc8bbb6de.tar.bz2 bcfg2-73c61dd6c0c464f06637db750484417bc8bbb6de.zip |
Merge branch 'options-rewrite'
Conflicts:
src/lib/Bcfg2/Client/Frame.py
src/lib/Bcfg2/Options.py
src/lib/Bcfg2/Server/Admin/Init.py
src/lib/Bcfg2/Server/Admin/Xcmd.py
src/lib/Bcfg2/Server/BuiltinCore.py
src/lib/Bcfg2/Server/Core.py
src/lib/Bcfg2/Server/MultiprocessingCore.py
src/lib/Bcfg2/Server/Plugin/base.py
src/lib/Bcfg2/Server/Plugin/helpers.py
src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
src/lib/Bcfg2/Server/Plugins/Packages/__init__.py
src/lib/Bcfg2/Server/SSLServer.py
src/lib/Bcfg2/Utils.py
src/lib/Bcfg2/settings.py
src/sbin/bcfg2-crypt
src/sbin/bcfg2-info
src/sbin/bcfg2-lint
src/sbin/bcfg2-test
src/sbin/bcfg2-yum-helper
tools/bcfg2-profile-templates.py
Diffstat (limited to 'tools/upgrade/1.3/migrate_configs.py')
-rwxr-xr-x | tools/upgrade/1.3/migrate_configs.py | 51 |
1 files changed, 27 insertions, 24 deletions
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()) |