Deprecate ServerDetails class

We have recently introduced possibility to alter base_path for 
operations on the resource and shifted some of the services to use it. 
For compute.servers(details) we still use an inherited class with 
modified base_path. Remove this class and instead alter the base_path 
for the list servers operation. This also has an advantage, that we get 
a list of servers with details and are immediately able to execute 
operations on the instance without any conversion or re-fetch by id.

Change-Id: I4c4649ee1390676f3ccc6bf19e4b11b1964b5aaa
This commit is contained in:
Artem Goncharov 2019-03-09 16:50:55 +01:00
parent 1066c9385f
commit ddd8d84cef
5 changed files with 13 additions and 28 deletions

View File

@ -484,10 +484,8 @@ class Proxy(proxy.Proxy):
"""Retrieve a generator of servers
:param bool details: When set to ``False``
:class:`~openstack.compute.v2.server.Server` instances
will be returned. The default, ``True``, will cause
:class:`~openstack.compute.v2.server.ServerDetail`
instances to be returned.
instances with only basic data will be returned. The default,
``True``, will cause instances with full data to be returned.
:param kwargs query: Optional query parameters to be sent to limit
the servers being returned. Available parameters include:
@ -521,8 +519,8 @@ class Proxy(proxy.Proxy):
"""
if all_projects:
query['all_projects'] = True
srv = _server.ServerDetail if details else _server.Server
return self._list(srv, **query)
base_path = '/servers/detail' if details else None
return self._list(_server.Server, base_path=base_path, **query)
def update_server(self, server, **attrs):
"""Update a server

View File

@ -440,12 +440,4 @@ class Server(resource.Resource, metadata.MetadataMixin, resource.TagMixin):
session, {'os-migrateLive': body}, microversion=microversion)
class ServerDetail(Server):
base_path = '/servers/detail'
# capabilities
allow_create = False
allow_fetch = False
allow_commit = False
allow_delete = False
allow_list = True
ServerDetail = Server

View File

@ -214,10 +214,11 @@ class TestComputeProxy(test_proxy_base.TestProxyBase):
self.verify_get(self.proxy.get_server, server.Server)
def test_servers_detailed(self):
self.verify_list(self.proxy.servers, server.ServerDetail,
self.verify_list(self.proxy.servers, server.Server,
method_kwargs={"details": True,
"changes_since": 1, "image": 2},
expected_kwargs={"changes_since": 1, "image": 2})
expected_kwargs={"changes_since": 1, "image": 2,
"base_path": "/servers/detail"})
def test_servers_not_detailed(self):
self.verify_list(self.proxy.servers, server.Server,

View File

@ -149,17 +149,6 @@ class TestServer(base.TestCase):
sot.scheduler_hints)
self.assertEqual(EXAMPLE['OS-EXT-SRV-ATTR:user_data'], sot.user_data)
def test_detail(self):
sot = server.ServerDetail()
self.assertEqual('server', sot.resource_key)
self.assertEqual('servers', sot.resources_key)
self.assertEqual('/servers/detail', sot.base_path)
self.assertFalse(sot.allow_create)
self.assertFalse(sot.allow_fetch)
self.assertFalse(sot.allow_commit)
self.assertFalse(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test__prepare_server(self):
zone = 1
data = 2

View File

@ -0,0 +1,5 @@
---
deprecations:
- |
Listing servers with details `servers(details=True)` will return
instances of the Server class instead of ServerDetails.