Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / api / callpoint.py @ 73fbaec4

History | View | Annotate | Download (4.9 kB)

1
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
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.
15
#
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.
28
#
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.
33

    
34
from astakos.im.api.spec import AstakosAPI
35
from astakos.im.api.backends import get_backend
36

    
37
from synnefo.lib.commissioning import CorruptedError
38

    
39
from django.db import transaction
40

    
41
class AstakosCallpoint():
42

    
43
    api_spec = AstakosAPI()
44

    
45
#     http_exc_lookup = {
46
#         CorruptedError:   550,
47
#         InvalidDataError: 400,
48
#         InvalidKeyError:  401,
49
#         NoEntityError:    404,
50
#         NoQuantityError:  413,
51
#         NoCapacityError:  413,
52
#     }
53

    
54
    def init_connection(self, connection):
55
        if connection is not None:
56
            raise ValueError("Cannot specify connection args with %s" %
57
                             type(self).__name__)
58
        pass
59

    
60
    def commit(self):
61
        transaction.commit()
62

    
63
    def rollback(self):
64
        transaction.rollback()
65

    
66
    def do_make_call(self, call_name, data):
67
        call_fn = getattr(self, call_name, None)
68
        if not call_fn:
69
            m = "cannot find call '%s'" % (call_name,)
70
            raise CorruptedError(m)
71

    
72
        return call_fn(**data)
73

    
74
    def create_users(self, users=()):
75
        b = get_backend()
76
        rejected = (b.create_user(**u) for u in users)
77
        return rejected
78

    
79
    def update_users(self, users=()):
80
        b = get_backend()
81
        rejected = (b.update_user(**u) for u in users)
82
        return rejected
83

    
84
    def add_user_policies(self, user_id, update=False, policies=()):
85
        b = get_backend()
86
        rejected = b.add_policies(user_id, update, policies)
87
        return rejected
88

    
89
    def remove_user_policies(self, user_id, policies=()):
90
        b = get_backend()
91
        rejected = b.remove_policies(user_id, policies)
92
        return rejected
93

    
94
    def add_user_permissions(self, user_id, permissions=()):
95
        b = get_backend()
96
        rejected = b.add_permissions(user_id, permissions)
97
        return rejected
98

    
99
    def remove_user_permissions(self, user_id, permissions=()):
100
        b = get_backend()
101
        rejected = b.remove_permissions(user_id, permissions)
102
        return rejected
103

    
104
    def invite_users(self, sender_id, recipients=()):
105
        b = get_backend()
106
        rejected = b.invite_users(sender_id, recipients)
107
        return rejected
108

    
109
    def list_users(self, filter=()):
110
        b = get_backend()
111
        return b.list_users(filter)
112

    
113
    def get_user_usage(self, user_id):
114
        b = get_backend()
115
        return b.get_resource_usage(user_id)
116

    
117
    def list_resources(self, filter=()):
118
        b = get_backend()
119
        return b.list_resources(filter)
120

    
121
    def add_services(self, services=()):
122
        b = get_backend()
123
        rejected = (b.create_service(**s) for s in services)
124
        return rejected
125

    
126
    def update_services(self, services=()):
127
        b = get_backend()
128
        rejected = (b.update_service(**s) for s in services)
129
        return rejected
130

    
131
    def remove_services(self, ids=()):
132
        b = get_backend()
133
        rejected = b.remove_services(ids)
134
        return rejected
135

    
136
    def add_resources(self, service_id, update=False, resources=()):
137
        b = get_backend()
138
        rejected = b.add_resources(service_id, update, resources)
139
        return rejected
140
    
141
    def remove_resources(self, service_id, ids=()):
142
        b = get_backend()
143
        rejected = b.remove_resources(service_id, ids)
144
        return rejected
145
    
146
#     def create_groups(self, groups=()):
147
#         b = get_backend()
148
#         rejected = (b.create_group(**g) for g in groups)
149
#         return rejected
150

    
151
API_Callpoint = AstakosCallpoint