From 200cd5c4f8f06d69ae886880fdcf9f2000463c20 Mon Sep 17 00:00:00 2001 From: whoami-rajat Date: Thu, 25 May 2023 18:57:04 +0530 Subject: [PATCH] Add block storage summary support Added support to provide block storage summary. Change-Id: I1e665a45c8c2c3658099aa6aa070facb3a6c9e60 --- doc/source/user/proxies/block_storage_v3.rst | 8 +++ .../user/resources/block_storage/index.rst | 1 + .../v3/block_storage_summary.rst | 14 ++++ openstack/block_storage/v3/_proxy.py | 22 ++++++ .../block_storage/v3/block_storage_summary.py | 30 ++++++++ .../v3/test_block_storage_summary.py | 21 ++++++ .../v3/test_block_storage_summary.py | 69 +++++++++++++++++++ ...rage-summary-support-dd00d424c4e6a3b1.yaml | 5 ++ 8 files changed, 170 insertions(+) create mode 100644 doc/source/user/resources/block_storage/v3/block_storage_summary.rst create mode 100644 openstack/block_storage/v3/block_storage_summary.py create mode 100644 openstack/tests/functional/block_storage/v3/test_block_storage_summary.py create mode 100644 openstack/tests/unit/block_storage/v3/test_block_storage_summary.py create mode 100644 releasenotes/notes/add-block-storage-summary-support-dd00d424c4e6a3b1.yaml diff --git a/doc/source/user/proxies/block_storage_v3.rst b/doc/source/user/proxies/block_storage_v3.rst index d91c5ea5e..df619305e 100644 --- a/doc/source/user/proxies/block_storage_v3.rst +++ b/doc/source/user/proxies/block_storage_v3.rst @@ -133,3 +133,11 @@ Helpers .. autoclass:: openstack.block_storage.v3._proxy.Proxy :noindex: :members: wait_for_status, wait_for_delete + +BlockStorageSummary Operations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.block_storage.v3._proxy.Proxy + :noindex: + :members: summary + diff --git a/doc/source/user/resources/block_storage/index.rst b/doc/source/user/resources/block_storage/index.rst index 7f9e16d21..564597d89 100644 --- a/doc/source/user/resources/block_storage/index.rst +++ b/doc/source/user/resources/block_storage/index.rst @@ -15,3 +15,4 @@ Block Storage Resources v3/snapshot v3/type v3/volume + v3/block_storage_summary diff --git a/doc/source/user/resources/block_storage/v3/block_storage_summary.rst b/doc/source/user/resources/block_storage/v3/block_storage_summary.rst new file mode 100644 index 000000000..2215db8f0 --- /dev/null +++ b/doc/source/user/resources/block_storage/v3/block_storage_summary.rst @@ -0,0 +1,14 @@ +openstack.block_storage.v3.block_storage_summary +================================================ + +.. automodule:: openstack.block_storage.v3.block_storage_summary + +The Block Storage Summary Class +------------------------------- + +The ``Block Storage Summary`` class inherits from +:class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.block_storage.v3.block_storage_summary.BlockStorageSummary + :members: + diff --git a/openstack/block_storage/v3/_proxy.py b/openstack/block_storage/v3/_proxy.py index 642e74049..34f03aea9 100644 --- a/openstack/block_storage/v3/_proxy.py +++ b/openstack/block_storage/v3/_proxy.py @@ -13,6 +13,7 @@ from openstack.block_storage import _base_proxy from openstack.block_storage.v3 import availability_zone from openstack.block_storage.v3 import backup as _backup +from openstack.block_storage.v3 import block_storage_summary as _summary from openstack.block_storage.v3 import capabilities as _capabilities from openstack.block_storage.v3 import extension as _extension from openstack.block_storage.v3 import group as _group @@ -44,6 +45,7 @@ class Proxy(_base_proxy.BaseBlockStorageProxy): "resource_filter": _resource_filter.ResourceFilter, "snapshot": _snapshot.Snapshot, "stats_pools": _stats.Pools, + "summary": _summary.BlockStorageSummary, "type": _type.Type, "volume": _volume.Volume, } @@ -662,6 +664,26 @@ class Proxy(_base_proxy.BaseBlockStorageProxy): else: volume.delete_metadata(self) + def summary(self, all_projects): + """Get Volumes Summary + + This method returns the volumes summary in the deployment. + + :param all_projects: Whether to return the summary of all projects + or not. + + :returns: One :class: + `~openstack.block_storage.v3.block_storage_summary.Summary` + instance. + """ + res = self._get(_summary.BlockStorageSummary, requires_id=False) + return res.fetch( + self, + requires_id=False, + resource_response_key='volume-summary', + all_projects=all_projects, + ) + # ====== VOLUME ACTIONS ====== def extend_volume(self, volume, size): """Extend a volume diff --git a/openstack/block_storage/v3/block_storage_summary.py b/openstack/block_storage/v3/block_storage_summary.py new file mode 100644 index 000000000..410424fe4 --- /dev/null +++ b/openstack/block_storage/v3/block_storage_summary.py @@ -0,0 +1,30 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstack import resource + + +class BlockStorageSummary(resource.Resource): + base_path = "/volumes/summary" + + # capabilities + allow_fetch = True + + # Properties + #: Total size of all the volumes + total_size = resource.Body("total_size") + #: Total count of all the volumes + total_count = resource.Body("total_count") + #: Metadata of all the volumes + metadata = resource.Body("metadata") + + _max_microversion = "3.36" diff --git a/openstack/tests/functional/block_storage/v3/test_block_storage_summary.py b/openstack/tests/functional/block_storage/v3/test_block_storage_summary.py new file mode 100644 index 000000000..1efff92a3 --- /dev/null +++ b/openstack/tests/functional/block_storage/v3/test_block_storage_summary.py @@ -0,0 +1,21 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstack.tests.functional.block_storage.v3 import base + + +class TestBlockStorageSummary(base.BaseBlockStorageTest): + def test_get(self): + sot = self.conn.block_storage.summary(all_projects=True) + self.assertIn('total_size', sot) + self.assertIn('total_count', sot) + self.assertIn('metadata', sot) diff --git a/openstack/tests/unit/block_storage/v3/test_block_storage_summary.py b/openstack/tests/unit/block_storage/v3/test_block_storage_summary.py new file mode 100644 index 000000000..32b00689f --- /dev/null +++ b/openstack/tests/unit/block_storage/v3/test_block_storage_summary.py @@ -0,0 +1,69 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import copy + +from openstack.block_storage.v3 import block_storage_summary as summary +from openstack.tests.unit import base + + +BLOCK_STORAGE_SUMMARY_312 = { + "total_size": "4", + "total_count": "2", + "metadata": {"key1": "value1"}, +} + + +BLOCK_STORAGE_SUMMARY_326 = copy.deepcopy(BLOCK_STORAGE_SUMMARY_312) +BLOCK_STORAGE_SUMMARY_326['metadata'] = {"key1": "value1"} + + +class TestBlockStorageSummary(base.TestCase): + def test_basic(self): + summary_resource = summary.BlockStorageSummary() + self.assertEqual(None, summary_resource.resource_key) + self.assertEqual(None, summary_resource.resources_key) + self.assertEqual("/volumes/summary", summary_resource.base_path) + self.assertTrue(summary_resource.allow_fetch) + self.assertFalse(summary_resource.allow_create) + self.assertFalse(summary_resource.allow_commit) + self.assertFalse(summary_resource.allow_delete) + self.assertFalse(summary_resource.allow_list) + + def test_get_summary_312(self): + summary_resource = summary.BlockStorageSummary( + **BLOCK_STORAGE_SUMMARY_312 + ) + self.assertEqual( + BLOCK_STORAGE_SUMMARY_312["total_size"], + summary_resource.total_size, + ) + self.assertEqual( + BLOCK_STORAGE_SUMMARY_312["total_count"], + summary_resource.total_count, + ) + + def test_get_summary_326(self): + summary_resource = summary.BlockStorageSummary( + **BLOCK_STORAGE_SUMMARY_326 + ) + self.assertEqual( + BLOCK_STORAGE_SUMMARY_326["total_size"], + summary_resource.total_size, + ) + self.assertEqual( + BLOCK_STORAGE_SUMMARY_326["total_count"], + summary_resource.total_count, + ) + self.assertEqual( + BLOCK_STORAGE_SUMMARY_326["metadata"], summary_resource.metadata + ) diff --git a/releasenotes/notes/add-block-storage-summary-support-dd00d424c4e6a3b1.yaml b/releasenotes/notes/add-block-storage-summary-support-dd00d424c4e6a3b1.yaml new file mode 100644 index 000000000..4620d2e3b --- /dev/null +++ b/releasenotes/notes/add-block-storage-summary-support-dd00d424c4e6a3b1.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Added support for block storage summary. +