Skip to content

Commit

Permalink
changed method to set share properties
Browse files Browse the repository at this point in the history
  • Loading branch information
tasherif-msft committed Oct 15, 2020
1 parent c50f937 commit 5598b19
Show file tree
Hide file tree
Showing 10 changed files with 2,951 additions and 843 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
ShareSmbSettings,
SmbMultichannel,
ShareProtocolSettings,
ShareSetPropertiesOptions,
AccessPolicy,
FileSasPermissions,
ShareSasPermissions,
Expand Down Expand Up @@ -60,6 +61,7 @@
'ShareAccessTier',
'SmbMultichannel',
'ShareProtocolSettings',
'ShareSetPropertiesOptions',
'AccessPolicy',
'FileSasPermissions',
'ShareSasPermissions',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ def _from_generated(cls, generated):
smb=generated.smb)


class ShareSetPropertiesOptions(object):
"""Sets the properties for the share.
:param access_tier:
Specifies the access tier of the share.
Possible values: 'TransactionOptimized', 'Hot', and 'Cool'
:type access_tier: str or ~azure.storage.fileshare.models.ShareAccessTier
:param int quota:
Specifies the maximum size of the share, in gigabytes.
Must be greater than 0, and less than or equal to 5TB.
"""
def __init__(self, quota=None, access_tier=None):
self.quota = quota
self.access_tier = access_tier


