Commit 8a5fd86b authored by Stavros Sachtouris's avatar Stavros Sachtouris

Make project code to comply w. kamaki conventions

Notable changes:
 in CLI, --project --> --project-id
 in clients, create_floating_ip overwrites OS/network method
parent 277a1e2d
......@@ -783,7 +783,7 @@ class _application_action(_init_synnefo_astakosclient):
def main(self, project_id):
super(_application_action, self)._run()
self._run(self['app_id'], self['reason'] or '')
self._run(project_id, self['app_id'], self['reason'] or '')
@command(project_commands)
......
......@@ -473,7 +473,7 @@ class server_create(_init_cyclades, _optional_json, _server_wait):
'network policy is applied. These policies are set on the cloud, '
'so kamaki is oblivious to them',
'--no-network'),
project=ValueArgument('Assign the server to project', '--project'),
project_id=ValueArgument('Assign server to project', '--project-id'),
)
required = ('server_name', 'flavor_id', 'image_id')
......@@ -519,7 +519,7 @@ class server_create(_init_cyclades, _optional_json, _server_wait):
def _run(self, name, flavor_id, image_id):
for r in self._create_cluster(
name, flavor_id, image_id, size=self['cluster_size'] or 1,
project=self['project']):
project=self['project_id']):
if not r:
self.error('Create %s: server response was %s' % (name, r))
continue
......@@ -659,8 +659,12 @@ class server_modify(_init_cyclades, _optional_output_cmd):
@command(server_cmds)
class server_reassign(_init_cyclades, _optional_json):
"""Assign a VM to a different project
"""
"""Assign a virtual server to a different project"""
arguments = dict(
project_id=ValueArgument('The project to assign', '--project-id')
)
required = ('project_id', )
@errors.generic.all
@errors.cyclades.connection
......@@ -668,9 +672,9 @@ class server_reassign(_init_cyclades, _optional_json):
def _run(self, server_id, project):
self.client.reassign_server(server_id, project)
def main(self, server_id, project):
def main(self, server_id):
super(self.__class__, self)._run()
self._run(server_id=server_id, project=project)
self._run(server_id=server_id, project=self['project_id'])
@command(server_cmds)
......
......@@ -189,7 +189,7 @@ class network_create(_init_network, _optional_json):
name=ValueArgument('Network name', '--name'),
shared=FlagArgument(
'Make network shared (special privileges required)', '--shared'),
project=ValueArgument('Assign the network to project', '--project'),
project_id=ValueArgument('Assign network to project', '--project-id'),
network_type=NetworkTypeArgument(
'Valid network types: %s' % (', '.join(NetworkTypeArgument.types)),
'--type')
......@@ -200,9 +200,10 @@ class network_create(_init_network, _optional_json):
@errors.cyclades.network_type
def _run(self, network_type):
net = self.client.create_network(
network_type, name=self['name'],
network_type,
name=self['name'],
shared=self['shared'],
project=self['project'])
project=self['project_id'])
self._print(net, self.print_dict)
def main(self):
......@@ -212,8 +213,12 @@ class network_create(_init_network, _optional_json):
@command(network_cmds)
class network_reassign(_init_network, _optional_json):
"""Assign a network to a different project
"""
"""Assign a network to a different project"""
arguments = dict(
project_id=ValueArgument('Assign network to project', '--project-id'),
)
required = ('project_id', )
@errors.generic.all
@errors.cyclades.connection
......@@ -221,9 +226,9 @@ class network_reassign(_init_network, _optional_json):
def _run(self, network_id, project):
self.client.reassign_network(network_id, project)
def main(self, network_id, project):
def main(self, network_id):
super(self.__class__, self)._run()
self._run(network_id=network_id, project=project)
self._run(network_id=network_id, project=self['project_id'])
@command(network_cmds)
......@@ -647,16 +652,21 @@ class ip_create(_init_network, _optional_json):
@command(ip_cmds)
class ip_reassign(_init_network, _optional_output_cmd):
"""Assign a floating IP to a different project
"""
"""Assign a floating IP to a different project"""
arguments = dict(
project_id=ValueArgument('Assign the IP to project', '--project-id'),
)
required = ('project_id', )
@errors.generic.all
@errors.cyclades.connection
def _run(self, ip, project):
self._optional_output(self.client.reassign_floating_ip(ip, project))
def main(self, IP, project):
def main(self, IP):
super(self.__class__, self)._run()
self._run(ip=IP, project=project)
self._run(ip=IP, project=self['project_id'])
@command(ip_cmds)
......
......@@ -1546,7 +1546,8 @@ class container_create(_pithos_account):
limit=IntArgument('set default container limit', '--limit'),
meta=KeyValueArgument(
'set container metadata (can be repeated)', '--meta'),
project=ValueArgument('assign the container to project', '--project'),
project_id=ValueArgument('assign the container to project',
'--project-id'),
)
@errors.generic.all
......@@ -1558,7 +1559,7 @@ class container_create(_pithos_account):
container=container,
sizelimit=self['limit'],
versioning=self['versioning'],
project=self['project'],
project_id=self['project_id'],
metadata=self['meta'],
success=(201, ))
except ClientError as ce:
......@@ -1628,8 +1629,12 @@ class container_empty(_pithos_account):
@command(container_cmds)
class container_reassign(_pithos_account, _optional_output_cmd):
"""Assign a container to a different project
"""
"""Assign a container to a different project"""
arguments = dict(
project_id=ValueArgument('The project to assign', '--project-id')
)
required = ('project_id', )
@errors.generic.all
@errors.pithos.connection
......@@ -1639,10 +1644,10 @@ class container_reassign(_pithos_account, _optional_output_cmd):
self.client.container = self.container
self._optional_output(self.client.reassign_container(project))
def main(self, container, project):
def main(self, container):
super(self.__class__, self)._run()
self.container = container
self._run(project)
self._run(project=self['project_id'])
@command(sharer_cmds)
......
......@@ -395,11 +395,7 @@ class ComputeRestClient(Client):
def floating_ips_post(self, json_data, ip='', success=200, **kwargs):
path = path4url('os-floating-ips', ip or '')
if json_data is not None:
json_data = json.dumps(json_data)
self.set_header('Content-Type', 'application/json')
self.set_header('Content-Length', len(json_data))
return self.post(path, data=json_data, success=success, **kwargs)
return self.post(path, json=json_data, success=success, **kwargs)
def floating_ips_delete(self, ip='', success=204, **kwargs):
path = path4url('os-floating-ips', ip or '')
......
......@@ -37,6 +37,7 @@ from kamaki.clients.utils import path4url
from kamaki.clients import ClientError, Waiter
import json
class CycladesClient(CycladesRestClient, Waiter):
"""Synnefo Cyclades Compute API client"""
......@@ -199,22 +200,14 @@ class CycladesNetworkClient(NetworkClient):
r = self.networks_post(json_data=req, success=201)
return r.json['network']
def networks_action_post(
self, network_id='', json_data=None, success=202, **kwargs):
def reassign_network(self, network_id, project, **kwargs):
"""POST base_url/networks/<network_id>/action
:returns: request response
"""
if json_data:
json_data = json.dumps(json_data)
self.set_header('Content-Type', 'application/json')
self.set_header('Content-Length', len(json_data))
path = path4url('networks', network_id, 'action')
return self.post(path, data=json_data, success=success, **kwargs)
def reassign_network(self, network_id, project):
req = {'reassign': {'project': project}}
r = self.networks_action_post(network_id, json_data=req, success=200)
r = self.post(path, json=req, success=200, **kwargs)
return r.headers
def list_ports(self, detail=None):
......@@ -257,7 +250,7 @@ class CycladesNetworkClient(NetworkClient):
floatingip['floating_network_id'] = floating_network_id
if floating_ip_address:
floatingip['floating_ip_address'] = floating_ip_address
if project_id:
if project_id is not None:
floatingip['project'] = project_id
r = self.floatingips_post(
json_data=dict(floatingip=floatingip), success=200)
......
......@@ -331,9 +331,7 @@ class NetworkClient(NetworkRestClient, Waiter):
def create_floatingip(
self, floating_network_id,
floating_ip_address='', port_id='', fixed_ip_address='',
args=None):
"""Cyclades do not use port_id and fixed_ip_address"""
floating_ip_address='', port_id='', fixed_ip_address=''):
floatingip = dict(floating_network_id=floating_network_id)
if floating_ip_address:
floatingip['floating_ip_address'] = floating_ip_address
......@@ -341,8 +339,6 @@ class NetworkClient(NetworkRestClient, Waiter):
floatingip['port_id'] = port_id
if fixed_ip_address:
floatingip['fixed_ip_address'] = fixed_ip_address
if args is not None:
floatingip.update(args)
r = self.floatingips_post(
json_data=dict(floatingip=floatingip), success=200)
return r.json['floatingip']
......
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