diff --git a/openstack/cloud/openstackcloud.py b/openstack/cloud/openstackcloud.py index f6a1534ab..ac22ac27f 100755 --- a/openstack/cloud/openstackcloud.py +++ b/openstack/cloud/openstackcloud.py @@ -7267,6 +7267,23 @@ class OpenStackCloud(_normalize.Normalizer): data = self._object_store_client.get('/', params=dict(format='json')) return self._get_and_munchify(None, data) + def search_containers(self, name=None, filters=None): + """Search containers. + + :param string name: container 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 containers. + + :raises: ``OpenStackCloudException``: if something goes wrong during + the OpenStack API call. + """ + containers = self.list_containers() + return _utils._filter_list(containers, name, filters) + def get_container(self, name, skip_cache=False): """Get metadata about a container. diff --git a/releasenotes/notes/container-search-b0f4253ce2deeda5.yaml b/releasenotes/notes/container-search-b0f4253ce2deeda5.yaml new file mode 100644 index 000000000..3587a7b5c --- /dev/null +++ b/releasenotes/notes/container-search-b0f4253ce2deeda5.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Containers are now searchable both with a JMESPath expression or a dict of + container attributes via the + ``openstack.connection.Connection.search_containers`` function.