Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more parameters for file create, modify interfaces #331

Merged
merged 4 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions storops/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,26 @@ class UnityCifsServiceNotEnabledError(UnityException):
pass


@rest_exception
class UnityActiveDirectoryDomainNotSpecifiedError(UnityException):
error_code = 108011879


@rest_exception
class UnityDNSServerRequiredError(UnityException):
error_code = 108011895


@rest_exception
class UnityUnableToLocateDomainControllerInADDomainError(UnityException):
error_code = 108011915


@rest_exception
class UnitySystemTimeNotSynchronizedError(UnityException):
error_code = 108011924


class UnityHostInitiatorNotFoundError(UnityException):
pass

Expand Down Expand Up @@ -419,6 +439,11 @@ class UnitySmbNameInUseError(UnityException):
error_code = 108011873


@rest_exception
class UnitySmbShareMaskInvalidError(UnityException):
error_code = 151036427


@rest_exception
class UnityIpAddressUsedError(UnityException):
error_code = 108011747
Expand Down Expand Up @@ -459,6 +484,36 @@ class UnityFileSystemNameAlreadyExisted(UnityException):
error_code = 108008464


@rest_exception
class UnityNfsCannotAddHostStringError(UnityException):
error_code = 151036201


@rest_exception
class UnityFileSystemThinThickConversionNotSupportedError(UnityException):
error_code = 108008493


@rest_exception
class UnitySharePathNotExistError(UnityException):
error_code = 151035906


@rest_exception
class UnityNasServerSecureNfsNotEnableError(UnityException):
error_code = 151036182


@rest_exception
class UnitySpecifiedServerNotExistError(UnityException):
error_code = 131149864


@rest_exception
class UnityExportOptionInvalidError(UnityException):
error_code = 131150149


class UnityCreateSnapError(UnityException):
pass

Expand Down Expand Up @@ -507,6 +562,11 @@ class UnityFileSystemSizeTooSmallError(UnityException):
error_code = 108008449


@rest_exception
class UnityModifyingAccessPolicyNotAllowedError(UnityException):
error_code = 108008486


class UnityQosException(UnityException):
pass

Expand Down
11 changes: 11 additions & 0 deletions storops/unity/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,3 +1205,14 @@ class DayOfWeekEnumList(UnityEnumList):
@classmethod
def get_enum_class(cls):
return DayOfWeekEnum


class FSRenamePolicyEnum(UnityEnum):
ALL_RENAME_ALLOWED = (0, 'All_Rename_Allowed')
SMB_RENAME_FORBIDDEN = (1, 'SMB_Rename_Forbidden')
ALL_RENAME_FORBIDDEN = (2, 'All_Rename_Forbidden')


class FSLockingPolicyEnum(UnityEnum):
ADVISORY = (0, 'Advisory')
MANDATORY = (1, 'Mandatory')
26 changes: 25 additions & 1 deletion storops/unity/parser_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ UnityPool:
is_index: True
- label: raidType
converter: RaidTypeEnum
- label: harbestState
- label: objectId
- label: health
converter: UnityHealth
Expand Down Expand Up @@ -285,6 +284,8 @@ UnityNasServer:
- label: sizeAllocated
- label: tenant
converter: UnityTenant
- label: isBackupOnly
- label: isPacketReflectEnabled
- label: isReplicationEnabled
- label: isReplicationDestination
- label: replicationType
Expand Down Expand Up @@ -325,8 +326,16 @@ UnityFileSystem:
- label: sizeTotal
- label: sizeUsed
- label: sizeAllocated
- label: sizePreallocated
- label: sizeAllocatedTotal
- label: minSizeAllocated
- label: isReadOnly
- label: isThinEnabled
- label: isDataReductionEnabled
- label: dataReductionSizeSaved
- label: dataReductionPercent
- label: dataReductionRatio
- label: isAdvancedDedupEnabled
- label: storageResource
converter: UnityStorageResource
- label: isCIFSSyncWritesEnabled
Expand All @@ -350,6 +359,10 @@ UnityFileSystem:
- label: isSMBCA
- label: accessPolicy
converter: AccessPolicyEnum
- label: folderRenamePolicy
converter: FSRenamePolicyEnum
- label: lockingPolicy
converter: FSLockingPolicyEnum
- label: format
converter: FSFormatEnum
- label: hostIOSize
Expand Down Expand Up @@ -457,14 +470,25 @@ UnityNfsShare:
converter: NFSShareDefaultAccessEnum
- label: minSecurity
converter: NFSShareSecurityEnum
- label: nfsOwnerUsername
- label: noAccessHosts
converter: UnityHostList
- label: readOnlyHosts
converter: UnityHostList
- label: readWriteHosts
converter: UnityHostList
- label: readOnlyRootAccessHosts
converter: UnityHostList
- label: rootAccessHosts
converter: UnityHostList
- label: noAccessHostsString
- label: readOnlyHostsString
- label: readWriteHostsString
- label: readOnlyRootHostsString
- label: readWriteRootHostsString
- label: anonymousUID
- label: anonymousGID
- label: exportOption
- label: hostAccesses


