-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[storage-ors-preview] Support ORS policy for storage account (#1461)
* initialize * add commands * update function * add test * add validation * add readme * Add help message * assign policy to both src and dest account * redefine commands * add sdk and test * refine help and add examples * refine help * update test * add example for ors-policy create * refine help and add test * fix APIVersion cannot be found in test * update tests * add recording file * change update * fix style and update README * revert help.py * remove index.json, add vendored sdk and change setup.py for publish * Update README.md * change filter to filters * apply new generated SDK * add set command * update test * rearrange commands * update index and readme * remove maxVersion in metadata * add new SDK * addd UTC datetime converter * add test and new parameter * add release note and readme * revert gitinore * refine README * refine README * refine README * refine README * fix static analysis * fix linter * refine README * refine help * fix typo and rerun test * try to fix unused import * fix style * remove azure-cli-core in dependency * rename ors-policy to or-policy * Default to --account-name for --destination-account when creating policy in destination account. * rerun test * rebuild the package for 1.3.0 * update README with new version * refine release note * fix ci * fix static analytic
- Loading branch information
Showing
50 changed files
with
16,471 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.. :changelog: | ||
Release History | ||
=============== | ||
|
||
0.1.0 | ||
++++++ | ||
* Initial release. | ||
|
||
0.2.0 | ||
++++++ | ||
* Support --min-creation-time for ORS filter. | ||
|
||
0.3.0 | ||
++++++ | ||
* Rename `az storage account ors-policy` to `az storage account or-policy`. | ||
* Default to `--account-name` for `--destination-account` when creating policy in destination account. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
# Azure CLI storage-ors-preview Extension # | ||
This is an extension for storage-ors-preview features. | ||
|
||
### How to use ### | ||
Install this extension using the below CLI command after release: | ||
``` | ||
az extension add -n storage-ors-preview | ||
``` | ||
Currently you can install use source wheel: | ||
``` | ||
az extension add -s https://storageextension.blob.core.windows.net/cliextension/storage_ors_preview-0.3.0-py2.py3-none-any.whl | ||
``` | ||
|
||
For release history, please refer to https://github.com/Juliehzl/azure-cli-extensions/blob/ors/src/storage-ors-preview/HISTORY.rst. | ||
|
||
### Prepare | ||
1. Prepare general purpose v2 storage account | ||
``` | ||
az storage account create -n storageaccount -g groupName --kind StorageV2 | ||
``` | ||
|
||
2. Enable Versioning for both source and destination storage accounts | ||
``` | ||
az storage account blob-service-properties update --enable-versioning --account-name srcAccountName | ||
``` | ||
Note: | ||
- `--enable-versioning` is supported in [azure cli 2.3.0](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest#install), which will be officially release at 2020/03/31. | ||
- Another option to enable Versioning in azure cli is as follows: | ||
``` | ||
az storage account blob-service-properties update --account-name srcAccountName --set is_versioning_enabled=True | ||
``` | ||
|
||
3. Enable ChangeFeed for source storage account | ||
``` | ||
az storage account blob-service-properties update --enable-change-feed --account-name srcAccountName | ||
``` | ||
|
||
### Included Features | ||
#### ORS Policy: | ||
Manage data policy rules associated with a storage account: [more info](https://docs.microsoft.com/azure/storage/common/storage-lifecycle-managment-concepts)\ | ||
|
||
*Examples:* | ||
|
||
##### Create ORS Policy on destination storage account | ||
1. Using JSON file or JSON string. | ||
``` | ||
az storage account or-policy create \ | ||
--account-name destAccountName \ | ||
--resource-group groupName \ | ||
--properties @{path} | ||
``` | ||
2. Using command parameters. | ||
``` | ||
az storage account or-policy create \ | ||
--account-name destAccountName \ | ||
--resource-group groupName \ | ||
--source-account srcAccountName \ | ||
--destination-account destAccountName \ | ||
--source-container srcContainer \ | ||
--destination-container destContainer \ | ||
``` | ||
``` | ||
az storage account or-policy create \ | ||
--account-name destAccountName \ | ||
--resource-group groupName \ | ||
--source-account srcAccountName \ | ||
--destination-account destAccountName \ | ||
--source-container srcContainer \ | ||
--min-creation-time '2020-02-19T16:05:00Z' \ | ||
--prefix-match blobA blobB | ||
``` | ||
|
||
3. Create Object Replication Service Policy to source storage account through policy associated with destination storage account. | ||
``` | ||
az storage account or-policy show -g groupName -n destAccountName --policy-id "3496e652-4cea-4581-b2f7-c86b3971ba92" | az storage account or-policy create -g ResourceGroupName -n srcAccountName -p "@-" | ||
``` | ||
|
||
To save the policyId/ruleId in PowerShell Scripts, you can use: | ||
|
||
`$policyId = (az storage account or-policy create --account-name accountName --resource-group groupName --properties @{path}) --query policyId)` | ||
|
||
`$ruleId = (az storage account or-policy create --account-name accountName --resource-group groupName --properties @{path}) --query rules.ruleId)` | ||
|
||
##### List ORS Policies on storage account | ||
``` | ||
az storage account or-policy list \ | ||
--account-name accountName \ | ||
--resource-group groupName | ||
``` | ||
|
||
##### Show ORS Policy on storage account | ||
``` | ||
az storage account or-policy show \ | ||
--policy-id $policyId \ | ||
--account-name accountName \ | ||
--resource-group groupName | ||
``` | ||
|
||
##### Update ORS Policy on storage account | ||
Change source storage account name of existing ORS policy. | ||
``` | ||
az storage account or-policy update \ | ||
--policy-id $policyId \ | ||
--account-name destAccountName \ | ||
--resource-group groupName \ | ||
-s newSourceAccount | ||
``` | ||
|
||
Update existing ORS policy through json file. | ||
``` | ||
az storage account or-policy update \ | ||
--policy @policy.json \ | ||
--account-name destAccountName \ | ||
--resource-group groupName \ | ||
``` | ||
##### Add rule to existing ORS Policy | ||
``` | ||
az storage account or-policy rule add \ | ||
--policy-id $policyId \ | ||
--account-name accountName \ | ||
--resource-group groupName \ | ||
--destination-container destContainer \ | ||
--source-container srcContainer \ | ||
--prefix-match blobA blobB \ | ||
--min-creation-time '2020-02-19T16:05:00Z' | ||
``` | ||
|
||
##### List rules for ORS Policy | ||
``` | ||
az storage account or-policy rule list \ | ||
--policy-id $policyId \ | ||
--account-name accountName \ | ||
--resource-group groupName | ||
``` | ||
|
||
##### Show properties of specific rule in ORS Policy | ||
``` | ||
az storage account or-policy rule show \ | ||
--rule-id $ruleId \ | ||
--policy-id $policyId \ | ||
--account-name accountName \ | ||
--resource-group groupName | ||
``` | ||
|
||
##### Update properties for specific ORS Policy Rule | ||
Change prefix match filter properties. | ||
``` | ||
az storage account or-policy rule update \ | ||
--rule-id $ruleId \ | ||
--policy-id $policyId \ | ||
--account-name accountName \ | ||
--resource-group groupName \ | ||
--prefix-match blobA | ||
``` | ||
|
||
Change min creation time in filter properties. | ||
``` | ||
az storage account or-policy rule update \ | ||
--rule-id $ruleId \ | ||
--policy-id $policyId \ | ||
--account-name accountName \ | ||
--resource-group groupName \ | ||
--min-creation-time '2020-02-19T16:05:00Z' | ||
``` | ||
##### Remove the specified rule in existing ORS Policy | ||
``` | ||
az storage account or-policy rule remove \ | ||
--rule-id $ruleId \ | ||
--policy-id $policyId \ | ||
--account-name accountName \ | ||
--resource-group groupName | ||
``` | ||
|
||
##### Delete the specified ORS Policy for storage account | ||
``` | ||
az storage account or-policy delete \ | ||
--policy-id $policyId \ | ||
--account-name accountName \ | ||
--resource-group groupName | ||
``` | ||
|
||
|
||
If you have issues, please give feedback by opening an issue at https://github.com/Azure/azure-cli-extensions/issues. |
Empty file.
37 changes: 37 additions & 0 deletions
37
src/storage-ors-preview/azext_storage_ors_preview/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from azure.cli.core import AzCommandsLoader | ||
from azure.cli.core.profiles import register_resource_type | ||
|
||
from ._help import helps # pylint: disable=unused-import | ||
from .profiles import CUSTOM_MGMT_STORAGE_ORS | ||
|
||
|
||
class StorageCommandsLoader(AzCommandsLoader): | ||
|
||
def __init__(self, cli_ctx=None): | ||
from azure.cli.core.commands import CliCommandType | ||
|
||
register_resource_type('latest', CUSTOM_MGMT_STORAGE_ORS, '2019-06-01') | ||
storage_custom = CliCommandType(operations_tmpl='azext_storage_ors_preview.custom#{}') | ||
|
||
super(StorageCommandsLoader, self).__init__(cli_ctx=cli_ctx, | ||
resource_type=CUSTOM_MGMT_STORAGE_ORS, | ||
custom_command_type=storage_custom) | ||
|
||
def load_command_table(self, args): | ||
super(StorageCommandsLoader, self).load_command_table(args) | ||
from .commands import load_command_table | ||
load_command_table(self, args) | ||
return self.command_table | ||
|
||
def load_arguments(self, command): | ||
super(StorageCommandsLoader, self).load_arguments(command) | ||
from ._params import load_arguments | ||
load_arguments(self, command) | ||
|
||
|
||
COMMAND_LOADER_CLS = StorageCommandsLoader |
20 changes: 20 additions & 0 deletions
20
src/storage-ors-preview/azext_storage_ors_preview/_client_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from azure.cli.core.commands.client_factory import get_mgmt_service_client | ||
|
||
from .profiles import CUSTOM_MGMT_STORAGE_ORS | ||
|
||
|
||
def storage_client_factory(cli_ctx, **_): | ||
return get_mgmt_service_client(cli_ctx, CUSTOM_MGMT_STORAGE_ORS) | ||
|
||
|
||
def cf_sa(cli_ctx, _): | ||
return storage_client_factory(cli_ctx).storage_accounts | ||
|
||
|
||
def cf_or_policy(cli_ctx, _): | ||
return storage_client_factory(cli_ctx).object_replication_policies |
104 changes: 104 additions & 0 deletions
104
src/storage-ors-preview/azext_storage_ors_preview/_help.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from knack.help_files import helps # pylint: disable=unused-import | ||
|
||
|
||
helps['storage account or-policy'] = """ | ||
type: group | ||
short-summary: Manage storage account Object Replication Policy. | ||
""" | ||
|
||
helps['storage account or-policy create'] = """ | ||
type: command | ||
short-summary: Create Object Replication Service Policy for storage account. | ||
examples: | ||
- name: Create Object Replication Service Policy for storage account. | ||
text: az storage account or-policy create -g ResourceGroupName -n storageAccountName -d destAccountName -s srcAccountName --destination-container dcont --source-container scont | ||
- name: Create Object Replication Service Policy trough json file for storage account. | ||
text: az storage account or-policy create -g ResourceGroupName -n storageAccountName --policy @policy.json | ||
- name: Create Object Replication Service Policy to source storage account through policy associated with destination storage account. | ||
text: az storage account or-policy show -g ResourceGroupName -n destAccountName --policy-id "3496e652-4cea-4581-b2f7-c86b3971ba92" | az storage account or-policy create -g ResourceGroupName -n srcAccountName -p "@-" | ||
""" | ||
|
||
helps['storage account or-policy list'] = """ | ||
type: command | ||
short-summary: List Object Replication Service Policies associated with the specified storage account. | ||
examples: | ||
- name: List Object Replication Service Policies associated with the specified storage account. | ||
text: az storage account or-policy list -g ResourceGroupName -n StorageAccountName | ||
""" | ||
|
||
helps['storage account or-policy delete'] = """ | ||
type: command | ||
short-summary: Delete specified Object Replication Service Policy associated with the specified storage account. | ||
examples: | ||
- name: Delete Object Replication Service Policy associated with the specified storage account. | ||
text: az storage account or-policy delete -g ResourceGroupName -n StorageAccountName --policy-id "04344ea7-aa3c-4846-bfb9-e908e32d3bf8" | ||
""" | ||
|
||
helps['storage account or-policy show'] = """ | ||
type: command | ||
short-summary: Show the properties of specified Object Replication Service Policy for storage account. | ||
examples: | ||
- name: Show the properties of specified Object Replication Service Policy for storage account. | ||
text: az storage account or-policy show -g ResourceGroupName -n StorageAccountName --policy-id "04344ea7-aa3c-4846-bfb9-e908e32d3bf8" | ||
""" | ||
|
||
helps['storage account or-policy update'] = """ | ||
type: command | ||
short-summary: Update Object Replication Service Policy properties for storage account. | ||
examples: | ||
- name: Update source storage account in Object Replication Service Policy. | ||
text: az storage account or-policy update -g ResourceGroupName -n StorageAccountName --source-account newSourceAccount --policy-id "04344ea7-aa3c-4846-bfb9-e908e32d3bf8" | ||
- name: Update Object Replication Service Policy through json file. | ||
text: az storage account or-policy update -g ResourceGroupName -n StorageAccountName -p @policy.json | ||
""" | ||
|
||
helps['storage account or-policy rule'] = """ | ||
type: group | ||
short-summary: Manage Object Replication Service Policy Rules. | ||
""" | ||
|
||
helps['storage account or-policy rule add'] = """ | ||
type: command | ||
short-summary: Add rule to the specified Object Replication Service Policy. | ||
examples: | ||
- name: Add rule to the specified Object Replication Service Policy. | ||
text: az storage account or-policy rule add -g ResourceGroupName -n StorageAccountName --policy-id "04344ea7-aa3c-4846-bfb9-e908e32d3bf8" -d destContainer -s srcContainer | ||
""" | ||
|
||
helps['storage account or-policy rule list'] = """ | ||
type: command | ||
short-summary: List all the rules in the specified Object Replication Service Policy. | ||
examples: | ||
- name: List all the rules in the specified Object Replication Service Policy. | ||
text: az storage account or-policy rule list -g ResourceGroupName -n StorageAccountName --policy-id "04344ea7-aa3c-4846-bfb9-e908e32d3bf8" | ||
""" | ||
|
||
helps['storage account or-policy rule remove'] = """ | ||
type: command | ||
short-summary: Remove the specified rule from the specified Object Replication Service Policy. | ||
examples: | ||
- name: Remove the specified rule from the specified Object Replication Service Policy. | ||
text: az storage account or-policy rule remove -g ResourceGroupName -n StorageAccountName --policy-id "04344ea7-aa3c-4846-bfb9-e908e32d3bf8" --rule-id "78746d86-d3b7-4397-a99c-0837e6741332" | ||
""" | ||
|
||
helps['storage account or-policy rule show'] = """ | ||
type: command | ||
short-summary: Show the properties of specified rule in Object Replication Service Policy. | ||
examples: | ||
- name: Show the properties of specified rule in Object Replication Service Policy. | ||
text: az storage account or-policy rule show -g ResourceGroupName -n StorageAccountName --policy-id "04344ea7-aa3c-4846-bfb9-e908e32d3bf8" --rule-id "78746d86-d3b7-4397-a99c-0837e6741332" | ||
""" | ||
|
||
helps['storage account or-policy rule update'] = """ | ||
type: command | ||
short-summary: Update rule properties to Object Replication Service Policy. | ||
examples: | ||
- name: Update rule properties to Object Replication Service Policy. | ||
text: az storage account or-policy rule update -g ResourceGroupName -n StorageAccountName --policy-id "04344ea7-aa3c-4846-bfb9-e908e32d3bf8" --rule-id "78746d86-d3b7-4397-a99c-0837e6741332" --prefix-match blobA blobB | ||
""" |
Oops, something went wrong.