_commands = OrderedDict()
GROUPS = {}
-CLI_LOCATIONS = ['', 'kamaki', 'kamaki.clients', 'kamaki.clis']
+CLI_LOCATIONS = ['', 'kamaki', 'kamaki.commands']
class CLIError(Exception):
def __init__(self, message, status=0, details='', importance=0):
def load_groups(config):
"""load groups and import CLIs and Modules"""
- #apis = set(['config']+config.apis())
loaded_modules = {}
for api in config.apis():
api_cli = config.get(api, 'cli')
self.status = status
self.details = details
+class ClientResponse(object):
+
+ def __init__(self):
+ #Dict of response headers
+ self.headers = {}
+ #CLear text in the response
+ self.text = ''
+ #Json formated response
+ self.json = None
+ #xml formated response
+ self.xml = None
+ #Content in byte form
+ self.content = None
+
+ def load_request_object(self, request):
+ r.headers = request.headers
+ r.text = request.text
+ r.json = request.json
+ r.xml = request.xml
+ r.content = request.content
+
class Client(object):
- def __init__(self, base_url, token):
+
+ def __init__(self, base_url, token, http_client=None):
self.base_url = base_url
self.token = token
self.headers = {}
self.DATE_FORMATS = ["%a %b %d %H:%M:%S %Y",
"%A, %d-%b-%y %H:%M:%S GMT",
"%a, %d %b %Y %H:%M:%S GMT"]
+ self.http_client = http_client
def raise_for_status(self, r):
message = "%d %s" % (r.status_code, r.status)
def move(self, path, **kwargs):
return self.request('move', path, **kwargs)
-from .compute import ComputeClient as compute
-from .image import ImageClient as image
-from .storage import StorageClient as storage
-from .cyclades import CycladesClient as cyclades
-from .pithos import PithosClient as pithos
-from .astakos import AstakosClient as astakos
--- /dev/null
+# Copyright 2011-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, self.list of conditions and the following
+# disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above
+# copyright notice, self.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.
+
+class ClientResponse(object):
+
+ def __init__(self):
+ #Dict of response headers
+ self.headers = {}
+ #CLear text in the response
+ self.text = ''
+ #Json formated response
+ self.json = None
+ #xml formated response
+ self.xml = None
+ #Content in byte form
+ self.content = None
+
+ def load_request_object(self, request):
+ r.headers = request.headers
+ r.text = request.text
+ r.json = request.json
+ r.xml = request.xml
+ r.content = request.content
\ No newline at end of file
from kamaki.cli import command, set_api_description
set_api_description('astakos', 'Astakos API commands')
-from .astakos import AstakosClient, ClientError
+from kamaki.clients.astakos import AstakosClient, ClientError
from .cli_utils import raiseCLIError
from kamaki.utils import print_dict
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.command
-from . import ClientError
+from kamaki.clients import ClientError
from kamaki.cli import CLIError
-from inspect import getargspec
+#from inspect import getargspec
def raiseCLIError(err, importance = -1):
if importance < 0:
importance = 3
raise CLIError(err.message, err.status, err.details, importance)
+def dict2file(d, f, depth = 0):
+ for k, v in d.items():
+ f.write('%s%s: '%('\t'*depth, k))
+ if type(v) is dict:
+ f.write('\n')
+ dict2file(v, f, depth+1)
+ elif type(v) is list:
+ f.write('\n')
+ list2file(v, f, depth+1)
+ else:
+ f.write(' %s\n'%unicode(v))
+
+def list2file(l, f, depth = 1):
+ for item in l:
+ if type(item) is dict:
+ dict2file(item, f, depth+1)
+ elif type(item) is list:
+ list2file(item, f, depth+1)
+ else:
+ f.write('%s%s\n'%('\t'*depth, unicode(item)))
\ No newline at end of file
set_api_description('flavor', "Compute/Cyclades API flavor commands")
set_api_description('image', "Compute/Cyclades or Glance API image commands")
set_api_description('network', "Compute/Cyclades API network commands")
-from .cyclades import CycladesClient, ClientError
+from kamaki.clients.cyclades import CycladesClient, ClientError
from .cli_utils import raiseCLIError
from colors import yellow
from kamaki.cli import command, set_api_description
from kamaki.utils import print_dict, print_items
set_api_description('image', "Compute/Cyclades or Glance API image commands")
-from .image import ImageClient, ClientError
+from kamaki.clients.image import ImageClient, ClientError
from .cli_utils import raiseCLIError
class _init_image(object):
from kamaki.clients.utils import filter_in
from kamaki.utils import format_size
set_api_description('store', 'Pithos+ storage commands')
-from .pithos import PithosClient, ClientError
+from kamaki.clients.pithos import PithosClient, ClientError
from .cli_utils import raiseCLIError
from kamaki.utils import print_dict, pretty_keys, print_list
from colors import bold
from kamaki.cli import command, CLIError
from kamaki.utils import print_list
-from .utils import dict2file, list2file
+from .cli_utils import dict2file, list2file
from .pithos_cli import _store_container_command, _store_account_command
from colors import bold
from sys import stdout#argv, exit, stdin, stdout
#from datetime import datetime
-from .pithos_sh_lib.client import Pithos_Client, Fault
+from kamaki.clients.pithos_sh_lib.client import Pithos_Client, Fault
#from .pithos_sh_lib.util import get_user, get_auth, get_url
-from .pithos_sh_lib.transfer import download, cat#,upload
+from kamaki.clients.pithos_sh_lib.transfer import download, cat#,upload
#import json
#import logging