2019-01-04 10:02:28 +00:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
from peeringdb_server import maintenance
|
|
|
|
|
|
2019-12-05 16:57:52 +00:00
|
|
|
|
2019-01-04 10:02:28 +00:00
|
|
|
class Command(BaseCommand):
|
|
|
|
|
help = "Put instance in or out of maintenance mode"
|
|
|
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
2019-12-05 16:57:52 +00:00
|
|
|
parser.add_argument("state", nargs="?", choices=["on", "off"])
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--commit", action="store_true", help="will commit the changes"
|
|
|
|
|
)
|
2019-01-04 10:02:28 +00:00
|
|
|
|
|
|
|
|
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:
|
2019-12-05 16:57:52 +00:00
|
|
|
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."
|
|
|
|
|
)
|
2019-01-04 10:02:28 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
|
|
self.log("Setting maintenance mode {}".format(self.state))
|
|
|
|
|
if self.state == "on":
|
|
|
|
|
maintenance.on()
|
|
|
|
|
else:
|
|
|
|
|
maintenance.off()
|