Commit b4368e33 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Add all quotaholder files in kamaki

parent d1304043
...@@ -33,16 +33,33 @@ ...@@ -33,16 +33,33 @@
# Import general commission framework # Import general commission framework
from .exception import (CallError, CorruptedError, InvalidDataError, from kamaki.clients.commissioning.exception import (
ReturnButFail, CallError,
register_exception, register_exceptions) CorruptedError,
InvalidDataError,
ReturnButFail,
register_exception,
register_exceptions)
from .callpoint import Callpoint, mkcallargs from kamaki.clients.commissioning.callpoint import (
Callpoint,
mkcallargs)
from .specificator import (Specificator, SpecifyException, from kamaki.clients.commissioning.specificator import (
Canonifier, CanonifyException, Specificator,
Canonical, SpecifyException,
Null, Nothing, Integer, Serial, Canonifier,
Text, Bytes, Tuple, ListOf, Dict, Args) CanonifyException,
Canonical,
Null,
Nothing,
Integer,
Serial,
Text,
Bytes,
Tuple,
ListOf,
Dict,
Args)
# Import standard implementations? # Import standard implementations?
...@@ -32,12 +32,15 @@ ...@@ -32,12 +32,15 @@
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
from .specificator import CanonifyException from kamaki.clients.commissioning.specificator import CanonifyException
from .exception import CorruptedError, InvalidDataError, ReturnButFail from kamaki.clients.commissioning.exception import CorruptedError
from .importing import imp_module from kamaki.clients.commissioning.exception import InvalidDataError
from kamaki.clients.commissioning.exception import ReturnButFail
from kamaki.clients.commissioning.importing import imp_module
from re import compile as re_compile, sub as re_sub from re import compile as re_compile, sub as re_sub
class Callpoint(object): class Callpoint(object):
api_spec = None api_spec = None
......
...@@ -35,13 +35,16 @@ ...@@ -35,13 +35,16 @@
from random import random, choice, randint from random import random, choice, randint
from math import log from math import log
from inspect import isclass from inspect import isclass
from .utils.argmap import (argmap_decode, argmap_check, argmap_unpack_dict, from kamaki.clients.commissioning.utils.argmap import (
argmap_unpack_list) argmap_decode,
argmap_check,
argmap_unpack_dict,
argmap_unpack_list)
try: try:
from collections import OrderedDict from collections import OrderedDict
except ImportError: except ImportError:
from .utils.ordereddict import OrderedDict from kamaki.clients.commissioning.utils.ordereddict import OrderedDict
def shorts(s): def shorts(s):
if not isinstance(s, unicode): if not isinstance(s, unicode):
......
...@@ -34,12 +34,13 @@ ...@@ -34,12 +34,13 @@
try: try:
from collections import OrderedDict from collections import OrderedDict
except ImportError: except ImportError:
from .ordereddict import OrderedDict from kamaki.clients.commissioning.utils.ordereddict import OrderedDict
from itertools import chain from itertools import chain
from cStringIO import StringIO from cStringIO import StringIO
ARGMAP_MAGIC = '[=ARGMAP=]' ARGMAP_MAGIC = '[=ARGMAP=]'
class arguments(object): class arguments(object):
__slots__ = ('args', 'kw') __slots__ = ('args', 'kw')
......
# Copyright 2012 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from time import time from time import time
_counter = 0 _counter = 0
......
# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy. #!/usr/bin/env python
# Passes Python2.7's test suite and incorporates all the latest updates.
# Copyright 2012 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and
# pypy. Passes Python2.7's test suite and incorporates all the latest updates.
try: try:
from thread import get_ident as _get_ident from thread import get_ident as _get_ident
...@@ -17,9 +52,11 @@ class OrderedDict(dict): ...@@ -17,9 +52,11 @@ class OrderedDict(dict):
# An inherited dict maps keys to values. # An inherited dict maps keys to values.
# The inherited dict provides __getitem__, __len__, __contains__, and get. # The inherited dict provides __getitem__, __len__, __contains__, and get.
# The remaining methods are order-aware. # The remaining methods are order-aware.
# Big-O running times for all methods are the same as for regular dictionaries. # Big-O running times for all methods are the same as for regular
# dictionaries.
# The internal self.__map dictionary maps keys to links in a doubly linked list. # The internal self.__map dictionary maps keys to links in a doubly linked
# list.
# The circular doubly linked list starts and ends with a sentinel element. # The circular doubly linked list starts and ends with a sentinel element.
# The sentinel element never gets deleted (this simplifies the algorithm). # The sentinel element never gets deleted (this simplifies the algorithm).
# Each link is stored as a list of length three: [PREV, NEXT, KEY]. # Each link is stored as a list of length three: [PREV, NEXT, KEY].
...@@ -42,8 +79,10 @@ class OrderedDict(dict): ...@@ -42,8 +79,10 @@ class OrderedDict(dict):
def __setitem__(self, key, value, dict_setitem=dict.__setitem__): def __setitem__(self, key, value, dict_setitem=dict.__setitem__):
'od.__setitem__(i, y) <==> od[i]=y' 'od.__setitem__(i, y) <==> od[i]=y'
# Setting a new item creates a new link which goes at the end of the linked # Setting a new item creates a new link which goes at the end of the
# list, and the inherited dictionary is updated with the new key/value pair. # linked
# list, and the inherited dictionary is updated with the new key/value
# pair.
if key not in self: if key not in self:
root = self.__root root = self.__root
last = root[0] last = root[0]
...@@ -53,7 +92,8 @@ class OrderedDict(dict): ...@@ -53,7 +92,8 @@ class OrderedDict(dict):
def __delitem__(self, key, dict_delitem=dict.__delitem__): def __delitem__(self, key, dict_delitem=dict.__delitem__):
'od.__delitem__(y) <==> del od[y]' 'od.__delitem__(y) <==> del od[y]'
# Deleting an existing item uses self.__map to find the link which is # Deleting an existing item uses self.__map to find the link which is
# then removed by updating the links in the predecessor and successor nodes. # then removed by updating the links in the predecessor and successor
# nodes.
dict_delitem(self, key) dict_delitem(self, key)
link_prev, link_next, key = self.__map.pop(key) link_prev, link_next, key = self.__map.pop(key)
link_prev[1] = link_next link_prev[1] = link_next
...@@ -142,9 +182,9 @@ class OrderedDict(dict): ...@@ -142,9 +182,9 @@ class OrderedDict(dict):
'''od.update(E, **F) -> None. Update od from dict/iterable E and F. '''od.update(E, **F) -> None. Update od from dict/iterable E and F.
If E is a dict instance, does: for k in E: od[k] = E[k] If E is a dict instance, does: for k in E: od[k] = E[k]
If E has a .keys() method, does: for k in E.keys(): od[k] = E[k] If E has a .keys() method, does: for k in E.keys(): od[k]=E[k]
Or if E is an iterable of items, does: for k, v in E: od[k] = v Or if E is an iterable of items, does: for k, v in E: od[k] = v
In either case, this is followed by: for k, v in F.items(): od[k] = v In either case, this is followed by: for k, v in F.items(): od[k]=v
''' '''
if len(args) > 2: if len(args) > 2:
......
...@@ -31,12 +31,13 @@ ...@@ -31,12 +31,13 @@
# interpreted as representing official policies, either expressed # interpreted as representing official policies, either expressed
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
from synnefo.lib.commissioning import Callpoint, CallError from kamaki.clients.commissioning import Callpoint, CallError
from synnefo.lib.commissioning.utils.debug import debug from kamaki.clients.commissioning.utils.debug import debug
from . import Client from kamaki.clients import Client
from json import loads as json_loads, dumps as json_dumps from json import loads as json_loads, dumps as json_dumps
class CommissioningClient(Callpoint): class CommissioningClient(Callpoint):
def __init__(self, base_url, token): def __init__(self, base_url, token):
...@@ -46,7 +47,7 @@ class CommissioningClient(Callpoint): ...@@ -46,7 +47,7 @@ class CommissioningClient(Callpoint):
def do_make_call(self, api_call, data): def do_make_call(self, api_call, data):
_kc = self._kc _kc = self._kc
gettable = ['list', 'get', 'read'] gettable = ['list', 'get', 'read']
method = (_kc.get if any(api_call.startswith(x) for x in gettable) method = (_kc.get if any(api_call.startswith(x) for x in gettable)
else _kc.post) else _kc.post)
...@@ -54,10 +55,10 @@ class CommissioningClient(Callpoint): ...@@ -54,10 +55,10 @@ class CommissioningClient(Callpoint):
path = api_call path = api_call
json_data = json_dumps(data) json_data = json_dumps(data)
debug("%s %s\n%s\n<<<\n", method.func_name, path, json_data) debug("%s %s\n%s\n<<<\n", method.func_name, path, json_data)
resp = method(path, data=json_data, success=(200,450,500)) resp = method(path, data=json_data, success=(200, 450, 500))
debug(">>>\nStatus: %s", resp.status_code) debug(">>>\nStatus: %s", resp.status_code)
body = resp.text body = resp.text
debug("\n%s\n<<<\n", body[:128] if body else None) debug("\n%s\n<<<\n", body[:128] if body else None)
......
# Copyright 2012 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from synnefo.lib.quotaholder.api import QuotaholderAPI, QH_PRACTICALLY_INFINITE
from .commissioning_client import CommissioningClient
class QuotaholderClient(CommissioningClient):
api_spec = QuotaholderAPI()
appname = 'quotaholder'
def __init__(self, base_url=None, token=None):
default_url = 'http://127.0.0.1:8008/quotaholder/v'
base_url = base_url if base_url else default_url
super(self.__class__, self).__init__(base_url, token)
...@@ -31,9 +31,10 @@ ...@@ -31,9 +31,10 @@
# interpreted as representing official policies, either expressed # interpreted as representing official policies, either expressed
# or implied, of GRNET S.A. # or implied, of GRNET S.A.
from kamaki.clients.quotaholder.api import QuotaholderAPI from kamaki.clients.quotaholder.api.quotaholder import (
from kamaki.clients.quotaholder.api import QH_PRACTICALLY_INFINITE QuotaholderAPI,
from kamaki.clients.quotaholder.exception import ( QH_PRACTICALLY_INFINITE)
from kamaki.clients.quotaholder.api.exception import (
InvalidKeyError, InvalidKeyError,
NoEntityError, NoEntityError,
NoQuantityError, NoQuantityError,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment