API v2.40, share groups quotas

API v2.39 adds share type quotas, registered
https://blueprints.launchpad.net/manila-ui/+spec/share-types-quotas
to implement this feature in a future release.

Change-Id: I6f264de815f18ffebf80712714b5771620f75509
Signed-off-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
This commit is contained in:
Goutham Pacha Ravi 2020-04-06 17:33:03 -07:00 committed by Dina Saparbaeva
parent 3b8d685dd7
commit ae882d743d
8 changed files with 38 additions and 10 deletions

View File

@ -28,7 +28,7 @@ from manilaclient import client as manila_client
LOG = logging.getLogger(__name__)
MANILA_UI_USER_AGENT_REPR = "manila_ui_plugin_for_horizon"
MANILA_VERSION = "2.38"
MANILA_VERSION = "2.40"
MANILA_SERVICE_TYPE = "sharev2"
# API static values
@ -41,8 +41,11 @@ MANILA_QUOTA_FIELDS = {
"share_snapshots",
"share_snapshot_gigabytes",
"share_networks",
"share_groups",
"share_group_snapshots",
}
# UI field names do not match data field names returned, have
# a map to convert them.
MANILA_QUOTA_FIELDS_DATA_MAP = {
@ -50,7 +53,9 @@ MANILA_QUOTA_FIELDS_DATA_MAP = {
"share_gigabytes": "gigabytes",
"share_snapshots": "snapshots",
"share_snapshot_gigabytes": "snapshot_gigabytes",
"share_networks": "share_networks"
"share_networks": "share_networks",
"share_groups": "share_groups",
"share_group_snapshots": "share_group_snapshots",
}

View File

@ -20,9 +20,11 @@ from openstack_dashboard.dashboards.admin.defaults import tables as default_tbl
MANILA_QUOTA_NAMES = {
'shares': _('Shares'),
'gigabytes': _('Share gigabytes'),
'snapshots': _('Share snapshots'),
'snapshot_gigabytes': _('Share snapshot gigabytes'),
'share_networks': _('Shares Networks'),
'snapshots': _('Share Snapshots'),
'snapshot_gigabytes': _('Share Snapshot gigabytes'),
'share_networks': _('Share Networks'),
"share_groups": _('Share Groups'),
"share_group_snapshots": _('Share Group Snapshots'),
}

View File

@ -31,6 +31,8 @@ class UpdateDefaultShareQuotasAction(workflows.Action):
min_value=-1, label=_("Share snapshot gigabytes"))
share_networks = forms.IntegerField(
min_value=-1, label=_("Share Networks"))
# Share group quotas are missing here because default quota update
# for share groups is not possible yet, see LP #1871252
def __init__(self, request, context, *args, **kwargs):
super(UpdateDefaultShareQuotasAction, self).__init__(
@ -44,8 +46,16 @@ class UpdateDefaultShareQuotasAction(workflows.Action):
def handle(self, request, data):
try:
if base.is_service_enabled(request, 'share'):
manila_data = dict([(key, data[key]) for key in
api_manila.MANILA_QUOTA_FIELDS])
manila_data = {}
# Share group quotas are removed here because default
# quota update for share groups is not possible yet, see
# LP #1871252
allowed_updates = (
api_manila.MANILA_QUOTA_FIELDS -
{'share_groups', 'share_group_snapshots'}
)
for key in allowed_updates:
manila_data[key] = data[key]
api_manila.default_quota_update(request, **manila_data)
return True
except Exception:
@ -70,7 +80,9 @@ class UpdateDefaultShareQuotasStep(workflows.Step):
quota_defaults = api_manila.default_quota_get(
request, request.user.tenant_id)
for field in api_manila.MANILA_QUOTA_FIELDS:
context[field] = quota_defaults.get(field).limit
# Resolve mismatch UI field names and data field names.
data_field = api_manila.MANILA_QUOTA_FIELDS_DATA_MAP[field]
context[field] = quota_defaults.get(data_field).limit
except Exception:
exceptions.handle(request,
_('Unable to retrieve default share quotas.'))

View File

@ -37,6 +37,10 @@ class ShareQuotaAction(project_workflows.CommonQuotaAction):
min_value=-1, label=_("Share snapshot gigabytes"))
share_networks = forms.IntegerField(
min_value=-1, label=_("Share Networks"))
share_groups = forms.IntegerField(
min_value=-1, label=_("Share Groups"))
share_group_snapshots = forms.IntegerField(
min_value=-1, label=_("Share Group Snapshots"))
_quota_fields = api_manila.MANILA_QUOTA_FIELDS

View File

@ -119,6 +119,7 @@ class CreateShareGroupSnapshotView(forms.ModalFormView):
context['share_group_id'] = sg_id
# TODO(vponomaryov): add support of quotas when it is implemented
# for share group snapshots on server side.
# https://bugs.launchpad.net/manila/+bug/1868644
return context
def get_initial(self):

View File

@ -72,6 +72,7 @@ class CreateShareGroup(tables.LinkAction):
def allowed(self, request, share=None):
# TODO(vponomaryov): implement quota restriction when quota support
# is implemented for share groups.
# https://bugs.launchpad.net/manila/+bug/1868644
return True

View File

@ -110,6 +110,7 @@ class ShareGroupCreateView(forms.ModalFormView):
try:
# TODO(vponomaryov): add quota logic here when quotas are
# implemented for share groups.
# https://bugs.launchpad.net/manila/+bug/1868644
pass
except Exception:
exceptions.handle(self.request)

View File

@ -632,13 +632,15 @@ class ManilaApiTests(base.APITestCase):
@ddt.data({
'shares': 24, 'gigabytes': 333, 'snapshots': 14,
'snapshot_gigabytes': 444, 'share_networks': 14
'snapshot_gigabytes': 444, 'share_networks': 14,
"share_groups": 30, "share_group_snapshots": 5,
})
@ddt.unpack
def test_ui_data_map(self, **kwargs):
expected_result = {
'shares': 24, 'share_gigabytes': 333, 'share_snapshots': 14,
'share_snapshot_gigabytes': 444, 'share_networks': 14
'share_snapshot_gigabytes': 444, 'share_networks': 14,
"share_groups": 30, "share_group_snapshots": 5,
}
converted_result_for_ui = {}