mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
from django.core.management.base import BaseCommand
|
|
from django.conf import settings
|
|
from peeringdb_server import maintenance
|
|
|
|
class Command(BaseCommand):
|
|
help = "Put instance in or out of maintenance mode"
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument("state", nargs="?", choices=["on","off"])
|
|
parser.add_argument('--commit', action='store_true',
|
|
help="will commit the changes")
|
|
|
|
def log(self, msg):
|
|
if self.commit:
|
|
self.stdout.write(msg)
|
|
else:
|
|
self.stdout.write("[pretend] {}".format(msg))
|
|
|
|
def handle(self, *args, **options):
|
|
self.commit = options.get("commit", False)
|
|
self.state = options.get("state")
|
|
|
|
if not settings.TUTORIAL_MODE:
|
|
self.log("Command cannot be run on environment's that are not in tutorial mode. "\
|
|
" Maintenance mode "\
|
|
" is currently implemented to the extent that it is required to facilitate"\
|
|
" an environment reset on `tutorial` type servers and probably needs more work"\
|
|
" to be useful on production.")
|
|
return
|
|
|
|
|
|
self.log("Setting maintenance mode {}".format(self.state))
|
|
if self.state == "on":
|
|
maintenance.on()
|
|
else:
|
|
maintenance.off()
|