From 12cf1871dbf5cfe3288f17f943f19617ca7f115d Mon Sep 17 00:00:00 2001 From: Serghei MIHAI Date: Tue, 10 Feb 2015 16:07:10 +0100 Subject: [PATCH] re-usable tenant deploy command --- .../multitenant/management/commands/__init__.py | 29 ++++++++++++++++++++- .../multitenant/management/commands/deploy.py | 30 ---------------------- 2 files changed, 28 insertions(+), 31 deletions(-) delete mode 100644 entrouvert/djommon/multitenant/management/commands/deploy.py diff --git a/entrouvert/djommon/multitenant/management/commands/__init__.py b/entrouvert/djommon/multitenant/management/commands/__init__.py index 601f3fd..1998022 100644 --- a/entrouvert/djommon/multitenant/management/commands/__init__.py +++ b/entrouvert/djommon/multitenant/management/commands/__init__.py @@ -3,6 +3,11 @@ # Email: carneiro.be@gmail.com # License: MIT license # Home-page: http://github.com/bcarneiro/django-tenant-schemas + +import json +import sys +import urllib2 + from optparse import make_option from django.conf import settings from django.core.management import call_command, get_commands, load_command_class @@ -12,7 +17,7 @@ try: from django.utils.six.moves import input except ImportError: input = raw_input -from tenant_schemas.utils import get_public_schema_name +from tenant_schemas.utils import get_public_schema_name, tenant_context from entrouvert.djommon.multitenant.middleware import TenantMiddleware @@ -169,3 +174,25 @@ class SyncCommon(BaseCommand): def _notice(self, output): self.stdout.write(self.style.NOTICE(output)) + +class DeployCommand(BaseCommand): + help = 'Deploy a tenant from hobo' + + def handle(self, base_url, **options): + environment = json.load(sys.stdin) + for service in environment['services']: + if service['base_url'] == base_url: + break + else: + raise CommandError('Service %s not found' % base_url) + hostname = urllib2.urlparse.urlsplit(base_url).netloc + print "HOSTNAME: %s" % hostname + + call_command('create_tenant', hostname) + + tenant = TenantMiddleware.get_tenant_by_hostname(hostname) + with tenant_context(tenant): + self.deploy_tenant(environment, service, options) + + def deploy_tenant(self, environment, service, options): + pass diff --git a/entrouvert/djommon/multitenant/management/commands/deploy.py b/entrouvert/djommon/multitenant/management/commands/deploy.py deleted file mode 100644 index f37d155..0000000 --- a/entrouvert/djommon/multitenant/management/commands/deploy.py +++ /dev/null @@ -1,30 +0,0 @@ -import urllib2 -import json -import sys - -from django.core.management import call_command -from django.core.management.base import BaseCommand, CommandError - -from tenant_schemas.utils import tenant_context -from entrouvert.djommon.multitenant.middleware import TenantMiddleware - -class Command(BaseCommand): - help = 'Deploy a tenant from hobo' - - def handle(self, base_url, **options): - environment = json.load(sys.stdin) - for service in environment['services']: - if service['base_url'] == base_url: - break - else: - raise CommandError('Service %s not found' % base_url) - hostname = urllib2.urlparse.urlsplit(base_url).netloc - - call_command('create_tenant', hostname) - - tenant = TenantMiddleware.get_tenant_by_hostname(hostname) - with tenant_context(tenant): - self.deploy_tenant(environment, service, options) - - def deploy_tenant(self, environment, service, options): - pass -- 2.1.4