From 7ea256aa1960cdb2846aae41d5b4e8349ddf25b5 Mon Sep 17 00:00:00 2001 From: songlu <37168047+PARADISSEEKR@users.noreply.github.com> Date: Fri, 30 Jul 2021 10:42:43 +0800 Subject: [PATCH] [Storage] `az storage copy` add new option `--cap-mbps` (#18344) * [storage] Add new option `--cap-mbps` * Update azcopy.py * Update test_storage_azcopy_scenarios.py * Update src/azure-cli/azure/cli/command_modules/storage/_params_azure_stack.py Co-authored-by: Zunli Hu Co-authored-by: Zunli Hu --- src/azure-cli/azure/cli/command_modules/storage/_params.py | 3 +++ .../azure/cli/command_modules/storage/_params_azure_stack.py | 3 +++ .../azure/cli/command_modules/storage/operations/azcopy.py | 5 ++++- .../storage/tests/latest/test_storage_azcopy_scenarios.py | 4 ++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/storage/_params.py b/src/azure-cli/azure/cli/command_modules/storage/_params.py index 9b47b806e2d..c286e8ed6c2 100644 --- a/src/azure-cli/azure/cli/command_modules/storage/_params.py +++ b/src/azure-cli/azure/cli/command_modules/storage/_params.py @@ -990,6 +990,9 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem c.argument('content_type', arg_group='Additional Flags', help="Specify content type of the file. ") c.argument('follow_symlinks', arg_group='Additional Flags', action='store_true', help='Follow symbolic links when uploading from local file system.') + c.argument('cap_mbps', arg_group='Additional Flags', help="Caps the transfer rate, in megabits per second. " + "Moment-by-moment throughput might vary slightly from the cap. " + "If this option is set to zero, or it is omitted, the throughput isn't capped. ") with self.argument_context('storage blob copy') as c: for item in ['destination', 'source']: diff --git a/src/azure-cli/azure/cli/command_modules/storage/_params_azure_stack.py b/src/azure-cli/azure/cli/command_modules/storage/_params_azure_stack.py index 25841cb0d2e..40f459b2fd0 100644 --- a/src/azure-cli/azure/cli/command_modules/storage/_params_azure_stack.py +++ b/src/azure-cli/azure/cli/command_modules/storage/_params_azure_stack.py @@ -634,6 +634,9 @@ def load_arguments(self, _): # pylint: disable=too-many-locals, too-many-statem c.argument('content_type', arg_group='Additional Flags', help="Specify content type of the file. ") c.argument('follow_symlinks', arg_group='Additional Flags', action='store_true', help='Follow symbolic links when uploading from local file system.') + c.argument('cap_mbps', arg_group='Additional Flags', help="Cap the transfer rate, in megabits per second. " + "Moment-by-moment throughput might vary slightly from the cap. " + "If this option is set to zero, or it is omitted, the throughput isn't capped. ") with self.argument_context('storage blob copy') as c: for item in ['destination', 'source']: diff --git a/src/azure-cli/azure/cli/command_modules/storage/operations/azcopy.py b/src/azure-cli/azure/cli/command_modules/storage/operations/azcopy.py index ce76eead051..f79e9343262 100644 --- a/src/azure-cli/azure/cli/command_modules/storage/operations/azcopy.py +++ b/src/azure-cli/azure/cli/command_modules/storage/operations/azcopy.py @@ -9,7 +9,8 @@ # pylint: disable=too-many-statements, too-many-locals, unused-argument def storage_copy(source, destination, put_md5=None, recursive=None, blob_type=None, preserve_s2s_access_tier=None, content_type=None, follow_symlinks=None, - exclude_pattern=None, include_pattern=None, exclude_path=None, include_path=None, **kwargs): + exclude_pattern=None, include_pattern=None, exclude_path=None, include_path=None, + cap_mbps=None, **kwargs): azcopy = AzCopy() flags = [] @@ -33,6 +34,8 @@ def storage_copy(source, destination, put_md5=None, recursive=None, blob_type=No flags.append('--content-type=' + content_type) if follow_symlinks is not None: flags.append('--follow-symlinks=true') + if cap_mbps is not None: + flags.append('--cap-mbps=' + cap_mbps) azcopy.copy(source, destination, flags=flags) diff --git a/src/azure-cli/azure/cli/command_modules/storage/tests/latest/test_storage_azcopy_scenarios.py b/src/azure-cli/azure/cli/command_modules/storage/tests/latest/test_storage_azcopy_scenarios.py index 809e7263000..f2fd279d31d 100644 --- a/src/azure-cli/azure/cli/command_modules/storage/tests/latest/test_storage_azcopy_scenarios.py +++ b/src/azure-cli/azure/cli/command_modules/storage/tests/latest/test_storage_azcopy_scenarios.py @@ -655,7 +655,7 @@ def test_storage_azcopy_file_url(self, resource_group, storage_account_info, tes import os # Upload a single file - self.cmd('storage copy -s "{}" -d "{}"' + self.cmd('storage copy -s "{}" -d "{}" --cap-mbps 1.0' .format(os.path.join(test_dir, 'readme'), share_url)) self.cmd('storage file list -s {} --account-name {}' .format(share, storage_account), checks=JMESPathCheck('length(@)', 1)) @@ -699,7 +699,7 @@ def test_storage_azcopy_file_account(self, resource_group, storage_account_info, import os # Upload a single file - self.cmd('storage copy --source-local-path "{}" --destination-account-name {} --destination-share {}' + self.cmd('storage copy --source-local-path "{}" --destination-account-name {} --destination-share {} --cap-mbps 1.0' .format(os.path.join(test_dir, 'readme'), storage_account, share)) self.cmd('storage file list -s {} --account-name {}' .format(share, storage_account), checks=JMESPathCheck('length(@)', 1))