Project

General

Profile

« Previous | Next » 

Revision d2ffb5af

Added by Benjamin Dauvergne over 9 years ago

Add a generic command to deploy service tenants from hobo (#6340)

It must be overloaded by applications.

View differences:

entrouvert/djommon/multitenant/management/commands/deploy.py
1
import urllib2
2
import json
3
import sys
4

  
5
from django.core.management import call_command
6
from django.core.management.base import BaseCommand, CommandError
7

  
8
from tenant_schemas.utils import tenant_context
9
from entrouvert.djommon.multitenant.middleware import TenantMiddleware
10

  
11
class Command(BaseCommand):
12
    help = 'Deploy a tenant from hobo'
13

  
14
    def handle(self, base_url, **options):
15
        environment = json.load(sys.stdin)
16
        for service in environment['services']:
17
            if service['base_url'] == base_url:
18
                break
19
        else:
20
            raise CommandError('Service %s not found' % base_url)
21
        hostname = urllib2.urlparse.urlsplit(base_url).netloc
22

  
23
        call_command('create_tenant', hostname)
24

  
25
        tenant_name = TenantMiddleware.hostname2schema(hostname)
26
        with tenant_context(tenant_name):
27
            self.deploy_tenant(environment, service)
28

  
29
    def deploy_tenant(self, options, environment, service):
30
        pass

Also available in: Unified diff