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

Implement client.cyclades.CycladesNetworkClient

Refs: #4563

This class implements APi extentions custom to Cyclades
parent 5c433331
......@@ -85,9 +85,9 @@ DEFAULTS = {
'file_cli': 'pithos',
'server_cli': 'cyclades',
'flavor_cli': 'cyclades',
'network_cli': 'networking',
'subnet_cli': 'networking',
'port_cli': 'networking',
'network_cli': 'network',
'subnet_cli': 'network',
'port_cli': 'network',
'ip_cli': 'cyclades',
'image_cli': 'image',
'config_cli': 'config',
......@@ -34,6 +34,7 @@
from time import sleep
from kamaki.clients.cyclades.rest_api import CycladesRestClient
from import NetworkClient
from kamaki.clients import ClientError
......@@ -502,3 +503,19 @@ class CycladesClient(CycladesRestClient):
req = dict(removeFloatingIp=dict(address=address))
r = self.servers_action_post(server_id, json_data=req)
return r.headers
class CycladesNetworkClient(NetworkClient):
"""Cyclades Network API extentions"""
network_types = (
def create_network(self, type, name=None, shared=None):
req = dict(network=dict(type=type, admin_state_up=True))
if name:
req['network']['name'] = name
if shared not in (None, ):
req['network']['shared'] = bool(shared)
r = self.networks_post(json_data=req, success=201)
return r.json['network']
......@@ -239,6 +239,37 @@ class CycladesRestClient(TestCase):
'/os-floating-ips/%s' % fip, success=success, **kwargs))
class CycladesNetworkClient(TestCase):
"""Set up a ComputesRest thorough test"""
def setUp(self):
self.url = ''
self.token = 'n2tw0rk70k3n'
self.client = cyclades.CycladesNetworkClient(self.url, self.token)
def tearDown(self):
FR.json = vm_recv
del self.client
def test_create_network(self, networks_post):
for name, shared in product((None, 'net name'), (None, True)):
FR.json = dict(network='ret val')
type = 'net type'
self.client.create_network(type, name=name, shared=shared),
'ret val')
req = dict(type=type, admin_state_up=True)
if name:
req['name'] = name
if shared:
req['shared'] = shared
expargs = dict(json_data=dict(network=req), success=201)
self.assertEqual(networks_post.mock_calls[-1], call(**expargs))
class CycladesClient(TestCase):
def assert_dicts_are_equal(self, d1, d2):
......@@ -533,7 +564,10 @@ if __name__ == '__main__':
not_found = True
if not argv[1:] or argv[1] == 'CycladesClient':
not_found = False
runTestCase(CycladesClient, 'Cyclades Client', argv[2:])
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':
not_found = False
runTestCase(CycladesRestClient, 'CycladesRest Client', argv[2:])
......@@ -42,7 +42,7 @@ from kamaki.clients.utils.test import Utils
from kamaki.clients.astakos.test import AstakosClient
from kamaki.clients.compute.test import ComputeClient, ComputeRestClient
from import (NetworkClient, NetworkRestClient)
from kamaki.clients.cyclades.test import CycladesClient
from kamaki.clients.cyclades.test import CycladesClient, CycladesNetworkClient
from kamaki.clients.cyclades.test import CycladesRestClient
from kamaki.clients.image.test import ImageClient
from import StorageClient
......@@ -76,7 +76,7 @@ setup(
'Operating System :: OS Independent',
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