diff options
Diffstat (limited to 'src/lib/Bcfg2/Server/Admin.py')
-rw-r--r-- | src/lib/Bcfg2/Server/Admin.py | 123 |
1 files changed, 57 insertions, 66 deletions
diff --git a/src/lib/Bcfg2/Server/Admin.py b/src/lib/Bcfg2/Server/Admin.py index b88aa837f..7c2241f58 100644 --- a/src/lib/Bcfg2/Server/Admin.py +++ b/src/lib/Bcfg2/Server/Admin.py @@ -1,6 +1,5 @@ """ Subcommands and helpers for bcfg2-admin """ -import re import os import sys import time @@ -20,7 +19,6 @@ import Bcfg2.Server.Core import Bcfg2.Client.Proxy from Bcfg2.Server.Plugin import PullSource, Generator, MetadataConsistencyError from Bcfg2.Utils import hostnames2ranges, Executor, safe_input -from Bcfg2.Compat import xmlrpclib import Bcfg2.Server.Plugins.Metadata try: @@ -413,13 +411,15 @@ class Init(AdminCmd): config = '''[server] repository = %s plugins = %s +# Uncomment the following to listen on all interfaces +#listen_all = true [database] #engine = sqlite3 # 'postgresql', 'mysql', 'mysql_old', 'sqlite3' or 'ado_mssql'. #name = # Or path to database file if using sqlite3. -#<repository>/bcfg2.sqlite is default path if left empty +#<repository>/etc/bcfg2.sqlite is default path if left empty #user = # Not used with sqlite3. #password = @@ -830,6 +830,49 @@ class _ReportsCmd(AdminCmd): Bcfg2.Reporting.models.Performance) +if HAS_DJANGO: + class _DjangoProxyCmd(AdminCmd): + command = None + args = [] + + def run(self, _): + '''Call a django command''' + if self.command is not None: + command = self.command + else: + command = self.__class__.__name__.lower() + args = [command] + self.args + management.call_command(*args) + + class DBShell(_DjangoProxyCmd): + """ Call the Django 'dbshell' command on the database """ + + class Shell(_DjangoProxyCmd): + """ Call the Django 'shell' command on the database """ + + class ValidateDB(_DjangoProxyCmd): + """ Call the Django 'validate' command on the database """ + command = "validate" + + class Syncdb(AdminCmd): + """ Sync the Django ORM with the configured database """ + + def run(self, setup): + management.setup_environ(Bcfg2.settings) + Bcfg2.Server.models.load_models() + try: + management.call_command("syncdb", interactive=False, + verbosity=setup.verbose + setup.debug) + except ImproperlyConfigured: + err = sys.exc_info()[1] + self.logger.error("Django configuration problem: %s" % err) + raise SystemExit(1) + except: + err = sys.exc_info()[1] + self.logger.error("Database update failed: %s" % err) + raise SystemExit(1) + + if HAS_REPORTS: import datetime @@ -875,11 +918,9 @@ if HAS_REPORTS: (self.__class__.__name__.title(), sys.exc_info()[1])) - class UpdateReports(InitReports): """ Apply updates to the reporting database """ - class ReportsStats(_ReportsCmd): """ Print Reporting database statistics """ def run(self, _): @@ -887,7 +928,6 @@ if HAS_REPORTS: print("%s has %s records" % (cls.__name__, cls.objects.count())) - class PurgeReports(_ReportsCmd): """ Purge records from the Reporting database """ @@ -969,12 +1009,12 @@ if HAS_REPORTS: self.logger.debug("Deleted %s of %s" % (rnum, count)) except: # pylint: disable=W0702 self.logger.error("Failed to remove interactions: %s" % - sys.exc_info()[1]) + sys.exc_info()[1]) # Prune any orphaned ManyToMany relations for m2m in self.reports_entries: - self.logger.debug("Pruning any orphaned %s objects" % \ - m2m.__name__) + self.logger.debug("Pruning any orphaned %s objects" % + m2m.__name__) m2m.prune_orphans() if client and not filtered: @@ -984,7 +1024,7 @@ if HAS_REPORTS: cobj.delete() except: # pylint: disable=W0702 self.logger.error("Failed to delete client %s: %s" % - (client, sys.exc_info()[1])) + (client, sys.exc_info()[1])) def purge_expired(self, maxdate=None): """ Purge expired clients from the Reporting database """ @@ -1005,63 +1045,11 @@ if HAS_REPORTS: client=client).delete() client.delete() - - class _DjangoProxyCmd(AdminCmd): - command = None - args = [] - _reports_re = re.compile(r'^(?:Reports)?(?P<command>.*?)(?:Reports)?$') - - def run(self, _): - '''Call a django command''' - if self.command is not None: - command = self.command - else: - match = self._reports_re.match(self.__class__.__name__) - if match: - command = match.group("command").lower() - else: - command = self.__class__.__name__.lower() - args = [command] + self.args - management.call_command(*args) - - - class ReportsDBShell(_DjangoProxyCmd): - """ Call the Django 'dbshell' command on the Reporting database """ - - - class ReportsShell(_DjangoProxyCmd): - """ Call the Django 'shell' command on the Reporting database """ - - - class ValidateReports(_DjangoProxyCmd): - """ Call the Django 'validate' command on the Reporting database """ - - class ReportsSQLAll(_DjangoProxyCmd): """ Call the Django 'sqlall' command on the Reporting database """ args = ["Reporting"] -if HAS_DJANGO: - class Syncdb(AdminCmd): - """ Sync the Django ORM with the configured database """ - - def run(self, setup): - management.setup_environ(Bcfg2.settings) - Bcfg2.Server.models.load_models() - try: - management.call_command("syncdb", interactive=False, - verbosity=setup.verbose + setup.debug) - except ImproperlyConfigured: - err = sys.exc_info()[1] - self.logger.error("Django configuration problem: %s" % err) - raise SystemExit(1) - except: - err = sys.exc_info()[1] - self.logger.error("Database update failed: %s" % err) - raise SystemExit(1) - - class Viz(_ServerAdminCmd): """ Produce graphviz diagrams of metadata structures """ @@ -1101,10 +1089,12 @@ class Viz(_ServerAdminCmd): if setup.outfile: cmd.extend(["-o", setup.outfile]) inputlist = ["digraph groups {", - '\trankdir="LR";', - self.metadata.viz(setup.includehosts, setup.includebundles, - setup.includekey, setup.only_client, - self.colors)] + '\trankdir="LR";', + self.metadata.viz(setup.includehosts, + setup.includebundles, + setup.includekey, + setup.only_client, + self.colors)] if setup.includekey: inputlist.extend( ["\tsubgraph cluster_key {", @@ -1150,6 +1140,7 @@ class Xcmd(_ProxyAdminCmd): class CLI(Bcfg2.Options.CommandRegistry): + """ CLI class for bcfg2-admin """ def __init__(self): Bcfg2.Options.CommandRegistry.__init__(self) Bcfg2.Options.register_commands(self.__class__, globals().values(), |