summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-01-26 13:19:58 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-01-26 13:19:58 -0500
commit75c6e2ac28a6f406d679a44dc399c5eb6d6d25e1 (patch)
tree28a76153bba1848017aaf750d5c9b14a0c6e122e /src/lib
parent1ef9f2ce0af301cda6f21653def563450eaaf327 (diff)
downloadbcfg2-75c6e2ac28a6f406d679a44dc399c5eb6d6d25e1.tar.gz
bcfg2-75c6e2ac28a6f406d679a44dc399c5eb6d6d25e1.tar.bz2
bcfg2-75c6e2ac28a6f406d679a44dc399c5eb6d6d25e1.zip
made bcfg2-admin accept -Q flag and a few others; general code cleanup
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Server/Admin/Backup.py10
-rw-r--r--src/lib/Server/Admin/Bundle.py16
-rw-r--r--src/lib/Server/Admin/Client.py4
-rw-r--r--src/lib/Server/Admin/Compare.py4
-rw-r--r--src/lib/Server/Admin/Group.py4
-rw-r--r--src/lib/Server/Admin/Init.py3
-rw-r--r--src/lib/Server/Admin/Minestruct.py4
-rw-r--r--src/lib/Server/Admin/Perf.py5
-rw-r--r--src/lib/Server/Admin/Pull.py7
-rw-r--r--src/lib/Server/Admin/Query.py23
-rw-r--r--src/lib/Server/Admin/Reports.py12
-rw-r--r--src/lib/Server/Admin/Snapshots.py9
-rw-r--r--src/lib/Server/Admin/Tidy.py11
-rw-r--r--src/lib/Server/Admin/Viz.py16
-rw-r--r--src/lib/Server/Admin/__init__.py57
15 files changed, 65 insertions, 120 deletions
diff --git a/src/lib/Server/Admin/Backup.py b/src/lib/Server/Admin/Backup.py
index 9bd644ff9..3744abca3 100644
--- a/src/lib/Server/Admin/Backup.py
+++ b/src/lib/Server/Admin/Backup.py
@@ -12,17 +12,9 @@ class Backup(Bcfg2.Server.Admin.MetadataCore):
#"\n\nbcfg2-admin backup restore")
__usage__ = ("bcfg2-admin backup")
- def __init__(self, configfile):
- Bcfg2.Server.Admin.MetadataCore.__init__(self, configfile,
- self.__usage__)
-
def __call__(self, args):
Bcfg2.Server.Admin.MetadataCore.__call__(self, args)
- # Get Bcfg2 repo directory
- opts = {'repo': Bcfg2.Options.SERVER_REPOSITORY}
- setup = Bcfg2.Options.OptionParser(opts)
- setup.parse(sys.argv[1:])
- self.datastore = setup['repo']
+ self.datastore = self.setup['repo']
timestamp = time.strftime('%Y%m%d%H%M%S')
format = 'gz'
mode = 'w:' + format
diff --git a/src/lib/Server/Admin/Bundle.py b/src/lib/Server/Admin/Bundle.py
index 9b2a71783..89c099602 100644
--- a/src/lib/Server/Admin/Bundle.py
+++ b/src/lib/Server/Admin/Bundle.py
@@ -15,19 +15,13 @@ class Bundle(Bcfg2.Server.Admin.MetadataCore):
"\nbcfg2-admin bundle show\n")
__usage__ = ("bcfg2-admin bundle [options] [add|del] [group]")
- def __init__(self, configfile):
- Bcfg2.Server.Admin.MetadataCore.__init__(self, configfile,
- self.__usage__)
-
def __call__(self, args):
Bcfg2.Server.Admin.MetadataCore.__call__(self, args)
- reg = '((?:[a-z][a-z\\.\\d\\-]+)\\.(?:[a-z][a-z\\-]+))(?![\\w\\.])'
+ rg = re.compile(r'([^.]+\.(?:[a-z][a-z\-]+))(?![\w\.])',
+ re.IGNORECASE | re.DOTALL)
# Get all bundles out of the Bundle/ directory
- opts = {'repo': Bcfg2.Options.SERVER_REPOSITORY}
- setup = Bcfg2.Options.OptionParser(opts)
- setup.parse(sys.argv[1:])
- repo = setup['repo']
+ repo = self.setup['repo']
xml_list = glob.glob("%s/Bundler/*.xml" % repo)
genshi_list = glob.glob("%s/Bundler/*.genshi" % repo)
@@ -50,7 +44,6 @@ class Bundle(Bcfg2.Server.Admin.MetadataCore):
elif args[0] in ['list-xml', 'ls-xml']:
bundle_name = []
for bundle_path in xml_list:
- rg = re.compile(reg, re.IGNORECASE | re.DOTALL)
bundle_name.append(rg.search(bundle_path).group(1))
for bundle in bundle_name:
print(bundle.split('.')[0])
@@ -58,7 +51,6 @@ class Bundle(Bcfg2.Server.Admin.MetadataCore):
elif args[0] in ['list-genshi', 'ls-gen']:
bundle_name = []
for bundle_path in genshi_list:
- rg = re.compile(reg, re.IGNORECASE | re.DOTALL)
bundle_name.append(rg.search(bundle_path).group(1))
for bundle in bundle_name:
print(bundle.split('.')[0])
@@ -71,7 +63,7 @@ class Bundle(Bcfg2.Server.Admin.MetadataCore):
bundle_name = []
bundle_list = xml_list + genshi_list
for bundle_path in bundle_list:
- rg = re.compile(reg, re.IGNORECASE | re.DOTALL)
+ print "matching %s" % bundle_path
bundle_name.append(rg.search(bundle_path).group(1))
text = "Available bundles (Number of bundles: %s)" % \
(len(bundle_list))
diff --git a/src/lib/Server/Admin/Client.py b/src/lib/Server/Admin/Client.py
index c746374a2..4d580c54c 100644
--- a/src/lib/Server/Admin/Client.py
+++ b/src/lib/Server/Admin/Client.py
@@ -13,10 +13,6 @@ class Client(Bcfg2.Server.Admin.MetadataCore):
"\nbcfg2-admin client del <client>\n")
__usage__ = ("bcfg2-admin client [options] [add|del|update|list] [attr=val]")
- def __init__(self, configfile):
- Bcfg2.Server.Admin.MetadataCore.__init__(self, configfile,
- self.__usage__)
-
def __call__(self, args):
Bcfg2.Server.Admin.MetadataCore.__call__(self, args)
if len(args) == 0:
diff --git a/src/lib/Server/Admin/Compare.py b/src/lib/Server/Admin/Compare.py
index 82d0d690c..050dd69f8 100644
--- a/src/lib/Server/Admin/Compare.py
+++ b/src/lib/Server/Admin/Compare.py
@@ -12,8 +12,8 @@ class Compare(Bcfg2.Server.Admin.Mode):
__usage__ = ("bcfg2-admin compare <old> <new>\n\n"
" -r\trecursive")
- def __init__(self, configfile):
- Bcfg2.Server.Admin.Mode.__init__(self, configfile)
+ def __init__(self, setup):
+ Bcfg2.Server.Admin.Mode.__init__(self, setup)
self.important = {'Path': ['name', 'type', 'owner', 'group', 'perms',
'important', 'paranoid', 'sensitive',
'dev_type', 'major', 'minor', 'prune',
diff --git a/src/lib/Server/Admin/Group.py b/src/lib/Server/Admin/Group.py
index 1c5d0c12f..16a773d6f 100644
--- a/src/lib/Server/Admin/Group.py
+++ b/src/lib/Server/Admin/Group.py
@@ -13,10 +13,6 @@ class Group(Bcfg2.Server.Admin.MetadataCore):
"\nbcfg2-admin group del <group>\n")
__usage__ = ("bcfg2-admin group [options] [add|del|update|list] [attr=val]")
- def __init__(self, configfile):
- Bcfg2.Server.Admin.MetadataCore.__init__(self, configfile,
- self.__usage__)
-
def __call__(self, args):
Bcfg2.Server.Admin.MetadataCore.__call__(self, args)
if len(args) == 0:
diff --git a/src/lib/Server/Admin/Init.py b/src/lib/Server/Admin/Init.py
index b7c71e9df..832190b7d 100644
--- a/src/lib/Server/Admin/Init.py
+++ b/src/lib/Server/Admin/Init.py
@@ -173,9 +173,6 @@ class Init(Bcfg2.Server.Admin.Mode):
repopath = ""
response = ""
- def __init__(self, configfile):
- Bcfg2.Server.Admin.Mode.__init__(self, configfile)
-
def _set_defaults(self):
"""Set default parameters."""
self.configfile = self.opts['configfile']
diff --git a/src/lib/Server/Admin/Minestruct.py b/src/lib/Server/Admin/Minestruct.py
index abe1d5a7a..b929a9a8c 100644
--- a/src/lib/Server/Admin/Minestruct.py
+++ b/src/lib/Server/Admin/Minestruct.py
@@ -18,10 +18,6 @@ class Minestruct(Bcfg2.Server.Admin.StructureMode):
"-g <groups>",
"only build config for groups"))
- def __init__(self, configfile):
- Bcfg2.Server.Admin.StructureMode.__init__(self, configfile,
- self.__usage__)
-
def __call__(self, args):
Bcfg2.Server.Admin.Mode.__call__(self, args)
if len(args) == 0:
diff --git a/src/lib/Server/Admin/Perf.py b/src/lib/Server/Admin/Perf.py
index d03b37d57..411442698 100644
--- a/src/lib/Server/Admin/Perf.py
+++ b/src/lib/Server/Admin/Perf.py
@@ -10,9 +10,6 @@ class Perf(Bcfg2.Server.Admin.Mode):
__longhelp__ = (__shorthelp__ + "\n\nbcfg2-admin perf\n")
__usage__ = ("bcfg2-admin perf")
- def __init__(self, configfile):
- Bcfg2.Server.Admin.Mode.__init__(self, configfile)
-
def __call__(self, args):
output = [('Name', 'Min', 'Max', 'Mean', 'Count')]
optinfo = {
@@ -25,7 +22,7 @@ class Perf(Bcfg2.Server.Admin.Mode):
'timeout': Bcfg2.Options.CLIENT_TIMEOUT,
}
setup = Bcfg2.Options.OptionParser(optinfo)
- setup.parse(sys.argv[2:])
+ setup.parse(sys.argv[1:])
proxy = Bcfg2.Proxy.ComponentProxy(setup['server'],
setup['user'],
setup['password'],
diff --git a/src/lib/Server/Admin/Pull.py b/src/lib/Server/Admin/Pull.py
index 47a8be253..daf353107 100644
--- a/src/lib/Server/Admin/Pull.py
+++ b/src/lib/Server/Admin/Pull.py
@@ -28,14 +28,13 @@ class Pull(Bcfg2.Server.Admin.MetadataCore):
"stdin"))
allowed = ['Metadata', 'BB', "DBStats", "Statistics", "Cfg", "SSHbase"]
- def __init__(self, configfile):
- Bcfg2.Server.Admin.MetadataCore.__init__(self, configfile,
- self.__usage__)
+ def __init__(self, setup):
+ Bcfg2.Server.Admin.MetadataCore.__init__(self, setup)
self.log = False
self.mode = 'interactive'
def __call__(self, args):
- Bcfg2.Server.Admin.Mode.__call__(self, args)
+ Bcfg2.Server.Admin.MetadataCore.__call__(self, args)
use_stdin = False
try:
opts, gargs = getopt.getopt(args, 'vfIs')
diff --git a/src/lib/Server/Admin/Query.py b/src/lib/Server/Admin/Query.py
index ff6d9f9b4..3dd326645 100644
--- a/src/lib/Server/Admin/Query.py
+++ b/src/lib/Server/Admin/Query.py
@@ -4,7 +4,7 @@ import Bcfg2.Logger
import Bcfg2.Server.Admin
-class Query(Bcfg2.Server.Admin.Mode):
+class Query(Bcfg2.Server.Admin.MetadataCore):
__shorthelp__ = "Query clients"
__longhelp__ = (__shorthelp__ + "\n\nbcfg2-admin query [-n] [-c] "
"[-f filename] g=group p=profile")
@@ -19,23 +19,14 @@ class Query(Bcfg2.Server.Admin.Mode):
"-f filename",
"write query to file"))
- def __init__(self, cfile):
+ def __init__(self, setup):
+ Bcfg2.Server.Admin.MetadataCore.__init__(self, setup)
logging.root.setLevel(100)
Bcfg2.Logger.setup_logging(100, to_console=False, to_syslog=False)
- Bcfg2.Server.Admin.Mode.__init__(self, cfile)
- try:
- self.bcore = Bcfg2.Server.Core.Core(self.get_repo_path(),
- ['Metadata', 'Probes'],
- 'foo', False, 'UTF-8')
- except Bcfg2.Server.Core.CoreInitError:
- msg = sys.exc_info()[1]
- self.errExit("Core load failed because %s" % msg)
- self.bcore.fam.handle_events_in_interval(1)
- self.meta = self.bcore.metadata
def __call__(self, args):
- Bcfg2.Server.Admin.Mode.__call__(self, args)
- clients = list(self.meta.clients.keys())
+ Bcfg2.Server.Admin.MetadataCore.__call__(self, args)
+ clients = list(self.metadata.clients.keys())
filename_arg = False
filename = None
for arg in args:
@@ -54,9 +45,9 @@ class Query(Bcfg2.Server.Admin.Mode):
print("Unknown argument %s" % arg)
continue
if k == 'p':
- nc = self.meta.get_client_names_by_profiles(v.split(','))
+ nc = self.metadata.get_client_names_by_profiles(v.split(','))
elif k == 'g':
- nc = self.meta.get_client_names_by_groups(v.split(','))
+ nc = self.metadata.get_client_names_by_groups(v.split(','))
# add probed groups (if present)
for conn in self.bcore.connectors:
if isinstance(conn, Bcfg2.Server.Plugins.Probes.Probes):
diff --git a/src/lib/Server/Admin/Reports.py b/src/lib/Server/Admin/Reports.py
index bdfa5c2d6..981d93a08 100644
--- a/src/lib/Server/Admin/Reports.py
+++ b/src/lib/Server/Admin/Reports.py
@@ -77,6 +77,7 @@ class Reports(Bcfg2.Server.Admin.Mode):
'''Admin interface for dynamic reports'''
__shorthelp__ = "Manage dynamic reports"
__longhelp__ = (__shorthelp__)
+ django_commands = ['syncdb', 'sqlall', 'validate']
__usage__ = ("bcfg2-admin reports [command] [options]\n"
" -v|--verbose Be verbose\n"
" -q|--quiet Print only errors\n"
@@ -93,14 +94,13 @@ class Reports(Bcfg2.Server.Admin.Mode):
" --expired Expired clients only\n"
" scrub Scrub the database for duplicate reasons and orphaned entries\n"
" update Apply any updates to the reporting database\n"
- "\n")
+ "\n"
+ " Django commands:\n "
+ "\n ".join(self.django_commands))
- def __init__(self, cfile):
- Bcfg2.Server.Admin.Mode.__init__(self, cfile)
+ def __init__(self, setup):
+ Bcfg2.Server.Admin.Mode.__init__(self, setup)
self.log.setLevel(logging.INFO)
- self.django_commands = ['syncdb', 'sqlall', 'validate']
- self.__usage__ = self.__usage__ + " Django commands:\n " + \
- "\n ".join(self.django_commands)
def __call__(self, args):
Bcfg2.Server.Admin.Mode.__call__(self, args)
diff --git a/src/lib/Server/Admin/Snapshots.py b/src/lib/Server/Admin/Snapshots.py
index 052545b61..8bc56f1f1 100644
--- a/src/lib/Server/Admin/Snapshots.py
+++ b/src/lib/Server/Admin/Snapshots.py
@@ -23,11 +23,10 @@ class Snapshots(Bcfg2.Server.Admin.Mode):
'package': Package,
'snapshot': Snapshot}
- def __init__(self, configfile):
- Bcfg2.Server.Admin.Mode.__init__(self, configfile)
- #self.session = Bcfg2.Server.Snapshots.setup_session(debug=True)
- self.session = Bcfg2.Server.Snapshots.setup_session(configfile)
- self.cfile = configfile
+ def __init__(self, setup):
+ Bcfg2.Server.Admin.Mode.__init__(self, setup)
+ self.session = Bcfg2.Server.Snapshots.setup_session(self.configfile)
+ self.cfile = self.configfile
def __call__(self, args):
Bcfg2.Server.Admin.Mode.__call__(self, args)
diff --git a/src/lib/Server/Admin/Tidy.py b/src/lib/Server/Admin/Tidy.py
index f79991fd9..82319b93e 100644
--- a/src/lib/Server/Admin/Tidy.py
+++ b/src/lib/Server/Admin/Tidy.py
@@ -16,9 +16,6 @@ class Tidy(Bcfg2.Server.Admin.Mode):
"-I",
"interactive"))
- def __init__(self, cfile):
- Bcfg2.Server.Admin.Mode.__init__(self, cfile)
-
def __call__(self, args):
Bcfg2.Server.Admin.Mode.__call__(self, args)
badfiles = self.buildTidyList()
@@ -49,7 +46,7 @@ class Tidy(Bcfg2.Server.Admin.Mode):
bad = []
# clean up unresolvable hosts in SSHbase
- for name in os.listdir("%s/SSHbase" % (self.get_repo_path())):
+ for name in os.listdir("%s/SSHbase" % self.setup['repo']):
if hostmatcher.match(name):
hostname = hostmatcher.match(name).group(1)
if hostname in good + bad:
@@ -59,14 +56,14 @@ class Tidy(Bcfg2.Server.Admin.Mode):
good.append(hostname)
except:
bad.append(hostname)
- for name in os.listdir("%s/SSHbase" % (self.get_repo_path())):
+ for name in os.listdir("%s/SSHbase" % self.setup['repo']):
if not hostmatcher.match(name):
- to_remove.append("%s/SSHbase/%s" % (self.get_repo_path(),
+ to_remove.append("%s/SSHbase/%s" % (self.setup['repo'],
name))
else:
if hostmatcher.match(name).group(1) in bad:
to_remove.append("%s/SSHbase/%s" %
- (self.get_repo_path(), name))
+ (self.setup['repo'], name))
# clean up file~
# clean up files without parsable names in Cfg
return to_remove
diff --git a/src/lib/Server/Admin/Viz.py b/src/lib/Server/Admin/Viz.py
index 2c618634a..2faa423c1 100644
--- a/src/lib/Server/Admin/Viz.py
+++ b/src/lib/Server/Admin/Viz.py
@@ -32,16 +32,10 @@ class Viz(Bcfg2.Server.Admin.MetadataCore):
'indianred1', 'limegreen', 'orange1', 'lightblue2',
'green1', 'blue1', 'yellow1', 'darkturquoise', 'gray66']
- plugin_blacklist = ['DBStats', 'Snapshots', 'Cfg', 'Pkgmgr', 'Packages',
- 'Rules', 'Account', 'Decisions', 'Deps', 'Git', 'Svn',
- 'Fossil', 'Bzr', 'Bundler', 'TGenshi', 'SGenshi',
- 'Base']
-
- def __init__(self, cfile):
-
- Bcfg2.Server.Admin.MetadataCore.__init__(self, cfile,
- self.__usage__,
- pblacklist=self.plugin_blacklist)
+ __plugin_blacklist__ = ['DBStats', 'Snapshots', 'Cfg', 'Pkgmgr', 'Packages',
+ 'Rules', 'Account', 'Decisions', 'Deps', 'Git',
+ 'Svn', 'Fossil', 'Bzr', 'Bundler', 'TGenshi',
+ 'SGenshi', 'Base']
def __call__(self, args):
Bcfg2.Server.Admin.MetadataCore.__call__(self, args)
@@ -73,7 +67,7 @@ class Viz(Bcfg2.Server.Admin.MetadataCore):
elif opt in ("-o", "--outfile"):
outputfile = arg
- data = self.Visualize(self.get_repo_path(), hset, bset,
+ data = self.Visualize(self.setup['repo'], hset, bset,
kset, only_client, outputfile)
if data:
print(data)
diff --git a/src/lib/Server/Admin/__init__.py b/src/lib/Server/Admin/__init__.py
index d71d789e7..a9f0b8cd6 100644
--- a/src/lib/Server/Admin/__init__.py
+++ b/src/lib/Server/Admin/__init__.py
@@ -36,12 +36,16 @@ class Mode(object):
"""Help message has not yet been added for mode."""
__shorthelp__ = 'Shorthelp not defined yet'
__longhelp__ = 'Longhelp not defined yet'
+ __usage__ = None
__args__ = []
- def __init__(self, configfile):
- self.configfile = configfile
+ def __init__(self, setup):
+ self.setup = setup
+ self.configfile = setup['configfile']
self.__cfp = False
self.log = logging.getLogger('Bcfg2.Server.Admin.Mode')
+ if self.__usage__ is not None:
+ setup.hm = self.__usage__
def getCFP(self):
if not self.__cfp:
@@ -58,16 +62,8 @@ class Mode(object):
print(emsg)
raise SystemExit(1)
- def get_repo_path(self):
- """Return repository path"""
- try:
- return self.cfp.get('server', 'repository')
- except ConfigParser.NoSectionError:
- self.errExit("Unable to find server section in bcfg2.conf")
-
def load_stats(self, client):
- stats = lxml.etree.parse("%s/etc/statistics.xml" %
- (self.get_repo_path()))
+ stats = lxml.etree.parse("%s/etc/statistics.xml" % self.setup['repo'])
hostent = stats.xpath('//Node[@name="%s"]' % client)
if not hostent:
self.errExit("Could not find stats for client %s" % (client))
@@ -110,27 +106,30 @@ class Mode(object):
class MetadataCore(Mode):
"""Base class for admin-modes that handle metadata."""
- def __init__(self, configfile, usage, pwhitelist=None, pblacklist=None):
- Mode.__init__(self, configfile)
- options = {'plugins': Bcfg2.Options.SERVER_PLUGINS,
- 'configfile': Bcfg2.Options.CFILE,
- 'encoding': Bcfg2.Options.ENCODING}
- setup = Bcfg2.Options.OptionParser(options)
- setup.hm = usage
- setup.parse(sys.argv[1:])
- if pwhitelist is not None:
- setup['plugins'] = [x for x in setup['plugins']
- if x in pwhitelist]
- elif pblacklist is not None:
- setup['plugins'] = [x for x in setup['plugins']
- if x not in pblacklist]
+ __plugin_whitelist__ = None
+ __plugin_blacklist__ = None
+
+ def __init__(self, setup):
+ Mode.__init__(self, setup)
+ if self.__plugin_whitelist__ is not None:
+ setup['plugins'] = [p for p in setup['plugins']
+ if p in self.__plugin_whitelist__]
+ elif self.__plugin_blacklist__ is not None:
+ setup['plugins'] = [p for p in setup['plugins']
+ if p not in self.__plugin_blacklist__]
+
try:
- self.bcore = Bcfg2.Server.Core.Core(self.get_repo_path(),
- setup['plugins'],
- 'foo', setup['encoding'])
+ self.bcore = \
+ Bcfg2.Server.Core.Core(setup['repo'],
+ setup['plugins'],
+ setup['password'],
+ setup['encoding'],
+ filemonitor=setup['filemonitor'])
+ if setup['event debug']:
+ self.bcore.fam.debug = True
except Bcfg2.Server.Core.CoreInitError:
msg = sys.exc_info()[1]
- self.errExit("Core load failed because %s" % msg)
+ self.errExit("Core load failed: %s" % msg)
self.bcore.fam.handle_events_in_interval(5)
self.metadata = self.bcore.metadata