Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Comment on lines +2682 to +2686
Copy link
Member Author

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.

_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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we condition this on no_wait parameter?

if no_wait==true
print command id
instruct how to fetch result with "az aks command result"
else
...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, a sample screenshot
image



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
Copy link
Member Author

Choose a reason for hiding this comment

The 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}")
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.
Expand All @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed a misleading colon (:).



def _get_command_context(command_files):
Expand Down