summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Admin.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Bcfg2/Server/Admin.py')
-rw-r--r--src/lib/Bcfg2/Server/Admin.py50
1 files changed, 44 insertions, 6 deletions
diff --git a/src/lib/Bcfg2/Server/Admin.py b/src/lib/Bcfg2/Server/Admin.py
index c294e6be5..c32b1989b 100644
--- a/src/lib/Bcfg2/Server/Admin.py
+++ b/src/lib/Bcfg2/Server/Admin.py
@@ -25,15 +25,19 @@ import Bcfg2.Server.Plugins.Metadata
try:
from django.core.exceptions import ImproperlyConfigured
from django.core import management
+ import django
import django.conf
import Bcfg2.Server.models
HAS_DJANGO = True
- try:
- import south # pylint: disable=W0611
+ if django.VERSION[0] == 1 and django.VERSION[1] >= 7:
HAS_REPORTS = True
- except ImportError:
- HAS_REPORTS = False
+ else:
+ try:
+ import south # pylint: disable=W0611
+ HAS_REPORTS = True
+ except ImportError:
+ HAS_REPORTS = False
except ImportError:
HAS_DJANGO = False
HAS_REPORTS = False
@@ -439,6 +443,25 @@ class Compare(AdminCmd):
print("")
+class ExpireCache(_ProxyAdminCmd):
+ """ Expire the metadata cache """
+
+ options = _ProxyAdminCmd.options + [
+ Bcfg2.Options.PositionalArgument(
+ "hostname", nargs="*", default=[],
+ help="Expire cache for the given host(s)")]
+
+ def run(self, setup):
+ clients = None
+ if setup.hostname is not None and len(setup.hostname) > 0:
+ clients = setup.hostname
+
+ try:
+ self.proxy.expire_metadata_cache(clients)
+ except Bcfg2.Client.Proxy.ProxyError:
+ self.errExit("Proxy Error: %s" % sys.exc_info()[1])
+
+
class Init(AdminCmd):
"""Interactively initialize a new repository."""
@@ -877,6 +900,7 @@ if HAS_DJANGO:
Django management system """
command = None
args = []
+ kwargs = {}
def run(self, _):
'''Call a django command'''
@@ -885,7 +909,7 @@ if HAS_DJANGO:
else:
command = self.__class__.__name__.lower()
args = [command] + self.args
- management.call_command(*args)
+ management.call_command(*args, **self.kwargs)
class DBShell(_DjangoProxyCmd):
""" Call the Django 'dbshell' command on the database """
@@ -901,7 +925,6 @@ if HAS_DJANGO:
""" Sync the Django ORM with the configured database """
def run(self, setup):
- Bcfg2.Server.models.load_models()
try:
Bcfg2.DBSettings.sync_databases(
interactive=False,
@@ -915,6 +938,17 @@ if HAS_DJANGO:
self.logger.error("Database update failed: %s" % err)
raise SystemExit(1)
+ if django.VERSION[0] == 1 and django.VERSION[1] >= 7:
+ class Makemigrations(_DjangoProxyCmd):
+ """ Call the 'makemigrations' command on the database """
+ args = ['Reporting']
+
+ else:
+ class Schemamigration(_DjangoProxyCmd):
+ """ Call the South 'schemamigration' command on the database """
+ args = ['Bcfg2.Reporting']
+ kwargs = {'auto': True}
+
if HAS_REPORTS:
import datetime
@@ -1194,6 +1228,10 @@ class CLI(Bcfg2.Options.CommandRegistry):
components=[self])
parser.add_options(self.subcommand_options)
parser.parse()
+ if django.VERSION[0] == 1 and django.VERSION[1] >= 7:
+ # this has been introduced in django 1.7, so pylint fails with
+ # older django releases
+ django.setup() # pylint: disable=E1101
def run(self):
""" Run bcfg2-admin """