Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / api / callpoint.py @ 1ebea3d3

History | View | Annotate | Download (4.9 kB)

1 9a06d96f Olga Brani
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2 9a06d96f Olga Brani
#
3 9a06d96f Olga Brani
# Redistribution and use in source and binary forms, with or
4 9a06d96f Olga Brani
# without modification, are permitted provided that the following
5 9a06d96f Olga Brani
# conditions are met:
6 9a06d96f Olga Brani
#
7 9a06d96f Olga Brani
#   1. Redistributions of source code must retain the above
8 9a06d96f Olga Brani
#      copyright notice, this list of conditions and the following
9 9a06d96f Olga Brani
#      disclaimer.
10 9a06d96f Olga Brani
#
11 9a06d96f Olga Brani
#   2. Redistributions in binary form must reproduce the above
12 9a06d96f Olga Brani
#      copyright notice, this list of conditions and the following
13 9a06d96f Olga Brani
#      disclaimer in the documentation and/or other materials
14 9a06d96f Olga Brani
#      provided with the distribution.
15 9a06d96f Olga Brani
#
16 9a06d96f Olga Brani
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 9a06d96f Olga Brani
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 9a06d96f Olga Brani
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 9a06d96f Olga Brani
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 9a06d96f Olga Brani
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 9a06d96f Olga Brani
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 9a06d96f Olga Brani
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 9a06d96f Olga Brani
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 9a06d96f Olga Brani
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 9a06d96f Olga Brani
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 9a06d96f Olga Brani
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 9a06d96f Olga Brani
# POSSIBILITY OF SUCH DAMAGE.
28 9a06d96f Olga Brani
#
29 9a06d96f Olga Brani
# The views and conclusions contained in the software and
30 9a06d96f Olga Brani
# documentation are those of the authors and should not be
31 9a06d96f Olga Brani
# interpreted as representing official policies, either expressed
32 9a06d96f Olga Brani
# or implied, of GRNET S.A.
33 9a06d96f Olga Brani
34 9a06d96f Olga Brani
from astakos.im.api.spec import AstakosAPI
35 820b18e0 Sofia Papagiannaki
from astakos.im.api.backends import get_backend
36 9a06d96f Olga Brani
37 3b1912f4 root
from synnefo.lib.commissioning import CorruptedError
38 9a06d96f Olga Brani
39 c0b26605 Sofia Papagiannaki
from django.db import transaction
40 9a06d96f Olga Brani
41 820b18e0 Sofia Papagiannaki
class AstakosCallpoint():
42 9a06d96f Olga Brani
43 9a06d96f Olga Brani
    api_spec = AstakosAPI()
44 9a06d96f Olga Brani
45 9a06d96f Olga Brani
#     http_exc_lookup = {
46 9a06d96f Olga Brani
#         CorruptedError:   550,
47 9a06d96f Olga Brani
#         InvalidDataError: 400,
48 9a06d96f Olga Brani
#         InvalidKeyError:  401,
49 9a06d96f Olga Brani
#         NoEntityError:    404,
50 9a06d96f Olga Brani
#         NoQuantityError:  413,
51 9a06d96f Olga Brani
#         NoCapacityError:  413,
52 9a06d96f Olga Brani
#     }
53 9a06d96f Olga Brani
54 9a06d96f Olga Brani
    def init_connection(self, connection):
55 9a06d96f Olga Brani
        if connection is not None:
56 9a06d96f Olga Brani
            raise ValueError("Cannot specify connection args with %s" %
57 9a06d96f Olga Brani
                             type(self).__name__)
58 9a06d96f Olga Brani
        pass
59 9a06d96f Olga Brani
60 9a06d96f Olga Brani
    def commit(self):
61 9a06d96f Olga Brani
        transaction.commit()
62 9a06d96f Olga Brani
63 9a06d96f Olga Brani
    def rollback(self):
64 9a06d96f Olga Brani
        transaction.rollback()
65 9a06d96f Olga Brani
66 9a06d96f Olga Brani
    def do_make_call(self, call_name, data):
67 9a06d96f Olga Brani
        call_fn = getattr(self, call_name, None)
68 9a06d96f Olga Brani
        if not call_fn:
69 9a06d96f Olga Brani
            m = "cannot find call '%s'" % (call_name,)
70 9a06d96f Olga Brani
            raise CorruptedError(m)
71 9a06d96f Olga Brani
72 9a06d96f Olga Brani
        return call_fn(**data)
73 9a06d96f Olga Brani
74 9a06d96f Olga Brani
    def create_users(self, users=()):
75 9a06d96f Olga Brani
        b = get_backend()
76 9a06d96f Olga Brani
        rejected = (b.create_user(**u) for u in users)
77 9a06d96f Olga Brani
        return rejected
78 9a06d96f Olga Brani
79 9a06d96f Olga Brani
    def update_users(self, users=()):
