diff --git a/doc/source/user/resources/shared_file_system/index.rst b/doc/source/user/resources/shared_file_system/index.rst index 1b45f4f17..d34b4a0dd 100644 --- a/doc/source/user/resources/shared_file_system/index.rst +++ b/doc/source/user/resources/shared_file_system/index.rst @@ -18,3 +18,4 @@ Shared File System service resources v2/share_access_rule v2/share_group_snapshot v2/resource_locks + v2/quota_class_set diff --git a/doc/source/user/resources/shared_file_system/v2/quota_class_set.rst b/doc/source/user/resources/shared_file_system/v2/quota_class_set.rst new file mode 100644 index 000000000..4ad5311f8 --- /dev/null +++ b/doc/source/user/resources/shared_file_system/v2/quota_class_set.rst @@ -0,0 +1,13 @@ +openstack.shared_file_system.v2.quota_class_set +=============================================== + +.. automodule:: openstack.shared_file_system.v2.quota_class_set + +The QuotaClassSet Class +----------------------- + +The ``QuotaClassSet`` class inherits from +:class:`~openstack.resource.Resource` and can be used to query quota class + +.. autoclass:: openstack.shared_file_system.v2.quota_class_set.QuotaClassSet + :members: diff --git a/openstack/shared_file_system/v2/_proxy.py b/openstack/shared_file_system/v2/_proxy.py index 56c5dfb74..0293a405f 100644 --- a/openstack/shared_file_system/v2/_proxy.py +++ b/openstack/shared_file_system/v2/_proxy.py @@ -16,6 +16,7 @@ from openstack.shared_file_system.v2 import ( availability_zone as _availability_zone, ) from openstack.shared_file_system.v2 import limit as _limit +from openstack.shared_file_system.v2 import quota_class_set as _quota_class_set from openstack.shared_file_system.v2 import resource_locks as _resource_locks from openstack.shared_file_system.v2 import share as _share from openstack.shared_file_system.v2 import share_group as _share_group @@ -58,6 +59,7 @@ class Proxy(proxy.Proxy): "share_group": _share_group.ShareGroup, "share_group_snapshot": _share_group_snapshot.ShareGroupSnapshot, "resource_locks": _resource_locks.ResourceLock, + "quota_class_set": _quota_class_set.QuotaClassSet, } def availability_zones(self): @@ -1198,3 +1200,26 @@ class Proxy(proxy.Proxy): } attrs.pop('resource_type') return self._create(_resource_locks.ResourceLock, **attrs) + + def get_quota_class_set(self, quota_class_name): + """Get quota class set. + + :param quota_class_name: The name of the quota class + :returns: A :class:`~openstack.shared_file_system.v2 + .quota_class_set.QuotaClassSet` + """ + return self._get(_quota_class_set.QuotaClassSet, quota_class_name) + + def update_quota_class_set(self, quota_class_name, **attrs): + """Update quota class set. + + :param quota_class_name: The name of the quota class + :param attrs: The attributes to update on the quota class set + :returns: the updated quota class set + :rtype: :class:`~openstack.shared_file_system.v2 + .quota_class_set.QuotaClassSet` + """ + + return self._update( + _quota_class_set.QuotaClassSet, quota_class_name, **attrs + ) diff --git a/openstack/shared_file_system/v2/quota_class_set.py b/openstack/shared_file_system/v2/quota_class_set.py new file mode 100644 index 000000000..cf2090de5 --- /dev/null +++ b/openstack/shared_file_system/v2/quota_class_set.py @@ -0,0 +1,57 @@ +# 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 QuotaClassSet(resource.Resource): + base_path = '/quota-class-sets' + resource_key = 'quota_class_set' + + allow_create = False + allow_fetch = True + allow_commit = True + allow_delete = False + allow_list = False + allow_head = False + + _query_mapping = resource.QueryParameters("quota_class_name", "project_id") + #: Properties + #: A quota_class_set id. + id = resource.Body("id", type=str) + #: The maximum number of share groups. + share_groups = resource.Body("share_groups", type=int) + #: The maximum number of share group snapshots. + share_group_snapshots = resource.Body("share_group_snapshots", type=int) + #: The total maximum number of shares that are allowed in a project. + snapshots = resource.Body("snapshots", type=int) + #: The maximum number of snapshot gigabytes that are allowed in a project. + snapshot_gigabytes = resource.Body("snapshot_gigabytes", type=int) + #: The total maximum number of snapshot gigabytes that are allowed in a project. + shares = resource.Body("shares", type=int) + #: The maximum number of share-networks that are allowed in a project. + share_networks = resource.Body("share_networks", type=int) + #: The maximum number of share replicas that is allowed. + share_replicas = resource.Body("share_replicas", type=int) + #: The total maximum number of share gigabytes that are allowed in a project. + #: You cannot request a share that exceeds the allowed gigabytes quota. + gigabytes = resource.Body("gigabytes", type=int) + #: The maximum number of replica gigabytes that are allowed in a project. + #: You cannot create a share, share replica, manage a share or extend a share + #: if it is going to exceed the allowed replica gigabytes quota. + replica_gigabytes = resource.Body("replica_gigabytes", type=int) + #: The number of gigabytes per share allowed in a project. + per_share_gigabytes = resource.Body("per_share_gigabytes", type=int) + #: The total maximum number of share backups that are allowed in a project. + backups = resource.Body("backups", type=int) + #: The total maximum number of backup gigabytes that are allowed in a project. + backup_gigabytes = resource.Body("backup_gigabytes", type=int) diff --git a/openstack/tests/functional/shared_file_system/test_quota_class_set.py b/openstack/tests/functional/shared_file_system/test_quota_class_set.py new file mode 100644 index 000000000..cec5554ee --- /dev/null +++ b/openstack/tests/functional/shared_file_system/test_quota_class_set.py @@ -0,0 +1,43 @@ +# 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.shared_file_system import base + + +class QuotaClassSetTest(base.BaseSharedFileSystemTest): + def test_quota_class_set(self): + project_id = self.operator_cloud.current_project_id + + initial_quota_class_set = ( + self.operator_cloud.share.get_quota_class_set(project_id) + ) + self.assertIn('shares', initial_quota_class_set) + + initial_backups_value = initial_quota_class_set['backups'] + + updated_quota_class_set = ( + self.operator_cloud.share.update_quota_class_set( + project_id, + **{ + "backups": initial_backups_value + 1, + } + ) + ) + self.assertEqual( + updated_quota_class_set['backups'], initial_backups_value + 1 + ) + + reverted = self.operator_cloud.share.update_quota_class_set( + project_id, **{"backups": initial_backups_value} + ) + + self.assertEqual(initial_quota_class_set, reverted) diff --git a/openstack/tests/unit/shared_file_system/v2/test_quota_class_set.py b/openstack/tests/unit/shared_file_system/v2/test_quota_class_set.py new file mode 100644 index 000000000..daf2bb12f --- /dev/null +++ b/openstack/tests/unit/shared_file_system/v2/test_quota_class_set.py @@ -0,0 +1,99 @@ +# 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.shared_file_system.v2 import quota_class_set +from openstack.tests.unit import base + +EXAMPLE = { + "share_groups": 50, + "gigabytes": 1000, + "share_group_snapshots": 50, + "snapshots": 50, + "snapshot_gigabytes": 1000, + "shares": 50, + "id": "default", + "share_networks": 10, + "share_replicas": 100, + "replica_gigabytes": 1000, + "per_share_gigabytes": -1, + "backups": 50, + "backup_gigabytes": 1000, +} + + +class TestQuotaClassSet(base.TestCase): + def test_basic(self): + _quota_class_set = quota_class_set.QuotaClassSet() + + self.assertEqual('/quota-class-sets', _quota_class_set.base_path) + self.assertTrue(_quota_class_set.allow_fetch) + self.assertTrue(_quota_class_set.allow_commit) + self.assertFalse(_quota_class_set.allow_create) + self.assertFalse(_quota_class_set.allow_delete) + self.assertFalse(_quota_class_set.allow_list) + self.assertFalse(_quota_class_set.allow_head) + + def test_get_quota_class_set(self): + _quota_class_set = quota_class_set.QuotaClassSet(**EXAMPLE) + self.assertEqual( + EXAMPLE['share_groups'], _quota_class_set.share_groups + ) + self.assertEqual(EXAMPLE['gigabytes'], _quota_class_set.gigabytes) + self.assertEqual( + EXAMPLE['share_group_snapshots'], + _quota_class_set.share_group_snapshots, + ) + self.assertEqual(EXAMPLE['snapshots'], _quota_class_set.snapshots) + self.assertEqual( + EXAMPLE['snapshot_gigabytes'], _quota_class_set.snapshot_gigabytes + ) + self.assertEqual(EXAMPLE['shares'], _quota_class_set.shares) + self.assertEqual(EXAMPLE['id'], _quota_class_set.id) + self.assertEqual( + EXAMPLE['share_networks'], _quota_class_set.share_networks + ) + self.assertEqual( + EXAMPLE['share_replicas'], _quota_class_set.share_replicas + ) + self.assertEqual( + EXAMPLE['replica_gigabytes'], _quota_class_set.replica_gigabytes + ) + self.assertEqual( + EXAMPLE['per_share_gigabytes'], + _quota_class_set.per_share_gigabytes, + ) + self.assertEqual(EXAMPLE['backups'], _quota_class_set.backups) + self.assertEqual( + EXAMPLE['backup_gigabytes'], _quota_class_set.backup_gigabytes + ) + + def test_update_quota_class_set(self): + _quota_class_set = quota_class_set.QuotaClassSet(**EXAMPLE) + updated_attributes = { + "share_groups": 100, + "gigabytes": 2000, + "share_group_snapshots": 100, + } + _quota_class_set._update(**updated_attributes) + + self.assertEqual( + updated_attributes['share_groups'], _quota_class_set.share_groups + ) + self.assertEqual( + updated_attributes['gigabytes'], _quota_class_set.gigabytes + ) + self.assertEqual( + updated_attributes['share_group_snapshots'], + _quota_class_set.share_group_snapshots, + ) + self.assertEqual(EXAMPLE['snapshots'], _quota_class_set.snapshots) diff --git a/releasenotes/notes/add-quota-class-set-to-shared-file-systems-43da33e6a3ed65e3.yaml b/releasenotes/notes/add-quota-class-set-to-shared-file-systems-43da33e6a3ed65e3.yaml new file mode 100644 index 000000000..e102feb3d --- /dev/null +++ b/releasenotes/notes/add-quota-class-set-to-shared-file-systems-43da33e6a3ed65e3.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Added get and update to Quota Class Set to file system as a service.