class AccessPolicy(GenAccessPolicy):
"""Access Policy class used by the set and get acl methods in each service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
return_response_headers,
process_storage_error,
return_headers_and_deserialized)
from ._generated.models import ShareAccessTier
from ._generated import AzureFileStorage
from ._generated.version import VERSION
from ._generated.models import (
Expand All @@ -37,7 +36,7 @@
from ._lease import ShareLeaseClient

if TYPE_CHECKING:
from ._models import ShareProperties, AccessPolicy
from ._models import ShareProperties, AccessPolicy, ShareSetPropertiesOptions


class ShareClient(StorageAccountHostsMixin):
Expand Down Expand Up @@ -522,16 +521,15 @@ def set_share_quota(self, quota, **kwargs):
process_storage_error(error)

@distributed_trace
def set_share_tier(self, access_tier, **kwargs):
# type: (Union[str, ShareAccessTier], Any) -> Dict[str, Any]
"""Sets the tier for the share.
def set_share_properties(self, options, **kwargs):
# type: (ShareSetPropertiesOptions, Any) -> Dict[str, Any]
"""Sets the share properties.
.. versionadded:: 12.6.0
:param int access_tier:
Specifies the access tier of the share.
Possible values: 'TransactionOptimized', 'Hot', 'Cool'
:type access_tier: str or ~azure.storage.fileshare.models.ShareAccessTier
:param options:
Specifies the properties to set on the share.
:type options: ~azure.storage.fileshare.models.ShareSetPropertiesOptions
:keyword int timeout:
The timeout parameter is expressed in seconds.
:keyword lease:
Expand All @@ -543,19 +541,19 @@ def set_share_tier(self, access_tier, **kwargs):
.. admonition:: Example:
.. literalinclude:: ../samples/file_samples_share.py
:start-after: [START set_share_tier]
:end-before: [END set_share_tier]
:start-after: [START set_share_properties]
:end-before: [END set_share_properties]
:language: python
:dedent: 12
:caption: Sets the share tier.
:caption: Sets the share properties.
"""
access_conditions = get_access_conditions(kwargs.pop('lease', None))
timeout = kwargs.pop('timeout', None)
try:
return self._client.share.set_properties( # type: ignore
timeout=timeout,
quota=None,
access_tier=access_tier,
quota=options.quota,
access_tier=options.access_tier,
lease_access_conditions=access_conditions,
cls=return_response_headers,
**kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
return_response_headers,
process_storage_error,
return_headers_and_deserialized)
from .._generated.models import ShareAccessTier
from .._generated.aio import AzureFileStorage
from .._generated.version import VERSION
from .._generated.models import (
Expand All @@ -34,7 +33,7 @@


if TYPE_CHECKING:
from .._models import ShareProperties, AccessPolicy
from .._models import ShareProperties, AccessPolicy, ShareSetPropertiesOptions


class ShareClient(AsyncStorageAccountHostsMixin, ShareClientBase):
Expand Down Expand Up @@ -391,16 +390,15 @@ async def set_share_quota(self, quota, **kwargs):
except StorageErrorException as error:
process_storage_error(error)

async def set_share_tier(self, access_tier, **kwargs):
# type: (Union[str, ShareAccessTier], Any) -> Dict[str, Any]
"""Sets the tier for the share.
async def set_share_properties(self, options, **kwargs):
# type: (ShareSetPropertiesOptions, Any) -> Dict[str, Any]
"""Sets the share properties.
.. versionadded:: 12.6.0
:param int access_tier:
Specifies the access tier of the share.
Possible values: 'TransactionOptimized', 'Hot', 'Cool'
:type access_tier: str or ~azure.storage.fileshare.models.ShareAccessTier
:param options:
Specifies the properties to set on the share.
:type options: ~azure.storage.fileshare.models.ShareSetPropertiesOptions
:keyword int timeout:
The timeout parameter is expressed in seconds.
:keyword lease:
Expand All @@ -412,21 +410,21 @@ async def set_share_tier(self, access_tier, **kwargs):
.. admonition:: Example:
.. literalinclude:: ../samples/file_samples_share_async.py
:start-after: [START set_share_tier]
:end-before: [END set_share_tier]
:start-after: [START set_share_properties]
:end-before: [END set_share_properties]
:language: python
:dedent: 16
:caption: Sets the share tier.
:caption: Sets the share properties.
"""
access_conditions = get_access_conditions(kwargs.pop('lease', None))
timeout = kwargs.pop('timeout', None)
try:
return await self._client.share.set_properties( # type: ignore
timeout=timeout,
quota=None,
access_tier=access_tier,
cls=return_response_headers,
quota=options.quota,
access_tier=options.access_tier,
lease_access_conditions=access_conditions,
cls=return_response_headers,
**kwargs)
except StorageErrorException as error:
process_storage_error(error)
Expand Down
33 changes: 19 additions & 14 deletions sdk/storage/azure-storage-file-share/samples/file_samples_share.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""

import os
from azure.storage.fileshare import ShareAccessTier
from azure.storage.fileshare import ShareSetPropertiesOptions, ShareAccessTier

SOURCE_FILE = './SampleSource.txt'
DEST_FILE = './SampleDestination.txt'
Expand All @@ -38,7 +38,8 @@ def create_share_snapshot(self):
share = ShareClient.from_connection_string(self.connection_string, "sharesamples1")

# [START create_share]
share.create_share()
# Create share with Access Tier set to Hot
share.create_share(access_tier=ShareAccessTier("Hot"))
# [END create_share]
try:
# [START create_share_snapshot]
Expand Down Expand Up @@ -76,7 +77,7 @@ def set_share_quota_and_metadata(self):
# Delete the share
share.delete_share()

def set_share_tier(self):
def set_share_properties(self):
from azure.storage.fileshare import ShareClient
share1 = ShareClient.from_connection_string(self.connection_string, "sharesamples3a")
share2 = ShareClient.from_connection_string(self.connection_string, "sharesamples3b")
Expand All @@ -86,16 +87,20 @@ def set_share_tier(self):
share2.create_share()

try:
# [START set_share_tier]
# [START set_share_properties]
# Set the tier for the first share to Hot
share1.set_share_tier(access_tier="Hot")
# Set the tier for the second share to Hot
share2.set_share_tier(access_tier=ShareAccessTier("Cool"))
share1.set_share_properties(ShareSetPropertiesOptions(access_tier="Hot"))
# Set the quota for the first share to 3
share1.set_share_properties(ShareSetPropertiesOptions(quota=3))
# Set the tier for the second share to Cool and quota to 2
share2.set_share_properties(ShareSetPropertiesOptions(access_tier=ShareAccessTier("Cool"), quota=2))

# Get the shares' properties
print(share1.get_share_properties().access_tier)
print(share1.get_share_properties().quota)
print(share2.get_share_properties().access_tier)
# [END set_share_tier]
print(share2.get_share_properties().quota)
# [END set_share_properties]

finally:
# Delete the shares
Expand Down Expand Up @@ -156,9 +161,9 @@ def acquire_share_lease(self):

if __name__ == '__main__':
sample = ShareSamples()
sample.create_share_snapshot()
sample.set_share_quota_and_metadata()
sample.set_share_tier()
sample.list_directories_and_files()
sample.get_directory_or_file_client()
sample.acquire_share_lease()
# sample.create_share_snapshot()
# sample.set_share_quota_and_metadata()
sample.set_share_properties()
# sample.list_directories_and_files()
# sample.get_directory_or_file_client()
# sample.acquire_share_lease()
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import os
import asyncio
from azure.storage.fileshare import ShareAccessTier
from azure.storage.fileshare import ShareSetPropertiesOptions, ShareAccessTier

SOURCE_FILE = './SampleSource.txt'
DEST_FILE = './SampleDestination.txt'
Expand All @@ -40,7 +40,8 @@ async def create_share_snapshot_async(self):

async with share:
# [START create_share]
await share.create_share()
# Create share with Access Tier set to Hot
await share.create_share(access_tier=ShareAccessTier("Hot"))
# [END create_share]
try:
# [START create_share_snapshot]
Expand Down Expand Up @@ -79,7 +80,7 @@ async def set_share_quota_and_metadata_async(self):
# Delete the share
await share.delete_share()

async def set_share_tier(self):
async def set_share_properties(self):
from azure.storage.fileshare.aio import ShareClient
share1 = ShareClient.from_connection_string(self.connection_string, "sharesamples3a")
share2 = ShareClient.from_connection_string(self.connection_string, "sharesamples3b")
Expand All @@ -90,18 +91,22 @@ async def set_share_tier(self):
await share2.create_share()

try:
# [START set_share_tier]
# [START set_share_properties]
# Set the tier for the first share to Hot
await share1.set_share_tier(access_tier="Hot")
# Set the tier for the second share to Hot
await share2.set_share_tier(access_tier=ShareAccessTier("Cool"))
await share1.set_share_properties(ShareSetPropertiesOptions(access_tier="Hot"))
# Set the quota for the first share to 3
await share1.set_share_properties(ShareSetPropertiesOptions(quota=3))
# Set the tier for the second share to Cool and quota to 2
await share2.set_share_properties(ShareSetPropertiesOptions(access_tier=ShareAccessTier("Cool"), quota=2))

# Get the shares' properties
props1 = await share1.get_share_properties()
print(props1.access_tier)
props2 = await share2.get_share_properties()
print(props1.access_tier)
print(props1.quota)
print(props2.access_tier)
# [END set_share_tier]
print(props2.quota)
# [END set_share_properties]

finally:
# Delete the shares
Expand Down Expand Up @@ -152,7 +157,7 @@ async def main():
sample = ShareSamplesAsync()
await sample.create_share_snapshot_async()
await sample.set_share_quota_and_metadata_async()
await sample.set_share_tier()
await sample.set_share_properties()
await sample.list_directories_and_files_async()
await sample.get_directory_or_file_client_async()

Expand Down
Loading

0 comments on commit 5598b19

Please sign in to comment.