Skip to content

Commit

Permalink
Support for Unity quota management
Browse files Browse the repository at this point in the history
  • Loading branch information
rajendraindukuri committed Apr 22, 2021
1 parent 7254045 commit 86dd8a7
Show file tree
Hide file tree
Showing 34 changed files with 1,764 additions and 3 deletions.
5 changes: 5 additions & 0 deletions storops/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,3 +1505,8 @@ class UnityCompressionRequireLunIsThinError(UnityException):
@rest_exception
class UnityCompressionRequireAllFlashPoolError(UnityException):
error_code = 108009014


@rest_exception
class UnityQuotaConfigModifyException(UnityException):
error_code = 0x900022a
5 changes: 5 additions & 0 deletions storops/unity/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,3 +1222,8 @@ class FSRenamePolicyEnum(UnityEnum):
class FSLockingPolicyEnum(UnityEnum):
ADVISORY = (0, 'Advisory')
MANDATORY = (1, 'Mandatory')


class QuotaPolicyEnum(UnityEnum):
FILE_SIZE = (0, 'File_Size')
BLOCKS = (1, 'Blocks')
55 changes: 55 additions & 0 deletions storops/unity/parser_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2336,3 +2336,58 @@ UnityAlert:
- label: resolutionId
- label: resolution
- label: isAcknowledged

UnityUserQuota:
data_src: rest
name: userQuota
properties:
- label: id
- label: filesystem
converter: UnityFileSystem
- label: treeQuota
converter: UnityTreeQuota
- label: gpLeft
- label: hardLimit
- label: hardRatio
- label: sizeUsed
- label: softLimit
- label: softRatio
- label: state
- label: uid
- label: unixName
- label: windowsNames
- label: windowsSIDs

UnityTreeQuota:
data_src: rest
name: treeQuota
properties:
- label: id
- label: path
- label: description
- label: filesystem
converter: UnityFileSystem
- label: gpLeft
- label: hardLimit
- label: sizeUsed
- label: softLimit
- label: state

UnityQuotaConfig:
data_src: rest
name: quotaConfig
properties:
- label: id
- label: filesystem
converter: UnityFileSystem
- label: treeQuota
converter: UnityTreeQuota
- label: quotaPolicy
converter: QuotaPolicyEnum
- label: isUserQuotaEnabled
- label: isAccessDenyEnabled
- label: gracePeriod
- label: defaultHardLimit
- label: defaultSoftLimit
- label: lastUpdateTimeOfTreeQuotas
- label: lastUpdateTimeOfUserQuotas
100 changes: 100 additions & 0 deletions storops/unity/resource/quota_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# coding=utf-8
# Copyright (c) 2015 EMC Corporation.
# All Rights Reserved.
#
# 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 __future__ import unicode_literals

import logging

from storops.exception import UnityQuotaConfigModifyException, \
UnityResourceNotFoundError
from storops.unity.resource import UnityResource, UnityResourceList

__author__ = 'Rajendra Indukuri'

log = logging.getLogger(__name__)


class UnityQuotaConfig(UnityResource):
"""
Support for Unity quotaConfig component
Operations supported:
modify: Modify quota_config using the quota_config_id
"""

@classmethod
def modify(cls, cli, quota_config_id,
quota_policy=None,
is_user_quota_enabled=None,
delete_user_quotas_with_disable=None,
is_access_deny_enabled=None,
grace_period=None,
default_hard_limit=None,
default_soft_limit=None):
"""
Modifies tree_quota params for the specified tree_quota_id
:param quota_config_id: This is required which specifies
quota_config to be modified
:param quota_policy: This is an enum which specifies how
disk usage shold be measured in blocks/file_size
:param is_user_quota_enabled: To see if user_quota is
enabled. Cannot be passed with quota_policy
:param delete_user_quotas_with_disable: whether to delete
user_quotas when disabling user quotas
:param is_access_deny_enabled: when true access will be
denied when limit is exceeded
:param grace_period: Grace period for soft limit
:param default_hard_limit: Default hard limit of user quotas
and tree quotas
:param default_soft_limit: Default soft limit of user quotas
and tree quotas.
:return: None.
"""
quota_config = UnityQuotaConfig.get(_id=quota_config_id, cli=cli)
if not quota_config.existed:
raise UnityResourceNotFoundError(
'cannot find quota_config {}.'.format(quota_config_id))

# quota_policy and is_user_quota_enabled cannot be used together
if quota_policy is not None and is_user_quota_enabled is not None:
raise UnityQuotaConfigModifyException()