80 9a06d96f Olga Brani
        b = get_backend()
81 9a06d96f Olga Brani
        rejected = (b.update_user(**u) for u in users)
82 9a06d96f Olga Brani
        return rejected
83 9a06d96f Olga Brani
84 9a06d96f Olga Brani
    def add_user_policies(self, user_id, update=False, policies=()):
85 9a06d96f Olga Brani
        b = get_backend()
86 9a06d96f Olga Brani
        rejected = b.add_policies(user_id, update, policies)
87 9a06d96f Olga Brani
        return rejected
88 9a06d96f Olga Brani
89 9a06d96f Olga Brani
    def remove_user_policies(self, user_id, policies=()):
90 9a06d96f Olga Brani
        b = get_backend()
91 9a06d96f Olga Brani
        rejected = b.remove_policies(user_id, policies)
92 9a06d96f Olga Brani
        return rejected
93 9a06d96f Olga Brani
94 9a06d96f Olga Brani
    def add_user_permissions(self, user_id, permissions=()):
95 9a06d96f Olga Brani
        b = get_backend()
96 9a06d96f Olga Brani
        rejected = b.add_permissions(user_id, permissions)
97 9a06d96f Olga Brani
        return rejected
98 9a06d96f Olga Brani
99 9a06d96f Olga Brani
    def remove_user_permissions(self, user_id, permissions=()):
100 9a06d96f Olga Brani
        b = get_backend()
101 9a06d96f Olga Brani
        rejected = b.remove_permissions(user_id, permissions)
102 9a06d96f Olga Brani
        return rejected
103 9a06d96f Olga Brani
104 9a06d96f Olga Brani
    def invite_users(self, sender_id, recipients=()):
105 9a06d96f Olga Brani
        b = get_backend()
106 9a06d96f Olga Brani
        rejected = b.invite_users(sender_id, recipients)
107 9a06d96f Olga Brani
        return rejected
108 9a06d96f Olga Brani
109 9a06d96f Olga Brani
    def list_users(self, filter=()):
110 9a06d96f Olga Brani
        b = get_backend()
111 9a06d96f Olga Brani
        return b.list_users(filter)
112 9a06d96f Olga Brani
113 666c7490 Sofia Papagiannaki
    def get_user_usage(self, user_id):
114 9a06d96f Olga Brani
        b = get_backend()
115 9a06d96f Olga Brani
        return b.get_resource_usage(user_id)
116 9a06d96f Olga Brani
117 9a06d96f Olga Brani
    def list_resources(self, filter=()):
118 9a06d96f Olga Brani
        b = get_backend()
119 9a06d96f Olga Brani
        return b.list_resources(filter)
120 9a06d96f Olga Brani
121 9a06d96f Olga Brani
    def add_services(self, services=()):
122 9a06d96f Olga Brani
        b = get_backend()
123 9a06d96f Olga Brani
        rejected = (b.create_service(**s) for s in services)
124 9a06d96f Olga Brani
        return rejected
125 9a06d96f Olga Brani
126 9a06d96f Olga Brani
    def update_services(self, services=()):
127 9a06d96f Olga Brani
        b = get_backend()
128 9a06d96f Olga Brani
        rejected = (b.update_service(**s) for s in services)
129 9a06d96f Olga Brani
        return rejected
130 9a06d96f Olga Brani
131 9a06d96f Olga Brani
    def remove_services(self, ids=()):
132 9a06d96f Olga Brani
        b = get_backend()
133 9a06d96f Olga Brani
        rejected = b.remove_services(ids)
134 9a06d96f Olga Brani
        return rejected
135 9a06d96f Olga Brani
136 9a06d96f Olga Brani
    def add_resources(self, service_id, update=False, resources=()):
137 9a06d96f Olga Brani
        b = get_backend()
138 9a06d96f Olga Brani
        rejected = b.add_resources(service_id, update, resources)
139 9a06d96f Olga Brani
        return rejected
140 9a06d96f Olga Brani
    
141 9a06d96f Olga Brani
    def remove_resources(self, service_id, ids=()):
142 9a06d96f Olga Brani
        b = get_backend()
143 9a06d96f Olga Brani
        rejected = b.remove_resources(service_id, ids)
144 9a06d96f Olga Brani
        return rejected
145 9a06d96f Olga Brani
    
146 73fbaec4 Sofia Papagiannaki
#     def create_groups(self, groups=()):
147 73fbaec4 Sofia Papagiannaki
#         b = get_backend()
148 73fbaec4 Sofia Papagiannaki
#         rejected = (b.create_group(**g) for g in groups)
149 73fbaec4 Sofia Papagiannaki
#         return rejected
150 9a06d96f Olga Brani
151 820b18e0 Sofia Papagiannaki
API_Callpoint = AstakosCallpoint