Expand Down
116 changes: 99 additions & 17 deletions storops/unity/resource/cifs_share.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
import storops.unity.resource.snap
from storops.exception import UnityCreateSnapError
from storops.lib.common import instance_cache
from storops.unity.client import UnityClient
from storops.unity.enums import CIFSTypeEnum, ACEAccessTypeEnum, \
ACEAccessLevelEnum, FilesystemSnapAccessTypeEnum
ACEAccessLevelEnum, FilesystemSnapAccessTypeEnum, \
CifsShareOfflineAvailabilityEnum
from storops.unity.resource import UnityResource, UnityResourceList, \
UnityAttributeResource
from storops.unity.resp import RestResponse

__author__ = 'Jay Xu'

Expand All @@ -37,7 +40,11 @@

class UnityCifsShare(UnityResource):
@classmethod
def create(cls, cli, name, fs, path=None, cifs_server=None):
def create(cls, cli, name, fs, path=None, cifs_server=None,
is_read_only=None, is_encryption_enabled=None,
is_con_avail_enabled=None, is_abe_enabled=None,
is_branch_cache_enabled=None, offline_availability=None,
umask=None, description=None):
fs_clz = storops.unity.resource.filesystem.UnityFileSystem
fs = fs_clz.get(cli, fs).verify()
sr = fs.storage_resource
Expand All @@ -51,26 +58,48 @@ def create(cls, cli, name, fs, path=None, cifs_server=None):
server_clz = storops.unity.resource.cifs_server.UnityCifsServer
cifs_server = server_clz.get(cli, cifs_server)

share_param = cls.prepare_cifs_share_parameters(
is_read_only=is_read_only,
is_encryption_enabled=is_encryption_enabled,
is_con_avail_enabled=is_con_avail_enabled,
is_abe_enabled=is_abe_enabled,
is_branch_cache_enabled=is_branch_cache_enabled,
offline_availability=offline_availability,
umask=umask, description=description)

param = cli.make_body(name=name,
path=path,
cifsServer=cifs_server)
cifsServer=cifs_server,
cifsShareParameters=share_param)
resp = sr.modify_fs(cifsShareCreate=[param])
resp.raise_if_err()
return UnityCifsShareList(cli=cli, name=name).first_item

@classmethod
def create_from_snap(cls, cli, snap, name, path=None, is_read_only=None):
def create_from_snap(cls, cli, snap, name, path=None, is_read_only=None,
is_abe_enabled=None, is_branch_cache_enabled=None,
is_con_avail_enabled=None,
is_encryption_enabled=None,
offline_availability=None,
umask=None, description=None):
snap_clz = storops.unity.resource.snap.UnitySnap
snap = snap_clz.get(cli, snap)

if path is None:
path = '/'

