Allow search on objects

Implements search_objects, which can take a JMESPath expression or
a dict of object attributes to filter objects in.

Story: #2003695
Task: #26339

Change-Id: I7cda29f778acdcdeb8da737d001e957674e9284b
This commit is contained in:
Samuel de Medeiros Queiroz 2018-09-07 06:43:36 -03:00
parent c340e203e4
commit f96b13210c
2 changed files with 23 additions and 0 deletions

View File

@ -7771,6 +7771,23 @@ class OpenStackCloud(_normalize.Normalizer):
container, params=dict(format='json'))
return self._get_and_munchify(None, data)
def search_objects(self, container, name=None, filters=None):
"""Search objects.
:param string name: object name.
:param filters: a dict containing additional filters to use.
OR
A string containing a jmespath expression for further filtering.
Example:: "[?last_name==`Smith`] | [?other.gender]==`Female`]"
:returns: a list of ``munch.Munch`` containing the objects.
:raises: ``OpenStackCloudException``: if something goes wrong during
the OpenStack API call.
"""
objects = self.list_objects(container)
return _utils._filter_list(objects, name, filters)
def delete_object(self, container, name, meta=None):
"""Delete an object from a container.

View File

@ -0,0 +1,6 @@
---
features:
- |
Objects are now searchable both with a JMESPath expression or a dict of
object attributes via the
``openstack.connection.Connection.search_object`` function.