Add detailed list for instances

Currently, listing instances only allows to get basic information about
entities. To get the details, one need to query instance "show" endpoint
for each instance separately. This is inefficient and exposes API to a
heavier load.

There are use cases in which we want to obtain detailed information
about all instances. In particular, in services integrating with Trove.
For example, Vitrage project requires this information to build vertices
and edges in the resource graph for RCA analysis.

This change extends Trove client by optional parameter allowing user  to
specify whether API should include more instance details in the
response.

Change-Id: Iecea2f711a3e23fd63167beb6cab4cecc63bcabe
Signed-off-by: Bartosz Zurkowski <b.zurkowski@samsung.com>
This commit is contained in:
Bartosz Zurkowski 2018-10-08 14:17:40 +02:00
parent 84b1b0ae62
commit d2220578ff
3 changed files with 22 additions and 2 deletions

View File

@ -0,0 +1,7 @@
---
features:
- |
Added ``detailed`` option to instances client in ``instances.list``
command. Now, detailed instance list can be obtained by setting
``detailed`` parameter to ``True``. Trove will then include more details
in the API response.

View File

@ -124,6 +124,16 @@ class InstancesTest(testtools.TestCase):
page_mock.assert_called_with("/instances", "instances", limit, marker,
include_clustered)
def test_detailed_list(self):
page_mock = mock.Mock()
self.instances._paginated = page_mock
limit = "test-limit"
marker = "test-marker"
include_clustered = {'include_clustered': False}
self.instances.list(limit, marker, detailed=True)
page_mock.assert_called_with("/instances/detail", "instances", limit,
marker, include_clustered)
def test_get(self):
def side_effect_func(path, inst):
return path, inst

View File

@ -179,12 +179,15 @@ class Instances(base.ManagerWithFind):
resp, body = self.api.client.patch(url, body=body)
common.check_for_exceptions(resp, body, url)
def list(self, limit=None, marker=None, include_clustered=False):
def list(self, limit=None, marker=None, include_clustered=False,
detailed=False):
"""Get a list of all instances.
:rtype: list of :class:`Instance`.
"""
return self._paginated("/instances", "instances", limit, marker,
detail = "/detail" if detailed else ""
url = "/instances%s" % detail
return self._paginated(url, "instances", limit, marker,
{"include_clustered": include_clustered})
def get(self, instance):