resp = cli.post(cls().resource_class,
snap=snap,
path=path,
name=name,
isReadOnly=is_read_only)
share_param = cls.prepare_cifs_share_parameters(
is_read_only=is_read_only,
is_encryption_enabled=is_encryption_enabled,
is_con_avail_enabled=is_con_avail_enabled,
is_abe_enabled=is_abe_enabled,
is_branch_cache_enabled=is_branch_cache_enabled,
offline_availability=offline_availability,
umask=umask, description=description)

resp = cli.post(
cls().resource_class, snap=snap, path=path, name=name,
**share_param)
resp.raise_if_err()
return cls(_id=resp.resource_id, cli=cli)

Expand Down Expand Up @@ -181,22 +210,54 @@ def _make_remove_ace_entry(self, sid):
accessLevel=ACEAccessLevelEnum.FULL)

def modify(self, is_read_only=None, is_ace_enabled=None, add_ace=None,
delete_ace=None):
delete_ace=None, is_encryption_enabled=None,
is_con_avail_enabled=None, is_abe_enabled=None,
is_branch_cache_enabled=None, offline_availability=None,
umask=None, description=None):
if self.type == CIFSTypeEnum.CIFS_SHARE:
share_param = self.prepare_cifs_share_parameters(
is_read_only=is_read_only,
is_encryption_enabled=is_encryption_enabled,
is_con_avail_enabled=is_con_avail_enabled,
is_ace_enabled=is_ace_enabled,
add_ace=add_ace, delete_ace=delete_ace,
is_abe_enabled=is_abe_enabled,
is_branch_cache_enabled=is_branch_cache_enabled,
offline_availability=offline_availability,
umask=umask, description=description)
if share_param:
resp = self._modify_fs_share(share_param)
else:
resp = RestResponse('', self._cli)
if self.type == CIFSTypeEnum.CIFS_SNAPSHOT:
share_param = self.prepare_cifs_share_parameters(
is_encryption_enabled=is_encryption_enabled,
is_con_avail_enabled=is_con_avail_enabled,
is_abe_enabled=is_abe_enabled,
is_branch_cache_enabled=is_branch_cache_enabled,
offline_availability=offline_availability,
umask=umask, description=description)
if share_param:
resp = self._modify_snap_share(share_param)
else:
resp = RestResponse('', self._cli)

resp.raise_if_err()
return resp

def _modify_snap_share(self, cifs_share_param):
return self.action('modify', **cifs_share_param)

def _modify_fs_share(self, cifs_share_param):
sr = self.storage_resource
if sr is None:
raise ValueError('storage resource for share {} not found.'
.format(self.name))

share_param = self._cli.make_body(
allow_empty=True,
isReadOnly=is_read_only,
isACEEnabled=is_ace_enabled,
addACE=add_ace,
deleteAce=delete_ace)
modify_param = self._cli.make_body(
allow_empty=True,
cifsShare=self,
cifsShareParameters=share_param)
cifsShareParameters=cifs_share_param)
param = self._cli.make_body(
allow_empty=True,
cifsShareModify=[modify_param])
Expand Down Expand Up @@ -233,6 +294,27 @@ def create_snap(self, name=None, fs_access_type=None):
.format(self.name, self.type))
return ret

@staticmethod
def prepare_cifs_share_parameters(**kwargs):
offline_availability = kwargs.get('offline_availability')
CifsShareOfflineAvailabilityEnum.verify(offline_availability)

cifs_share_param = UnityClient.make_body(
allow_empty=True,
isReadOnly=kwargs.get('is_read_only'),
isEncryptionEnabled=kwargs.get('is_encryption_enabled'),
isContinuousAvailabilityEnabled=kwargs.get(
'is_con_avail_enabled'),
isACEEnabled=kwargs.get('is_ace_enabled'),
addACE=kwargs.get('add_ace'),
deleteACE=kwargs.get('delete_ace'),
isABEEnabled=kwargs.get('is_abe_enabled'),
isBranchCacheEnabled=kwargs.get('is_branch_cache_enabled'),
offlineAvailability=offline_availability,
umask=kwargs.get('umask'),
description=kwargs.get('description'))
return cifs_share_param


class UnityCifsShareList(UnityResourceList):
@classmethod
Expand Down
Loading