def create(cls, cli, filesystem_id=None, tree_quota_id=None, hard_limit=None, soft_limit=None, uid=None, unix_name=None, win_name=None): """ Creates user_quota on the speficied filesystem or tree quota :param filesystem_id: This is an optional parameter which if provided will create user_quota on the filesystem specified. :param tree_quota_id: This is an optional parameter which if provided will create user_quota on the tree_quota specified. :param hard_limit: sets hard_limit on the filesystem for the user specified :param soft_limit: sets soft_limit on the filesystem for the user specified :param uid: This is an optional parameter to specify user. Either of uid/unix_name/win_name should be provided :param unix_name: This is an optional parameter to specify user. Either of uid/unix_name/win_name should be provided :param win_name:This is an optional parameter to specify user. Either of uid/unix_name/win_name should be provided :return: created user quota. """ tree_quota = None filesystem = None if filesystem_id is not None: fs_clz = storops.unity.resource.filesystem.UnityFileSystem filesystem = fs_clz.get(_id=filesystem_id, cli=cli) if not filesystem.existed: raise UnityResourceNotFoundError( 'cannot find filesystem {}.'.format(filesystem_id)) if tree_quota_id is not None: tquota_clz = storops.unity.resource.tree_quota.UnityTreeQuota tree_quota = tquota_clz.get(_id=tree_quota_id, cli=cli) if not tree_quota.existed: raise UnityResourceNotFoundError( 'cannot find tree_quota {}.'.format(tree_quota_id)) user_quota_param = cls.prepare_user_quota_create_parameters( filesystem, tree_quota, hard_limit, soft_limit, uid, unix_name, win_name) resp = cli.post(cls().resource_class, **user_quota_param) resp.raise_if_err() return cls(_id=resp.resource_id, cli=cli)
def delete(self, async_mode=False, force_snap_delete=False, force_vvol_delete=False): sr = self.storage_resource if not self.existed or sr is None: raise UnityResourceNotFoundError('cannot find lun {}.'.format( self.get_id())) resp = self._cli.delete(sr.resource_class, self.get_id(), forceSnapDeletion=force_snap_delete, forceVvolDeletion=force_vvol_delete, async_mode=async_mode) try: resp.raise_if_err() except UnityBaseHasThinCloneError: log.warning( 'cannot delete the lun: %s, because it is a base lun ' 'of a thin-clone.', self.get_id()) TCHelper.notify(self, ThinCloneActionEnum.BASE_LUN_DELETE) return RESP_OK if self.is_thin_clone: TCHelper.notify(self, ThinCloneActionEnum.TC_DELETE) return resp
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( 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
def delete(self, force_snap_delete=False, force_vvol_delete=False, async_mode=False): sr = self.storage_resource if not self.existed or sr is None: raise UnityResourceNotFoundError( 'cannot find filesystem {}.'.format(self.get_id())) resp = self._cli.delete(sr.resource_class, sr.get_id(), forceSnapDeletion=force_snap_delete, forceVvolDeletion=force_vvol_delete, async_mode=async_mode) resp.raise_if_err() return resp
def _get_unity_rsc(self, clz, _id=None, **filters): ret = clz.get(cli=self._cli, _id=_id, **filters) if 'name' in filters and filters['name'] is not None: name = filters['name'] clz_name = clz.get_resource_class().__name__ if len(ret) == 0: raise UnityResourceNotFoundError( '{}:{} not found.'.format(clz_name, name)) elif len(ret) > 1: raise UnityNameNotUniqueError( 'multiple {} with name {} found.'.format(clz_name, name), # throw out the found multiple objects for later analysis objects=ret) else: ret = ret[0] return ret
def modify(cls, cli, user_quota_id, hard_limit=None, soft_limit=None): """ Modifies user_quota params for the specified user_quota_id :param user_quota_id: This is required which speicfies user_quota to be modified :param hard_limit: modifies hard_limit on the file_system for the user_quota specified :param soft_limit: modifies soft_limit on the file_system for the user_quota specified :return: None """ user_quota = UnityUserQuota.get(_id=user_quota_id, cli=cli) if not user_quota.existed: raise UnityResourceNotFoundError( 'cannot find user_quota {}.'.format(user_quota_id)) req_body = cli.make_body(hardLimit=hard_limit, softLimit=soft_limit) resp = cli.action(cls().resource_class, user_quota_id, 'modify', **req_body) resp.raise_if_err() return resp
is_repl_dst=is_repl_dst, tiering_policy=tiering_policy, snap_schedule=snap_schedule, is_compression=is_compression) resp = self._cli.action(UnityStorageResource().resource_class, self.get_id(), 'modifyLun', **req_body) resp.raise_if_err() return resp def delete(self, async=False, force_snap_delete=False, force_vvol_delete=False): sr = self.storage_resource if not self.existed or sr is None: raise UnityResourceNotFoundError('cannot find lun {}.'.format( self.get_id())) resp = self._cli.delete(sr.resource_class, self.get_id(), forceSnapDeletion=force_snap_delete, forceVvolDeletion=force_vvol_delete, async=async) try: resp.raise_if_err() except UnityBaseHasThinCloneError: log.warning( 'cannot delete the lun: %s, because it is a base lun ' 'of a thin-clone.', self.get_id()) TCHelper.notify(self, ThinCloneActionEnum.BASE_LUN_DELETE) return RESP_OK if self.is_thin_clone:
class UnityFileSystem(UnityResource): @classmethod def create(cls, cli, pool, nas_server, name, size, proto=None, is_thin=None, tiering_policy=None): pool_clz = storops.unity.resource.pool.UnityPool nas_server_clz = storops.unity.resource.nas_server.UnityNasServer if proto is None: proto = FSSupportedProtocolEnum.NFS pool = pool_clz.get(cli, pool) nas_server = nas_server_clz.get(cli, nas_server) FSSupportedProtocolEnum.verify(proto) TieringPolicyEnum.verify(tiering_policy) req_body = { 'name': name, 'fsParameters': { 'pool': pool, 'nasServer': nas_server, 'supportedProtocols': proto, 'isThinEnabled': is_thin, 'size': size, 'fastVPParameters': { 'tieringPolicy': tiering_policy } }, } resp = cli.type_action(UnityStorageResource().resource_class, 'createFilesystem', **req_body) resp.raise_if_err() sr = UnityStorageResource(_id=resp.resource_id, cli=cli) return sr.filesystem @property def first_available_cifs_server(self): ret = None if self.nas_server is not None: try: ret = self.nas_server.get_cifs_server() except UnityCifsServiceNotEnabledError as e: log.info(e.message) return ret def delete(self, force_snap_delete=False, force_vvol_delete=False, async=False): sr = self.storage_resource if not self.existed or sr is None: raise UnityResourceNotFoundError( 'cannot find filesystem {}.'.format(self.get_id())) resp = self._cli.delete(sr.resource_class, sr.get_id(), forceSnapDeletion=force_snap_delete, forceVvolDeletion=force_vvol_delete, async=async)