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

[Storage] az storage account, az storage share-rm: Support Azure Files provisioned v2 skus, add az storage account file-service-usage #30873

Merged
merged 8 commits into from
Feb 25, 2025
75 changes: 0 additions & 75 deletions src/azure-cli/azure/cli/command_modules/storage/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2941,39 +2941,6 @@
short-summary: Manage Azure file shares using the Microsoft.Storage resource provider.
"""

helps['storage share-rm create'] = """
type: command
short-summary: Create a new Azure file share under the specified storage account.
examples:
- name: Create a new Azure file share 'myfileshare' with metadata and quota as 10 GB under the storage account 'mystorageaccount'(account name) in resource group 'MyResourceGroup'.
text: az storage share-rm create -g MyResourceGroup --storage-account mystorageaccount --name myfileshare --quota 10 --metadata key1=value1 key2=value2
- name: Create a new Azure file share 'myfileshare' with metadata and quota as 6000 GB under the storage account 'mystorageaccount'(account name) which enables large file share in resource group 'MyResourceGroup'.
text: |
az storage account update -g MyResourceGroup --name mystorageaccount --enable-large-file-share
az storage share-rm create -g MyResourceGroup --storage-account mystorageaccount --name myfileshare --quota 6000 --metadata key1=value1 key2=value2
- name: Create a new Azure file share 'myfileshare' with metadata and quota as 10 GB under the storage account 'mystorageaccount' (account id).
text: az storage share-rm create --storage-account mystorageaccount --name myfileshare --quota 10 --metadata key1=value1 key2=value2
"""

helps['storage share-rm delete'] = """
type: command
short-summary: Delete the specified Azure file share or share snapshot.
long-summary: 'BREAKING CHANGE: Snapshot can not be deleted by default and we have added a new parameter to use if you want to include sanpshots for delete operation.'
examples:
- name: Delete an Azure file share 'myfileshare' under the storage account 'mystorageaccount' (account name) in resource group 'MyResourceGroup'.
text: az storage share-rm delete -g MyResourceGroup --storage-account mystorageaccount --name myfileshare
- name: Delete an Azure file share 'myfileshare' under the storage account 'mystorageaccount' (account id).
text: az storage share-rm delete --storage-account mystorageaccount --name myfileshare
- name: Delete an Azure file share by resource id.
text: az storage share-rm delete --ids file-share-id
- name: Delete an Azure file share snapshot.
text: az storage share-rm delete --ids file-share-id --snapshot "2021-03-25T05:29:56.0000000Z"
- name: Delete an Azure file share and all its snapshots.
text: az storage share-rm delete --include snapshots -g MyResourceGroup --storage-account mystorageaccount --name myfileshare
- name: Delete an Azure file share and all its snapshots (leased/unleased).
text: az storage share-rm delete --include leased-snapshots -g MyResourceGroup --storage-account mystorageaccount --name myfileshare
"""

helps['storage share-rm exists'] = """
type: command
short-summary: Check for the existence of an Azure file share.
Expand All @@ -2986,22 +2953,6 @@
text: az storage share-rm exists --ids file-share-id
"""

helps['storage share-rm list'] = """
type: command
short-summary: List the Azure file shares under the specified storage account.
examples:
- name: List the Azure file shares under the storage account 'mystorageaccount' (account name) in resource group 'MyResourceGroup'.
text: az storage share-rm list -g MyResourceGroup --storage-account mystorageaccount
- name: List the Azure file shares under the storage account 'mystorageaccount' (account id).
text: az storage share-rm list --storage-account mystorageaccount
- name: List all file shares include deleted under the storage account 'mystorageaccount' .
text: az storage share-rm list --storage-account mystorageaccount --include-deleted
- name: List all file shares include its all snapshots under the storage account 'mystorageaccount' .
text: az storage share-rm list --storage-account mystorageaccount --include-snapshot
- name: List all file shares include its all snapshots and deleted file shares under the storage account 'mystorageaccount' .
text: az storage share-rm list --storage-account mystorageaccount --include-deleted --include-snapshot
"""

helps['storage share-rm restore'] = """
type: command
short-summary: Restore a file share within a valid retention days if share soft delete is enabled.
Expand All @@ -3012,20 +2963,6 @@
text: az storage share-rm restore -n deletedshare --deleted-version 01D64EB9886F00C4 --restored-name newname -g MyResourceGroup --storage-account mystorageaccount
"""

helps['storage share-rm show'] = """
type: command
short-summary: Show the properties for a specified Azure file share or share snapshot.
examples:
- name: Show the properties for an Azure file share 'myfileshare' under the storage account 'mystorageaccount' (account name) in resource group 'MyResourceGroup'.
text: az storage share-rm show -g MyResourceGroup --storage-account mystorageaccount --name myfileshare
- name: Show the properties for an Azure file share 'myfileshare' under the storage account 'mystorageaccount' (account id).
text: az storage share-rm show --storage-account mystorageaccount --name myfileshare
- name: Show the properties of an Azure file share by resource id.
text: az storage share-rm show --ids file-share-id
- name: Show the properties of an Azure file share snapshot
text: az storage share-rm show --ids file-share-id --snapshot "2021-03-25T05:29:56.0000000Z"
"""

helps['storage share-rm stats'] = """
type: command
short-summary: Get the usage bytes of the data stored on the share.
Expand All @@ -3034,18 +2971,6 @@
text: az storage share-rm stats -g MyResourceGroup --storage-account mystorageaccount --name myfileshare
"""

helps['storage share-rm update'] = """
type: command
short-summary: Update the properties for an Azure file share.
examples:
- name: Update the properties for an Azure file share 'myfileshare' under the storage account 'mystorageaccount' (account name) in resource group 'MyResourceGroup'.
text: az storage share-rm update -g MyResourceGroup --storage-account mystorageaccount --name myfileshare --quota 3 --metadata key1=value1 key2=value2
- name: Update the properties for an Azure file share 'myfileshare' under the storage account 'mystorageaccount' (account id).
text: az storage share-rm update --storage-account mystorageaccount --name myfileshare --quota 3 --metadata key1=value1 key2=value2
- name: Update the properties for an Azure file shares by resource id.
text: az storage share-rm update --ids file-share-id --quota 3 --metadata key1=value1 key2=value2
"""

helps['storage share-rm snapshot'] = """
type: command
short-summary: Create a snapshot of an existing share under the specified account.
Expand Down
15 changes: 1 addition & 14 deletions src/azure-cli/azure/cli/command_modules/storage/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1743,13 +1743,7 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
help='The DateTime value that specifies the share snapshot to retrieve.')
c.ignore('filter', 'maxpagesize')

