Skip to content

Commit

Permalink
[Storage] az storage copy add new option --cap-mbps (#18344)
Browse files Browse the repository at this point in the history
* [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 <[email protected]>

Co-authored-by: Zunli Hu <[email protected]>
  • Loading branch information
Jing-song and Juliehzl authored Jul 30, 2021
1 parent 4a8879f commit 7ea256a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/azure-cli/azure/cli/command_modules/storage/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 7ea256a

Please sign in to comment.