summaryrefslogtreecommitdiffstats
path: root/src/lib/Server
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Server')
-rw-r--r--src/lib/Server/Admin/Init.py162
-rw-r--r--src/lib/Server/Plugin.py10
-rw-r--r--src/lib/Server/Plugins/Packages.py4
-rw-r--r--src/lib/Server/Plugins/Probes.py2
4 files changed, 93 insertions, 85 deletions
diff --git a/src/lib/Server/Admin/Init.py b/src/lib/Server/Admin/Init.py
index aee91b244..8f54b836e 100644
--- a/src/lib/Server/Admin/Init.py
+++ b/src/lib/Server/Admin/Init.py
@@ -65,55 +65,50 @@ clients = '''<Clients version="3.0">
'''
# Mapping of operating system names to groups
-os_list = [
- ('Red Hat/Fedora/RHEL/RHAS/Centos', 'redhat'),
- ('SUSE/SLES', 'suse'),
- ('Mandrake', 'mandrake'),
- ('Debian', 'debian'),
- ('Ubuntu', 'ubuntu'),
- ('Gentoo', 'gentoo'),
- ('FreeBSD', 'freebsd')
- ]
+os_list = [('Red Hat/Fedora/RHEL/RHAS/Centos', 'redhat'),
+ ('SUSE/SLES', 'suse'),
+ ('Mandrake', 'mandrake'),
+ ('Debian', 'debian'),
+ ('Ubuntu', 'ubuntu'),
+ ('Gentoo', 'gentoo'),
+ ('FreeBSD', 'freebsd')]
# Complete list of plugins
-plugin_list = [
- 'Account',
- 'Base',
- 'Bundler',
- 'Bzr',
- 'Cfg',
- 'Decisions',
- 'Deps',
- 'Git',
- 'Guppy',
- 'Hg',
- 'Metadata',
- 'NagiosGen',
- 'Ohai',
- 'Packages',
- 'Pkgmgr',
- 'Probes',
- 'Properties',
- 'Rules',
- 'Snapshots',
- 'SSHbase',
- 'SSLCA',
- 'Statistics',
- 'Svcmgr',
- 'TCheetah',
- 'TGenshi'
- ]
+plugin_list = ['Account',
+ 'Base',
+ 'Bundler',
+ 'Bzr',
+ 'Cfg',
+ 'Decisions',
+ 'Deps',
+ 'Git',
+ 'Guppy',
+ 'Hg',
+ 'Metadata',
+ 'NagiosGen',
+ 'Ohai',
+ 'Packages',
+ 'Pkgmgr',
+ 'Probes',
+ 'Properties',
+ 'Rules',
+ 'Snapshots',
+ 'SSHbase',
+ 'SSLCA',
+ 'Statistics',
+ 'Svcmgr',
+ 'TCheetah',
+ 'TGenshi']
# Default list of plugins to use
-default_plugins = [
- 'Base',
- 'Bundler'
- 'Cfg',
- 'Metadata',
- 'Pkgmgr',
- 'Rules',
- 'SSHbase'
- ]
+default_plugins = ['Base',
+ 'Bundler',
+ 'Cfg',
+ 'Metadata',
+ 'Pkgmgr',
+ 'Rules',
+ 'SSHbase']
+
def gen_password(length):
"""Generates a random alphanumeric password with length characters."""
@@ -123,14 +118,28 @@ def gen_password(length):
newpasswd = newpasswd + random.choice(chars)
return newpasswd
+
def create_key(hostname, keypath, certpath, country, state, location):
"""Creates a bcfg2.key at the directory specifed by keypath."""
- kcstr = "openssl req -batch -x509 -nodes -subj '/C=%s/ST=%s/L=%s/CN=%s' -days 1000 -newkey rsa:2048 -keyout %s -noout" % (country, state, location, hostname, keypath)
+ kcstr = ("openssl req -batch -x509 -nodes -subj '/C=%s/ST=%s/L=%s/CN=%s' "
+ "-days 1000 -newkey rsa:2048 -keyout %s -noout" % (country,
+ state,
+ location,
+ hostname,
+ keypath))
subprocess.call((kcstr), shell=True)
- ccstr = "openssl req -batch -new -subj '/C=%s/ST=%s/L=%s/CN=%s' -key %s | openssl x509 -req -days 1000 -signkey %s -out %s" % (country, state, location, hostname, keypath, keypath, certpath)
+ ccstr = ("openssl req -batch -new -subj '/C=%s/ST=%s/L=%s/CN=%s' -key %s "
+ "| openssl x509 -req -days 1000 -signkey %s -out %s" % (country,
+ state,
+ location,
+ hostname,
+ keypath,
+ keypath,
+ certpath))
subprocess.call((ccstr), shell=True)
os.chmod(keypath, 0600)
+
def create_conf(confpath, confdata):
# Don't overwrite existing bcfg2.conf file
if os.path.exists(confpath):
@@ -153,15 +162,14 @@ class Init(Bcfg2.Server.Admin.Mode):
__shorthelp__ = ("Interactively initialize a new repository.")
__longhelp__ = __shorthelp__ + "\n\nbcfg2-admin init"
__usage__ = "bcfg2-admin init"
- options = {
- 'configfile': Bcfg2.Options.CFILE,
- 'plugins' : Bcfg2.Options.SERVER_PLUGINS,
- 'proto' : Bcfg2.Options.SERVER_PROTOCOL,
- 'repo' : Bcfg2.Options.SERVER_REPOSITORY,
- 'sendmail' : Bcfg2.Options.SENDMAIL_PATH,
- }
+ options = {'configfile': Bcfg2.Options.CFILE,
+ 'plugins': Bcfg2.Options.SERVER_PLUGINS,
+ 'proto': Bcfg2.Options.SERVER_PROTOCOL,
+ 'repo': Bcfg2.Options.SERVER_REPOSITORY,
+ 'sendmail': Bcfg2.Options.SENDMAIL_PATH}
repopath = ""
response = ""
+
def __init__(self, configfile):
Bcfg2.Server.Admin.Mode.__init__(self, configfile)
@@ -196,8 +204,8 @@ class Init(Bcfg2.Server.Admin.Mode):
def _prompt_hostname(self):
"""Ask for the server hostname."""
- data = raw_input("What is the server's hostname [%s]: " %
- socket.getfqdn())
+ data = raw_input("What is the server's hostname [%s]: " %
+ socket.getfqdn())
if data != '':
self.shostname = data
else:
@@ -254,8 +262,8 @@ class Init(Bcfg2.Server.Admin.Mode):
continue
def _prompt_plugins(self):
- default = raw_input("Use default plugins? (%s) [Y/n]: " %
- ''.join(default_plugins)).lower()
+ default = raw_input("Use default plugins? (%s) [Y/n]: " %
+ ''.join(default_plugins)).lower()
if default != 'y' or default != '':
while True:
plugins_are_valid = True
@@ -271,8 +279,8 @@ class Init(Bcfg2.Server.Admin.Mode):
def _prompt_certificate(self):
"""Ask for the key details (country, state, and location)."""
- print "The following questions affects the certificate."
- print "If there are no data provided the default values are used."
+ print "The following questions affect SSL certificate generation."
+ print "If no data is provided, the default values are used."
newcountry = raw_input("Country name (2 letter code) for certificate: ")
if newcountry != '':
if len(newcountry) == 2:
@@ -302,8 +310,10 @@ class Init(Bcfg2.Server.Admin.Mode):
"""Initialize each plugin-specific portion of the repository."""
for plugin in self.plugins:
if plugin == 'Metadata':
- Bcfg2.Server.Plugins.Metadata.Metadata.init_repo(self.repopath,
- groups, self.os_sel, clients)
+ Bcfg2.Server.Plugins.Metadata.Metadata.init_repo(self.repopath,
+ groups,
+ self.os_sel,
+ clients)
else:
try:
module = __import__("Bcfg2.Server.Plugins.%s" % plugin, '',
@@ -311,30 +321,28 @@ class Init(Bcfg2.Server.Admin.Mode):
cls = getattr(module, plugin)
cls.init_repo(self.repopath)
except Exception, e:
- print 'Plugin setup for %s failed: %s'
- print 'Check that dependencies are installed?' % (plugin, e)
+ print("Plugin setup for %s failed: %s\n"
+ "Check that dependencies are installed?" % (plugin, e))
def init_repo(self):
"""Setup a new repo and create the content of the configuration file."""
keypath = os.path.dirname(os.path.abspath(self.configfile))
- confdata = config % (
- self.repopath,
- ','.join(self.opts['plugins']),
- self.opts['sendmail'],
- self.opts['proto'],
- self.password,
- keypath, 'bcfg2.crt',
- keypath, 'bcfg2.key',
- keypath, 'bcfg2.crt',
- self.server_uri
- )
+ confdata = config % (self.repopath,
+ ','.join(self.opts['plugins']),
+ self.opts['sendmail'],
+ self.opts['proto'],
+ self.password,
+ keypath, 'bcfg2.crt',
+ keypath, 'bcfg2.key',
+ keypath, 'bcfg2.crt',
+ self.server_uri)
# Create the configuration file and SSL key
create_conf(self.configfile, confdata)
kpath = keypath + '/bcfg2.key'
cpath = keypath + '/bcfg2.crt'
- create_key(self.shostname, kpath, cpath, self.country,
- self.state, self.location)
+ create_key(self.shostname, kpath, cpath, self.country,
+ self.state, self.location)
# Create the repository
path = "%s/%s" % (self.repopath, 'etc')
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py
index 186d1198a..73d054409 100644
--- a/src/lib/Server/Plugin.py
+++ b/src/lib/Server/Plugin.py
@@ -680,7 +680,7 @@ class SpecificData(object):
class EntrySet:
"""Entry sets deal with the host- and group-specific entries."""
- ignore = re.compile("^(\.#.*|.*~|\\..*\\.(sw[px]))$")
+ ignore = re.compile("^(\.#.*|.*~|\\..*\\.(sw[px])|.*\\.genshi_include)$")
def __init__(self, basename, path, entry_type, encoding):
self.path = path
self.entry_type = entry_type
@@ -784,10 +784,10 @@ class EntrySet:
return cmp(x.specific.prio, y.specific.prio)
def bind_info_to_entry(self, entry, metadata):
- if not self.infoxml:
- for key in self.metadata:
- entry.set(key, self.metadata[key])
- else:
+ # first set defaults from global metadata/:info
+ for key in self.metadata:
+ entry.set(key, self.metadata[key])
+ if self.infoxml:
mdata = {}
self.infoxml.pnode.Match(metadata, mdata)
if 'Info' not in mdata:
diff --git a/src/lib/Server/Plugins/Packages.py b/src/lib/Server/Plugins/Packages.py
index ee21fb622..438c1d5c0 100644
--- a/src/lib/Server/Plugins/Packages.py
+++ b/src/lib/Server/Plugins/Packages.py
@@ -280,12 +280,12 @@ class YUMSource(Source):
sdata = self.packages.values()
self.packages['global'] = copy.deepcopy(sdata.pop())
while sdata:
- self.packages['global'].intersection(sdata.pop())
+ self.packages['global'] = self.packages['global'].intersection(sdata.pop())
for key in self.packages:
if key == 'global':
continue
- self.packages[key] = self.packages['global'].difference(self.packages[key])
+ self.packages[key] = self.packages[key].difference(self.packages['global'])
self.save_state()
def parse_filelist(self, data, arch):
diff --git a/src/lib/Server/Plugins/Probes.py b/src/lib/Server/Plugins/Probes.py
index c00185732..7ffc65bac 100644
--- a/src/lib/Server/Plugins/Probes.py
+++ b/src/lib/Server/Plugins/Probes.py
@@ -73,7 +73,7 @@ class Probes(Bcfg2.Server.Plugin.Plugin,
def write_data(self):
"""Write probe data out for use with bcfg2-info."""
top = lxml.etree.Element("Probed")
- for client, probed in self.probedata.iteritems():
+ for client, probed in sorted(self.probedata.items()):
cx = lxml.etree.SubElement(top, 'Client', name=client)
for probe in probed:
lxml.etree.SubElement(cx, 'Probe', name=probe,