Skip to content
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
2 changes: 1 addition & 1 deletion src/storage-preview/azext_storage_preview/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType

register_resource_type('latest', CUSTOM_DATA_STORAGE, '2017-11-09')
register_resource_type('latest', CUSTOM_MGMT_STORAGE, '2018-02-01')
register_resource_type('latest', CUSTOM_MGMT_STORAGE, '2018-03-01-preview')
storage_custom = CliCommandType(operations_tmpl='azext_storage_preview.custom#{}')

super(StorageCommandsLoader, self).__init__(cli_ctx=cli_ctx,
Expand Down
15 changes: 15 additions & 0 deletions src/storage-preview/azext_storage_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,21 @@
short-summary: Remove a network rule.
"""

helps['storage account management-policy'] = """
type: group
short-summary: Manage storage account management policies.
"""

helps['storage account management-policy create'] = """
type: command
short-summary: Creates the data policy rules associated with the specified storage account.
"""

helps['storage account management-policy update'] = """
type: command
short-summary: Updates the data policy rules associated with the specified storage account.
"""

helps['storage account generate-sas'] = """
type: command
parameters:
Expand Down
7 changes: 6 additions & 1 deletion src/storage-preview/azext_storage_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
with self.argument_context('storage account create') as c:
t_account_type, t_sku_name, t_kind = self.get_models('AccountType', 'SkuName', 'Kind',
resource_type=CUSTOM_MGMT_STORAGE)

c.register_common_storage_account_options()
c.argument('location', get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group)
c.argument('account_type', help='The storage account type', arg_type=get_enum_type(t_account_type))
Expand Down Expand Up @@ -172,6 +171,12 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem
validator=get_permission_validator(t_account_permissions))
c.ignore('sas_token')

with self.argument_context('storage account management-policy create') as c:
c.argument('policy', type=file_type, completer=FilesCompleter(),
help='The Storage Account ManagementPolicies Rules, in JSON format. See more details in: '
'https://docs.microsoft.com/en-us/azure/storage/common/storage-lifecycle-managment-concepts.')
c.argument('account_name', help='The name of the storage account within the specified resource group.')

with self.argument_context('storage logging show') as c:
c.extra('services', validator=get_char_options_validator('bqt', 'services'), default='bqt')

Expand Down
12 changes: 11 additions & 1 deletion src/storage-preview/azext_storage_preview/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

def load_command_table(self, _): # pylint: disable=too-many-locals, too-many-statements
storage_account_sdk = CliCommandType(
operations_tmpl='azure.mgmt.storage.operations.storage_accounts_operations#StorageAccountsOperations.{}',
operations_tmpl='azext_storage_preview.vendored_sdks.azure_mgmt_storage.operations.storage_accounts_operations'
'#StorageAccountsOperations.{}',
client_factory=cf_sa,
resource_type=CUSTOM_MGMT_STORAGE
)
Expand Down Expand Up @@ -56,6 +57,15 @@ def get_custom_sdk(custom_module, client_factory, resource_type=CUSTOM_DATA_STOR
g.command('keys list', 'list_keys', transform=lambda x: getattr(x, 'keys', x))
g.storage_command('generate-sas', 'generate_shared_access_signature', command_type=cloud_data_plane_sdk)

with self.command_group('storage account management-policy', storage_account_sdk, resource_type=CUSTOM_MGMT_STORAGE,
custom_command_type=storage_account_custom_type) as g:
g.command('show', 'get_management_policies')
g.custom_command('create', 'create_management_policies')
g.generic_update_command('update', getter_name='get_management_policies',
setter_name='update_management_policies',
setter_type=storage_account_custom_type)
g.command('delete', 'delete_management_policies')

with self.command_group('storage account network-rule', storage_account_sdk,
custom_command_type=storage_account_custom_type,
resource_type=CUSTOM_MGMT_STORAGE, min_api='2017-06-01') as g:
Expand Down
22 changes: 19 additions & 3 deletions src/storage-preview/azext_storage_preview/operations/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

"""Custom operations for storage account commands"""

import os
from azure.cli.core.util import get_file_json, shell_safe_json_parse
from .._client_factory import storage_client_factory


Expand Down Expand Up @@ -77,8 +79,8 @@ def show_storage_account_connection_string(cmd, resource_group_name, account_nam
def show_storage_account_usage(cmd, location=None):
scf = storage_client_factory(cmd.cli_ctx)
if not location:
return next((x for x in scf.usage.list() if x.name.value == 'StorageAccounts'), None) # pylint: disable=no-member
return next((x for x in scf.usage.list_by_location(location) if x.name.value == 'StorageAccounts'), None) # pylint: disable=no-member
return next((x for x in scf.usages.list() if x.name.value == 'StorageAccounts'), None) # pylint: disable=no-member
return next((x for x in scf.usages.list_by_location(location) if x.name.value == 'StorageAccounts'), None) # pylint: disable=no-member


# pylint: disable=too-many-locals
Expand Down Expand Up @@ -133,7 +135,6 @@ def update_storage_account(cmd, instance, sku=None, tags=None, custom_domain=Non
from knack.util import CLIError
raise CLIError('incorrect usage: --default-action ACTION [--bypass SERVICE ...]')
params.network_rule_set = acl

return params


Expand Down Expand Up @@ -182,3 +183,18 @@ def remove_network_rule(cmd, client, resource_group_name, storage_account_name,
StorageAccountUpdateParameters = cmd.get_models('StorageAccountUpdateParameters')
params = StorageAccountUpdateParameters(network_rule_set=rules)
return client.update(resource_group_name, storage_account_name, params)


def create_management_policies(client, resource_group_name, account_name, policy=None):
if policy:
if os.path.exists(policy):
policy = get_file_json(policy)
else:
policy = shell_safe_json_parse(policy)
return client.create_or_update_management_policies(resource_group_name, account_name, policy=policy)


def update_management_policies(client, resource_group_name, account_name, parameters=None):
if parameters:
parameters = parameters.policy
return client.create_or_update_management_policies(resource_group_name, account_name, policy=parameters)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"version": "0.5",
"rules": [
{
"name": "olcmtest",
"type": "Lifecycle",
"definition": {
"filters": {
"blobTypes": [
"blockBlob"
],
"prefixMatch": [
"olcmtestcontainer"
]
},
"actions": {
"baseBlob": {
"tierToCool": {
"daysAfterModificationGreaterThan": 1000
},
"tierToArchive": {
"daysAfterModificationGreaterThan": 90
},
"delete": {
"daysAfterModificationGreaterThan": 1000
}
},
"snapshot": {
"delete": {
"daysAfterCreationGreaterThan": 5000
}
}
}
}
}
]
}

Large diffs are not rendered by default.

Loading