1 # Copyright 2011-2012 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
11 # 2. Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following
13 # disclaimer in the documentation and/or other materials
14 # provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
29 # The views and conclusions contained in the software and
30 # documentation are those of the authors and should not be
31 # interpreted as representing official policies, either expressed
32 # or implied, of GRNET S.A.
34 from astakos.im.api.spec import AstakosAPI
35 from backends import get_backend
37 from commissioning import (Callpoint,
38 # CommissionException,
39 # CorruptedError, InvalidDataError,
40 # InvalidKeyError, NoEntityError,
41 # NoQuantityError, NoCapacityError,
42 # ExportLimitError, ImportLimitError
46 # from commissioning.utils.newname import newname
47 # from django.db.models import Model, BigIntegerField, CharField, ForeignKey, Q
48 # from django.db import transaction, IntegrityError
49 # from .models import (Holder, Entity, Policy, Holding,
50 # Commission, Provision, ProvisionLog, now)
52 class AstakosDjangoDBCallpoint():
54 api_spec = AstakosAPI()
57 # CorruptedError: 550,
58 # InvalidDataError: 400,
59 # InvalidKeyError: 401,
61 # NoQuantityError: 413,
62 # NoCapacityError: 413,
65 def init_connection(self, connection):
66 if connection is not None:
67 raise ValueError("Cannot specify connection args with %s" %
75 transaction.rollback()
77 def do_make_call(self, call_name, data):
78 call_fn = getattr(self, call_name, None)
80 m = "cannot find call '%s'" % (call_name,)
81 raise CorruptedError(m)
83 return call_fn(**data)
85 def create_users(self, users=()):
87 rejected = (b.create_user(**u) for u in users)
90 def update_users(self, users=()):
92 rejected = (b.update_user(**u) for u in users)
95 def add_user_policies(self, user_id, update=False, policies=()):
97 rejected = b.add_policies(user_id, update, policies)
100 def remove_user_policies(self, user_id, policies=()):
102 rejected = b.remove_policies(user_id, policies)
105 def add_user_permissions(self, user_id, permissions=()):
107 rejected = b.add_permissions(user_id, permissions)
110 def remove_user_permissions(self, user_id, permissions=()):
112 rejected = b.remove_permissions(user_id, permissions)
115 def invite_users(self, sender_id, recipients=()):
117 rejected = b.invite_users(sender_id, recipients)
120 def list_users(self, filter=()):
122 return b.list_users(filter)
124 def get_user_status(self, user_id):
126 return b.get_resource_usage(user_id)
128 def list_resources(self, filter=()):
130 return b.list_resources(filter)
132 def add_services(self, services=()):
134 rejected = (b.create_service(**s) for s in services)
137 def update_services(self, services=()):
139 rejected = (b.update_service(**s) for s in services)
142 def remove_services(self, ids=()):
144 rejected = b.remove_services(ids)
147 def add_resources(self, service_id, update=False, resources=()):
149 rejected = b.add_resources(service_id, update, resources)
152 def remove_resources(self, service_id, ids=()):
154 rejected = b.remove_resources(service_id, ids)
157 def create_groups(self, groups=()):
159 rejected = (b.create_group(**g) for g in groups)
162 API_Callpoint = AstakosDjangoDBCallpoint