Projet

Général

Profil

0001-Add-a-generic-command-to-deploy-service-tenants-from.patch

Benjamin Dauvergne, 23 janvier 2015 18:11

Télécharger (1,73 ko)

Voir les différences:

Subject: [PATCH] Add a generic command to deploy service tenants from hobo

It must be overloaded by applications.
 .../multitenant/management/commands/deploy.py      |   30 ++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 entrouvert/djommon/multitenant/management/commands/deploy.py
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
0
-