Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / api / callpoint.py @ 820b18e0

History | View | Annotate | Download (5.6 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 commissioning import (Callpoint,
38
                           #                             CommissionException,
39
                           #                             CorruptedError, InvalidDataError,
40
                           #                             InvalidKeyError, NoEntityError,
41
                           #                             NoQuantityError, NoCapacityError,
42
                           #                             ExportLimitError, ImportLimitError
43
                           )
44

    
45

    
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)
51

    
52
class AstakosCallpoint():
53

    
54
    api_spec = AstakosAPI()
55

    
56
#     http_exc_lookup = {
57
#         CorruptedError:   550,
58
#         InvalidDataError: 400,
59
#         InvalidKeyError:  401,
60
#         NoEntityError:    404,
61
#         NoQuantityError:  413,
62
#         NoCapacityError:  413,
63
#     }
64

    
65
    def init_connection(self, connection):
66
        if connection is not None:
67
            raise ValueError("Cannot specify connection args with %s" %
68
                             type(self).__name__)
69
        pass
70

    
71
    def commit(self):
72
        transaction.commit()
73

    
74
    def rollback(self):
75
        transaction.rollback()
76

    
77
    def do_make_call(self, call_name, data):
78
        call_fn = getattr(self, call_name, None)
79
        if not call_fn:
80
            m = "cannot find call '%s'" % (call_name,)
81
            raise CorruptedError(m)
82

    
83
        return call_fn(**data)
84

    
85
    def create_users(self, users=()):
86
        b = get_backend()
87
        rejected = (b.create_user(**u) for u in users)
88
        return rejected
89

    
90
    def update_users(self, users=()):
91
        b = get_backend()
92
        rejected = (b.update_user(**u) for u in users)
93
        return rejected
94

    
95
    def add_user_policies(self, user_id, update=False, policies=()):
96
        b = get_backend()
97
        rejected = b.add_policies(user_id, update, policies)
98
        return rejected
99

    
100
    def remove_user_policies(self, user_id, policies=()):
101
        b = get_backend()
102
        rejected = b.remove_policies(user_id, policies)
103
        return rejected
104

    
105
    def add_user_permissions(self, user_id, permissions=()):
106
        b = get_backend()
107
        rejected = b.add_permissions(user_id, permissions)
108
        return rejected
109

    
110
    def remove_user_permissions(self, user_id, permissions=()):
111
        b = get_backend()
112
        rejected = b.remove_permissions(user_id, permissions)
113
        return rejected
114

    
115
    def invite_users(self, sender_id, recipients=()):
116
        b = get_backend()
117
        rejected = b.invite_users(sender_id, recipients)
118
        return rejected
119

    
120
    def list_users(self, filter=()):
121
        b = get_backend()
122
        return b.list_users(filter)
123

    
124
    def get_user_status(self, user_id):
125
        b = get_backend()
126
        return b.get_resource_usage(user_id)
127

    
128
    def list_resources(self, filter=()):
129
        b = get_backend()
130
        return b.list_resources(filter)
131

    
132
    def add_services(self, services=()):
133
        b = get_backend()
134
        rejected = (b.create_service(**s) for s in services)
135
        return rejected
136

    
137
    def update_services(self, services=()):
138
        b = get_backend()
139
        rejected = (b.update_service(**s) for s in services)
140
        return rejected
141

    
142
    def remove_services(self, ids=()):
143
        b = get_backend()
144
        rejected = b.remove_services(ids)
145
        return rejected
146

    
147
    def add_resources(self, service_id, update=False, resources=()):
148
        b = get_backend()
149
        rejected = b.add_resources(service_id, update, resources)
150
        return rejected
151
    
152
    def remove_resources(self, service_id, ids=()):
153
        b = get_backend()
154
        rejected = b.remove_resources(service_id, ids)
155
        return rejected
156
    
157
    def create_groups(self, groups=()):
158
        b = get_backend()
159
        rejected = (b.create_group(**g) for g in groups)
160
        return rejected
161

    
162
API_Callpoint = AstakosCallpoint