summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/Bcfg2/Options.py98
-rw-r--r--src/lib/Bcfg2/Server/Admin/__init__.py3
-rw-r--r--src/lib/Bcfg2/Server/Core.py8
-rw-r--r--src/lib/Bcfg2/Server/Plugin.py62
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/PackagesConfig.py15
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py8
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/Source.py8
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/Yum.py42
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/__init__.py47
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Rules.py6
-rwxr-xr-xsrc/sbin/bcfg2-admin3
-rwxr-xr-xsrc/sbin/bcfg2-info12
-rwxr-xr-xsrc/sbin/bcfg2-lint8
-rwxr-xr-xsrc/sbin/bcfg2-server44
-rwxr-xr-xsrc/sbin/bcfg2-test3
-rw-r--r--tools/README16
-rw-r--r--tools/upgrade/1.1/posixunified.py (renamed from tools/posixunified.py)0
-rwxr-xr-xtools/upgrade/1.2/nagiosgen-convert.py (renamed from tools/nagiosgen-convert.py)0
-rwxr-xr-xtools/upgrade/1.2/packages-convert.py (renamed from tools/packages-convert.py)0
-rwxr-xr-xtools/upgrade/1.3/migrate_configs.py54
20 files changed, 225 insertions, 212 deletions
diff --git a/src/lib/Bcfg2/Options.py b/src/lib/Bcfg2/Options.py
index 30d3a420f..32c3c02e4 100644
--- a/src/lib/Bcfg2/Options.py
+++ b/src/lib/Bcfg2/Options.py
@@ -21,17 +21,40 @@ class OptionFailure(Exception):
DEFAULT_CONFIG_LOCATION = '/etc/bcfg2.conf' #/etc/bcfg2.conf
DEFAULT_INSTALL_PREFIX = '/usr' #/usr
-class Option(object):
- cfpath = DEFAULT_CONFIG_LOCATION
- __cfp = False
+class DefaultConfigParser(ConfigParser.ConfigParser):
+ def get(self, section, option, **kwargs):
+ """ convenience method for getting config items """
+ default = None
+ if 'default' in kwargs:
+ default = kwargs['default']
+ del kwargs['default']
+ try:
+ return ConfigParser.ConfigParser.get(self, section, option,
+ **kwargs)
+ except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
+ if default is not None:
+ return default
+ else:
+ raise
+
+ def getboolean(self, section, option, **kwargs):
+ """ convenience method for getting boolean config items """
+ default = None
+ if 'default' in kwargs:
+ default = kwargs['default']
+ del kwargs['default']
+ try:
+ return ConfigParser.ConfigParser.getboolean(self, section,
+ option, **kwargs)
+ except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
+ ValueError):
+ if default is not None:
+ return default
+ else:
+ raise
- def getCFP(self):
- if not self.__cfp:
- self.__cfp = ConfigParser.ConfigParser()
- self.__cfp.readfp(open(self.cfpath))
- return self.__cfp
- cfp = property(getCFP)
+class Option(object):
def get_cooked_value(self, value):
if self.boolean:
return True
@@ -93,7 +116,7 @@ class Option(object):
else:
return self.cmd[2:]
- def parse(self, opts, rawopts):
+ def parse(self, opts, rawopts, configparser=None):
if self.cmd and opts:
# Processing getopted data
optinfo = [opt[1] for opt in opts if opt[0] == self.cmd]
@@ -111,26 +134,35 @@ class Option(object):
if self.env and self.env in os.environ:
self.value = self.get_cooked_value(os.environ[self.env])
return
- if self.cf:
- # FIXME: This is potentially masking a lot of errors
+ if self.cf and configparser:
try:
- self.value = self.get_cooked_value(self.cfp.get(*self.cf))
+ self.value = self.get_cooked_value(configparser.get(*self.cf))
return
- except:
+ except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
pass
# Default value not cooked
self.value = self.default
class OptionSet(dict):
- def __init__(self, *args):
+ def __init__(self, *args, **kwargs):
dict.__init__(self, *args)
self.hm = self.buildHelpMessage()
+ if 'configfile' in kwargs:
+ self.cfile = kwargs['configfile']
+ else:
+ self.cfile = DEFAULT_CONFIG_LOCATION
+ self.cfp = DefaultConfigParser()
+ if (len(self.cfp.read(self.cfile)) == 0 and
+ ('quiet' not in kwargs or not kwargs['quiet'])):
+ print("Warning! Unable to read specified configuration file: %s" %
+ self.cfile)
def buildGetopt(self):
return ''.join([opt.buildGetopt() for opt in list(self.values())])
def buildLongGetopt(self):
- return [opt.buildLongGetopt() for opt in list(self.values()) if opt.long]
+ return [opt.buildLongGetopt() for opt in list(self.values())
+ if opt.long]
def buildHelpMessage(self):
if hasattr(self, 'hm'):
@@ -165,9 +197,9 @@ class OptionSet(dict):
continue
option = self[key]
if do_getopt:
- option.parse(opts, [])
+ option.parse(opts, [], configparser=self.cfp)
else:
- option.parse([], argv)
+ option.parse([], argv, configparser=self.cfp)
if hasattr(option, 'value'):
val = option.value
self[key] = val
@@ -385,15 +417,23 @@ class OptionParser(OptionSet):
getting the value of the config file
"""
def __init__(self, args):
- self.Bootstrap = OptionSet([('configfile', CFILE)])
+ self.Bootstrap = OptionSet([('configfile', CFILE)], quiet=True)
self.Bootstrap.parse(sys.argv[1:], do_getopt=False)
- if self.Bootstrap['configfile'] != Option.cfpath:
- Option.cfpath = self.Bootstrap['configfile']
- Option.__cfp = False
- OptionSet.__init__(self, args)
- try:
- f = open(Option.cfpath, 'r')
- f.close()
- except IOError:
- e = sys.exc_info()[1]
- print("Warning! Unable to read specified configuration file: %s" % e)
+ OptionSet.__init__(self, args, configfile=self.Bootstrap['configfile'])
+ self.optinfo = args
+
+ def HandleEvent(self, event):
+ if not self['configfile'].endswith(event.filename):
+ print("Got event for unknown file: %s" % event.filename)
+ return
+ if event.code2str() == 'deleted':
+ return
+ for key, opt in self.optinfo:
+ self[key] = opt
+ self.parse(self.argv, self.do_getopt)
+
+ def parse(self, argv, do_getopt=True):
+ self.argv = argv
+ self.do_getopt = do_getopt
+ OptionSet.parse(self, self.argv, do_getopt=self.do_getopt)
+
diff --git a/src/lib/Bcfg2/Server/Admin/__init__.py b/src/lib/Bcfg2/Server/Admin/__init__.py
index fdb9a0972..618fa450e 100644
--- a/src/lib/Bcfg2/Server/Admin/__init__.py
+++ b/src/lib/Bcfg2/Server/Admin/__init__.py
@@ -122,7 +122,8 @@ class MetadataCore(Mode):
setup['plugins'],
setup['password'],
setup['encoding'],
- filemonitor=setup['filemonitor'])
+ filemonitor=setup['filemonitor'],
+ setup=setup)
if setup['event debug']:
self.bcore.fam.debug = True
except Bcfg2.Server.Core.CoreInitError:
diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py
index a253fd367..8482925b7 100644
--- a/src/lib/Bcfg2/Server/Core.py
+++ b/src/lib/Bcfg2/Server/Core.py
@@ -62,7 +62,7 @@ class Core(Component):
implementation = 'bcfg2-server'
def __init__(self, repo, plugins, password, encoding,
- cfile='/etc/bcfg2.conf', ca=None,
+ cfile='/etc/bcfg2.conf', ca=None, setup=None,
filemonitor='default', start_fam_thread=False):
Component.__init__(self)
self.datastore = repo
@@ -85,6 +85,7 @@ class Core(Component):
self.revision = '-1'
self.password = password
self.encoding = encoding
+ self.setup = setup
atexit.register(self.shutdown)
# Create an event to signal worker threads to shutdown
self.terminate = threading.Event()
@@ -131,6 +132,11 @@ class Core(Component):
self.fam_thread = threading.Thread(target=self._file_monitor_thread)
if start_fam_thread:
self.fam_thread.start()
+ self.monitor_cfile()
+
+ def monitor_cfile(self):
+ if self.setup:
+ self.fam.AddMonitor(self.cfile, self.setup)
def plugins_by_type(self, base_cls):
"""Return a list of loaded plugins that match the passed type.
diff --git a/src/lib/Bcfg2/Server/Plugin.py b/src/lib/Bcfg2/Server/Plugin.py
index d7b4baf45..ca37431a2 100644
--- a/src/lib/Bcfg2/Server/Plugin.py
+++ b/src/lib/Bcfg2/Server/Plugin.py
@@ -1211,65 +1211,3 @@ class GroupSpool(Plugin, Generator):
return
reqid = self.core.fam.AddMonitor(name, self)
self.handles[reqid] = relative
-
-class SimpleConfig(FileBacked,
- ConfigParser.SafeConfigParser):
- ''' a simple plugin config using ConfigParser '''
- _required = True
-
- def __init__(self, plugin):
- filename = os.path.join(plugin.data, plugin.name.lower() + ".conf")
- self.plugin = plugin
- self.fam = self.plugin.core.fam
- self.read_files = set()
- Bcfg2.Server.Plugin.FileBacked.__init__(self, filename)
- ConfigParser.SafeConfigParser.__init__(self)
-
- if (self._required or
- (not self._required and os.path.exists(self.name))):
- self.fam.AddMonitor(self.name, self)
-
- def Index(self):
- """ Build local data structures """
- for section in self.sections():
- self.remove_section(section)
- self.read_files.update(self.read(self.name))
-
- def get(self, section, option, **kwargs):
- """ convenience method for getting config items """
- default = None
- if 'default' in kwargs:
- default = kwargs['default']
- del kwargs['default']
- try:
- return ConfigParser.SafeConfigParser.get(self, section, option,
- **kwargs)
- except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
- if default is not None:
- return default
- else:
- raise
-
- def getboolean(self, section, option, **kwargs):
- """ convenience method for getting boolean config items """
- default = None
- if 'default' in kwargs:
- default = kwargs['default']
- del kwargs['default']
- try:
- return ConfigParser.SafeConfigParser.getboolean(self, section,
- option, **kwargs)
- except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
- ValueError):
- if default is not None:
- return default
- else:
- raise
-
- @property
- def loaded(self):
- if os.path.exists(self.name):
- return self.name in self.read_files
- else:
- return True
-
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/PackagesConfig.py b/src/lib/Bcfg2/Server/Plugins/Packages/PackagesConfig.py
deleted file mode 100644
index 3846c06ce..000000000
--- a/src/lib/Bcfg2/Server/Plugins/Packages/PackagesConfig.py
+++ /dev/null
@@ -1,15 +0,0 @@
-import Bcfg2.Server.Plugin
-
-class PackagesConfig(Bcfg2.Server.Plugin.SimpleConfig):
- _required = False
-
- def Index(self):
- """ Build local data structures """
- Bcfg2.Server.Plugin.SimpleConfig.Index(self)
-
- if hasattr(self.plugin, "sources") and self.plugin.sources.loaded:
- # only reload Packages plugin if sources have been loaded.
- # otherwise, this is getting called on server startup, and
- # we have to wait until all sources have been indexed
- # before we can call Packages.Reload()
- self.plugin.Reload()
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py b/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py
index a966268c0..7796b9e34 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py
@@ -9,7 +9,7 @@ class PackagesSources(Bcfg2.Server.Plugin.SingleXMLFileBacked,
Bcfg2.Server.Plugin.Debuggable):
__identifier__ = None
- def __init__(self, filename, cachepath, fam, packages, config):
+ def __init__(self, filename, cachepath, fam, packages, setup):
Bcfg2.Server.Plugin.Debuggable.__init__(self)
try:
Bcfg2.Server.Plugin.SingleXMLFileBacked.__init__(self,
@@ -24,7 +24,7 @@ class PackagesSources(Bcfg2.Server.Plugin.SingleXMLFileBacked,
raise Bcfg2.Server.Plugin.PluginInitError(msg)
Bcfg2.Server.Plugin.StructFile.__init__(self, filename)
self.cachepath = cachepath
- self.config = config
+ self.setup = setup
if not os.path.exists(self.cachepath):
# create cache directory if needed
try:
@@ -56,7 +56,7 @@ class PackagesSources(Bcfg2.Server.Plugin.SingleXMLFileBacked,
self.parsed.add(fname)
break
- if self.config.loaded and self.loaded:
+ if self.loaded:
self.logger.info("Reloading Packages plugin")
self.pkg_obj.Reload()
@@ -91,7 +91,7 @@ class PackagesSources(Bcfg2.Server.Plugin.SingleXMLFileBacked,
return None
try:
- source = cls(self.cachepath, xsource, self.config)
+ source = cls(self.cachepath, xsource, self.setup)
except SourceInitError:
err = sys.exc_info()[1]
self.logger.error("Packages: %s" % err)
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py
index ada04c067..edcdcd9f2 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py
@@ -36,11 +36,11 @@ class Source(Bcfg2.Server.Plugin.Debuggable):
genericrepo_re = re.compile('https?://.*?/([^/]+)/?$')
basegroups = []
- def __init__(self, basepath, xsource, config):
+ def __init__(self, basepath, xsource, setup):
Bcfg2.Server.Plugin.Debuggable.__init__(self)
self.basepath = basepath
self.xsource = xsource
- self.config = config
+ self.setup = setup
self.essentialpkgs = set()
try:
@@ -272,8 +272,8 @@ class Source(Bcfg2.Server.Plugin.Debuggable):
if not found_arch:
return False
- if self.config.getboolean("global", "magic_groups",
- default=True) == False:
+ if not self.setup.cfp.getboolean("packages", "magic_groups",
+ default=True):
return True
else:
for group in self.basegroups:
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
index 941203db3..53344e200 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
@@ -15,7 +15,6 @@ from Bcfg2.Bcfg2Py3k import StringIO, cPickle, HTTPError, ConfigParser, file
from Bcfg2.Server.Plugins.Packages.Collection import Collection
from Bcfg2.Server.Plugins.Packages.Source import SourceInitError, Source, \
fetch_url
-from Bcfg2.Server.Plugins.Packages.PackagesConfig import PackagesConfig
logger = logging.getLogger(__name__)
@@ -50,7 +49,7 @@ PULPSERVER = None
PULPCONFIG = None
-def _setup_pulp(config):
+def _setup_pulp(setup):
global PULPSERVER, PULPCONFIG
if not has_pulp:
msg = "Packages: Cannot create Pulp collection: Pulp libraries not found"
@@ -59,8 +58,8 @@ def _setup_pulp(config):
if PULPSERVER is None:
try:
- username = config.get("pulp", "username")
- password = config.get("pulp", "password")
+ username = setup.cfp.get("packages:pulp", "username")
+ password = setup.cfp.get("packages:pulp", "password")
except ConfigParser.NoSectionError:
msg = "Packages: No [pulp] section found in Packages/packages.conf"
logger.error(msg)
@@ -91,11 +90,6 @@ class YumCollection(Collection):
Collection.__init__(self, metadata, sources, basepath, debug=debug)
self.keypath = os.path.join(self.basepath, "keys")
- if len(sources):
- self.config = sources[0].config
- else:
- self.config = PackageConfig('Packages')
-
if self.use_yum:
self.cachefile = os.path.join(self.cachepath,
"cache-%s" % self.cachekey)
@@ -109,17 +103,18 @@ class YumCollection(Collection):
"%s-yum.conf" % self.cachekey)
self.write_config()
if has_pulp and self.has_pulp_sources:
- _setup_pulp(self.config)
+ _setup_pulp(self.setup)
@property
def helper(self):
- return self.config.get("yum", "helper",
- default="/usr/sbin/bcfg2-yum-helper")
+ return self.setup.cfp.get("packages:yum", "helper",
+ default="/usr/sbin/bcfg2-yum-helper")
@property
def use_yum(self):
- return has_yum and self.config.getboolean("yum", "use_yum_libraries",
- default=False)
+ return has_yum and self.setup.cfp.getboolean("packages:yum",
+ "use_yum_libraries",
+ default=False)
@property
def has_pulp_sources(self):
@@ -140,9 +135,9 @@ class YumCollection(Collection):
debuglevel="0",
reposdir="/dev/null")
try:
- for opt in self.config.options("yum"):
+ for opt in self.setup.cfp.options("packages:yum"):
if opt not in self.option_blacklist:
- mainopts[opt] = self.config.get("yum", opt)
+ mainopts[opt] = self.setup.cfp.get("packages:yum", opt)
except ConfigParser.NoSectionError:
pass
@@ -228,8 +223,8 @@ class YumCollection(Collection):
for key in needkeys:
# figure out the path of the key on the client
- keydir = self.config.get("global", "gpg_keypath",
- default="/etc/pki/rpm-gpg")
+ keydir = self.setup.cfp.get("global", "gpg_keypath",
+ default="/etc/pki/rpm-gpg")
remotekey = os.path.join(keydir, os.path.basename(key))
localkey = os.path.join(self.keypath, os.path.basename(key))
kdata = open(localkey).read()
@@ -451,13 +446,13 @@ class YumSource(Source):
basegroups = ['yum', 'redhat', 'centos', 'fedora']
ptype = 'yum'
- def __init__(self, basepath, xsource, config):
- Source.__init__(self, basepath, xsource, config)
+ def __init__(self, basepath, xsource, setup):
+ Source.__init__(self, basepath, xsource, setup)
self.pulp_id = None
if has_pulp and xsource.get("pulp_id"):
self.pulp_id = xsource.get("pulp_id")
- _setup_pulp(self.config)
+ _setup_pulp(self.setup)
repoapi = RepositoryAPI()
try:
self.repo = repoapi.repository(self.pulp_id)
@@ -499,8 +494,9 @@ class YumSource(Source):
@property
def use_yum(self):
- return has_yum and self.config.getboolean("yum", "use_yum_libraries",
- default=False)
+ return has_yum and self.setup.cfp.getboolean("packages:yum",
+ "use_yum_libraries",
+ default=False)
def save_state(self):
if not self.use_yum:
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py b/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py
index 4070b13ca..d789a6d39 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py
@@ -10,7 +10,6 @@ import Bcfg2.Server.Plugin
from Bcfg2.Bcfg2Py3k import ConfigParser, urlopen
from Bcfg2.Server.Plugins.Packages import Collection
from Bcfg2.Server.Plugins.Packages.PackagesSources import PackagesSources
-from Bcfg2.Server.Plugins.Packages.PackagesConfig import PackagesConfig
class Packages(Bcfg2.Server.Plugin.Plugin,
Bcfg2.Server.Plugin.StructureValidator,
@@ -36,11 +35,9 @@ class Packages(Bcfg2.Server.Plugin.Plugin,
# create key directory if needed
os.makedirs(self.keypath)
- # set up config files
- self.config = PackagesConfig(self)
self.sources = PackagesSources(os.path.join(self.data, "sources.xml"),
self.cachepath, core.fam, self,
- self.config)
+ self.core.setup)
def toggle_debug(self):
Bcfg2.Server.Plugin.Plugin.toggle_debug(self)
@@ -49,7 +46,7 @@ class Packages(Bcfg2.Server.Plugin.Plugin,
@property
def disableResolver(self):
try:
- return not self.config.getboolean("global", "resolver")
+ return not self.core.setup.cfp.getboolean("packages", "resolver")
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
return False
except ValueError:
@@ -57,20 +54,20 @@ class Packages(Bcfg2.Server.Plugin.Plugin,
# "disabled", which are not handled according to the
# Python docs but appear to be handled properly by
# ConfigParser in at least some versions
- return self.config.get("global", "resolver",
- default="enabled").lower() == "disabled"
+ return self.core.setup.cfp.get("packages", "resolver",
+ default="enabled").lower() == "disabled"
@property
def disableMetaData(self):
try:
- return not self.config.getboolean("global", "resolver")
+ return not self.core.setup.cfp.getboolean("packages", "resolver")
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
return False
except ValueError:
# for historical reasons we also accept "enabled" and
# "disabled"
- return self.config.get("global", "metadata",
- default="enabled").lower() == "disabled"
+ return self.core.setup.cfp.get("packages", "metadata",
+ default="enabled").lower() == "disabled"
def create_config(self, entry, metadata):
""" create yum/apt config for the specified host """
@@ -89,20 +86,23 @@ class Packages(Bcfg2.Server.Plugin.Plugin,
def HandleEntry(self, entry, metadata):
if entry.tag == 'Package':
collection = self._get_collection(metadata)
- entry.set('version', self.config.get("global",
+ entry.set('version', self.core.setup.cfp.get("packages",
"version",
default="auto"))
entry.set('type', collection.ptype)
elif entry.tag == 'Path':
- if (entry.get("name") == self.config.get("global", "yum_config",
- default="") or
- entry.get("name") == self.config.get("global", "apt_config",
- default="")):
+ if (entry.get("name") == self.core.setup.cfp.get("packages",
+ "yum_config",
+ default="") or
+ entry.get("name") == self.core.setup.cfp.get("packages",
+ "apt_config",
+ default="")):
self.create_config(entry, metadata)
def HandlesEntry(self, entry, metadata):
if entry.tag == 'Package':
- if self.config.getboolean("global", "magic_groups", default=True):
+ if self.core.setup.cfp.getboolean("packages", "magic_groups",
+ default=True):
collection = self._get_collection(metadata)
if collection.magic_groups_match():
return True
@@ -110,10 +110,12 @@ class Packages(Bcfg2.Server.Plugin.Plugin,
return True
elif entry.tag == 'Path':
# managed entries for yum/apt configs
- if (entry.get("name") == self.config.get("global", "yum_config",
- default="") or
- entry.get("name") == self.config.get("global", "apt_config",
- default="")):
+ if (entry.get("name") == self.core.setup.cfp.get("packages",
+ "yum_config",
+ default="") or
+ entry.get("name") == self.core.setup.cfp.get("packages",
+ "apt_config",
+ default="")):
return True
return False
@@ -183,8 +185,9 @@ class Packages(Bcfg2.Server.Plugin.Plugin,
newpkgs.sort()
for pkg in newpkgs:
lxml.etree.SubElement(independent, 'BoundPackage', name=pkg,
- version=self.config.get("global", "version",
- default="auto"),
+ version=self.core.setup.cfp.get("packages",
+ "version",
+ default="auto"),
type=collection.ptype, origin='Packages')
def Refresh(self):
diff --git a/src/lib/Bcfg2/Server/Plugins/Rules.py b/src/lib/Bcfg2/Server/Plugins/Rules.py
index b80ef351a..e77d08653 100644
--- a/src/lib/Bcfg2/Server/Plugins/Rules.py
+++ b/src/lib/Bcfg2/Server/Plugins/Rules.py
@@ -3,9 +3,6 @@
import re
import Bcfg2.Server.Plugin
-class RulesConfig(Bcfg2.Server.Plugin.SimpleConfig):
- _required = False
-
class Rules(Bcfg2.Server.Plugin.PrioDir):
"""This is a generator that handles service assignments."""
name = 'Rules'
@@ -13,7 +10,6 @@ class Rules(Bcfg2.Server.Plugin.PrioDir):
def __init__(self, core, datastore):
Bcfg2.Server.Plugin.PrioDir.__init__(self, core, datastore)
- self.config = RulesConfig(self)
self._regex_cache = dict()
def HandlesEntry(self, entry, metadata):
@@ -52,4 +48,4 @@ class Rules(Bcfg2.Server.Plugin.PrioDir):
return False
def _regex_enabled(self):
- return self.config.getboolean("rules", "regex", default=False)
+ return self.core.setup.cfp.getboolean("rules", "regex", default=False)
diff --git a/src/sbin/bcfg2-admin b/src/sbin/bcfg2-admin
index d3b06733f..007dd0af3 100755
--- a/src/sbin/bcfg2-admin
+++ b/src/sbin/bcfg2-admin
@@ -3,7 +3,6 @@
import sys
import logging
-import Bcfg2.Server.Core
import Bcfg2.Logger
import Bcfg2.Options
import Bcfg2.Server.Admin
@@ -31,7 +30,7 @@ def create_description():
for mode in modes:
try:
description.write((" %-15s %s\n" %
- (mode, mode_import(mode).__shorthelp__)))
+ (mode, mode_import(mode).__shorthelp__)))
except (ImportError, SystemExit):
pass
return description.getvalue()
diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info
index 5e260d94d..8598a58eb 100755
--- a/src/sbin/bcfg2-info
+++ b/src/sbin/bcfg2-info
@@ -133,11 +133,13 @@ def displayTrace(trace, num=80, sort=('time', 'calls')):
class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
"""Main class for bcfg2-info."""
- def __init__(self, repo, plgs, passwd, encoding, event_debug, filemonitor='default'):
+ def __init__(self, repo, plgs, passwd, encoding, event_debug,
+ filemonitor='default', setup=None):
cmd.Cmd.__init__(self)
try:
Bcfg2.Server.Core.Core.__init__(self, repo, plgs, passwd,
- encoding, filemonitor=filemonitor)
+ encoding, filemonitor=filemonitor,
+ setup=setup)
if event_debug:
self.fam.debug = True
except Bcfg2.Server.Core.CoreInitError:
@@ -668,12 +670,14 @@ if __name__ == '__main__':
prof = profile.Profile()
loop = prof.runcall(infoCore, setup['repo'], setup['plugins'],
setup['password'], setup['encoding'],
- setup['event debug'], setup['filemonitor'])
+ setup['event debug'], setup['filemonitor'],
+ setup)
displayTrace(prof)
else:
if setup['profile']:
print("Profiling functionality not available.")
loop = infoCore(setup['repo'], setup['plugins'], setup['password'],
- setup['encoding'], setup['event debug'], setup['filemonitor'])
+ setup['encoding'], setup['event debug'],
+ setup['filemonitor'], setup)
loop.Run(setup['args'])
diff --git a/src/sbin/bcfg2-lint b/src/sbin/bcfg2-lint
index 5ee88535d..78b833f02 100755
--- a/src/sbin/bcfg2-lint
+++ b/src/sbin/bcfg2-lint
@@ -62,7 +62,9 @@ def get_errorhandler(config):
def load_server(setup):
""" load server """
core = Bcfg2.Server.Core.Core(setup['repo'], setup['plugins'],
- setup['password'], setup['encoding'])
+ setup['password'], setup['encoding'],
+ filemonitor=setup['filemonitor'],
+ setup=setup)
if setup['event debug']:
core.fam.debug = True
core.fam.handle_events_in_interval(4)
@@ -73,8 +75,6 @@ if __name__ == '__main__':
'configfile': Bcfg2.Options.CFILE,
'help': Bcfg2.Options.HELP,
'verbose': Bcfg2.Options.VERBOSE,
- }
- optinfo.update({
'event debug': Bcfg2.Options.DEBUG,
'encoding': Bcfg2.Options.ENCODING,
# Server options
@@ -101,7 +101,7 @@ if __name__ == '__main__':
'showerrors': Bcfg2.Options.Option('Show error handling', False,
cmd='--list-errors',
long_arg=True),
- })
+ }
setup = Bcfg2.Options.OptionParser(optinfo)
setup.parse(sys.argv[1:])
diff --git a/src/sbin/bcfg2-server b/src/sbin/bcfg2-server
index 89bc7c331..757172464 100755
--- a/src/sbin/bcfg2-server
+++ b/src/sbin/bcfg2-server
@@ -15,7 +15,6 @@ from Bcfg2.Server.Core import CoreInitError
logger = logging.getLogger('bcfg2-server')
if __name__ == '__main__':
-
OPTINFO = {
'configfile': Bcfg2.Options.CFILE,
'daemon' : Bcfg2.Options.DAEMON,
@@ -23,26 +22,22 @@ if __name__ == '__main__':
'help' : Bcfg2.Options.HELP,
'verbose' : Bcfg2.Options.VERBOSE,
'to_file' : Bcfg2.Options.LOGGING_FILE_PATH,
+ 'repo' : Bcfg2.Options.SERVER_REPOSITORY,
+ 'plugins' : Bcfg2.Options.SERVER_PLUGINS,
+ 'password' : Bcfg2.Options.SERVER_PASSWORD,
+ 'fm' : Bcfg2.Options.SERVER_FILEMONITOR,
+ 'key' : Bcfg2.Options.SERVER_KEY,
+ 'cert' : Bcfg2.Options.SERVER_CERT,
+ 'ca' : Bcfg2.Options.SERVER_CA,
+ 'listen_all': Bcfg2.Options.SERVER_LISTEN_ALL,
+ 'location' : Bcfg2.Options.SERVER_LOCATION,
+ 'passwd' : Bcfg2.Options.SERVER_PASSWORD,
+ 'static' : Bcfg2.Options.SERVER_STATIC,
+ 'encoding' : Bcfg2.Options.ENCODING,
+ 'filelog' : Bcfg2.Options.LOGGING_FILE_PATH,
+ 'protocol' : Bcfg2.Options.SERVER_PROTOCOL,
}
- OPTINFO.update({'repo' : Bcfg2.Options.SERVER_REPOSITORY,
- 'plugins' : Bcfg2.Options.SERVER_PLUGINS,
- 'password' : Bcfg2.Options.SERVER_PASSWORD,
- 'fm' : Bcfg2.Options.SERVER_FILEMONITOR,
- })
-
- OPTINFO.update({'key' : Bcfg2.Options.SERVER_KEY,
- 'cert' : Bcfg2.Options.SERVER_CERT,
- 'ca' : Bcfg2.Options.SERVER_CA,
- 'listen_all' : Bcfg2.Options.SERVER_LISTEN_ALL,
- 'location' : Bcfg2.Options.SERVER_LOCATION,
- 'passwd' : Bcfg2.Options.SERVER_PASSWORD,
- 'static' : Bcfg2.Options.SERVER_STATIC,
- 'encoding' : Bcfg2.Options.ENCODING,
- 'filelog' : Bcfg2.Options.LOGGING_FILE_PATH,
- 'protocol' : Bcfg2.Options.SERVER_PROTOCOL,
- })
-
setup = Bcfg2.Options.OptionParser(OPTINFO)
setup.parse(sys.argv[1:])
try:
@@ -53,9 +48,9 @@ if __name__ == '__main__':
Bcfg2.Component.run_component(Bcfg2.Server.Core.Core,
listen_all=setup['listen_all'],
location=setup['location'],
- daemon = setup['daemon'],
- pidfile_name = setup['daemon'],
- protocol = setup['protocol'],
+ daemon=setup['daemon'],
+ pidfile_name=setup['daemon'],
+ protocol=setup['protocol'],
to_file=setup['to_file'],
cfile=setup['configfile'],
register=False,
@@ -65,10 +60,11 @@ if __name__ == '__main__':
'encoding':setup['encoding'],
'ca':setup['ca'],
'filemonitor':setup['fm'],
- 'start_fam_thread':True},
+ 'start_fam_thread':True,
+ 'setup':setup},
keyfile=setup['key'],
certfile=setup['cert'],
- ca=setup['ca'],
+ ca=setup['ca']
)
except CoreInitError:
msg = sys.exc_info()[1]
diff --git a/src/sbin/bcfg2-test b/src/sbin/bcfg2-test
index 01a2a4893..472534152 100755
--- a/src/sbin/bcfg2-test
+++ b/src/sbin/bcfg2-test
@@ -86,7 +86,8 @@ def main():
setup['plugins'],
setup['password'],
setup['encoding'],
- filemonitor='pseudo'
+ filemonitor='pseudo',
+ setup=setup
)
ignore = dict()
diff --git a/tools/README b/tools/README
index deb04bf3f..738ec1731 100644
--- a/tools/README
+++ b/tools/README
@@ -66,12 +66,6 @@ hostbase.py {-l|-c} <hostname>
hostinfo.py {-q <query>|--showfields}
- Query the hostbase databse
-nagios-convert.py
- - Convert 1.1.x-style NagiosGen config to 1.2.x-style
-
-packages-convert.py
- - Convert 1.1.x-style Packages config to 1.2.x-style
-
pkgmgr_gen.py
- Generate Pkgmgr XML files from a list of directories that
contain RPMS
@@ -80,14 +74,14 @@ pkgmgr_update.py
- Update Pkgmgr XML files from a list of directories that contain
RPMS
-posixunified.py
- - Convert 1.0.x-style Rules, Bundler, and Base configs to 1.1.x
- POSIX unified-style configs (i.e., ConfigFile, Directory,
- Permissions, and SymLink all become Path entries)
-
rpmlisting.py
- ???
+upgrade
+ - This directory contains scripts used to upgrade to the specified
+ version. E.g., upgrade/1.2 has scripts needed to upgrade to
+ Bcfg2 1.2.x from bcfg2 1.1.x
+
yum-listpkgs.xml.py
- Produces a list of all packages installed and available in a
format suitable for use by Packages or Pkgmgr
diff --git a/tools/posixunified.py b/tools/upgrade/1.1/posixunified.py
index 8eb4ed734..8eb4ed734 100644
--- a/tools/posixunified.py
+++ b/tools/upgrade/1.1/posixunified.py
diff --git a/tools/nagiosgen-convert.py b/tools/upgrade/1.2/nagiosgen-convert.py
index 2c2142735..2c2142735 100755
--- a/tools/nagiosgen-convert.py
+++ b/tools/upgrade/1.2/nagiosgen-convert.py
diff --git a/tools/packages-convert.py b/tools/upgrade/1.2/packages-convert.py
index c7b43279f..c7b43279f 100755
--- a/tools/packages-convert.py
+++ b/tools/upgrade/1.2/packages-convert.py
diff --git a/tools/upgrade/1.3/migrate_configs.py b/tools/upgrade/1.3/migrate_configs.py
new file mode 100755
index 000000000..c6e6cd2c3
--- /dev/null
+++ b/tools/upgrade/1.3/migrate_configs.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+import os
+import sys
+from Bcfg2.Bcfg2Py3k import ConfigParser
+import Bcfg2.Options
+
+def copy_section(src_file, tgt_cfg, section, newsection=None):
+ if newsection is None:
+ newsection = section
+
+ cfg = ConfigParser.ConfigParser()
+ if len(cfg.read(src_file)) == 1:
+ if cfg.has_section(section):
+ try:
+ tgt_cfg.add_section(newsection)
+ except ConfigParser.DuplicateSectionError:
+ print("[%s] section already exists in %s, adding options" %
+ (newsection, setup['cfile']))
+ 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'],
+ tgt_cfg.get(newsection, opt)))
+ print(" %s: %s" % (src_file, val))
+ else:
+ print("Set %s in [%s] to %s" % (opt, newsection, val))
+ 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:])
+
+ copy_section(os.path.join(setup['repo'], 'Rules', 'rules.conf'), setup.cfp,
+ "rules")
+ pkgs_conf = os.path.join(setup['repo'], 'Packages', 'packages.conf')
+ copy_section(pkgs_conf, setup.cfp, "global", newsection="packages")
+ for section in ["apt", "yum", "pulp"]:
+ copy_section(pkgs_conf, setup.cfp, section,
+ newsection="packages:" + section)
+
+ print("Writing %s" % setup['configfile'])
+ try:
+ setup.cfp.write(open(setup['configfile'], "w"))
+ except IOError:
+ err = sys.exc_info()[1]
+ print("Could not write %s: %s" % (setup['configfile'], err))
+
+if __name__ == '__main__':
+ sys.exit(main())