Revision cd42f8d8 kamaki/clients/astakos/__init__.py

b/kamaki/clients/astakos/__init__.py
32 32
# or implied, of GRNET S.A.
33 33

  
34 34
from logging import getLogger
35
from astakosclient import *
36
#  astakosclient contains: AstakosCLient, AstakosClientException
35
from astakosclient import AstakosClient as OriginalAstakosClient
36
from astakosclient import AstakosClientException, parse_endpoints
37 37

  
38 38
from kamaki.clients import Client, ClientError, RequestManager, recvlog
39 39

  
40 40

  
41
class AstakosClient(OriginalAstakosClient):
42
    """Wrap Original AstakosClient to ensure compatibility in kamaki clients"""
43

  
44
    def __init__(self, *args, **kwargs):
45
        if args:
46
            args = list(args)
47
            url = args.pop(0)
48
            token = args.pop(0) if args else kwargs.pop('token', None)
49
            args = tuple([token, url] + args)
50
        elif 'base_url' in kwargs:
51
            kwargs['auth_url'] = kwargs.get('auth_url', kwargs['base_url'])
52
        super(AstakosClient, self).__init__(*args, **kwargs)
53

  
41 54

  
42 55
def _astakos_error(foo):
43 56
    def wrap(self, *args, **kwargs):
......
48 61
    return wrap
49 62

  
50 63

  
51
class SynnefoAstakosClient(AstakosClient):
52
    """An astakosclient.AstakosClient wrapper, that logs the way of kamaki"""
64
class LoggedAstakosClient(AstakosClient):
65
    """An AstakosClient wrapper with modified logging
66

  
67
    Logs are adjusted to appear similar to the ones of kamaki clients.
68
    No other changes are made to the parent class.
69
    """
53 70

  
54 71
    LOG_TOKEN = False
55 72
    LOG_DATA = False
......
66 83
        recvlog.info('-             -        -     -   -  - -')
67 84

  
68 85
    def _call_astakos(self, *args, **kwargs):
69
        r = super(SynnefoAstakosClient, self)._call_astakos(*args, **kwargs)
86
        r = super(LoggedAstakosClient, self)._call_astakos(*args, **kwargs)
70 87
        try:
71 88
            log_request = getattr(self, 'log_request', None)
72 89
            if log_request:
......
129 146
        :param token: (str) custom token to authenticate
130 147
        """
131 148
        token = self._resolve_token(token)
132
        astakos = SynnefoAstakosClient(
133
            token, self.base_url, logger=getLogger('astakosclient'))
149
        astakos = LoggedAstakosClient(
150
            self.base_url, token, logger=getLogger('astakosclient'))
134 151
        astakos.LOG_TOKEN = getattr(self, 'LOG_TOKEN', False)
135 152
        astakos.LOG_DATA = getattr(self, 'LOG_DATA', False)
136 153
        r = astakos.authenticate()

Also available in: Unified diff