req_body = cli.make_body(
allow_empty=False,
quotaPolicy=quota_policy,
isUserQuotaEnabled=is_user_quota_enabled,
deleteUserQuotasWithDisable=delete_user_quotas_with_disable,
isAccessDenyEnabled=is_access_deny_enabled,
gracePeriod=grace_period,
defaultHardLimit=default_hard_limit,
defaultSoftLimit=default_soft_limit
)
resp = cli.action(cls().resource_class, quota_config_id,
'modify', **req_body)
resp.raise_if_err()
return resp


class UnityQuotaConfigList(UnityResourceList):
"""
List representation of quota_config
"""

def __init__(self, cli=None, **filters):
super(UnityQuotaConfigList, self).__init__(cli, **filters)

@classmethod
def get_resource_class(cls):
return UnityQuotaConfig
72 changes: 72 additions & 0 deletions storops/unity/resource/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
from storops.unity.resource.metric import UnityMetricRealTimeQuery
from storops.unity.resource.move_session import UnityMoveSessionList
from storops.unity.resource.nas_server import UnityNasServerList
from storops.unity.resource.user_quota import UnityUserQuota, \
UnityUserQuotaList
from storops.unity.resource.tree_quota import UnityTreeQuota, \
UnityTreeQuotaList
from storops.unity.resource.quota_config import UnityQuotaConfig, \
UnityQuotaConfigList
from storops.unity.resource.nfs_server import UnityNfsServerList
from storops.unity.resource.nfs_share import UnityNfsShareList
from storops.unity.resource.pool import UnityPoolList, UnityPool
Expand Down Expand Up @@ -179,6 +185,15 @@ def get_nas_server(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityNasServerList, _id=_id, name=name,
**filters)

def get_user_quota(self, _id=None, **filters):
return self._get_unity_rsc(UnityUserQuotaList, _id=_id, **filters)

def get_tree_quota(self, _id=None, **filters):
return self._get_unity_rsc(UnityTreeQuotaList, _id=_id, **filters)

def get_quota_config(self, _id=None, **filters):
return self._get_unity_rsc(UnityQuotaConfigList, _id=_id, **filters)

def get_cifs_server(self, _id=None, name=None, **filters):
return self._get_unity_rsc(UnityCifsServerList, _id=_id, name=name,
**filters)
Expand All @@ -199,6 +214,63 @@ def create_nas_server(self, name, sp=None, pool=None, is_repl_dst=None,
is_repl_dst=is_repl_dst,
multi_proto=multi_proto, tenant=tenant)

def create_user_quota(self, filesystem_id=None, tree_quota_id=None,
hard_limit=None, soft_limit=None, uid=None,
unix_name=None, win_name=None):
return UnityUserQuota.create(cli=self._cli,
filesystem_id=filesystem_id,
tree_quota_id=tree_quota_id,
hard_limit=hard_limit,
soft_limit=soft_limit,
uid=uid,
unix_name=unix_name,
win_name=win_name)

def create_tree_quota(self, filesystem_id=None, path=None,
description=None, hard_limit=None, soft_limit=None):
return UnityTreeQuota.create(cli=self._cli,
filesystem_id=filesystem_id,
path=path,
description=description,
hard_limit=hard_limit,
soft_limit=soft_limit)

def modify_user_quota(self, user_quota_id,
hard_limit=None, soft_limit=None):
return UnityUserQuota.modify(self._cli,
user_quota_id=user_quota_id,
hard_limit=hard_limit,
soft_limit=soft_limit)

def modify_tree_quota(self, tree_quota_id, description=None,
hard_limit=None, soft_limit=None):
return UnityTreeQuota.modify(self._cli,
tree_quota_id=tree_quota_id,
description=description,
hard_limit=hard_limit,
soft_limit=soft_limit)

def modify_quota_config(self, quota_config_id, quota_policy=None,
is_user_quota_enabled=None,
delete_user_quotas_with_disable=None,
is_access_deny_enabled=None,
grace_period=None,
default_hard_limit=None,
default_soft_limit=None):
return UnityQuotaConfig.modify(
self._cli,
quota_config_id,
quota_policy=quota_policy,
is_user_quota_enabled=is_user_quota_enabled,
delete_user_quotas_with_disable=delete_user_quotas_with_disable,
is_access_deny_enabled=is_access_deny_enabled,
grace_period=grace_period,
default_hard_limit=default_hard_limit,
default_soft_limit=default_soft_limit)

def delete_tree_quota(self, tree_quota_id):
return UnityTreeQuota.delete(self._cli, tree_quota_id)

def _auto_balance_sp(self):
sp_list = self.get_sp()
if len(sp_list) < 2:
Expand Down
Loading

0 comments on commit 86dd8a7

Please sign in to comment.