commit 9619cc6421e06eb2b6a4889b9277c1ab504bc2ed
Author: Georgios D. Tsoukalas <gtsouk@cslab.ece.ntua.gr>
Date:   Fri Aug 3 18:16:34 2012 +0300

    cleanup django settings startup and auto-config

diff --git a/commissioning/servers/fscrud/__init__.py b/commissioning/servers/fscrud/__init__.py
index 8b13789..8d1c8b6 100644
--- a/commissioning/servers/fscrud/__init__.py
+++ b/commissioning/servers/fscrud/__init__.py
@@ -1 +1 @@
-
+ 
diff --git a/commissioning/servers/fscrud/callpoint.py b/commissioning/servers/fscrud/callpoint.py
deleted file mode 100644
index d02791a..0000000
--- a/commissioning/servers/fscrud/callpoint.py
+++ /dev/null
@@ -1,56 +0,0 @@
-
-from commissioning import ControlledCallpoint, get_callpoint, mkcallargs
-from commissioning.controllers.django_controller \
-    import Controller as DjangoController
-from commissioning.specs.fscrud import API_Spec as FSCrudAPI
-from commissioning.physicals.fscrud import FSCrudPhysical
-from django.conf import settings
-
-
-qh_callpoint = get_callpoint('clients.quotaholder', automake='http')
-fscrud_api_spec = FSCrudAPI()
-
-class FSCrudDjangoController(DjangoController):
-
-    def controller_init(self):
-        self.context = {}
-        self.clientkey = 'fscrudck'
-        self.entitykey = 'fscrudek'
-        self.entityroot = 'fscrud'
-
-    def get_commission_issue(self, commission_spec):
-        call_data = commission_spec['call_data']
-        path = call_data['path']
-        args = mkcallargs (
-                context     =   self.context,
-                entity      =   path,
-                key         =   self.entitykey,
-                clientkey   =   self.clientkey,
-                owner       =   self.entityroot,
-                ownerkey    =   self.entitykey,
-                provisions  =   [('access', 'path', 1)]
-        )
-
-        return args
-
-
-class FSCrudControlled(ControlledCallpoint):
-
-    api_spec = fscrud_api_spec
-
-    def init_connection(self, connection):
-	# ignore connection
-	queuepath = settings.FSCRUD_QUEUE_PATH
-	dataroot = settings.FSCRUD_DATA_ROOT
-        physical = FSCrudPhysical(queuepath, dataroot)
-        quotaholder = qh_callpoint('null://wherever/')
-        self.controller = FSCrudDjangoController(quotaholder, physical)
-
-    def commit(self):
-        pass
-
-    def rollback(self):
-        pass
-
-API_Callpoint = FSCrudControlled
-
diff --git a/commissioning/servers/fscrud/fscrud-manage b/commissioning/servers/fscrud/fscrud-manage
deleted file mode 100755
index cc255f8..0000000
--- a/commissioning/servers/fscrud/fscrud-manage
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/env python
-from os import environ
-from os.path import basename
-from sys import argv
-
-
-environ['COMMISSIONING_APP_NAME'] = 'fscrud'
-
-from django.core.management import execute_manager
-try:
-    import commissioning.servers.fscrud.settings as settings
-except ImportError:
-    import sys
-    sys.stderr.write("%s: Can't import settings." % __file__)
-    sys.exit(1)
-
-if __name__ == "__main__":
-    execute_manager(settings)
diff --git a/commissioning/servers/fscrud/fscrud_django/__init__.py b/commissioning/servers/fscrud/fscrud_django/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/commissioning/servers/fscrud/fscrud_django/__init__.py
@@ -0,0 +1 @@
+
diff --git a/commissioning/servers/fscrud/fscrud_django/callpoint.py b/commissioning/servers/fscrud/fscrud_django/callpoint.py
new file mode 100644
index 0000000..d02791a
--- /dev/null
+++ b/commissioning/servers/fscrud/fscrud_django/callpoint.py
@@ -0,0 +1,56 @@
+
+from commissioning import ControlledCallpoint, get_callpoint, mkcallargs
+from commissioning.controllers.django_controller \
+    import Controller as DjangoController
+from commissioning.specs.fscrud import API_Spec as FSCrudAPI
+from commissioning.physicals.fscrud import FSCrudPhysical
+from django.conf import settings
+
+
+qh_callpoint = get_callpoint('clients.quotaholder', automake='http')
+fscrud_api_spec = FSCrudAPI()
+
+class FSCrudDjangoController(DjangoController):
+
+    def controller_init(self):
+        self.context = {}
+        self.clientkey = 'fscrudck'
+        self.entitykey = 'fscrudek'
+        self.entityroot = 'fscrud'
+
+    def get_commission_issue(self, commission_spec):
+        call_data = commission_spec['call_data']
+        path = call_data['path']
+        args = mkcallargs (
+                context     =   self.context,
+                entity      =   path,
+                key         =   self.entitykey,
+                clientkey   =   self.clientkey,
+                owner       =   self.entityroot,
+                ownerkey    =   self.entitykey,
+                provisions  =   [('access', 'path', 1)]
+        )
+
+        return args
+
+
+class FSCrudControlled(ControlledCallpoint):
+
+    api_spec = fscrud_api_spec
+
+    def init_connection(self, connection):
+	# ignore connection
+	queuepath = settings.FSCRUD_QUEUE_PATH
+	dataroot = settings.FSCRUD_DATA_ROOT
+        physical = FSCrudPhysical(queuepath, dataroot)
+        quotaholder = qh_callpoint('null://wherever/')
+        self.controller = FSCrudDjangoController(quotaholder, physical)
+
+    def commit(self):
+        pass
+
+    def rollback(self):
+        pass
+
+API_Callpoint = FSCrudControlled
+
diff --git a/commissioning/servers/fscrud/fscrud_django/fscrud-manage b/commissioning/servers/fscrud/fscrud_django/fscrud-manage
new file mode 100755
index 0000000..cc255f8
--- /dev/null
+++ b/commissioning/servers/fscrud/fscrud_django/fscrud-manage
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+from os import environ
+from os.path import basename
+from sys import argv
+
+
+environ['COMMISSIONING_APP_NAME'] = 'fscrud'
+
+from django.core.management import execute_manager
+try:
+    import commissioning.servers.fscrud.settings as settings
+except ImportError:
+    import sys
+    sys.stderr.write("%s: Can't import settings." % __file__)
+    sys.exit(1)
+
+if __name__ == "__main__":
+    execute_manager(settings)
diff --git a/commissioning/servers/fscrud/fscrud_django/settings.py b/commissioning/servers/fscrud/fscrud_django/settings.py
new file mode 100644
index 0000000..b0255f8
--- /dev/null
+++ b/commissioning/servers/fscrud/fscrud_django/settings.py
@@ -0,0 +1,106 @@
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+FSCRUD_QUEUE_PATH = '/var/lib/fscrude/queue'
+FSCRUD_DATA_ROOT = '/var/lib/fscrude/data'
+
+DATABASES = {
+    'default': {
+        # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+        'ENGINE': 'django.db.backends.postgresql_psycopg2',
+        'NAME': 'holder',               # Or path to database file if using sqlite3.
+        'USER': 'holder',               # Not used with sqlite3.
+        'PASSWORD': 'holder',           # Not used with sqlite3.
+        'HOST': '127.0.0.1',            # Set to empty string for localhost. Not used with sqlite3.
+        'PORT': '5432',                 # Set to empty string for default. Not used with sqlite3.
+    }
+}
+
+from commissioning.utils.pyconf import pyconf_globals
+pyconf_globals('/etc/fscrud/django.conf')
+
+import sys
+sys.stderr = sys.stdout
+
+COMMISSIONING_APP_NAME = 'fscrud'
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+TIME_ZONE = 'UTC'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = False
+
+# If you set this to False, Django will not format dates, numbers and
+# calendars according to the current locale
+USE_L10N = False
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = 'ee=*x%x6sp=hcm7j4zzkvpam27g*7*d59fca-q!azaqma!jx*+'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.Loader',
+    'django.template.loaders.app_directories.Loader',
+#     'django.template.loaders.eggs.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    #'django.middleware.transaction.TransactionMiddleware',
+    #'django.contrib.sessions.middleware.SessionMiddleware',
+    #'django.middleware.csrf.CsrfViewMiddleware',
+    #'django.contrib.auth.middleware.AuthenticationMiddleware',
+    #'django.contrib.messages.middleware.MessageMiddleware',
+)
+
+ROOT_URLCONF = 'commissioning.servers.fscrud.urls'
+
+TEMPLATE_DIRS = (
+    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+    # Always use forward slashes, even on Windows.
+    # Don't forget to use absolute paths, not relative paths.
+)
+
+
+INSTALLED_APPS = (
+    #'django.contrib.auth',
+    'django.contrib.contenttypes',
+    #'django.contrib.sessions',
+    #'django.contrib.sites',
+    #'django.contrib.messages',
+    'commissioning.controllers.django_controller',
+    'commissioning.servers.django_server.server_app',
+    #'commissioning.servers.django_server.server_app',
+    # Uncomment the next line to enable the admin:
+    # 'django.contrib.admin',
+    # Uncomment the next line to enable admin documentation:
+    # 'django.contrib.admindocs',
+)
+
+names = COMMISSIONING_APP_NAME.split(',')
+names = ('commissioning.servers.%s.django_backend' % (n,) for n in names)
+from django.utils.importlib import import_module
+
+applist = []
+for name in names:
+    try:
+        import_module(name)
+        applist.append(name)
+    except ImportError:
+        pass
+
+INSTALLED_APPS += tuple(applist)
+
diff --git a/commissioning/servers/fscrud/fscrud_django/urls.py b/commissioning/servers/fscrud/fscrud_django/urls.py
new file mode 100644
index 0000000..400747f
--- /dev/null
+++ b/commissioning/servers/fscrud/fscrud_django/urls.py
@@ -0,0 +1,17 @@
+from django.conf.urls.defaults import *
+
+# Uncomment the next two lines to enable the admin:
+# from django.contrib import admin
+# admin.autodiscover()
+
+urlpatterns = patterns('',
+    # Example:
+    # (r'^quota/', include('quota.foo.urls')),
+
+    # Uncomment the admin/doc line below to enable admin documentation:
+    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+    # Uncomment the next line to enable the admin:
+    # (r'^admin/', include(admin.site.urls)),
+    (r'^api/', include('commissioning.servers.django_server.server_app.urls')),
+)
diff --git a/commissioning/servers/fscrud/settings.py b/commissioning/servers/fscrud/settings.py
deleted file mode 100644
index b0255f8..0000000
--- a/commissioning/servers/fscrud/settings.py
+++ /dev/null
@@ -1,106 +0,0 @@
-
-DEBUG = True
-TEMPLATE_DEBUG = DEBUG
-
-FSCRUD_QUEUE_PATH = '/var/lib/fscrude/queue'
-FSCRUD_DATA_ROOT = '/var/lib/fscrude/data'
-
-DATABASES = {
-    'default': {
-        # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
-        'ENGINE': 'django.db.backends.postgresql_psycopg2',
-        'NAME': 'holder',               # Or path to database file if using sqlite3.
-        'USER': 'holder',               # Not used with sqlite3.
-        'PASSWORD': 'holder',           # Not used with sqlite3.
-        'HOST': '127.0.0.1',            # Set to empty string for localhost. Not used with sqlite3.
-        'PORT': '5432',                 # Set to empty string for default. Not used with sqlite3.
-    }
-}
-
-from commissioning.utils.pyconf import pyconf_globals
-pyconf_globals('/etc/fscrud/django.conf')
-
-import sys
-sys.stderr = sys.stdout
-
-COMMISSIONING_APP_NAME = 'fscrud'
-
-ADMINS = (
-    # ('Your Name', 'your_email@domain.com'),
-)
-
-MANAGERS = ADMINS
-
-TIME_ZONE = 'UTC'
-
-# Language code for this installation. All choices can be found here:
-# http://www.i18nguy.com/unicode/language-identifiers.html
-LANGUAGE_CODE = 'en-us'
-
-SITE_ID = 1
-
-# If you set this to False, Django will make some optimizations so as not
-# to load the internationalization machinery.
-USE_I18N = False
-
-# If you set this to False, Django will not format dates, numbers and
-# calendars according to the current locale
-USE_L10N = False
-
-# Make this unique, and don't share it with anybody.
-SECRET_KEY = 'ee=*x%x6sp=hcm7j4zzkvpam27g*7*d59fca-q!azaqma!jx*+'
-
-# List of callables that know how to import templates from various sources.
-TEMPLATE_LOADERS = (
-    'django.template.loaders.filesystem.Loader',
-    'django.template.loaders.app_directories.Loader',
-#     'django.template.loaders.eggs.Loader',
-)
-
-MIDDLEWARE_CLASSES = (
-    'django.middleware.common.CommonMiddleware',
-    #'django.middleware.transaction.TransactionMiddleware',
-    #'django.contrib.sessions.middleware.SessionMiddleware',
-    #'django.middleware.csrf.CsrfViewMiddleware',
-    #'django.contrib.auth.middleware.AuthenticationMiddleware',
-    #'django.contrib.messages.middleware.MessageMiddleware',
-)
-
-ROOT_URLCONF = 'commissioning.servers.fscrud.urls'
-
-TEMPLATE_DIRS = (
-    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
-    # Always use forward slashes, even on Windows.
-    # Don't forget to use absolute paths, not relative paths.
-)
-
-
-INSTALLED_APPS = (
-    #'django.contrib.auth',
-    'django.contrib.contenttypes',
-    #'django.contrib.sessions',
-    #'django.contrib.sites',
-    #'django.contrib.messages',
-    'commissioning.controllers.django_controller',
-    'commissioning.servers.django_server.server_app',
-    #'commissioning.servers.django_server.server_app',
-    # Uncomment the next line to enable the admin:
-    # 'django.contrib.admin',
-    # Uncomment the next line to enable admin documentation:
-    # 'django.contrib.admindocs',
-)
-
-names = COMMISSIONING_APP_NAME.split(',')
-names = ('commissioning.servers.%s.django_backend' % (n,) for n in names)
-from django.utils.importlib import import_module
-
-applist = []
-for name in names:
-    try:
-        import_module(name)
-        applist.append(name)
-    except ImportError:
-        pass
-
-INSTALLED_APPS += tuple(applist)
-
diff --git a/commissioning/servers/fscrud/urls.py b/commissioning/servers/fscrud/urls.py
deleted file mode 100644
index 400747f..0000000
--- a/commissioning/servers/fscrud/urls.py
+++ /dev/null
@@ -1,17 +0,0 @@
-from django.conf.urls.defaults import *
-
-# Uncomment the next two lines to enable the admin:
-# from django.contrib import admin
-# admin.autodiscover()
-
-urlpatterns = patterns('',
-    # Example:
-    # (r'^quota/', include('quota.foo.urls')),
-
-    # Uncomment the admin/doc line below to enable admin documentation:
-    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
-
-    # Uncomment the next line to enable the admin:
-    # (r'^admin/', include(admin.site.urls)),
-    (r'^api/', include('commissioning.servers.django_server.server_app.urls')),
-)
diff --git a/commissioning/servers/quotaholder/__init__.py b/commissioning/servers/quotaholder/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/commissioning/servers/quotaholder/__init__.py
@@ -0,0 +1 @@
+
diff --git a/commissioning/servers/quotaholder/django_backend/__init__.py b/commissioning/servers/quotaholder/django_backend/__init__.py
new file mode 100644
index 0000000..96b0914
--- /dev/null
+++ b/commissioning/servers/quotaholder/django_backend/__init__.py
@@ -0,0 +1 @@
+from .models import QuotaholderDjangoDBCallpoint
diff --git a/commissioning/servers/quotaholder/django_backend/fixtures/initial_data.json b/commissioning/servers/quotaholder/django_backend/fixtures/initial_data.json
new file mode 100644
index 0000000..178f46d
--- /dev/null
+++ b/commissioning/servers/quotaholder/django_backend/fixtures/initial_data.json
@@ -0,0 +1,10 @@
+[
+    {
+        "model": "quotaholder.backend.entity",
+        "pk": "system",
+        "fields": {
+            "owner": "system",
+            "key": ""
+        }
+    }
+]
diff --git a/commissioning/servers/quotaholder/django_backend/models.py b/commissioning/servers/quotaholder/django_backend/models.py
new file mode 100644
index 0000000..4693c33
--- /dev/null
+++ b/commissioning/servers/quotaholder/django_backend/models.py
@@ -0,0 +1,500 @@
+
+from commissioning.quotaholder \
+import (QuotaholderCallpoint,  QuotaholderException,
+        QuotaholderController, QuotaholderPhysical,
+        QuotaholderCorrupted,  QuotaholderInvalidData,
+        QuotaholderInvalidKey, QuotaholderNoEntity,
+        QuotaholderNoQuantity, QuotaholderNoCapacity)
+
+
+from django.db.models import Model, BigIntegerField, CharField, ForeignKey
+from django.db import transaction
+
+
+class Holder(Model):
+
+    attribute   =   CharField(max_length=72, primary_key=True)
+    intval      =   BigIntegerField()
+    strval      =   CharField(max_length=72)
+
+
+def alloc_serial(nr=1):
+    if nr < 0:
+        m = "Can only receive a positive argument, not %d" % (nr,)
+        raise QuotaholderCorrupted(m)
+
+    try:
+        holder = Holder.objects.get(attribute='serial')
+    except Holder.DoesNotExist:
+        holder = Holder(attribute='serial', inval=1)
+
+    serial = holder.serial
+    holder.serial += nr
+    holder.save()
+
+    return serial
+
+
+class Entity(Model):
+
+    entity      =   CharField(max_length=72, primary_key=True)
+    owner       =   ForeignKey('self', to_field='entity',
+                               related_name='entities')
+    key         =   CharField(max_length=72, null=False)
+
+
+class Policy(Model):
+
+    policy          =   CharField(max_length=72, primary_key=True)
+    quantity        =   BigIntegerField(null=False, default=0)
+    capacity        =   BigIntegerField(null=False, default=0)
+    import_limit    =   BigIntegerField(null=False, default=0)
+    export_limit    =   BigIntegerField(null=False, default=0)
+
+
+class Holding(Model):
+
+    entity      =   ForeignKey(Entity, to_field='entity')
+    resource    =   CharField(max_length=72, null=False)
+
+    policy      =   ForeignKey(Policy, to_field='policy')
+    flags       =   BigIntegerField(null=False, default=0)
+
+    imported    =   BigIntegerField(null=False, default=0)
+    importing   =   BigIntegerField(null=False, default=0)
+    exported    =   BigIntegerField(null=False, default=0)
+    exporting   =   BigIntegerField(null=False, default=0)
+
+    class Meta:
+        unique_together = (('entity', 'resource'),)
+
+
+from datetime import datetime
+
+def now():
+    return datetime.now().strftime('%Y-%m-%dT:%H:%M:%S.%f')[:24]
+
+
+class Commission(Model):
+
+    serial      =   BigIntegerField(primary_key=True, default=alloc_serial)
+    entity      =   ForeignKey(Entity, to_field='entity')
+    clientkey   =   CharField(max_length=72, null=False)
+    issue_time  =   CharField(max_length=24, default=now)
+
+
+class Provision(Model):
+
+    serial      =   ForeignKey( Commission,
+                                to_field='serial',
+                                related_name='provisions'   )
+
+    entity      =   ForeignKey(Entity, to_field='entity')
+    resource    =   CharField(max_length=72, null=False)
+    quantity    =   BigIntegerField(null=False)
+
+
+
+class QuotaholderDjangoDBCallpoint(QuotaholderCallpoint):
+
+    http_exc_lookup = {
+        QuotaholderCorrupted:   550,
+        QuotaholderInvalidData: 400,
+        QuotaholderInvalidKey:  401,
+        QuotaholderNoEntity:    404,
+        QuotaholderNoQuantity:  413,
+        QuotaholderNoCapacity:  413,
+    }
+
+    def init_connection(self, connection):
+        if connection is not None:
+            raise ValueError("Cannot specify connection args with %s" %
+                             type(self).__name__)
+        pass
+
+    def commit(self):
+        transaction.commit()
+
+    def rollback(self):
+        transaction.rollback()
+
+    def do_make_call(self, call_name, data):
+        call_fn = getattr(self, call_name, None)
+        if not call_fn:
+            m = "cannot find call '%s'" % (call_name,)
+            raise QuotaholderCorrupted(m)
+
+        return call_fn(**data)
+
+    @classmethod
+    def http_exception(cls, exc):
+        if not isinstance(exc, QuotaholderException):
+            raise exc
+
+        body = str(exc.args)
+        status = cls.http_exc_lookup.get(type(exc), 400)
+        return status, body
+
+    def create_entity(self, context={}, create_entity=()):
+        rejected = []
+        append = rejected.append
+
+        for entity, owner, key, ownerkey in create_entity:
+            try:
+                owner = Entity.objects.get(entity=owner, key=ownerkey)
+            except Entity.DoesNotExist:
+                append(entity)
+
+            Entity.objects.create(entity=entity, owner=owner, key=key)
+
+        return rejected
+
+    def list_entities(self, context={}, entity=None, key=None):
+        try:
+            e = Entity.objects.get(entity=entity, key=key)
+        except Entity.DoesNotExist:
+            m = "Entity '%s' does not exist" % (entity,)
+            raise QuotaholderNoEntity(m)
+
+        children = e.entities.all()
+        entities = [e.entity for e in children]
+        return entities
+
+    def get_entity(self, context={}, get_entity=()):
+        entities = []
+        append = entities.append
+
+        for entity, key in get_entity:
+            try:
+                Entity.objects.get(entity=entity, key=key)
+            except Entity.DoesNotExist:
+                continue
+
+            append((entity, key))
+
+        return entities
+
+    def get_limits(self, context={}, get_limits=()):
+        limits = []
+        append = limits.append
+
+        for entity, resource, key in get_limits:
+            try:
+                h = Holding.objects.get(entity=entity, resource=resource)
+            except Policy.DoesNotExist:
+                continue
+
+            if h.entity.key != key:
+                continue
+            p = h.policy
+            append((h.entity, h.resource, p.quantity, p.capacity,
+                    p.import_limit, p.export_limit, h.flags))
+
+        return limits
+
+    def set_limits(self, context={}, set_limits=()):
+
+        for (   policy, quantity, capacity,
+                import_limit, export_limit  ) in set_limits:
+
+                #XXX: create or replace?
+                Policy.objects.create(  policy=policy,
+                                        quantity=quantity,
+                                        capacity=capacity,
+                                        import_limit=import_limit,
+                                        export_limit=export_limit   )
+
+        return ()
+
+    def get_holding(self, context={}, get_holding=()):
+        holdings = []
+        append = holdings.append
+
+        for entity, resource, key in get_holding:
+            try:
+                h = Holding.objects.get(entity=entity, resource=resource)
+            except Holding.DoesNotExist:
+                continue
+
+            if h.entity.key != key:
+                continue
+
+            append((h.entity, h.resource, h.policy,
+                    h.imported, h.exported, h.flags))
+
+        return holdings
+
+    def set_holding(self, context={}, set_holding=()):
+        rejected = []
+        append = rejected.append
+
+        for entity, resource, key, policy, flags in set_holding:
+            try:
+                e = Entity.objects.get(entity=entity, key=key)
+            except Entity.DoesNotExist:
+                append((entity, resource, policy))
+                continue
+
+            if e.key != key:
+                append((entity, resource, policy))
+                continue
+
+            try:
+                p = Policy.objects.get(policy=policy)
+            except Policy.DoesNotExist:
+                append((entity, resource, policy))
+                continue
+
+            try:
+                h = Holding.objects.get(entity=entity, resource=resource)
+                h.policy = p
+                h.flags = flags
+                h.save()
+            except Holding.DoesNotExist:
+                h = Holding.objects.create( entity=entity, resource=resource,
+                                            policy=policy, flags=flags      )
+
+        return rejected
+
+    def list_resources(self, context={}, entity=None, key=None):
+        try:
+            e = Entity.objects.get()
+        except Entity.DoesNotExist:
+            m = "No such entity '%s'" % (entity,)
+            raise QuotaholderNoEntity(m)
+
+        if e.key != key:
+            m = "Invalid key for entity '%s'" % (entity,)
+            raise QuotaholderInvalidKey(m)
+
+        holdings = e.holdings.filter(entity=entity)
+        resources = [h.resource for h in holdings]
+        return resources
+
+    def get_quota(self, context={}, get_quota=()):
+        quotas = []
+        append = quotas.append
+
+        for entity, resource, key in get_quota:
+            try:
+                h = Holding.objects.get(entity=entity, resource=resource)
+            except Holding.DoesNotExist:
+                continue
+
+            if h.entity.key != key:
+                continue
+
+            p = h.policy
+
+            append((h.entity.entity, h.resource, p.quantity, p.capacity,
+                    p.import_limit, p.export_limit,
+                    h.imported, h.exported, h.flags))
+
+        return quotas
+
+    def set_quota(self, context={}, set_quota=()):
+        rejected = []
+        append = rejected.append
+
+        for (   entity, resource, key,
+                quantity, capacity,
+                import_limit, export_limit, flags  ) in set_quota:
+
+                try:
+                    h = Holding.objects.get(entity=entity, resource=resource)
+                    if h.entity.key != key:
+                        append((entity, resource))
+                        continue
+                except Holding.DoesNotExist:
+                    append(entity, resource)
+
+                p = h.policy
+                policy = newname()
+                newp = Policy.objects.create    (
+                            policy=policy,
+                            quantity=quantity,
+                            capacity=capacity,
+                            import_limit=import_limit,
+                            export_limit=export_limit
+                )
+
+                h.policy = newp
+                h.save()
+
+                if p.holdings.count() == 0:
+                    p.delete()
+
+        return rejected
+
+    def issue_commission(self,  context={}, clientkey=None,
+                                target=None, key=None,
+                                owner=None, ownerkey=None,
+                                provisions=()               ):
+
+        try:
+            t = Entity.objects.get(entity=target)
+        except Entity.DoesNotExist:
+            create_entity = ((entity, owner, key, ownerkey),)
+            rejected = self.create_entity(  context=context,
+                                            create_entity=create_entity )
+            if rejected:
+                raise QuotaholderNoEntity("No target entity '%s'" % (target,))
+
+            t = Entity.objects.get(entity=target)
+        else:
+            if t.key != key:
+                m = "Invalid key for target entity '%s'" % (target,)
+                raise QuotaholderInvalidKey(m)
+
+        commission = Commission.objects.create( entity=target,
+                                                clientkey=clientkey )
+        serial = commission.serial
+
+        for entity, resource, quantity in provisions:
+            try:
+                h = Holding.objects.get(entity=entity, resource=resource)
+            except Holding.DoesNotExist:
+                m = ("There is not enough quantity "
+                     "to allocate from in %s.%s" % (entity, resource))
+                raise QuotaholderNoQuantity(m)
+
+            hp = h.policy
+
+            if h.importing - h.exported + hp.quantity - quantity < 0:
+                m = ("There is not enough quantity "
+                     "to allocate from in %s.%s" % (entity, resource))
+                raise QuotaholderNoQuantity(m)
+
+            try:
+                th = Holding.objects.get(entity=target, resource=resource)
+            except Holding.DoesNotExist:
+                m = ("There is not enough capacity "
+                     "to allocate into in %s.%s" % (target, resource))
+                raise QuotaholderNoCapacity(m)
+
+            tp = th.policy
+
+            if (    th.exported - th.importing - tp.quantity
+                    + tp.capacity - quantity                ) < 0:
+
+                    m = ("There is not enough capacity "
+                         "to allocate into in %s.%s" % (target, resource))
+                    raise QuotaholderNoCapacity(m)
+
+            Provision.objects.create(   serial=serial,
+                                        entity=entity,
+                                        resource=resource,
+                                        quantity=quantity   )
+
+            h.exporting += quantity
+            th.importing += quantity
+
+            h.save()
+            th.save()
+
+        return serial
+
+    def accept_commission(self, context={}, clientkey=None, serial=None):
+        try:
+            c = Commission.objects.get(clientkey=clientkey, serial=serial)
+        except Commission.DoesNotExist:
+            return
+
+        t = c.entity
+
+        provisions = Provision.objects.filter(  clientkey=clientkey,
+                                                serial=serial       )
+        for pv in provisions:
+            pv.entity,
+            pv.resource
+            try:
+                h = Holding.objects.get(entity=pv.entity.entity,
+                                        resource=pv.resource    )
+                th = Holding.objects.get(entity=t, resource=pv.resource)
+            except Holding.DoesNotExist:
+                m = "Corrupted provision"
+                raise QuotaholderCorrupted(m)
+
+            h.exported += pv.quantity
+            th.imported += pv.quantity
+            h.save()
+            th.save()
+            pv.delete()
+
+        return
+
+    def reject_commission(self, context={}, clientkey=None, serial=None):
+        try:
+            c = Commission.objects.get(clientkey=clientkey, serial=serial)
+        except Commission.DoesNotExist:
+            return
+
+        t = c.entity
+
+        provisions = Provision.objects.filter(  clientkey=clientkey,
+                                                serial=serial       )
+        for pv in provisions:
+            pv.entity,
+            pv.resource
+            try:
+                h = Holding.objects.get(entity=pv.entity.entity,
+                                        resource=pv.resource    )
+                th = Holding.objects.get(entity=t, resource=pv.resource)
+            except Holding.DoesNotExist:
+                m = "Corrupted provision"
+                raise QuotaholderCorrupted(m)
+
+            h.exporting -= pv.quantity
+            th.importing -= pv.quantity
+            h.save()
+            th.save()
+            pv.delete()
+
+        return
+
+    def get_pending_commissions(self, context={}, clientkey=None):
+        pending = Commission.objects.filter(clientkey=clientkey)
+        return pending
+
+    def resolve_pending_commissions(self,   context={}, clientkey=None,
+                                            max_serial=None, accept_set=()  ):
+        accept_set = set(accept_set)
+        pending = self.get_pending_commissions(clientkey=clientkey)
+        pending = sorted(pending)
+
+        accept = self.accept_commission
+        reject = self.reject_commission
+
+        for serial in pending:
+            if serial > max_serial:
+                break
+
+            if serial in accept_set:
+                accept(clientkey=clientkey, serial=serial)
+            else:
+                reject(clientkey=clientkey, serial=serial)
+
+        return
+
+    def release_entity(self, context={}, release_entity=()):
+        rejected = []
+        append = rejected.append
+        for entity, key in release_entity:
+            try:
+                e = Entity.objects.get(entity=entity, key=key)
+            except Entity.DoesNotExist:
+                append(entity)
+                continue
+
+            if e.entities.count() != 0:
+                append(entity)
+                continue
+
+            if e.holdings.count() != 0:
+                append(entity)
+                continue
+
+            e.delete()
+
+        return rejected
+
diff --git a/commissioning/servers/quotaholder/quotaholder_django/__init__.py b/commissioning/servers/quotaholder/quotaholder_django/__init__.py
new file mode 100644
index 0000000..139597f
--- /dev/null
+++ b/commissioning/servers/quotaholder/quotaholder_django/__init__.py
@@ -0,0 +1,2 @@
+
+
diff --git a/commissioning/servers/quotaholder/quotaholder_django/quotaholder-manage b/commissioning/servers/quotaholder/quotaholder_django/quotaholder-manage
new file mode 100755
index 0000000..f76221a
--- /dev/null
+++ b/commissioning/servers/quotaholder/quotaholder_django/quotaholder-manage
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+    import commissioning.servers.quotaholder_django.settings as settings
+except ImportError:
+    import sys
+    sys.stderr.write("%s: Can't import settings." % __file__)
+    sys.exit(1)
+
+if __name__ == "__main__":
+    execute_manager(settings)
diff --git a/commissioning/servers/quotaholder/quotaholder_django/settings.py b/commissioning/servers/quotaholder/quotaholder_django/settings.py
new file mode 100644
index 0000000..ce54cfc
--- /dev/null
+++ b/commissioning/servers/quotaholder/quotaholder_django/settings.py
@@ -0,0 +1,105 @@
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+DATABASES = {
+    'default': {
+        # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+        'ENGINE': 'django.db.backends.postgresql_psycopg2',
+        'NAME': 'holder',                       # Or path to database file if using sqlite3.
+        'USER': 'holder',                       # Not used with sqlite3.
+        'PASSWORD': 'holder',                   # Not used with sqlite3.
+        'HOST': 'dev84.dev.grnet.gr',           # Set to empty string for localhost. Not used with sqlite3.
+        'PORT': '5432',                         # Set to empty string for default. Not used with sqlite3.
+    }
+}
+
+from commissioning.utils.pyconf import pyconf_globals
+pyconf_globals('/etc/fscrud/django.conf')
+
+COMMISSIONING_APP_NAME='quotaholder'
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# On Unix systems, a value of None will cause Django to use the same
+# timezone as the operating system.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'Europe/Athens'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# If you set this to False, Django will not format dates, numbers and
+# calendars according to the current locale
+USE_L10N = True
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = ''
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = 'ee=*x%x6sp=hcm7j4zzkvpam27g*7*d59fca-q!azaqma!jx*+'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.Loader',
+    'django.template.loaders.app_directories.Loader',
+#     'django.template.loaders.eggs.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    #'django.middleware.transaction.TransactionMiddleware',
+    #'django.contrib.sessions.middleware.SessionMiddleware',
+    #'django.middleware.csrf.CsrfViewMiddleware',
+    #'django.contrib.auth.middleware.AuthenticationMiddleware',
+    #'django.contrib.messages.middleware.MessageMiddleware',
+)
+
+ROOT_URLCONF = 'urls'
+
+TEMPLATE_DIRS = (
+    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+    # Always use forward slashes, even on Windows.
+    # Don't forget to use absolute paths, not relative paths.
+)
+
+INSTALLED_APPS = (
+    #'django.contrib.auth',
+    'django.contrib.contenttypes',
+    #'django.contrib.sessions',
+    #'django.contrib.sites',
+    #'django.contrib.messages',
+    #('commissioning.%s.backends.django_backend'
+    #                    % (COMMISSIONING_APP_NAME,)),
+    'commissioning.servers.django_server.server_app',
+    # Uncomment the next line to enable the admin:
+    # 'django.contrib.admin',
+    # Uncomment the next line to enable admin documentation:
+    # 'django.contrib.admindocs',
+)
diff --git a/commissioning/servers/quotaholder/quotaholder_django/urls.py b/commissioning/servers/quotaholder/quotaholder_django/urls.py
new file mode 100644
index 0000000..4671756
--- /dev/null
+++ b/commissioning/servers/quotaholder/quotaholder_django/urls.py
@@ -0,0 +1,17 @@
+from django.conf.urls.defaults import *
+
+# Uncomment the next two lines to enable the admin:
+# from django.contrib import admin
+# admin.autodiscover()
+
+urlpatterns = patterns('',
+    # Example:
+    # (r'^quota/', include('quota.foo.urls')),
+
+    # Uncomment the admin/doc line below to enable admin documentation:
+    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+    # Uncomment the next line to enable the admin:
+    # (r'^admin/', include(admin.site.urls)),
+    (r'^api/', include('server_app.urls')),
+)
diff --git a/commissioning/servers/quotaholder_django/__init__.py b/commissioning/servers/quotaholder_django/__init__.py
deleted file mode 100644
index 139597f..0000000
--- a/commissioning/servers/quotaholder_django/__init__.py
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/commissioning/servers/quotaholder_django/django_backend/__init__.py b/commissioning/servers/quotaholder_django/django_backend/__init__.py
deleted file mode 100644
index 96b0914..0000000
--- a/commissioning/servers/quotaholder_django/django_backend/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-from .models import QuotaholderDjangoDBCallpoint
diff --git a/commissioning/servers/quotaholder_django/django_backend/fixtures/initial_data.json b/commissioning/servers/quotaholder_django/django_backend/fixtures/initial_data.json
deleted file mode 100644
index 178f46d..0000000
--- a/commissioning/servers/quotaholder_django/django_backend/fixtures/initial_data.json
+++ /dev/null
@@ -1,10 +0,0 @@
-[
-    {
-        "model": "quotaholder.backend.entity",
-        "pk": "system",
-        "fields": {
-            "owner": "system",
-            "key": ""
-        }
-    }
-]
diff --git a/commissioning/servers/quotaholder_django/django_backend/models.py b/commissioning/servers/quotaholder_django/django_backend/models.py
deleted file mode 100644
index 4693c33..0000000
--- a/commissioning/servers/quotaholder_django/django_backend/models.py
+++ /dev/null
@@ -1,500 +0,0 @@
-
-from commissioning.quotaholder \
-import (QuotaholderCallpoint,  QuotaholderException,
-        QuotaholderController, QuotaholderPhysical,
-        QuotaholderCorrupted,  QuotaholderInvalidData,
-        QuotaholderInvalidKey, QuotaholderNoEntity,
-        QuotaholderNoQuantity, QuotaholderNoCapacity)
-
-
-from django.db.models import Model, BigIntegerField, CharField, ForeignKey
-from django.db import transaction
-
-
-class Holder(Model):
-
-    attribute   =   CharField(max_length=72, primary_key=True)
-    intval      =   BigIntegerField()
-    strval      =   CharField(max_length=72)
-
-
-def alloc_serial(nr=1):
-    if nr < 0:
-        m = "Can only receive a positive argument, not %d" % (nr,)
-        raise QuotaholderCorrupted(m)
-
-    try:
-        holder = Holder.objects.get(attribute='serial')
-    except Holder.DoesNotExist:
-        holder = Holder(attribute='serial', inval=1)
-
-    serial = holder.serial
-    holder.serial += nr
-    holder.save()
-
-    return serial
-
-
-class Entity(Model):
-
-    entity      =   CharField(max_length=72, primary_key=True)
-    owner       =   ForeignKey('self', to_field='entity',
-                               related_name='entities')
-    key         =   CharField(max_length=72, null=False)
-
-
-class Policy(Model):
-
-    policy          =   CharField(max_length=72, primary_key=True)
-    quantity        =   BigIntegerField(null=False, default=0)
-    capacity        =   BigIntegerField(null=False, default=0)
-    import_limit    =   BigIntegerField(null=False, default=0)
-    export_limit    =   BigIntegerField(null=False, default=0)
-
-
-class Holding(Model):
-
-    entity      =   ForeignKey(Entity, to_field='entity')
-    resource    =   CharField(max_length=72, null=False)
-
-    policy      =   ForeignKey(Policy, to_field='policy')
-    flags       =   BigIntegerField(null=False, default=0)
-
-    imported    =   BigIntegerField(null=False, default=0)
-    importing   =   BigIntegerField(null=False, default=0)
-    exported    =   BigIntegerField(null=False, default=0)
-    exporting   =   BigIntegerField(null=False, default=0)
-
-    class Meta:
-        unique_together = (('entity', 'resource'),)
-
-
-from datetime import datetime
-
-def now():
-    return datetime.now().strftime('%Y-%m-%dT:%H:%M:%S.%f')[:24]
-
-
-class Commission(Model):
-
-    serial      =   BigIntegerField(primary_key=True, default=alloc_serial)
-    entity      =   ForeignKey(Entity, to_field='entity')
-    clientkey   =   CharField(max_length=72, null=False)
-    issue_time  =   CharField(max_length=24, default=now)
-
-
-class Provision(Model):
-
-    serial      =   ForeignKey( Commission,
-                                to_field='serial',
-                                related_name='provisions'   )
-
-    entity      =   ForeignKey(Entity, to_field='entity')
-    resource    =   CharField(max_length=72, null=False)
-    quantity    =   BigIntegerField(null=False)
-
-
-
-class QuotaholderDjangoDBCallpoint(QuotaholderCallpoint):
-
-    http_exc_lookup = {
-        QuotaholderCorrupted:   550,
-        QuotaholderInvalidData: 400,
-        QuotaholderInvalidKey:  401,
-        QuotaholderNoEntity:    404,
-        QuotaholderNoQuantity:  413,
-        QuotaholderNoCapacity:  413,
-    }
-
-    def init_connection(self, connection):
-        if connection is not None:
-            raise ValueError("Cannot specify connection args with %s" %
-                             type(self).__name__)
-        pass
-
-    def commit(self):
-        transaction.commit()
-
-    def rollback(self):
-        transaction.rollback()
-
-    def do_make_call(self, call_name, data):
-        call_fn = getattr(self, call_name, None)
-        if not call_fn:
-            m = "cannot find call '%s'" % (call_name,)
-            raise QuotaholderCorrupted(m)
-
-        return call_fn(**data)
-
-    @classmethod
-    def http_exception(cls, exc):
-        if not isinstance(exc, QuotaholderException):
-            raise exc
-
-        body = str(exc.args)
-        status = cls.http_exc_lookup.get(type(exc), 400)
-        return status, body
-
-    def create_entity(self, context={}, create_entity=()):
-        rejected = []
-        append = rejected.append
-
-        for entity, owner, key, ownerkey in create_entity:
-            try:
-                owner = Entity.objects.get(entity=owner, key=ownerkey)
-            except Entity.DoesNotExist:
-                append(entity)
-
-            Entity.objects.create(entity=entity, owner=owner, key=key)
-
-        return rejected
-
-    def list_entities(self, context={}, entity=None, key=None):
-        try:
-            e = Entity.objects.get(entity=entity, key=key)
-        except Entity.DoesNotExist:
-            m = "Entity '%s' does not exist" % (entity,)
-            raise QuotaholderNoEntity(m)
-
-        children = e.entities.all()
-        entities = [e.entity for e in children]
-        return entities
-
-    def get_entity(self, context={}, get_entity=()):
-        entities = []
-        append = entities.append
-
-        for entity, key in get_entity:
-            try:
-                Entity.objects.get(entity=entity, key=key)
-            except Entity.DoesNotExist:
-                continue
-
-            append((entity, key))
-
-        return entities
-
-    def get_limits(self, context={}, get_limits=()):
-        limits = []
-        append = limits.append
-
-        for entity, resource, key in get_limits:
-            try:
-                h = Holding.objects.get(entity=entity, resource=resource)
-            except Policy.DoesNotExist:
-                continue
-
-            if h.entity.key != key:
-                continue
-            p = h.policy
-            append((h.entity, h.resource, p.quantity, p.capacity,
-                    p.import_limit, p.export_limit, h.flags))
-
-        return limits
-
-    def set_limits(self, context={}, set_limits=()):
-
-        for (   policy, quantity, capacity,
-                import_limit, export_limit  ) in set_limits:
-
-                #XXX: create or replace?
-                Policy.objects.create(  policy=policy,
-                                        quantity=quantity,
-                                        capacity=capacity,
-                                        import_limit=import_limit,
-                                        export_limit=export_limit   )
-
-        return ()
-
-    def get_holding(self, context={}, get_holding=()):
-        holdings = []
-        append = holdings.append
-
-        for entity, resource, key in get_holding:
-            try:
-                h = Holding.objects.get(entity=entity, resource=resource)
-            except Holding.DoesNotExist:
-                continue
-
-            if h.entity.key != key:
-                continue
-
-            append((h.entity, h.resource, h.policy,
-                    h.imported, h.exported, h.flags))
-
-        return holdings
-
-    def set_holding(self, context={}, set_holding=()):
-        rejected = []
-        append = rejected.append
-
-        for entity, resource, key, policy, flags in set_holding:
-            try:
-                e = Entity.objects.get(entity=entity, key=key)
-            except Entity.DoesNotExist:
-                append((entity, resource, policy))
-                continue
-
-            if e.key != key:
-                append((entity, resource, policy))
-                continue
-
-            try:
-                p = Policy.objects.get(policy=policy)
-            except Policy.DoesNotExist:
-                append((entity, resource, policy))
-                continue
-
-            try:
-                h = Holding.objects.get(entity=entity, resource=resource)
-                h.policy = p
-                h.flags = flags
-                h.save()
-            except Holding.DoesNotExist:
-                h = Holding.objects.create( entity=entity, resource=resource,
-                                            policy=policy, flags=flags      )
-
-        return rejected
-
-    def list_resources(self, context={}, entity=None, key=None):
-        try:
-            e = Entity.objects.get()
-        except Entity.DoesNotExist:
-            m = "No such entity '%s'" % (entity,)
-            raise QuotaholderNoEntity(m)
-
-        if e.key != key:
-            m = "Invalid key for entity '%s'" % (entity,)
-            raise QuotaholderInvalidKey(m)
-
-        holdings = e.holdings.filter(entity=entity)
-        resources = [h.resource for h in holdings]
-        return resources
-
-    def get_quota(self, context={}, get_quota=()):
-        quotas = []
-        append = quotas.append
-
-        for entity, resource, key in get_quota:
-            try:
-                h = Holding.objects.get(entity=entity, resource=resource)
-            except Holding.DoesNotExist:
-                continue
-
-            if h.entity.key != key:
-                continue
-
-            p = h.policy
-
-            append((h.entity.entity, h.resource, p.quantity, p.capacity,
-                    p.import_limit, p.export_limit,
-                    h.imported, h.exported, h.flags))
-
-        return quotas
-
-    def set_quota(self, context={}, set_quota=()):
-        rejected = []
-        append = rejected.append
-
-        for (   entity, resource, key,
-                quantity, capacity,
-                import_limit, export_limit, flags  ) in set_quota:
-
-                try:
-                    h = Holding.objects.get(entity=entity, resource=resource)
-                    if h.entity.key != key:
-                        append((entity, resource))
-                        continue
-                except Holding.DoesNotExist:
-                    append(entity, resource)
-
-                p = h.policy
-                policy = newname()
-                newp = Policy.objects.create    (
-                            policy=policy,
-                            quantity=quantity,
-                            capacity=capacity,
-                            import_limit=import_limit,
-                            export_limit=export_limit
-                )
-
-                h.policy = newp
-                h.save()
-
-                if p.holdings.count() == 0:
-                    p.delete()
-
-        return rejected
-
-    def issue_commission(self,  context={}, clientkey=None,
-                                target=None, key=None,
-                                owner=None, ownerkey=None,
-                                provisions=()               ):
-
-        try:
-            t = Entity.objects.get(entity=target)
-        except Entity.DoesNotExist:
-            create_entity = ((entity, owner, key, ownerkey),)
-            rejected = self.create_entity(  context=context,
-                                            create_entity=create_entity )
-            if rejected:
-                raise QuotaholderNoEntity("No target entity '%s'" % (target,))
-
-            t = Entity.objects.get(entity=target)
-        else:
-            if t.key != key:
-                m = "Invalid key for target entity '%s'" % (target,)
-                raise QuotaholderInvalidKey(m)
-
-        commission = Commission.objects.create( entity=target,
-                                                clientkey=clientkey )
-        serial = commission.serial
-
-        for entity, resource, quantity in provisions:
-            try:
-                h = Holding.objects.get(entity=entity, resource=resource)
-            except Holding.DoesNotExist:
-                m = ("There is not enough quantity "
-                     "to allocate from in %s.%s" % (entity, resource))
-                raise QuotaholderNoQuantity(m)
-
-            hp = h.policy
-
-            if h.importing - h.exported + hp.quantity - quantity < 0:
-                m = ("There is not enough quantity "
-                     "to allocate from in %s.%s" % (entity, resource))
-                raise QuotaholderNoQuantity(m)
-
-            try:
-                th = Holding.objects.get(entity=target, resource=resource)
-            except Holding.DoesNotExist:
-                m = ("There is not enough capacity "
-                     "to allocate into in %s.%s" % (target, resource))
-                raise QuotaholderNoCapacity(m)
-
-            tp = th.policy
-
-            if (    th.exported - th.importing - tp.quantity
-                    + tp.capacity - quantity                ) < 0:
-
-                    m = ("There is not enough capacity "
-                         "to allocate into in %s.%s" % (target, resource))
-                    raise QuotaholderNoCapacity(m)
-
-            Provision.objects.create(   serial=serial,
-                                        entity=entity,
-                                        resource=resource,
-                                        quantity=quantity   )
-
-            h.exporting += quantity
-            th.importing += quantity
-
-            h.save()
-            th.save()
-
-        return serial
-
-    def accept_commission(self, context={}, clientkey=None, serial=None):
-        try:
-            c = Commission.objects.get(clientkey=clientkey, serial=serial)
-        except Commission.DoesNotExist:
-            return
-
-        t = c.entity
-
-        provisions = Provision.objects.filter(  clientkey=clientkey,
-                                                serial=serial       )
-        for pv in provisions:
-            pv.entity,
-            pv.resource
-            try:
-                h = Holding.objects.get(entity=pv.entity.entity,
-                                        resource=pv.resource    )
-                th = Holding.objects.get(entity=t, resource=pv.resource)
-            except Holding.DoesNotExist:
-                m = "Corrupted provision"
-                raise QuotaholderCorrupted(m)
-
-            h.exported += pv.quantity
-            th.imported += pv.quantity
-            h.save()
-            th.save()
-            pv.delete()
-
-        return
-
-    def reject_commission(self, context={}, clientkey=None, serial=None):
-        try:
-            c = Commission.objects.get(clientkey=clientkey, serial=serial)
-        except Commission.DoesNotExist:
-            return
-
-        t = c.entity
-
-        provisions = Provision.objects.filter(  clientkey=clientkey,
-                                                serial=serial       )
-        for pv in provisions:
-            pv.entity,
-            pv.resource
-            try:
-                h = Holding.objects.get(entity=pv.entity.entity,
-                                        resource=pv.resource    )
-                th = Holding.objects.get(entity=t, resource=pv.resource)
-            except Holding.DoesNotExist:
-                m = "Corrupted provision"
-                raise QuotaholderCorrupted(m)
-
-            h.exporting -= pv.quantity
-            th.importing -= pv.quantity
-            h.save()
-            th.save()
-            pv.delete()
-
-        return
-
-    def get_pending_commissions(self, context={}, clientkey=None):
-        pending = Commission.objects.filter(clientkey=clientkey)
-        return pending
-
-    def resolve_pending_commissions(self,   context={}, clientkey=None,
-                                            max_serial=None, accept_set=()  ):
-        accept_set = set(accept_set)
-        pending = self.get_pending_commissions(clientkey=clientkey)
-        pending = sorted(pending)
-
-        accept = self.accept_commission
-        reject = self.reject_commission
-
-        for serial in pending:
-            if serial > max_serial:
-                break
-
-            if serial in accept_set:
-                accept(clientkey=clientkey, serial=serial)
-            else:
-                reject(clientkey=clientkey, serial=serial)
-
-        return
-
-    def release_entity(self, context={}, release_entity=()):
-        rejected = []
-        append = rejected.append
-        for entity, key in release_entity:
-            try:
-                e = Entity.objects.get(entity=entity, key=key)
-            except Entity.DoesNotExist:
-                append(entity)
-                continue
-
-            if e.entities.count() != 0:
-                append(entity)
-                continue
-
-            if e.holdings.count() != 0:
-                append(entity)
-                continue
-
-            e.delete()
-
-        return rejected
-
diff --git a/commissioning/servers/quotaholder_django/quotaholder-manage b/commissioning/servers/quotaholder_django/quotaholder-manage
deleted file mode 100755
index f76221a..0000000
--- a/commissioning/servers/quotaholder_django/quotaholder-manage
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-from django.core.management import execute_manager
-try:
-    import commissioning.servers.quotaholder_django.settings as settings
-except ImportError:
-    import sys
-    sys.stderr.write("%s: Can't import settings." % __file__)
-    sys.exit(1)
-
-if __name__ == "__main__":
-    execute_manager(settings)
diff --git a/commissioning/servers/quotaholder_django/settings.py b/commissioning/servers/quotaholder_django/settings.py
deleted file mode 100644
index ce54cfc..0000000
--- a/commissioning/servers/quotaholder_django/settings.py
+++ /dev/null
@@ -1,105 +0,0 @@
-
-DEBUG = True
-TEMPLATE_DEBUG = DEBUG
-
-DATABASES = {
-    'default': {
-        # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
-        'ENGINE': 'django.db.backends.postgresql_psycopg2',
-        'NAME': 'holder',                       # Or path to database file if using sqlite3.
-        'USER': 'holder',                       # Not used with sqlite3.
-        'PASSWORD': 'holder',                   # Not used with sqlite3.
-        'HOST': 'dev84.dev.grnet.gr',           # Set to empty string for localhost. Not used with sqlite3.
-        'PORT': '5432',                         # Set to empty string for default. Not used with sqlite3.
-    }
-}
-
-from commissioning.utils.pyconf import pyconf_globals
-pyconf_globals('/etc/fscrud/django.conf')
-
-COMMISSIONING_APP_NAME='quotaholder'
-
-ADMINS = (
-    # ('Your Name', 'your_email@domain.com'),
-)
-
-MANAGERS = ADMINS
-
-# Local time zone for this installation. Choices can be found here:
-# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
-# although not all choices may be available on all operating systems.
-# On Unix systems, a value of None will cause Django to use the same
-# timezone as the operating system.
-# If running in a Windows environment this must be set to the same as your
-# system time zone.
-TIME_ZONE = 'Europe/Athens'
-
-# Language code for this installation. All choices can be found here:
-# http://www.i18nguy.com/unicode/language-identifiers.html
-LANGUAGE_CODE = 'en-us'
-
-SITE_ID = 1
-
-# If you set this to False, Django will make some optimizations so as not
-# to load the internationalization machinery.
-USE_I18N = True
-
-# If you set this to False, Django will not format dates, numbers and
-# calendars according to the current locale
-USE_L10N = True
-
-# Absolute path to the directory that holds media.
-# Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = ''
-
-# URL that handles the media served from MEDIA_ROOT. Make sure to use a
-# trailing slash if there is a path component (optional in other cases).
-# Examples: "http://media.lawrence.com", "http://example.com/media/"
-MEDIA_URL = ''
-
-# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
-# trailing slash.
-# Examples: "http://foo.com/media/", "/media/".
-ADMIN_MEDIA_PREFIX = '/media/'
-
-# Make this unique, and don't share it with anybody.
-SECRET_KEY = 'ee=*x%x6sp=hcm7j4zzkvpam27g*7*d59fca-q!azaqma!jx*+'
-
-# List of callables that know how to import templates from various sources.
-TEMPLATE_LOADERS = (
-    'django.template.loaders.filesystem.Loader',
-    'django.template.loaders.app_directories.Loader',
-#     'django.template.loaders.eggs.Loader',
-)
-
-MIDDLEWARE_CLASSES = (
-    'django.middleware.common.CommonMiddleware',
-    #'django.middleware.transaction.TransactionMiddleware',
-    #'django.contrib.sessions.middleware.SessionMiddleware',
-    #'django.middleware.csrf.CsrfViewMiddleware',
-    #'django.contrib.auth.middleware.AuthenticationMiddleware',
-    #'django.contrib.messages.middleware.MessageMiddleware',
-)
-
-ROOT_URLCONF = 'urls'
-
-TEMPLATE_DIRS = (
-    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
-    # Always use forward slashes, even on Windows.
-    # Don't forget to use absolute paths, not relative paths.
-)
-
-INSTALLED_APPS = (
-    #'django.contrib.auth',
-    'django.contrib.contenttypes',
-    #'django.contrib.sessions',
-    #'django.contrib.sites',
-    #'django.contrib.messages',
-    #('commissioning.%s.backends.django_backend'
-    #                    % (COMMISSIONING_APP_NAME,)),
-    'commissioning.servers.django_server.server_app',
-    # Uncomment the next line to enable the admin:
-    # 'django.contrib.admin',
-    # Uncomment the next line to enable admin documentation:
-    # 'django.contrib.admindocs',
-)
diff --git a/commissioning/servers/quotaholder_django/urls.py b/commissioning/servers/quotaholder_django/urls.py
deleted file mode 100644
index 4671756..0000000
--- a/commissioning/servers/quotaholder_django/urls.py
+++ /dev/null
@@ -1,17 +0,0 @@
-from django.conf.urls.defaults import *
-
-# Uncomment the next two lines to enable the admin:
-# from django.contrib import admin
-# admin.autodiscover()
-
-urlpatterns = patterns('',
-    # Example:
-    # (r'^quota/', include('quota.foo.urls')),
-
-    # Uncomment the admin/doc line below to enable admin documentation:
-    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
-
-    # Uncomment the next line to enable the admin:
-    # (r'^admin/', include(admin.site.urls)),
-    (r'^api/', include('server_app.urls')),
-)
