2013-10-17 16:33:04 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from optparse import make_option
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
|
|
from zerver.models import get_realm
|
|
|
|
from zerver.lib.create_user import random_api_key
|
|
|
|
from zerver.management.commands.create_realm import Command as CreateRealm
|
|
|
|
|
|
|
|
from zilencer.models import Deployment
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = """Create a deployment and accompanying realm."""
|
|
|
|
|
|
|
|
option_list = CreateRealm.option_list + (
|
|
|
|
make_option('--no-realm',
|
|
|
|
dest='no_realm',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Do not create a new realm; associate with an existing one.' + \
|
2013-10-25 23:35:24 +02:00
|
|
|
' In this case, only the domain and URLs need to be specified.'),
|
|
|
|
make_option('-a', '--api-url',
|
|
|
|
dest='api',
|
|
|
|
type='str'),
|
|
|
|
make_option('-w', '--web-url',
|
|
|
|
dest='web',
|
|
|
|
type='str'),
|
|
|
|
|
2013-10-17 16:33:04 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2013-10-25 23:35:24 +02:00
|
|
|
if None in (options["api"], options["web"], options["domain"]):
|
|
|
|
print >>sys.stderr, "\033[1;31mYou must provide a domain, an API URL, and a web URL.\033[0m\n"
|
2013-10-17 16:33:04 +02:00
|
|
|
self.print_help("python manage.py", "create_realm")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
if not options["no_realm"]:
|
|
|
|
CreateRealm().handle(*args, **options)
|
|
|
|
print # Newline
|
|
|
|
|
|
|
|
realm = get_realm(options["domain"])
|
|
|
|
if realm is None:
|
|
|
|
print >>sys.stderr, "\033[1;31mRealm does not exist!\033[0m\n"
|
|
|
|
exit(2)
|
|
|
|
|
|
|
|
dep = Deployment()
|
|
|
|
dep.api_key = random_api_key()
|
|
|
|
dep.save()
|
2013-10-25 23:24:26 +02:00
|
|
|
old_dep = realm.deployment
|
|
|
|
if old_dep is not None:
|
|
|
|
old_dep.realms.remove(realm)
|
|
|
|
old_dep.save()
|
2013-10-17 16:33:04 +02:00
|
|
|
dep.realms = [realm]
|
2013-10-25 23:35:24 +02:00
|
|
|
dep.base_api_url = options["api"]
|
2013-11-14 16:15:25 +01:00
|
|
|
dep.base_site_url = options["web"]
|
2013-10-17 16:33:04 +02:00
|
|
|
dep.save()
|
2013-11-14 03:56:48 +01:00
|
|
|
print "Deployment %s created." % (dep.id,)
|
|
|
|
print "DEPLOYMENT_ROLE_NAME = %s" % (dep.name,)
|
|
|
|
print "DEPLOYMENT_ROLE_KEY = %s" % (dep.api_key,)
|