-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[AKS] az aks command invoke: Add support for --no-wait
#22813
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 all commits
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 |
|---|---|---|
|
|
@@ -2655,7 +2655,7 @@ def aks_get_versions(cmd, client, location): | |
| return client.list_orchestrators(location, resource_type='managedClusters') | ||
|
|
||
|
|
||
| def aks_runcommand(cmd, client, resource_group_name, name, command_string="", command_files=None): | ||
| def aks_runcommand(cmd, client, resource_group_name, name, command_string="", command_files=None, no_wait=False): | ||
| colorama.init() | ||
|
|
||
| mc = client.get(resource_group_name, name) | ||
|
|
@@ -2674,21 +2674,49 @@ def aks_runcommand(cmd, client, resource_group_name, name, command_string="", co | |
| request_payload.cluster_token = _get_dataplane_aad_token( | ||
| cmd.cli_ctx, "6dae42f8-4368-4678-94ff-3960e28e3630") | ||
|
|
||
| commandResultFuture = client.begin_run_command( | ||
| resource_group_name, name, request_payload, polling_interval=5, retry_total=0) | ||
|
|
||
| return _print_command_result(cmd.cli_ctx, commandResultFuture.result(300)) | ||
| command_result_poller = sdk_no_wait( | ||
| no_wait, client.begin_run_command, resource_group_name, name, request_payload, polling_interval=5, retry_total=0 | ||
| ) | ||
| if no_wait: | ||
| # pylint: disable=protected-access | ||
| command_result_polling_url = command_result_poller.polling_method()._initial_response.http_response.headers[ | ||
| "location" | ||
| ] | ||
| command_id_regex = re.compile(r"commandResults\/(\w*)\?") | ||
| command_id = command_id_regex.findall(command_result_polling_url)[0] | ||
| _aks_command_result_in_progess_helper(client, resource_group_name, name, command_id) | ||
| return | ||
| return _print_command_result(cmd.cli_ctx, command_result_poller.result(300)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we condition this on no_wait parameter? if no_wait==true
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
|
|
||
| def aks_command_result(cmd, client, resource_group_name, name, command_id=""): | ||
| if not command_id: | ||
| raise ValidationError('CommandID cannot be empty.') | ||
|
|
||
| commandResult = client.get_command_result( | ||
| resource_group_name, name, command_id) | ||
| commandResult = client.get_command_result(resource_group_name, name, command_id) | ||
| if commandResult is None: | ||
| _aks_command_result_in_progess_helper(client, resource_group_name, name, command_id) | ||
| return | ||
|
Comment on lines
+2697
to
+2699
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The SDK will not parse the response result of the query corresponding to the command that is still in running state. |
||
| return _print_command_result(cmd.cli_ctx, commandResult) | ||
|
|
||
|
|
||
| def _aks_command_result_in_progess_helper(client, resource_group_name, name, command_id): | ||
| # pylint: disable=unused-argument | ||
| def command_result_direct_response_handler(pipeline_response, *args, **kwargs): | ||
| deserialized_data = pipeline_response.context.get("deserialized_data", {}) | ||
| if deserialized_data: | ||
| provisioning_state = deserialized_data.get("properties", {}).get("provisioningState", None) | ||
| started_at = deserialized_data.get("properties", {}).get("startedAt", None) | ||
| print(f"command id: {command_id}, started at: {started_at}, status: {provisioning_state}") | ||
| print( | ||
| f"Please use command \"az aks command result -g {resource_group_name} -n {name} -i {command_id}\" " | ||
| "to get the future execution result" | ||
| ) | ||
| else: | ||
| print(f"failed to fetch command result for command id: {command_id}") | ||
zhoxing-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| client.get_command_result(resource_group_name, name, command_id, cls=command_result_direct_response_handler) | ||
|
|
||
|
|
||
| def _print_command_result(cli_ctx, commandResult): | ||
| # cli_ctx.data['safe_params'] contains list of parameter name user typed in, without value. | ||
| # cli core also use this calculate ParameterSetName header for all http request from cli. | ||
|
|
@@ -2715,8 +2743,8 @@ def _print_command_result(cli_ctx, commandResult): | |
| return | ||
|
|
||
| # *-ing state | ||
| print(f"{colorama.Fore.BLUE}command is in : {commandResult.provisioning_state} state{colorama.Style.RESET_ALL}") | ||
| return None | ||
| print(f"{colorama.Fore.BLUE}command is in {commandResult.provisioning_state} state{colorama.Style.RESET_ALL}") | ||
| return | ||
|
Comment on lines
+2746
to
+2747
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed a misleading colon ( |
||
|
|
||
|
|
||
| def _get_command_context(command_files): | ||
|
|
||

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.
The initial response content of the request is empty. The API path to query command result can only be obtained through the location field in the header of the response.