From 3ba6e5fe5e7dd9355b27172f004203612a37dee2 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Fri, 2 Feb 2018 07:24:19 -0600 Subject: [PATCH] Add all_projects as a preferred alias for all_tenants Now that we support both server-side and client-side names for parameters, we can add an all_projects alias. We already use project_id in resources instead of tenant_id. Put in logic to only pass all_projects along to the underlying list if it's True. That way we can easily use the interface with True/False and only send query parameters when we need to. Pehaps we could enhance QueryParameters to understand default values of parameters and that they don't need to be sent? Change-Id: I66117ab4c82d30ae3700e17f7598b3d3fbbac60d --- openstack/block_storage/v2/_proxy.py | 4 ++-- openstack/block_storage/v2/snapshot.py | 2 +- openstack/block_storage/v2/volume.py | 2 +- openstack/compute/v2/_proxy.py | 6 +++++- openstack/compute/v2/server.py | 5 +++-- openstack/tests/unit/block_storage/v2/test_snapshot.py | 2 +- openstack/tests/unit/block_storage/v2/test_volume.py | 2 +- openstack/tests/unit/compute/v2/test_server.py | 2 +- 8 files changed, 15 insertions(+), 10 deletions(-) diff --git a/openstack/block_storage/v2/_proxy.py b/openstack/block_storage/v2/_proxy.py index 88091c45d..cabff42b1 100644 --- a/openstack/block_storage/v2/_proxy.py +++ b/openstack/block_storage/v2/_proxy.py @@ -45,7 +45,7 @@ class Proxy(proxy.Proxy): the snapshots being returned. Available parameters include: * name: Name of the snapshot as a string. - * all_tenants: Whether return the snapshots of all tenants. + * all_projects: Whether return the snapshots in all projects. * volume_id: volume id of a snapshot. * status: Value of the status of the snapshot so that you can filter on "available" for example. @@ -154,7 +154,7 @@ class Proxy(proxy.Proxy): the volumes being returned. Available parameters include: * name: Name of the volume as a string. - * all_tenants: Whether return the volumes of all tenants + * all_projects: Whether return the volumes in all projects * status: Value of the status of the volume so that you can filter on "available" for example. diff --git a/openstack/block_storage/v2/snapshot.py b/openstack/block_storage/v2/snapshot.py index d9137934c..4962014cf 100644 --- a/openstack/block_storage/v2/snapshot.py +++ b/openstack/block_storage/v2/snapshot.py @@ -20,7 +20,7 @@ class Snapshot(resource.Resource): base_path = "/snapshots" _query_mapping = resource.QueryParameters( - 'all_tenants', 'name', 'status', 'volume_id') + 'name', 'status', 'volume_id', all_projects='all_tenants') # capabilities allow_fetch = True diff --git a/openstack/block_storage/v2/volume.py b/openstack/block_storage/v2/volume.py index 4402e624f..215e45ed1 100644 --- a/openstack/block_storage/v2/volume.py +++ b/openstack/block_storage/v2/volume.py @@ -20,7 +20,7 @@ class Volume(resource.Resource): base_path = "/volumes" _query_mapping = resource.QueryParameters( - 'all_tenants', 'name', 'status', 'project_id') + 'name', 'status', 'project_id', all_projects='all_tenants') # capabilities allow_fetch = True diff --git a/openstack/compute/v2/_proxy.py b/openstack/compute/v2/_proxy.py index 20c7ebffb..b0a14ede8 100644 --- a/openstack/compute/v2/_proxy.py +++ b/openstack/compute/v2/_proxy.py @@ -371,7 +371,7 @@ class Proxy(proxy.Proxy): """ return self._get(_server.Server, server) - def servers(self, details=True, **query): + def servers(self, details=True, all_projects=False, **query): """Retrieve a generator of servers :param bool details: When set to ``False`` @@ -395,6 +395,8 @@ class Proxy(proxy.Proxy): * status: Value of the status of the server so that you can filter on "ACTIVE" for example. * host: Name of the host as a string. + * all_projects: Flag to request servers be returned from all + projects, not just the currently scoped one. * limit: Requests a specified page size of returned items from the query. Returns a number of items up to the specified limit value. Use the limit parameter to make an initial @@ -408,6 +410,8 @@ class Proxy(proxy.Proxy): :returns: A generator of server instances. """ + if all_projects: + query['all_projects'] = True srv = _server.ServerDetail if details else _server.Server return self._list(srv, paginated=True, **query) diff --git a/openstack/compute/v2/server.py b/openstack/compute/v2/server.py index 2207b2f8c..c60a7962c 100644 --- a/openstack/compute/v2/server.py +++ b/openstack/compute/v2/server.py @@ -29,7 +29,7 @@ class Server(resource.Resource, metadata.MetadataMixin): _query_mapping = resource.QueryParameters( "image", "flavor", "name", - "status", "host", "all_tenants", + "status", "host", "sort_key", "sort_dir", "reservation_id", "tags", "project_id", @@ -39,7 +39,8 @@ class Server(resource.Resource, metadata.MetadataMixin): is_deleted="deleted", ipv4_address="ip", ipv6_address="ip6", - changes_since="changes-since") + changes_since="changes-since", + all_projects="all_tenants") #: A list of dictionaries holding links relevant to this server. links = resource.Body('links') diff --git a/openstack/tests/unit/block_storage/v2/test_snapshot.py b/openstack/tests/unit/block_storage/v2/test_snapshot.py index 16b59355c..e502f8b70 100644 --- a/openstack/tests/unit/block_storage/v2/test_snapshot.py +++ b/openstack/tests/unit/block_storage/v2/test_snapshot.py @@ -53,7 +53,7 @@ class TestSnapshot(base.TestCase): self.assertDictEqual({"name": "name", "status": "status", - "all_tenants": "all_tenants", + "all_projects": "all_tenants", "volume_id": "volume_id", "limit": "limit", "marker": "marker"}, diff --git a/openstack/tests/unit/block_storage/v2/test_volume.py b/openstack/tests/unit/block_storage/v2/test_volume.py index 3dc40afd0..739ffc5a2 100644 --- a/openstack/tests/unit/block_storage/v2/test_volume.py +++ b/openstack/tests/unit/block_storage/v2/test_volume.py @@ -76,7 +76,7 @@ class TestVolume(base.TestCase): self.assertDictEqual({"name": "name", "status": "status", - "all_tenants": "all_tenants", + "all_projects": "all_tenants", "project_id": "project_id", "limit": "limit", "marker": "marker"}, diff --git a/openstack/tests/unit/compute/v2/test_server.py b/openstack/tests/unit/compute/v2/test_server.py index 7de99b494..a39e937c0 100644 --- a/openstack/tests/unit/compute/v2/test_server.py +++ b/openstack/tests/unit/compute/v2/test_server.py @@ -84,7 +84,7 @@ class TestServer(base.TestCase): "name": "name", "status": "status", "host": "host", - "all_tenants": "all_tenants", + "all_projects": "all_tenants", "changes_since": "changes-since", "limit": "limit", "marker": "marker",