with self.argument_context('storage share-rm delete', resource_type=ResourceType.MGMT_STORAGE) as c:
c.argument('include', default='none')

with self.argument_context('storage share-rm update', resource_type=ResourceType.MGMT_STORAGE) as c:
c.ignore('x_ms_snapshot')

for item in ['create', 'update', 'snapshot']:
for item in ['snapshot']:
with self.argument_context('storage share-rm {}'.format(item), resource_type=ResourceType.MGMT_STORAGE) as c:
t_enabled_protocols, t_root_squash, t_access_tier = \
self.get_models('EnabledProtocols', 'RootSquashType', 'ShareAccessTier',
Expand All @@ -1770,13 +1764,6 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
help='Access tier for specific share. GpV2 account can choose between TransactionOptimized '
'(default), Hot, and Cool. FileStorage account can choose Premium.')

with self.argument_context('storage share-rm list', resource_type=ResourceType.MGMT_STORAGE) as c:
c.argument('account_name', storage_account_type, id_part=None)
c.argument('include_deleted', action='store_true',
help='Include soft deleted file shares when specified.')
c.argument('include_snapshot', action='store_true',
help='Include file share snapshots when specified.')

with self.argument_context('storage share-rm restore', resource_type=ResourceType.MGMT_STORAGE) as c:
c.argument('deleted_version',
help='Identify the version of the deleted share that will be restored.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,6 @@ def transform_share_rm_output(result):
return result


def transform_share_rm_list_output(result):
new_result = []
for item in result:
new_result.append(transform_share_rm_output(item))
return new_result


def delete_blob_output_key(_, result):
result.pop('additionalProperties', None)
return result
Expand Down
26 changes: 26 additions & 0 deletions src/azure-cli/azure/cli/command_modules/storage/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,32 @@ def parse_storage_account(cmd, namespace):
namespace.resource_group_name = _query_account_rg(cmd.cli_ctx, namespace.account_name)[0]


def parse_storage_account_aaz(cmd, args):
"""Parse storage account which can be either account name or account id for aaz"""
from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id

account_name = str(args.storage_account)
if account_name and is_valid_resource_id(account_name):
args.resource_group = parse_resource_id(account_name)['resource_group']
args.storage_account = parse_resource_id(account_name)['name']
elif account_name and not is_valid_resource_id(account_name) and \
not args.resource_group:
args.resource_group = _query_account_rg(cmd.cli_ctx, account_name)[0]


def parse_account_name_aaz(cmd, args):
"""Parse storage account which can be either account name or account id for aaz"""
from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id

account_name = str(args.account_name)
if account_name and is_valid_resource_id(account_name):
args.resource_group = parse_resource_id(account_name)['resource_group']
args.account_name = parse_resource_id(account_name)['name']
elif account_name and not is_valid_resource_id(account_name) and \
not args.resource_group:
args.resource_group = _query_account_rg(cmd.cli_ctx, account_name)[0]


def process_resource_group(cmd, namespace):
"""Processes the resource group parameter from the account name"""
if namespace.account_name and not namespace.resource_group_name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
# flake8: noqa

from .__cmd_group import *
from ._file_service_usage import *
Loading