Revision d1304043
/dev/null | ||
---|---|---|
1 |
# Copyright 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 kamaki.clients.commissioning import Callpoint, CallError |
|
35 |
from kamaki.clients.commissioning.utils.debug import debug |
|
36 |
from kamaki.clients import Client |
|
37 |
|
|
38 |
from json import loads as json_loads, dumps as json_dumps |
|
39 |
|
|
40 |
|
|
41 |
class CommissioningClient(Callpoint): |
|
42 |
|
|
43 |
def __init__(self, base_url, token): |
|
44 |
super(CommissioningClient, self).__init__() |
|
45 |
self._kc = Client(base_url, token) |
|
46 |
|
|
47 |
def do_make_call(self, api_call, data): |
|
48 |
|
|
49 |
_kc = self._kc |
|
50 |
|
|
51 |
gettable = ['list', 'get', 'read'] |
|
52 |
method = (_kc.get if any(api_call.startswith(x) for x in gettable) |
|
53 |
else _kc.post) |
|
54 |
|
|
55 |
path = api_call |
|
56 |
json_data = json_dumps(data) |
|
57 |
debug("%s %s\n%s\n<<<\n", method.func_name, path, json_data) |
|
58 |
|
|
59 |
resp = method(path, data=json_data, success=(200,450,500)) |
|
60 |
debug(">>>\nStatus: %s", resp.status_code) |
|
61 |
|
|
62 |
body = resp.text |
|
63 |
debug("\n%s\n<<<\n", body[:128] if body else None) |
|
64 |
|
|
65 |
status = int(resp.status_code) |
|
66 |
if status == 200: |
|
67 |
return json_loads(body) |
|
68 |
else: |
|
69 |
try: |
|
70 |
error = json_loads(body) |
|
71 |
except ValueError, e: |
|
72 |
exc = CallError(body, call_error='ValueError') |
|
73 |
else: |
|
74 |
exc = CallError.from_dict(error) |
|
75 |
raise exc |
b/kamaki/clients/commissioning/exception.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
|
35 |
def str_or_utf8(s): |
|
36 |
if isinstance(s, unicode): |
|
37 |
return s.encode('utf8') |
|
38 |
return str(s) |
|
39 |
|
|
40 |
|
|
35 | 41 |
class CallError(Exception): |
36 | 42 |
exceptions = {} |
37 | 43 |
|
... | ... | |
46 | 52 |
return self |
47 | 53 |
|
48 | 54 |
def __init__(self, *args, **kw): |
49 |
self.call_error = kw.get('call_error', self.__class__.__name__)
|
|
55 |
self.call_error = kw.pop('call_error', self.__class__.__name__)
|
|
50 | 56 |
self.args = args |
57 |
self.kwargs = kw |
|
51 | 58 |
|
52 | 59 |
def __str__(self): |
53 |
return '\n--------\n'.join(str(x) for x in self.args) |
|
60 |
return '\n--------\n'.join(str_or_utf8(x) for x in self.args)
|
|
54 | 61 |
|
55 | 62 |
def __repr__(self): |
56 | 63 |
return '%s(%s)' % (self.__class__.__name__, |
57 |
','.join(str(x) for x in self.args)) |
|
64 |
','.join(str_or_utf8(x) for x in self.args))
|
|
58 | 65 |
|
59 | 66 |
@classmethod |
60 | 67 |
def from_exception(cls, exc): |
... | ... | |
71 | 78 |
|
72 | 79 |
def to_dict(self): |
73 | 80 |
return {'call_error': self.call_error, |
74 |
'error_args': self.args}
|
|
81 |
'error_args': (self.args, self.kwargs)}
|
|
75 | 82 |
|
76 | 83 |
@classmethod |
77 | 84 |
def from_dict(cls, dictobj): |
... | ... | |
86 | 93 |
if args is None: |
87 | 94 |
args = (str(dictobj),) |
88 | 95 |
call_error = 'UnknownError' |
96 |
kw = {} |
|
97 |
else: |
|
98 |
args, kw = args |
|
89 | 99 |
|
90 |
self = cls(*args, call_error=call_error) |
|
100 |
self = cls(*args, call_error=call_error, **kw)
|
|
91 | 101 |
return self |
92 | 102 |
|
93 | 103 |
def register_exceptions(*exceptions): |
b/kamaki/clients/commissioning_client.py | ||
---|---|---|
1 |
# Copyright 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 synnefo.lib.commissioning import Callpoint, CallError |
|
35 |
from synnefo.lib.commissioning.utils.debug import debug |
|
36 |
from . import Client |
|
37 |
|
|
38 |
from json import loads as json_loads, dumps as json_dumps |
|
39 |
|
|
40 |
class CommissioningClient(Callpoint): |
|
41 |
|
|
42 |
def __init__(self, base_url, token): |
|
43 |
super(CommissioningClient, self).__init__() |
|
44 |
self._kc = Client(base_url, token) |
|
45 |
|
|
46 |
def do_make_call(self, api_call, data): |
|
47 |
|
|
48 |
_kc = self._kc |
|
49 |
|
|
50 |
gettable = ['list', 'get', 'read'] |
|
51 |
method = (_kc.get if any(api_call.startswith(x) for x in gettable) |
|
52 |
else _kc.post) |
|
53 |
|
|
54 |
path = api_call |
|
55 |
json_data = json_dumps(data) |
|
56 |
debug("%s %s\n%s\n<<<\n", method.func_name, path, json_data) |
|
57 |
|
|
58 |
resp = method(path, data=json_data, success=(200,450,500)) |
|
59 |
debug(">>>\nStatus: %s", resp.status_code) |
|
60 |
|
|
61 |
body = resp.text |
|
62 |
debug("\n%s\n<<<\n", body[:128] if body else None) |
|
63 |
|
|
64 |
status = int(resp.status_code) |
|
65 |
if status == 200: |
|
66 |
return json_loads(body) |
|
67 |
else: |
|
68 |
try: |
|
69 |
error = json_loads(body) |
|
70 |
except ValueError, e: |
|
71 |
exc = CallError(body, call_error='ValueError') |
|
72 |
else: |
|
73 |
exc = CallError.from_dict(error) |
|
74 |
raise exc |
b/kamaki/clients/quotaholder.py | ||
---|---|---|
1 |
# Copyright 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 synnefo.lib.quotaholder.api import QuotaholderAPI, QH_PRACTICALLY_INFINITE |
|
35 |
from .commissioning_client import CommissioningClient |
|
36 |
|
|
37 |
class QuotaholderClient(CommissioningClient): |
|
38 |
|
|
39 |
api_spec = QuotaholderAPI() |
|
40 |
appname = 'quotaholder' |
|
41 |
|
|
42 |
def __init__(self, base_url=None, token=None): |
|
43 |
default_url = 'http://127.0.0.1:8008/quotaholder/v' |
|
44 |
base_url = base_url if base_url else default_url |
|
45 |
super(self.__class__, self).__init__(base_url, token) |
b/kamaki/clients/quotaholder/__init__.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from kamaki.clients.quotaholder.api import QuotaholderAPI |
|
35 |
from kamaki.clients.commissioning.client import CommissioningClient |
|
34 |
from kamaki.clients.commissioning import Callpoint, CallError |
|
35 |
from kamaki.clients.commissioning.utils.debug import debug |
|
36 |
from kamaki.clients import Client |
|
36 | 37 |
|
38 |
from json import loads as json_loads, dumps as json_dumps |
|
37 | 39 |
|
38 |
class QuotaholderClient(CommissioningClient): |
|
39 | 40 |
|
40 |
api_spec = QuotaholderAPI() |
|
41 |
appname = 'quotaholder' |
|
41 |
class CommissioningClient(Callpoint): |
|
42 | 42 |
|
43 |
def __init__(self, base_url=None, token=None): |
|
44 |
super(self.__class__, self).__init__(base_url, token) |
|
43 |
def __init__(self, base_url, token): |
|
44 |
super(CommissioningClient, self).__init__() |
|
45 |
self._kc = Client(base_url, token) |
|
46 |
|
|
47 |
def do_make_call(self, api_call, data): |
|
48 |
|
|
49 |
_kc = self._kc |
|
50 |
|
|
51 |
gettable = ['list', 'get', 'read'] |
|
52 |
method = (_kc.get if any(api_call.startswith(x) for x in gettable) |
|
53 |
else _kc.post) |
|
54 |
|
|
55 |
path = api_call |
|
56 |
json_data = json_dumps(data) |
|
57 |
debug("%s %s\n%s\n<<<\n", method.func_name, path, json_data) |
|
58 |
|
|
59 |
resp = method(path, data=json_data, success=(200, 450, 500)) |
|
60 |
debug(">>>\nStatus: %s", resp.status_code) |
|
61 |
|
|
62 |
body = resp.text |
|
63 |
debug("\n%s\n<<<\n", body[:128] if body else None) |
|
64 |
|
|
65 |
status = int(resp.status_code) |
|
66 |
if status == 200: |
|
67 |
return json_loads(body) |
|
68 |
else: |
|
69 |
try: |
|
70 |
error = json_loads(body) |
|
71 |
except ValueError: |
|
72 |
exc = CallError(body, call_error='ValueError') |
|
73 |
else: |
|
74 |
exc = CallError.from_dict(error) |
|
75 |
raise exc |
b/kamaki/clients/quotaholder/api/__init__.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from kamaki.clients.quotaholder.api.quotaholder import QuotaholderAPI |
|
35 |
from kamaki.clients.quotaholder.api.exception import\ |
|
36 |
(InvalidKeyError, NoEntityError, |
|
37 |
NoQuantityError, NoCapacityError, |
|
38 |
ExportLimitError, ImportLimitError, |
|
39 |
CorruptedError, InvalidDataError, |
|
34 |
from kamaki.clients.quotaholder.api import QuotaholderAPI |
|
35 |
from kamaki.clients.quotaholder.api import QH_PRACTICALLY_INFINITE |
|
36 |
from kamaki.clients.quotaholder.exception import ( |
|
37 |
InvalidKeyError, |
|
38 |
NoEntityError, |
|
39 |
NoQuantityError, |
|
40 |
NoCapacityError, |
|
41 |
ExportLimitError, |
|
42 |
ImportLimitError, |
|
43 |
CorruptedError, |
|
44 |
InvalidDataError, |
|
40 | 45 |
DuplicateError) |
41 | 46 |
|
42 | 47 |
API_Spec = QuotaholderAPI |
b/kamaki/clients/quotaholder/api/exception.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from kamaki.clients.commissioning import (CallError, register_exception, |
|
35 |
InvalidDataError, CorruptedError) |
|
34 |
from kamaki.clients.commissioning import ( |
|
35 |
CallError, |
|
36 |
register_exception, |
|
37 |
InvalidDataError, |
|
38 |
CorruptedError) |
|
39 |
|
|
36 | 40 |
|
37 | 41 |
@register_exception |
38 | 42 |
class CommissionException(CallError): |
39 | 43 |
pass |
40 | 44 |
|
45 |
|
|
41 | 46 |
@register_exception |
42 | 47 |
class InvalidKeyError(CommissionException): |
43 | 48 |
pass |
44 | 49 |
|
50 |
|
|
45 | 51 |
@register_exception |
46 | 52 |
class NoEntityError(CommissionException): |
47 | 53 |
pass |
48 | 54 |
|
55 |
|
|
56 |
@register_exception |
|
57 |
class CommissionValueException(CommissionException): |
|
58 |
def __init__(self, *args, **kw): |
|
59 |
super(CommissionValueException, self).__init__(*args, **kw) |
|
60 |
kwargs = self.kwargs |
|
61 |
|
|
62 |
self.source = kwargs['source'] |
|
63 |
self.target = kwargs['target'] |
|
64 |
self.resource = kwargs['resource'] |
|
65 |
self.requested = kwargs['requested'] |
|
66 |
self.current = kwargs['current'] |
|
67 |
self.limit = kwargs['limit'] |
|
68 |
|
|
69 |
|
|
49 | 70 |
@register_exception |
50 |
class NoQuantityError(CommissionException): |
|
71 |
class NoQuantityError(CommissionValueException):
|
|
51 | 72 |
pass |
52 | 73 |
|
74 |
|
|
53 | 75 |
@register_exception |
54 |
class NoCapacityError(CommissionException): |
|
76 |
class NoCapacityError(CommissionValueException):
|
|
55 | 77 |
pass |
56 | 78 |
|
79 |
|
|
57 | 80 |
@register_exception |
58 |
class ExportLimitError(CommissionException): |
|
81 |
class ExportLimitError(CommissionValueException):
|
|
59 | 82 |
pass |
60 | 83 |
|
84 |
|
|
61 | 85 |
@register_exception |
62 |
class ImportLimitError(CommissionException): |
|
86 |
class ImportLimitError(CommissionValueException):
|
|
63 | 87 |
pass |
64 | 88 |
|
89 |
|
|
65 | 90 |
@register_exception |
66 | 91 |
class DuplicateError(CommissionException): |
67 | 92 |
pass |
b/kamaki/clients/quotaholder/api/quotaholder.py | ||
---|---|---|
34 | 34 |
# or implied, of GRNET S.A. |
35 | 35 |
|
36 | 36 |
|
37 |
from kamaki.clients.commissioning import (CanonifyException, SpecifyException, |
|
38 |
Specificator, Null, Integer, Text, |
|
39 |
Tuple, ListOf, Dict, Args) |
|
37 |
from kamaki.clients.commissioning import ( |
|
38 |
CanonifyException, |
|
39 |
SpecifyException, |
|
40 |
Specificator, |
|
41 |
Null, |
|
42 |
Integer, |
|
43 |
Text, |
|
44 |
Tuple, |
|
45 |
ListOf, |
|
46 |
Dict, |
|
47 |
Args) |
|
40 | 48 |
from random import choice, randint |
41 | 49 |
|
42 |
Context = Dict(classname='Context', null=True, show=False) |
|
50 |
Context = Dict(classname='Context', null=True, show=False) |
|
51 |
|
|
43 | 52 |
|
44 | 53 |
class Name(Text): |
45 | 54 |
def init(self): |
46 |
self.opts.update({'regex': "[\w.:@+/-]+", 'maxlen':512}) |
|
55 |
self.opts.update({'regex': "[\w.:@+/-]+", 'maxlen': 512})
|
|
47 | 56 |
Text.init(self) |
48 | 57 |
|
49 | 58 |
def _random_choice(self, kw): |
... | ... | |
51 | 60 |
length = randint(1, 48) |
52 | 61 |
return ''.join(choice(alphabet) for _ in xrange(length)) |
53 | 62 |
|
63 |
|
|
54 | 64 |
class Nonnegative(Integer): |
55 | 65 |
def init(self): |
56 | 66 |
self.opts.update({'minimum': 0}) |
57 | 67 |
|
68 |
|
|
58 | 69 |
class Positive(Integer): |
59 | 70 |
def init(self): |
60 | 71 |
self.opts.update({'minimum': 1}) |
61 | 72 |
|
62 |
Serial = Positive(classname='Serial') |
|
63 |
|
|
64 |
ClientKey = Name(classname='ClientKey') |
|
65 |
Nothing = Null(classname='Nothing') |
|
66 |
|
|
67 |
Entity = Name(classname='Entity') |
|
68 |
Owner = Name(classname='Owner') |
|
69 |
Key = Text(classname='Key') |
|
70 |
NewKey = Text(classname='Newkey') |
|
71 |
OwnerKey = Text(classname='OwnerKey') |
|
72 |
Resource = Name(classname='Resource') |
|
73 |
Policy = Name(classname='Policy') |
|
74 |
|
|
75 |
Quantity = Integer(classname='Quantity', null=True) |
|
76 |
Capacity = Nonnegative(classname='Capacity', null=True) |
|
77 |
ImportLimit = Nonnegative(classname='ImportLimit', null=True) |
|
78 |
ExportLimit = Nonnegative(classname='ExportLimit', null=True) |
|
79 |
Imported = Nonnegative(classname='Imported') |
|
80 |
Exported = Nonnegative(classname='Exported') |
|
81 |
Returned = Nonnegative(classname='Returned') |
|
82 |
Released = Nonnegative(classname='Released') |
|
83 |
Flags = Nonnegative(classname='Flags') |
|
84 |
Index = Nonnegative(classname='Index') |
|
85 |
|
|
86 |
Timepoint = Text(classname='Timepoint', maxlen=24) |
|
87 |
Reason = Text( classname = 'Reason', |
|
88 |
regex = '(ACCEPT|REJECT):.*', |
|
89 |
maxlen = 128 ) |
|
73 |
|
|
74 |
QH_PRACTICALLY_INFINITE = 10**32 |
|
75 |
|
|
76 |
Serial = Positive(classname='Serial') |
|
77 |
|
|
78 |
ClientKey = Name(classname='ClientKey') |
|
79 |
Nothing = Null(classname='Nothing') |
|
80 |
|
|
81 |
Entity = Name(classname='Entity') |
|
82 |
Owner = Name(classname='Owner') |
|
83 |
Key = Text(classname='Key') |
|
84 |
NewKey = Text(classname='Newkey') |
|
85 |
OwnerKey = Text(classname='OwnerKey') |
|
86 |
Resource = Name(classname='Resource') |
|
87 |
Policy = Name(classname='Policy') |
|
88 |
|
|
89 |
Quantity = Integer(classname='Quantity') |
|
90 |
Capacity = Nonnegative(classname='Capacity') |
|
91 |
ImportLimit = Nonnegative(classname='ImportLimit') |
|
92 |
ExportLimit = Nonnegative(classname='ExportLimit') |
|
93 |
QuantityDelta = Integer(classname='QuantityDelta') |
|
94 |
CapacityDelta = Integer(classname='CapacityDelta') |
|
95 |
ImportLimitDelta = Integer(classname='ImportLimitDelta') |
|
96 |
ExportLimitDelta = Integer(classname='ExportLimitDelta') |
|
97 |
Imported = Nonnegative(classname='Imported') |
|
98 |
Exported = Nonnegative(classname='Exported') |
|
99 |
Returned = Nonnegative(classname='Returned') |
|
100 |
Released = Nonnegative(classname='Released') |
|
101 |
Flags = Nonnegative(classname='Flags') |
|
102 |
Index = Nonnegative(classname='Index') |
|
103 |
|
|
104 |
Timepoint = Text(classname='Timepoint', maxlen=24) |
|
105 |
Reason = Text(classname='Reason', regex='(ACCEPT|REJECT):.*', maxlen=128) |
|
106 |
|
|
90 | 107 |
|
91 | 108 |
class QuotaholderAPI(Specificator): |
92 | 109 |
|
93 |
def create_entity ( |
|
94 |
self, |
|
95 |
context = Context, |
|
96 |
create_entity = ListOf(Entity, Owner, Key, OwnerKey, nonempty=1) |
|
97 |
): |
|
110 |
def create_entity( |
|
111 |
self, |
|
112 |
context=Context, |
|
113 |
create_entity=ListOf(Entity, Owner, Key, OwnerKey, |
|
114 |
nonempty=1) |
|
115 |
): |
|
98 | 116 |
rejected = ListOf(Index) |
99 | 117 |
return rejected |
100 | 118 |
|
101 |
def set_entity_key (
|
|
102 |
self,
|
|
103 |
context = Context,
|
|
104 |
set_entity_key = ListOf(Entity, Key, NewKey)
|
|
105 |
):
|
|
119 |
def set_entity_key( |
|
120 |
self, |
|
121 |
context=Context,
|
|
122 |
set_entity_key=ListOf(Entity, Key, NewKey)
|
|
123 |
): |
|
106 | 124 |
rejected = ListOf(Entity) |
107 | 125 |
return rejected |
108 | 126 |
|
109 |
def list_entities (
|
|
110 |
self,
|
|
111 |
context = Context,
|
|
112 |
entity = Entity,
|
|
113 |
key = Key
|
|
114 |
):
|
|
127 |
def list_entities( |
|
128 |
self, |
|
129 |
context=Context,
|
|
130 |
entity=Entity,
|
|
131 |
key=Key
|
|
132 |
): |
|
115 | 133 |
entities = ListOf(Entity) |
116 | 134 |
return entities |
117 | 135 |
|
118 |
def get_entity (
|
|
119 |
self,
|
|
120 |
context = Context,
|
|
121 |
get_entity = ListOf(Entity, Key, nonempty=1)
|
|
122 |
):
|
|
136 |
def get_entity( |
|
137 |
self, |
|
138 |
context=Context,
|
|
139 |
get_entity=ListOf(Entity, Key, nonempty=1)
|
|
140 |
): |
|
123 | 141 |
entities = ListOf(Entity, Owner) |
124 | 142 |
return entities |
125 | 143 |
|
126 |
def get_limits (
|
|
127 |
self,
|
|
128 |
context = Context,
|
|
129 |
get_limits = ListOf(Policy, nonempty=1)
|
|
130 |
):
|
|
144 |
def get_limits( |
|
145 |
self, |
|
146 |
context=Context,
|
|
147 |
get_limits=ListOf(Policy, nonempty=1)
|
|
148 |
): |
|
131 | 149 |
limits = ListOf(Policy, Quantity, Capacity, |
132 | 150 |
ImportLimit, ExportLimit) |
133 | 151 |
return limits |
134 | 152 |
|
135 |
def set_limits ( |
|
136 |
self, |
|
137 |
context = Context, |
|
138 |
set_limits = ListOf( Policy, Quantity, Capacity, |
|
139 |
ImportLimit, ExportLimit, |
|
140 |
nonempty=1 ) |
|
141 |
): |
|
153 |
def set_limits( |
|
154 |
self, |
|
155 |
context=Context, |
|
156 |
set_limits=ListOf( |
|
157 |
Policy, |
|
158 |
Quantity, |
|
159 |
Capacity, |
|
160 |
ImportLimit, |
|
161 |
ExportLimit, |
|
162 |
nonempty=1) |
|
163 |
): |
|
142 | 164 |
rejected = ListOf(Policy) |
143 | 165 |
return rejected |
144 | 166 |
|
145 |
def get_holding (
|
|
146 |
self,
|
|
147 |
context = Context,
|
|
148 |
get_holding = ListOf(Entity, Resource, Key)
|
|
149 |
):
|
|
167 |
def get_holding( |
|
168 |
self, |
|
169 |
context=Context,
|
|
170 |
get_holding=ListOf(Entity, Resource, Key)
|
|
171 |
): |
|
150 | 172 |
holdings = ListOf( Entity, Resource, Policy, |
151 | 173 |
Imported, Exported, Returned, Released, Flags ) |
152 | 174 |
return holdings |
153 | 175 |
|
154 |
def set_holding (
|
|
155 |
self,
|
|
156 |
context = Context,
|
|
157 |
set_holding = ListOf(Entity, Resource, Key, Policy, Flags)
|
|
158 |
):
|
|
176 |
def set_holding( |
|
177 |
self, |
|
178 |
context=Context,
|
|
179 |
set_holding=ListOf(Entity, Resource, Key, Policy, Flags)
|
|
180 |
): |
|
159 | 181 |
rejected = ListOf(Entity, Resource, Policy) |
160 | 182 |
return rejected |
161 | 183 |
|
162 |
def init_holding ( |
|
163 |
self, |
|
164 |
context = Context, |
|
165 |
init_holding = ListOf(Entity, Resource, Key, Policy, |
|
166 |
Imported, Exported, Returned, Released, |
|
167 |
Flags) |
|
168 |
): |
|
184 |
def init_holding( |
|
185 |
self, |
|
186 |
context=Context, |
|
187 |
init_holding=ListOf( |
|
188 |
Entity, |
|
189 |
Resource, |
|
190 |
Key, |
|
191 |
Policy, |
|
192 |
Imported, |
|
193 |
Exported, |
|
194 |
Returned, |
|
195 |
Released, |
|
196 |
Flags) |
|
197 |
): |
|
169 | 198 |
rejected = ListOf(Index) |
170 | 199 |
return rejected |
171 | 200 |
|
172 |
def reset_holding ( |
|
173 |
self, |
|
174 |
context = Context, |
|
175 |
reset_holding = ListOf(Entity, Resource, Key, |
|
176 |
Imported, Exported, Returned, Released) |
|
177 |
): |
|
201 |
def reset_holding( |
|
202 |
self, |
|
203 |
context=Context, |
|
204 |
reset_holding=ListOf( |
|
205 |
Entity, |
|
206 |
Resource, |
|
207 |
Key, |
|
208 |
Imported, |
|
209 |
Exported, |
|
210 |
Returned, |
|
211 |
Released) |
|
212 |
): |
|
178 | 213 |
rejected = ListOf(Index) |
179 | 214 |
return rejected |
180 | 215 |
|
181 |
def release_holding (
|
|
182 |
self,
|
|
183 |
context = Context,
|
|
184 |
release_holding = ListOf(Entity, Resource, Key)
|
|
185 |
):
|
|
216 |
def release_holding( |
|
217 |
self, |
|
218 |
context=Context,
|
|
219 |
release_holding=ListOf(Entity, Resource, Key)
|
|
220 |
): |
|
186 | 221 |
rejected = ListOf(Index) |
187 | 222 |
return rejected |
188 | 223 |
|
189 |
def list_resources ( |
|
190 |
self, |
|
191 |
context = Context, |
|
192 |
entity = Entity, |
|
193 |
key = Key |
|
194 |
): |
|
224 |
def list_resources(self, context=Context, entity=Entity, key=Key): |
|
195 | 225 |
resources = ListOf(Resource) |
196 | 226 |
return resources |
197 | 227 |
|
198 |
def list_holdings ( |
|
199 |
self, |
|
200 |
context = Context, |
|
201 |
list_holdings = ListOf(Entity, Key) |
|
202 |
): |
|
203 |
|
|
228 |
def list_holdings( |
|
229 |
self, |
|
230 |
context=Context, |
|
231 |
list_holdings=ListOf(Entity, Key) |
|
232 |
): |
|
204 | 233 |
rejected = ListOf(Entity) |
205 | 234 |
holdings_list = ListOf(ListOf(Entity, Resource, |
206 | 235 |
Imported, Exported, |
207 | 236 |
Returned, Released)) |
208 | 237 |
return Tuple(holdings_list, rejected) |
209 | 238 |
|
210 |
def get_quota (
|
|
211 |
self,
|
|
212 |
context = Context,
|
|
213 |
get_quota = ListOf(Entity, Resource, Key)
|
|
214 |
):
|
|
239 |
def get_quota( |
|
240 |
self, |
|
241 |
context=Context,
|
|
242 |
get_quota=ListOf(Entity, Resource, Key)
|
|
243 |
): |
|
215 | 244 |
quotas = ListOf(Entity, Resource, |
216 | 245 |
Quantity, Capacity, |
217 | 246 |
ImportLimit, ExportLimit, |
... | ... | |
220 | 249 |
Flags) |
221 | 250 |
return quotas |
222 | 251 |
|
223 |
def set_quota ( |
|
224 |
self, |
|
225 |
context = Context, |
|
226 |
set_quota = ListOf( Entity, Resource, Key, |
|
227 |
Quantity, Capacity, |
|
228 |
ImportLimit, ExportLimit, Flags ) |
|
229 |
): |
|
252 |
def set_quota( |
|
253 |
self, |
|
254 |
context=Context, |
|
255 |
set_quota=ListOf( |
|
256 |
Entity, |
|
257 |
Resource, |
|
258 |
Key, |
|
259 |
Quantity, |
|
260 |
Capacity, |
|
261 |
ImportLimit, |
|
262 |
ExportLimit, |
|
263 |
Flags) |
|
264 |
): |
|
265 |
rejected = ListOf(Entity, Resource) |
|
266 |
return rejected |
|
267 |
|
|
268 |
def add_quota( |
|
269 |
self, |
|
270 |
context=Context, |
|
271 |
clientkey=ClientKey, |
|
272 |
serial=Serial, |
|
273 |
sub_quota=ListOf( |
|
274 |
Entity, |
|
275 |
Resource, |
|
276 |
Key, |
|
277 |
QuantityDelta, |
|
278 |
CapacityDelta, |
|
279 |
ImportLimitDelta, |
|
280 |
ExportLimitDelta), |
|
281 |
add_quota=ListOf( |
|
282 |
Entity, |
|
283 |
Resource, |
|
284 |
Key, |
|
285 |
QuantityDelta, |
|
286 |
CapacityDelta, |
|
287 |
ImportLimitDelta, |
|
288 |
ExportLimitDelta) |
|
289 |
): |
|
230 | 290 |
rejected = ListOf(Entity, Resource) |
231 | 291 |
return rejected |
232 | 292 |
|
233 |
def issue_commission ( |
|
234 |
self, |
|
235 |
context = Context, |
|
236 |
target = Entity, |
|
237 |
key = Key, |
|
238 |
clientkey = ClientKey, |
|
239 |
name = Text(default=''), |
|
240 |
provisions = ListOf(Entity, Resource, Quantity) |
|
241 |
): |
|
293 |
def query_serials( |
|
294 |
self, |
|
295 |
context=Context, |
|
296 |
clientkey=ClientKey, |
|
297 |
serials=ListOf(Serial) |
|
298 |
): |
|
299 |
return ListOf(Serial) |
|
300 |
|
|
301 |
def ack_serials( |
|
302 |
self, |
|
303 |
context=Context, |
|
304 |
clientkey=ClientKey, |
|
305 |
serials=ListOf(Serial) |
|
306 |
): |
|
307 |
return Nothing |
|
308 |
|
|
309 |
def issue_commission( |
|
310 |
self, |
|
311 |
context=Context, |
|
312 |
target=Entity, |
|
313 |
key=Key, |
|
314 |
clientkey=ClientKey, |
|
315 |
name=Text(default=''), |
|
316 |
provisions=ListOf(Entity, Resource, Quantity) |
|
317 |
): |
|
242 | 318 |
return Serial |
243 | 319 |
|
244 |
def accept_commission (
|
|
245 |
self,
|
|
246 |
context = Context,
|
|
247 |
clientkey = ClientKey,
|
|
248 |
serials = ListOf(Serial),
|
|
249 |
reason = Text(default='ACCEPT')
|
|
250 |
):
|
|
320 |
def accept_commission( |
|
321 |
self, |
|
322 |
context=Context,
|
|
323 |
clientkey=ClientKey,
|
|
324 |
serials=ListOf(Serial),
|
|
325 |
reason=Text(default='ACCEPT')
|
|
326 |
): |
|
251 | 327 |
return Nothing |
252 | 328 |
|
253 |
def reject_commission (
|
|
254 |
self,
|
|
255 |
context = Context,
|
|
256 |
clientkey = ClientKey,
|
|
257 |
serials = ListOf(Serial),
|
|
258 |
reason = Text(default='REJECT')
|
|
259 |
):
|
|
329 |
def reject_commission( |
|
330 |
self, |
|
331 |
context=Context,
|
|
332 |
clientkey=ClientKey,
|
|
333 |
serials=ListOf(Serial),
|
|
334 |
reason=Text(default='REJECT')
|
|
335 |
): |
|
260 | 336 |
return Nothing |
261 | 337 |
|
262 |
def get_pending_commissions (
|
|
263 |
self,
|
|
264 |
context = Context,
|
|
265 |
clientkey = ClientKey
|
|
266 |
):
|
|
338 |
def get_pending_commissions( |
|
339 |
self, |
|
340 |
context=Context,
|
|
341 |
clientkey=ClientKey
|
|
342 |
): |
|
267 | 343 |
pending = ListOf(Serial) |
268 | 344 |
return pending |
269 | 345 |
|
270 |
def resolve_pending_commissions (
|
|
271 |
self,
|
|
272 |
context = Context,
|
|
273 |
clientkey = ClientKey,
|
|
274 |
max_serial = Serial,
|
|
275 |
accept_set = ListOf(Serial)
|
|
276 |
):
|
|
346 |
def resolve_pending_commissions( |
|
347 |
self, |
|
348 |
context=Context,
|
|
349 |
clientkey=ClientKey,
|
|
350 |
max_serial=Serial,
|
|
351 |
accept_set=ListOf(Serial)
|
|
352 |
): |
|
277 | 353 |
return Nothing |
278 | 354 |
|
279 |
def release_entity (
|
|
280 |
self,
|
|
281 |
context = Context,
|
|
282 |
release_entity = ListOf(Entity, Key, nonempty=1)
|
|
283 |
):
|
|
355 |
def release_entity( |
|
356 |
self, |
|
357 |
context=Context,
|
|
358 |
release_entity=ListOf(Entity, Key, nonempty=1)
|
|
359 |
): |
|
284 | 360 |
rejected = ListOf(Entity) |
285 | 361 |
return rejected |
286 | 362 |
|
287 |
def get_timeline (
|
|
288 |
self,
|
|
289 |
context = Context,
|
|
290 |
after = Timepoint,
|
|
291 |
before = Timepoint,
|
|
292 |
get_timeline = ListOf(Entity, Resource, Key)
|
|
293 |
):
|
|
363 |
def get_timeline( |
|
364 |
self, |
|
365 |
context=Context,
|
|
366 |
after=Timepoint,
|
|
367 |
before=Timepoint,
|
|
368 |
get_timeline=ListOf(Entity, Resource, Key)
|
|
369 |
): |
|
294 | 370 |
timeline = ListOf(Dict( |
295 |
serial = Serial, |
|
296 |
source = Entity, |
|
297 |
target = Entity, |
|
298 |
resource = Resource, |
|
299 |
name = Name(), |
|
300 |
quantity = Quantity, |
|
301 |
source_allocated = Quantity, |
|
302 |
source_allocated_through = Quantity, |
|
303 |
source_inbound = Quantity, |
|
304 |
source_inbound_through = Quantity, |
|
305 |
source_outbound = Quantity, |
|
306 |
source_outbound_through = Quantity, |
|
307 |
target_allocated = Quantity, |
|
308 |
target_allocated_through = Quantity, |
|
309 |
target_inbound = Quantity, |
|
310 |
target_inbound_through = Quantity, |
|
311 |
target_outbound = Quantity, |
|
312 |
target_outbound_through = Quantity, |
|
313 |
issue_time = Timepoint, |
|
314 |
log_time = Timepoint, |
|
315 |
reason = Reason, |
|
316 |
|
|
317 |
strict = True)) |
|
371 |
serial=Serial, |
|
372 |
source=Entity, |
|
373 |
target=Entity, |
|
374 |
resource=Resource, |
|
375 |
name=Name(), |
|
376 |
quantity=Quantity, |
|
377 |
source_allocated=Quantity, |
|
378 |
source_allocated_through=Quantity, |
|
379 |
source_inbound=Quantity, |
|
380 |
source_inbound_through=Quantity, |
|
381 |
source_outbound=Quantity, |
|
382 |
source_outbound_through=Quantity, |
|
383 |
target_allocated=Quantity, |
|
384 |
target_allocated_through=Quantity, |
|
385 |
target_inbound=Quantity, |
|
386 |
target_inbound_through=Quantity, |
|
387 |
target_outbound=Quantity, |
|
388 |
target_outbound_through=Quantity, |
|
389 |
issue_time=Timepoint, |
|
390 |
log_time=Timepoint, |
|
391 |
reason=Reason, |
|
392 |
strict=True)) |
|
318 | 393 |
return timeline |
319 |
|
Also available in: Unified diff