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 astakos.im.api.backends import get_backend
37 from synnefo.lib.commissioning import CorruptedError
39 from django.db import transaction
41 class AstakosCallpoint():
43 api_spec = AstakosAPI()
46 # CorruptedError: 550,
47 # InvalidDataError: 400,
48 # InvalidKeyError: 401,
50 # NoQuantityError: 413,
51 # NoCapacityError: 413,
54 def init_connection(self, connection):
55 if connection is not None:
56 raise ValueError("Cannot specify connection args with %s" %
64 transaction.rollback()
66 def do_make_call(self, call_name, data):
67 call_fn = getattr(self, call_name, None)
69 m = "cannot find call '%s'" % (call_name,)
70 raise CorruptedError(m)
72 return call_fn(**data)
74 def create_users(self, users=()):
76 rejected = (b.create_user(**u) for u in users)
79 def update_users(self, users=()):
81 rejected = (b.update_user(**u) for u in users)
84 def add_user_policies(self, user_id, update=False, policies=()):
86 rejected = b.add_policies(user_id, update, policies)
89 def remove_user_policies(self, user_id, policies=()):
91 rejected = b.remove_policies(user_id, policies)
94 def add_user_permissions(self, user_id, permissions=()):
96 rejected = b.add_permissions(user_id, permissions)
99 def remove_user_permissions(self, user_id, permissions=()):
101 rejected = b.remove_permissions(user_id, permissions)
104 def invite_users(self, sender_id, recipients=()):
106 rejected = b.invite_users(sender_id, recipients)
109 def list_users(self, filter=()):
111 return b.list_users(filter)
113 def get_user_usage(self, user_id):
115 return b.get_resource_usage(user_id)
117 def list_resources(self, filter=()):
119 return b.list_resources(filter)
121 def add_services(self, services=()):
123 rejected = (b.create_service(**s) for s in services)
126 def update_services(self, services=()):
128 rejected = (b.update_service(**s) for s in services)
131 def remove_services(self, ids=()):
133 rejected = b.remove_services(ids)
136 def add_resources(self, service_id, update=False, resources=()):
138 rejected = b.add_resources(service_id, update, resources)
141 def remove_resources(self, service_id, ids=()):
143 rejected = b.remove_resources(service_id, ids)
146 def create_groups(self, groups=()):
148 rejected = (b.create_group(**g) for g in groups)
151 API_Callpoint = AstakosCallpoint