From f96b13210cbce12131e0e2f8aa3433db38628106 Mon Sep 17 00:00:00 2001 From: Samuel de Medeiros Queiroz Date: Fri, 7 Sep 2018 06:43:36 -0300 Subject: [PATCH] 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 --- openstack/cloud/openstackcloud.py | 17 +++++++++++++++++ .../notes/object-search-a5f5ec4b2df3e045.yaml | 6 ++++++ 2 files changed, 23 insertions(+) create mode 100644 releasenotes/notes/object-search-a5f5ec4b2df3e045.yaml diff --git a/openstack/cloud/openstackcloud.py b/openstack/cloud/openstackcloud.py index 00612881a..023c42c6f 100755 --- a/openstack/cloud/openstackcloud.py +++ b/openstack/cloud/openstackcloud.py @@ -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. diff --git a/releasenotes/notes/object-search-a5f5ec4b2df3e045.yaml b/releasenotes/notes/object-search-a5f5ec4b2df3e045.yaml new file mode 100644 index 000000000..1ac05e9bf --- /dev/null +++ b/releasenotes/notes/object-search-a5f5ec4b2df3e045.yaml @@ -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.