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

Change kamaki.clients.cyclades class names

Names are changed for uniformity. Backwards compatibility is kept,
(old names are not dismissed)

Renames:
CycladesRestClient --> CycladesComputeRestClient
CycladesClient --> CycladesComputeClient

Users can still import and user CycladesRestClient and CycladesClient
parent 05985110
......@@ -23,7 +23,7 @@ There is a client for every API. An external applications should instantiate
the kamaki clients that fit their needs.
For example, to manage virtual servers and stored objects / files, an
application would probably need the CycladesClient and PithosClient
application would probably need the CycladesComputeClient and PithosClient
respectively.
.. code-block:: python
......@@ -32,16 +32,16 @@ respectively.
Example 1.1: Instantiate Cyclades and Pithos clients
from kamaki.clients.cyclades import CycladesClient
from kamaki.clients.cyclades import CycladesComputeClient
from kamaki.clients.pithos import PithosClient
cyclades = CycladesClient(computeURL, token)
cyclades = CycladesComputeClient(computeURL, token)
pithos = PithosClient(object-storeURL, token, account, container)
.. note:: *cyclades* and *pithos* clients inherit ComputeClient from *compute*
and StorageClient from *storage*, respectively. Separate ComputeClient or
StorageClient objects should be used only when implementing applications for
strict OpenStack Compute or Storage services.
StorageClient objects should be used only when implementing applications
for strict OpenStack Compute or Storage services.
Using endpoints to get the authentication url
---------------------------------------------
......@@ -59,7 +59,7 @@ stored in ``service_type`` attribute in the client class.
The values of ``service_type`` for each client are shown bellow::
storage.StorageClient, pithos.PithosClient --> object-store
compute.ComputeClient, cyclades.CycladesClient --> compute
compute.ComputeClient, cyclades.CycladesComputeClient --> compute
network.NetworkClient, cyclades.CycladesNetworkClient --> network
image.ImageClient --> image
astakos.AstakosClient --> identity
......@@ -87,7 +87,7 @@ will be used to initialize a *cyclades* and a *pithos* client respectively.
Example 1.3: Retrieve cyclades and pithos URLs
cyclades_URL = astakos.get_endpoint_url(CycladesClient.service_type)
cyclades_URL = astakos.get_endpoint_url(CycladesComputeClient.service_type)
pithos_URL = astakos.get_endpoint_url(PithosClent.service_type)
It's time to initialize both clients.
......@@ -97,10 +97,10 @@ It's time to initialize both clients.
Example 1.3.1 Initialize cyclades and pithos clients
from kamaki.clients.cyclades import CycladesClient
from kamaki.clients.cyclades import CycladesComputeClient
from kamaki.clients.pithos import PithosClient
cyclades = CycladesClient(cyclades_URL, TOKEN)
cyclades = CycladesComputeClient(cyclades_URL, TOKEN)
pithos = PithosClient(pithos_URL, TOKEN)
# Also, setup the account UUID and container for pithos client
......@@ -172,7 +172,7 @@ The following example concatenates examples 1.1 to 1.4 plus error handling
from kamaki.clients import ClientError
from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import CycladesClient
from kamaki.clients.cyclades import CycladesComputeClient
from kamaki.clients.pithos import PithosClient
try:
......@@ -182,12 +182,12 @@ The following example concatenates examples 1.1 to 1.4 plus error handling
raise
try:
CYCLADES_URL = astakos.get_endpoint_url(CycladesClient.service_type)
CYCLADES_URL = astakos.get_endpoint_url(CycladesComputeClient.service_type)
except ClientError:
print('Failed to get endpoints for cyclades')
try:
cyclades = CycladesClient(CYCLADES_URL, TOKEN)
cyclades = CycladesComputeClient(CYCLADES_URL, TOKEN)
except ClientError:
print('Failed to initialize Cyclades client')
......@@ -231,15 +231,15 @@ Batch-create servers
#! /usr/bin/python
from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import CycladesClient
from kamaki.clients.cyclades import CycladesComputeClient
AUTHENTICATION_URL = 'https://accounts.example.com/identity/v2.0'
TOKEN = 'replace this with your token'
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)
CYCLADES_URL = astakos.get_endpoint_url(CycladesClient.service_type)
cyclades = CycladesClient(CYCLADES_URL, TOKEN)
CYCLADES_URL = astakos.get_endpoint_url(CycladesComputeClient.service_type)
cyclades = CycladesComputeClient(CYCLADES_URL, TOKEN)
# (name, flavor-id, image-id)
servers = [
......@@ -310,7 +310,8 @@ Two servers and a private network
#! /user/bin/python
from kamaki.clients.astakos import AstakosClient
from kamaki.clients.cyclades import CycladesClient, CycladesNetworkClient
from kamaki.clients.cyclades import (
CycladesComputeClient, CycladesNetworkClient)
AUTHENTICATION_URL = 'https://accounts.example.com/identity/v2.0'
TOKEN = 'replace this with your token'
......@@ -322,8 +323,8 @@ Two servers and a private network
net = network.create_network(type='MAC_FILTERED', name='My private network')
CYCLADES_URL = astakos.get_endpoint_url(CycladesClient.service_type)
cyclades = CycladesClient(CYCLADES_URL, TOKEN)
CYCLADES_URL = astakos.get_endpoint_url(CycladesComputeClient.service_type)
cyclades = CycladesComputeClient(CYCLADES_URL, TOKEN)
FLAVOR_ID = 'put your flavor id here'
IMAGE_ID = 'put your image id here'
......
......@@ -86,7 +86,7 @@ This is the plan:
try:
endpoints = dict(
astakos=AUTH_URL,
cyclades=auth.get_endpoint_url(CycladesClient.service_type),
cyclades=auth.get_endpoint_url(CycladesComputeClient.service_type),
network=auth.get_endpoint_url(CycladesNetworkClient.service_type),
pithos=auth.get_endpoint_url(PithosClient.service_type),
plankton=auth.get_endpoint_url(ImageClient.service_type)
......@@ -209,7 +209,7 @@ Here is the plan:
.. code-block:: python
# 4. Create virtual cluster
from kamaki.clients.cyclades import CycladesClient
from kamaki.clients.cyclades import CycladesComputeClient
FLAVOR_ID = 42
IMAGE_ID = image['id']
......@@ -218,7 +218,7 @@ Here is the plan:
# 4.1 Initialize a cyclades client
try:
cyclades = CycladesClient(endpoints['cyclades'], AUTH_TOKEN)
cyclades = CycladesComputeClient(endpoints['cyclades'], AUTH_TOKEN)
except ClientError:
stderr.write('Failed to initialize cyclades client\n')
raise
......@@ -640,7 +640,7 @@ logging more. We also added some command line interaction candy.
# Astakos implements identity and account APIs - The endpoint
# URL is the same for both services
astakos=auth.get_endpoint_url('identity'),
cyclades=auth.get_endpoint_url(CycladesClient.service_type),
cyclades=auth.get_endpoint_url(CycladesComputeClient.service_type),
network=auth.get_endpoint_url(CycladesNetworkClient.service_type),
pithos=auth.get_endpoint_url(PithosClient.service_type),
plankton=auth.get_endpoint_url(ImageClient.service_type)
......@@ -743,11 +743,11 @@ logging more. We also added some command line interaction candy.
# Compute / Cyclades
def init_cyclades(endpoint, token):
from kamaki.clients.cyclades import CycladesClient
from kamaki.clients.cyclades import CycladesComputeClient
print(' Initialize a cyclades client')
try:
return CycladesClient(endpoint, token)
return CycladesComputeClient(endpoint, token)
except ClientError:
log.debug('Failed to initialize cyclades client')
raise
......
......@@ -40,9 +40,8 @@ from pydoc import pager
from kamaki.cli import command
from kamaki.cli.cmdtree import CommandTree
from kamaki.cli.utils import remove_from_items, filter_dicts_by_dict
from kamaki.cli.errors import (
raiseCLIError, CLISyntaxError, CLIBaseUrlError, CLIInvalidArgument)
from kamaki.clients.cyclades import CycladesClient
from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIInvalidArgument
from kamaki.clients.cyclades import CycladesComputeClient
from kamaki.cli.argument import (
FlagArgument, ValueArgument, KeyValueArgument, RepeatableArgument,
DateArgument, IntArgument, StatusArgument)
......@@ -86,7 +85,7 @@ class _CycladesInit(CommandInit):
@errors.Generic.all
@addLogSettings
def _run(self):
self.client = self.get_client(CycladesClient, 'cyclades')
self.client = self.get_client(CycladesComputeClient, 'cyclades')
@dataModification
def _restruct_server_info(self, vm):
......
......@@ -36,10 +36,9 @@ from pydoc import pager
from kamaki.cli import command
from kamaki.cli.cmdtree import CommandTree
from kamaki.cli.errors import (
CLIBaseUrlError, CLIInvalidArgument, raiseCLIError)
from kamaki.cli.errors import CLIInvalidArgument, raiseCLIError
from kamaki.clients.cyclades import (
CycladesNetworkClient, ClientError, CycladesClient)
CycladesNetworkClient, ClientError, CycladesComputeClient)
from kamaki.cli.argument import (
FlagArgument, ValueArgument, RepeatableArgument, IntArgument,
StatusArgument)
......@@ -766,7 +765,7 @@ class network_disconnect(_NetworkInit, _PortWait, OptionalOutput):
"""Disconnect a network from a device"""
def _cyclades_client(self):
return self.get_client(CycladesClient, 'cyclades')
return self.get_client(CycladesComputeClient, 'cyclades')
arguments = dict(
wait=FlagArgument('Wait network to disconnect', ('-w', '--wait')),
......
# Copyright 2011-2013 GRNET S.A. All rights reserved.
# Copyright 2011-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -31,14 +31,13 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from kamaki.clients.cyclades.rest_api import CycladesRestClient
from kamaki.clients.cyclades.rest_api import CycladesComputeRestClient
from kamaki.clients.network import NetworkClient
from kamaki.clients.utils import path4url
from kamaki.clients import ClientError, Waiter
import json
class CycladesClient(CycladesRestClient, Waiter):
class CycladesComputeClient(CycladesComputeRestClient, Waiter):
"""Synnefo Cyclades Compute API client"""
def create_server(
......@@ -79,7 +78,7 @@ class CycladesClient(CycladesRestClient, Waiter):
except KeyError:
pass
return super(CycladesClient, self).create_server(
return super(CycladesComputeClient, self).create_server(
name, flavor_id, image_id,
metadata=metadata, personality=personality, networks=networks,
project=project)
......@@ -178,6 +177,10 @@ class CycladesClient(CycladesRestClient, Waiter):
server_id, current_status, get_status, delay, max_wait, wait_cb)
# Backwards compatibility
CycladesClient = CycladesComputeClient
class CycladesNetworkClient(NetworkClient):
"""Cyclades Network API extentions"""
......
# Copyright 2012-2013 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -35,7 +35,7 @@ from kamaki.clients.compute import ComputeClient
from kamaki.clients.utils import path4url
class CycladesRestClient(ComputeClient):
class CycladesComputeRestClient(ComputeClient):
"""Synnefo Cyclades REST API Client"""
def servers_stats_get(self, server_id, **kwargs):
......@@ -47,3 +47,7 @@ class CycladesRestClient(ComputeClient):
"""GET base_url/servers/<server_id>/diagnostics"""
path = path4url('servers', server_id, 'diagnostics')
return self.get(path, success=200, **kwargs)
# Backwards compatibility
CycladesRestClient = CycladesComputeRestClient
......@@ -34,7 +34,6 @@
from mock import patch, call
from unittest import TestCase
from itertools import product
from json import dumps
from kamaki.clients import ClientError, cyclades
......@@ -88,16 +87,16 @@ class FR(object):
status = None
status_code = 200
rest_pkg = 'kamaki.clients.cyclades.CycladesRestClient'
cyclades_pkg = 'kamaki.clients.cyclades.CycladesClient'
rest_pkg = 'kamaki.clients.cyclades.CycladesComputeRestClient'
cyclades_pkg = 'kamaki.clients.cyclades.CycladesComputeClient'
class CycladesRestClient(TestCase):
class CycladesComputeRestClient(TestCase):
def setUp(self):
self.url = 'http://cyclades.example.com'
self.token = 'cyc14d3s70k3n'
self.client = cyclades.CycladesRestClient(self.url, self.token)
self.client = cyclades.CycladesComputeRestClient(self.url, self.token)
@patch('kamaki.clients.Client.get', return_value='ret')
def test_servers_stats_get(self, get):
......@@ -192,7 +191,7 @@ class CycladesNetworkClient(TestCase):
self.assertEqual(ports_post.mock_calls[-1], call(**expargs))
class CycladesClient(TestCase):
class CycladesComputeClient(TestCase):
def assert_dicts_are_equal(self, d1, d2):
for k, v in d1.items():
......@@ -206,7 +205,7 @@ class CycladesClient(TestCase):
def setUp(self):
self.url = 'http://cyclades.example.com'
self.token = 'cyc14d3s70k3n'
self.client = cyclades.CycladesClient(self.url, self.token)
self.client = cyclades.CycladesComputeClient(self.url, self.token)
def tearDown(self):
FR.status_code = 200
......@@ -241,14 +240,14 @@ if __name__ == '__main__':
from sys import argv
from kamaki.clients.test import runTestCase
not_found = True
if not argv[1:] or argv[1] == 'CycladesClient':
if not argv[1:] or argv[1] == 'CycladesComputeClient':
not_found = False
runTestCase(CycladesNetworkClient, 'Cyclades Client', argv[2:])
if not argv[1:] or argv[1] == 'CycladesNetworkClient':
not_found = False
runTestCase(CycladesNetworkClient, 'CycladesNetwork Client', argv[2:])
if not argv[1:] or argv[1] == 'CycladesRestClient':
if not argv[1:] or argv[1] == 'CycladesComputeRestClient':
not_found = False
runTestCase(CycladesRestClient, 'CycladesRest Client', argv[2:])
runTestCase(CycladesComputeRestClient, 'CycladesRest Client', argv[2:])
if not_found:
print('TestCase %s not found' % argv[1])
# Copyright 2013 GRNET S.A. All rights reserved.
# Copyright 2013-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -42,8 +42,9 @@ from kamaki.clients.utils.test import Utils
from kamaki.clients.astakos.test import AstakosClient
from kamaki.clients.compute.test import ComputeClient, ComputeRestClient
from kamaki.clients.network.test import (NetworkClient, NetworkRestClient)
from kamaki.clients.cyclades.test import CycladesClient, CycladesNetworkClient
from kamaki.clients.cyclades.test import CycladesRestClient
from kamaki.clients.cyclades.test import (
CycladesComputeClient, CycladesNetworkClient)
from kamaki.clients.cyclades.test import CycladesComputeRestClient
from kamaki.clients.image.test import ImageClient
from kamaki.clients.storage.test import StorageClient
from kamaki.clients.pithos.test import (
......
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