Commit e0b84074 authored by Stavros Sachtouris's avatar Stavros Sachtouris

Replace "project" with "project_id" in clients lib

Fixes #24
parent 00d76c0c
......@@ -957,13 +957,13 @@ class membership_list(_AstakosInit, OptionalOutput):
"""List all memberships"""
arguments = dict(
project=ValueArgument('Filter by project id', '--project-id')
project_id=ValueArgument('Filter by project id', '--project-id')
)
@errors.Generic.all
@errors.Astakos.astakosclient
def _run(self):
self.print_(self.client.get_memberships(self['project']))
self.print_(self.client.get_memberships(self['project_id']))
def main(self):
super(self.__class__, self)._run()
......
......@@ -420,14 +420,15 @@ class server_create(_CycladesInit, OptionalOutput, _ServerWait):
required = ('server_name', 'flavor_id', 'image_id')
@errors.Cyclades.cluster_size
def _create_cluster(self, prefix, flavor_id, image_id, size, project=None):
def _create_cluster(
self, prefix, flavor_id, image_id, size):
networks = self['network_configuration'] or (
[] if self['no_network'] else None)
servers = [dict(
name='%s%s' % (prefix, i if size > 1 else ''),
flavor_id=flavor_id,
image_id=image_id,
project=project,
project_id=self['project_id'],
personality=self['personality'],
networks=networks) for i in range(1, 1 + size)]
if size == 1:
......@@ -460,8 +461,7 @@ class server_create(_CycladesInit, OptionalOutput, _ServerWait):
@errors.Cyclades.flavor_id
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_id']):
name, flavor_id, image_id, size=self['cluster_size'] or 1):
if not r:
self.error('Create %s: server response was %s' % (name, r))
continue
......@@ -608,12 +608,12 @@ class server_reassign(_CycladesInit, OptionalOutput):
@errors.Generic.all
@errors.Cyclades.connection
@errors.Cyclades.server_id
def _run(self, server_id, project):
self.client.reassign_server(server_id, project)
def _run(self, server_id):
self.client.reassign_server(server_id, self['project_id'])
def main(self, server_id):
super(self.__class__, self)._run()
self._run(server_id=server_id, project=self['project_id'])
self._run(server_id=server_id)
@command(server_cmds)
......
......@@ -177,7 +177,7 @@ class network_create(_NetworkInit, OptionalOutput):
network_type,
name=self['name'],
shared=self['shared'],
project=self['project_id'])
project_id=self['project_id'])
self.print_(net, self.print_dict)
def main(self):
......@@ -197,12 +197,12 @@ class network_reassign(_NetworkInit, OptionalOutput):
@errors.Generic.all
@errors.Cyclades.connection
@errors.Cyclades.network_id
def _run(self, network_id, project):
self.client.reassign_network(network_id, project)
def _run(self, network_id):
self.client.reassign_network(network_id, self['project_id'])
def main(self, network_id):
super(self.__class__, self)._run()
self._run(network_id=network_id, project=self['project_id'])
self._run(network_id=network_id)
@command(network_cmds)
......@@ -617,12 +617,12 @@ class ip_reassign(_NetworkInit):
@errors.Generic.all
@errors.Cyclades.connection
def _run(self, ip, project):
self.client.reassign_floating_ip(ip, project)
def _run(self, ip):
self.client.reassign_floating_ip(ip, self['project_id'])
def main(self, IP):
super(self.__class__, self)._run()
self._run(ip=IP, project=self['project_id'])
self._run(ip=IP)
@command(ip_cmds)
......
......@@ -1632,15 +1632,13 @@ class container_reassign(_PithosAccount):
@errors.Generic.all
@errors.Pithos.connection
@errors.Pithos.container
def _run(self, project):
if self.container:
self.client.container = self.container
self.client.reassign_container(project)
def _run(self, container):
self.client.container = container
self.client.reassign_container(self['project_id'])
def main(self, container):
super(self.__class__, self)._run()
self.container = container
self._run(project=self['project_id'])
self._run(container=container)
@command(sharer_cmds)
......
......@@ -114,7 +114,6 @@ class ComputeClient(ComputeRestClient):
metadata=None,
personality=None,
networks=None,
project=None,
response_headers=dict(location=None)):
"""Submit request to create a new server
......@@ -152,9 +151,6 @@ class ComputeClient(ComputeRestClient):
if networks is not None:
req['server']['networks'] = networks
if project:
req['server']['project'] = project
r = self.servers_post(
json_data=req,
security_group=security_group,
......
......@@ -42,7 +42,8 @@ class CycladesComputeClient(CycladesComputeRestClient, Waiter):
def create_server(
self, name, flavor_id, image_id,
metadata=None, personality=None, networks=None, project=None):
metadata=None, personality=None, networks=None, project_id=None,
response_headers=dict(location=None)):
"""Submit request to create a new server
:param name: (str)
......@@ -64,7 +65,7 @@ class CycladesComputeClient(CycladesComputeRestClient, Waiter):
ATTENTION: Empty list is different to None. None means ' do not
mention it', empty list means 'automatically get an ip'
:param project: the project where to assign the server
:param project_id: the project where to assign the server
:returns: a dict with the new virtual server details
......@@ -78,10 +79,25 @@ class CycladesComputeClient(CycladesComputeRestClient, Waiter):
except KeyError:
pass
return super(CycladesComputeClient, self).create_server(
name, flavor_id, image_id,
metadata=metadata, personality=personality, networks=networks,
project=project)
req = {'server': {
'name': name, 'flavorRef': flavor_id, 'imageRef': image_id}}
if metadata:
req['server']['metadata'] = metadata
if personality:
req['server']['personality'] = personality
if networks is not None:
req['server']['networks'] = networks
if project_id is not None:
req['server']['project'] = project_id
r = self.servers_post(json_data=req, success=(202, ))
for k, v in response_headers.items():
response_headers[k] = r.headers.get(k, v)
return r.json['server']
def set_firewall_profile(self, server_id, profile, port_id):
"""Set the firewall profile for the public interface of a server
......@@ -192,24 +208,24 @@ class CycladesNetworkClient(NetworkClient):
r = self.get(path, success=200)
return r.json['networks']
def create_network(self, type, name=None, shared=None, project=None):
def create_network(self, type, name=None, shared=None, project_id=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)
if project is not None:
req['network']['project'] = project
if project_id is not None:
req['network']['project'] = project_id
r = self.networks_post(json_data=req, success=201)
return r.json['network']
def reassign_network(self, network_id, project, **kwargs):
def reassign_network(self, network_id, project_id, **kwargs):
"""POST endpoint_url/networks/<network_id>/action
:returns: request response
"""
path = path4url('networks', network_id, 'action')
req = {'reassign': {'project': project}}
req = {'reassign': {'project': project_id}}
r = self.post(path, json=req, success=200, **kwargs)
return r.headers
......
......@@ -109,7 +109,7 @@ class PithosClient(PithosRestClient):
def create_container(
self,
container=None, sizelimit=None, versioning=None, metadata=None,
project=None, **kwargs):
project_id=None, **kwargs):
"""
:param container: (str) if not given, self.container is used instead
......@@ -127,7 +127,7 @@ class PithosClient(PithosRestClient):
self.container = container or cnt_back_up
r = self.container_put(
quota=sizelimit, versioning=versioning, metadata=metadata,
project=project, **kwargs)
project_id=project_id, **kwargs)
return r.headers
finally:
self.container = cnt_back_up
......@@ -1552,6 +1552,6 @@ class PithosClient(PithosRestClient):
r = self.object_get(obj, format='json', version='list')
return r.json['versions']
def reassign_container(self, project):
r = self.container_post(project=project)
def reassign_container(self, project_id):
r = self.container_post(project_id=project_id)
return r.headers
......@@ -310,7 +310,7 @@ class PithosRestClient(StorageClient):
def container_put(
self,
quota=None, versioning=None, project=None, metadata=None,
quota=None, versioning=None, project_id=None, metadata=None,
*args, **kwargs):
""" Full Pithos+ PUT at container level
......@@ -330,8 +330,8 @@ class PithosRestClient(StorageClient):
self.set_header('X-Container-Policy-Quota', quota)
self.set_header('X-Container-Policy-Versioning', versioning)
if project:
self.set_header('X-Container-Policy-Project', project)
if project_id is not None:
self.set_header('X-Container-Policy-Project', project_id)
if metadata:
for metaname, metaval in metadata.items():
......@@ -349,7 +349,7 @@ class PithosRestClient(StorageClient):
format='json',
quota=None,
versioning=None,
project=None,
project_id=None,
metadata=None,
content_type=None,
content_length=None,
......@@ -388,8 +388,8 @@ class PithosRestClient(StorageClient):
self.set_header('X-Container-Policy-Quota', quota)
self.set_header('X-Container-Policy-Versioning', versioning)
if project:
self.set_header('X-Container-Policy-Project', project)
if project_id is not None:
self.set_header('X-Container-Policy-Project', project_id)
if metadata:
for metaname, metaval in metadata.items():
......
......@@ -1203,7 +1203,7 @@ class PithosClient(TestCase):
r = self.client.create_container()
self.assert_dicts_are_equal(r, container_info)
CP.assert_called_once_with(
project=None, quota=None, versioning=None, metadata=None)
project_id=None, quota=None, versioning=None, metadata=None)
bu_cont = self.client.container
r = self.client.create_container(cont)
......@@ -1211,15 +1211,14 @@ class PithosClient(TestCase):
self.assert_dicts_are_equal(r, container_info)
self.assertEqual(
CP.mock_calls[-1],
call(project=None, quota=None, versioning=None, metadata=None))
call(project_id=None, quota=None, versioning=None, metadata=None))
meta = dict(k1='v1', k2='v2')
r = self.client.create_container(cont, 42, 'auto', meta, 'prid')
self.assertEqual(self.client.container, bu_cont)
self.assert_dicts_are_equal(r, container_info)
self.assertEqual(
CP.mock_calls[-1],
call(quota=42, versioning='auto', project='prid', metadata=meta))
self.assertEqual(CP.mock_calls[-1], call(
quota=42, versioning='auto', project_id='prid', metadata=meta))
@patch('%s.container_delete' % pithos_pkg, return_value=FR())
def test_purge_container(self, CD):
......
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