Commit dba6ec94 authored by Giorgos Verigakis's avatar Giorgos Verigakis
Browse files

Add support for Astakos API

Add "astakos authenticate" command
parent a591a7b4
#!/usr/bin/env python
# Copyright 2011 GRNET S.A. All rights reserved.
# 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
......@@ -106,7 +106,8 @@ GROUPS = {
'image': "Compute API image commands",
'network': "Compute API network commands (Cyclades extension)",
'glance': "Image API commands",
'store': "Storage API commands"}
'store': "Storage API commands",
'astakos': "Astakos API commands"}
def command(api=None, group=None, name=None, syntax=None):
......@@ -796,6 +797,15 @@ class store_delete(_store_container_command):
self.client.delete_object(path)
@command(api='astakos')
class astakos_authenticate(object):
"""Authenticate a user"""
def main(self):
reply = self.client.authenticate()
print_dict(reply)
def print_groups():
puts('\nGroups:')
with indent(2):
......@@ -812,7 +822,7 @@ def print_commands(group):
puts('\nCommands:')
with indent(2):
for name, cls in _commands[group].items():
puts(columns([name, 12], [cls.description, 60]))
puts(columns([name, 14], [cls.description, 60]))
def add_handler(name, level, prefix=''):
......@@ -875,7 +885,7 @@ def main():
config.override(section.strip(), key.strip(), val.strip())
apis = set(['config'])
for api in ('compute', 'image', 'storage'):
for api in ('compute', 'image', 'storage', 'astakos'):
if config.getboolean(api, 'enable'):
apis.add(api)
if config.getboolean('compute', 'cyclades_extensions'):
......@@ -968,6 +978,10 @@ def main():
url = config.get('image', 'url')
token = config.get('image', 'token') or config.get('global', 'token')
cmd.client = clients.image(url, token)
elif api == 'astakos':
url = config.get('astakos', 'url')
token = config.get('astakos', 'token') or config.get('global', 'token')
cmd.client = clients.astakos(url, token)
cmd.options = options
cmd.config = config
......
# Copyright 2011 GRNET S.A. All rights reserved.
# 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
......@@ -74,23 +74,13 @@ class ClientError(Exception):
class Client(object):
def __init__(self, base_url, token, include=False, verbose=False):
def __init__(self, base_url, token):
self.base_url = base_url
self.auth = XAuthTokenAuth(token)
self.include = include
self.verbose = verbose
def raise_for_status(self, r):
if 400 <= r.status_code < 500:
message, sep, details = r.text.partition('\n')
elif 500 <= r.status_code < 600:
message = '%d Server Error' % (r.status_code,)
details = r.text
else:
message = '%d Unknown Error' % (r.status_code,)
details = r.text
message = message or "HTTP Error %d" % (r.status_code,)
def raise_for_status(self, r):
message = "%d %s" % (r.status_code, r.status)
details = r.text
raise ClientError(message, r.status_code, details)
def request(self, method, path, **kwargs):
......@@ -150,3 +140,4 @@ 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
# 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 . import Client, ClientError
class AstakosClient(Client):
"""GRNet Astakos API client"""
def authenticate(self):
r = self.get('/im/authenticate')
return r.json
# Copyright 2011 GRNET S.A. All rights reserved.
# 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
......@@ -51,21 +51,26 @@ DEFAULTS = {
'compute': {
'enable': 'on',
'cyclades_extensions': 'on',
'url': 'https://okeanos.grnet.gr/api/v1.1',
'url': 'https://cyclades.okeanos.grnet.gr/api/v1.1',
'token': ''
},
'image': {
'enable': 'on',
'url': 'https://okeanos.grnet.gr/plankton',
'url': 'https://plankton.okeanos.grnet.gr/plankton',
'token': ''
},
'storage': {
'enable': 'on',
'pithos_extensions': 'on',
'url': 'https://plus.pithos.grnet.gr/v1',
'url': 'https://pithos.okeanos.grnet.gr/v1',
'account': '',
'container': '',
'token': ''
},
'astakos': {
'enable': 'on',
'url': 'https://astakos.okeanos.grnet.gr',
'token': ''
}
}
......
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