-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Storage] az storage blob copy start: Support --tier and --rehydrate-priority
#18170
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
Changes from 7 commits
0827885
10273d3
c4ee8c6
632cf00
29aed82
3782060
db83e41
e0a1962
6889a60
2d89847
07057b0
b3594bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -387,6 +387,111 @@ def validate_source_uri(cmd, namespace): # pylint: disable=too-many-statements | |
| namespace.copy_source = uri | ||
|
|
||
|
|
||
| def validate_source_url(cmd, namespace): # pylint: disable=too-many-statements | ||
| from .util import create_short_lived_blob_sas, create_short_lived_file_sas | ||
| usage_string = \ | ||
| 'Invalid usage: {}. Supply only one of the following argument sets to specify source:' \ | ||
| '\n\t --source-uri [--source-sas]' \ | ||
| '\n\tOR --source-container --source-blob [--source-account-name & sas] [--source-snapshot]' \ | ||
| '\n\tOR --source-container --source-blob [--source-account-name & key] [--source-snapshot]' \ | ||
| '\n\tOR --source-share --source-path' \ | ||
| '\n\tOR --source-share --source-path [--source-account-name & sas]' \ | ||
| '\n\tOR --source-share --source-path [--source-account-name & key]' | ||
|
|
||
| ns = vars(namespace) | ||
|
|
||
| # source as blob | ||
| container = ns.pop('source_container', None) | ||
| blob = ns.pop('source_blob', None) | ||
| snapshot = ns.pop('source_snapshot', None) | ||
|
|
||
| # source as file | ||
| share = ns.pop('source_share', None) | ||
| path = ns.pop('source_path', None) | ||
| file_snapshot = ns.pop('file_snapshot', None) | ||
|
|
||
| # source credential clues | ||
| source_account_name = ns.pop('source_account_name', None) | ||
| source_account_key = ns.pop('source_account_key', None) | ||
| source_sas = ns.pop('source_sas', None) | ||
|
|
||
| # source in the form of an uri | ||
| uri = ns.get('source_url', None) | ||
| if uri: | ||
| if any([container, blob, snapshot, share, path, file_snapshot, source_account_name, | ||
| source_account_key]): | ||
| raise ValueError(usage_string.format('Unused parameters are given in addition to the ' | ||
| 'source URI')) | ||
| if source_sas: | ||
| source_sas = source_sas.lstrip('?') | ||
| uri = '{}{}{}'.format(uri, '?', source_sas) | ||
| namespace.copy_source = uri | ||
| return | ||
|
|
||
| # ensure either a file or blob source is specified | ||
| valid_blob_source = container and blob and not share and not path and not file_snapshot | ||
| valid_file_source = share and path and not container and not blob and not snapshot | ||
|
|
||
| if not valid_blob_source and not valid_file_source: | ||
| raise ValueError(usage_string.format('Neither a valid blob or file source is specified')) | ||
|
||
| if valid_blob_source and valid_file_source: | ||
| raise ValueError(usage_string.format('Ambiguous parameters, both blob and file sources are ' | ||
| 'specified')) | ||
|
||
|
|
||
| validate_client_parameters(cmd, namespace) # must run first to resolve storage account | ||
|
|
||
| if not source_account_name: | ||
| if source_account_key: | ||
| raise ValueError(usage_string.format('Source account key is given but account name is not')) | ||
|
||
| # assume that user intends to copy blob in the same account | ||
| source_account_name = ns.get('account_name', None) | ||
|
|
||
| # determine if the copy will happen in the same storage account | ||
| same_account = False | ||
|
|
||
| if not source_account_key and not source_sas: | ||
| if source_account_name == ns.get('account_name', None): | ||
| same_account = True | ||
| source_account_key = ns.get('account_key', None) | ||
| source_sas = ns.get('sas_token', None) | ||
| else: | ||
| # the source account is different from destination account but the key is missing try to query one. | ||
| try: | ||
| source_account_key = _query_account_key(cmd.cli_ctx, source_account_name) | ||
| except ValueError: | ||
| raise ValueError('Source storage account {} not found.'.format(source_account_name)) | ||
|
||
|
|
||
| # Both source account name and either key or sas (or both) are now available | ||
| if not source_sas: | ||
| # generate a sas token even in the same account when the source and destination are not the same kind. | ||
| if valid_file_source and (ns.get('container_name', None) or not same_account): | ||
| import os | ||
| dir_name, file_name = os.path.split(path) if path else (None, '') | ||
| source_sas = create_short_lived_file_sas(cmd, source_account_name, source_account_key, share, | ||
| dir_name, file_name) | ||
| elif valid_blob_source and (ns.get('share_name', None) or not same_account): | ||
| source_sas = create_short_lived_blob_sas(cmd, source_account_name, source_account_key, container, blob) | ||
|
|
||
| query_params = [] | ||
| if source_sas: | ||
| query_params.append(source_sas.lstrip('?')) | ||
| if snapshot: | ||
| query_params.append('snapshot={}'.format(snapshot)) | ||
| if file_snapshot: | ||
| query_params.append('sharesnapshot={}'.format(file_snapshot)) | ||
|
|
||
| uri = 'https://{0}.{1}.{6}/{2}/{3}{4}{5}'.format( | ||
| source_account_name, | ||
| 'blob' if valid_blob_source else 'file', | ||
| container if valid_blob_source else share, | ||
| encode_for_url(blob if valid_blob_source else path), | ||
| '?' if query_params else '', | ||
| '&'.join(query_params), | ||
| cmd.cli_ctx.cloud.suffixes.storage_endpoint) | ||
|
|
||
| namespace.source_url = uri | ||
|
|
||
|
|
||
| def validate_blob_type(namespace): | ||
| if not namespace.blob_type: | ||
| namespace.blob_type = 'page' if namespace.file_path.endswith('.vhd') else 'block' | ||
|
|
||
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we consider using the specific error type
InvalidArgumentValueErrorinstead ofValueErrorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated