From f129c948e1e4e5101d73b7f5c3079a3b34ab8a52 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Mon, 26 Jul 2021 17:46:39 -0600 Subject: [PATCH 01/14] custom action for script execution params --- src/vmware/CHANGELOG.md | 3 ++ src/vmware/azext_vmware/_params.py | 13 +++++ src/vmware/azext_vmware/action.py | 57 ++++++++++++++++++++ src/vmware/azext_vmware/commands.py | 15 ++++++ src/vmware/azext_vmware/custom.py | 38 +++++++++++++ src/vmware/azext_vmware/tests/test_action.py | 18 +++++++ 6 files changed, 144 insertions(+) create mode 100644 src/vmware/azext_vmware/action.py create mode 100644 src/vmware/azext_vmware/tests/test_action.py diff --git a/src/vmware/CHANGELOG.md b/src/vmware/CHANGELOG.md index 610aa1dd767..0ce93ae0073 100644 --- a/src/vmware/CHANGELOG.md +++ b/src/vmware/CHANGELOG.md @@ -2,6 +2,9 @@ ## 3.1.0 (2021-07) - Add `az vmware cloud-link` command group +- Add `az vmware script-cmdlet` command group +- Add `az vmware script-execution` command group +- Add `az vmware script-package` command group ## 3.0.0 (2021-07) - [BREAKING CHANGE] `az vmware datastore create` has been removed. Please use `az vmware datastore netapp-volume create` or `az vmware datastore disk-pool-volume create` instead. diff --git a/src/vmware/azext_vmware/_params.py b/src/vmware/azext_vmware/_params.py index db87f476b88..55b908a9672 100644 --- a/src/vmware/azext_vmware/_params.py +++ b/src/vmware/azext_vmware/_params.py @@ -5,6 +5,9 @@ # pylint: disable=line-too-long,too-many-statements +from azext_vmware.action import ScriptExecutionParameterAction + + def load_arguments(self, _): from azure.cli.core.commands.parameters import tags_type @@ -111,3 +114,13 @@ def load_arguments(self, _): with self.argument_context('vmware cloud-link') as c: c.argument('name', options_list=['--name', '-n'], help='The name of the cloud link.') c.argument('linked_cloud', help='Identifier of the other private cloud participating in the link.') + + with self.argument_context('vmware script-execution create') as c: + c.argument('name', options_list=['--name', '-n'], help='Name of the script execution.') + c.argument('timeout', help='Time limit for execution.') + c.argument('parameters', options_list=['--parameter', '-p'], action=ScriptExecutionParameterAction, nargs='*', help='Parameters the script will accept.') + c.argument('hidden_parameters', options_list=['--hidden-parameter', '-hp'], action=ScriptExecutionParameterAction, nargs='*', help='Parameters that will be hidden/not visible to ARM, such as passwords and credentials.') + c.argument('failure_reason', help='Error message if the script was able to run, but if the script itself had errors or powershell threw an exception.') + c.argument('retention', help='Time to live for the resource. If not provided, will be available for 60 days.') + c.argument('out', help='Standard output stream from the powershell execution.') + # c.argument('named_output', help='Dictionary in pair.') diff --git a/src/vmware/azext_vmware/action.py b/src/vmware/azext_vmware/action.py new file mode 100644 index 00000000000..d09e44481f2 --- /dev/null +++ b/src/vmware/azext_vmware/action.py @@ -0,0 +1,57 @@ + +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import argparse +from typing import Dict, List +from knack.util import CLIError +from azext_vmware.vendored_sdks.avs_client.models import ScriptExecutionParameter, ScriptExecutionParameterType, ScriptStringExecutionParameter, ScriptSecureStringExecutionParameter, PSCredentialExecutionParameter + + +class ScriptExecutionParameterAction(argparse._AppendAction): + + def __call__(self, parser, namespace, values, option_string=None): + print("action called with") + print(values) + parameter = script_execution_parameters(values) + if namespace.parameters: + namespace.parameters.append(parameter) + else: + namespace.parameters = [parameter] + + +def script_execution_parameters(values: List[str]) -> ScriptExecutionParameter: + values = dict(map(lambda x: x.split('=', 1), values)) + type = require(values, "type") + type_lower = type.lower() + + if type_lower == ScriptExecutionParameterType.VALUE.lower(): + try: + return ScriptStringExecutionParameter(name=require(values, "name"), value=values.get("value")) + except CLIError as error: + raise CLIError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.VALUE)) from error + + elif type_lower == ScriptExecutionParameterType.SECURE_VALUE.lower(): + try: + return ScriptSecureStringExecutionParameter(name=require(values, "name"), secure_value=values.get("secureValue")) + except CLIError as error: + raise CLIError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.SECURE_VALUE)) from error + + elif type_lower == ScriptExecutionParameterType.CREDENTIAL.lower(): + try: + return PSCredentialExecutionParameter(name=require(values, "name"), username=values.get("username"), password=values.get("password")) + except CLIError as error: + raise CLIError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.CREDENTIAL)) from error + + else: + raise CLIError('script execution paramater type \'{}\' not matched'.format(type)) + + +def require(values: Dict[str, str], key: str) -> str: + '''Gets the required script execution parameter or raises a CLIError.''' + value = values.get(key) + if value is None: + raise CLIError('script execution parameter \'{}\' required'.format(key)) + return value diff --git a/src/vmware/azext_vmware/commands.py b/src/vmware/azext_vmware/commands.py index cf6e55e4f69..8a24900a685 100644 --- a/src/vmware/azext_vmware/commands.py +++ b/src/vmware/azext_vmware/commands.py @@ -94,3 +94,18 @@ def load_command_table(self, _): g.custom_command('list', 'cloud_link_list') g.custom_command('delete', 'cloud_link_delete') g.custom_show_command('show', 'cloud_link_show') + + with self.command_group('vmware script-cmdlet', vmware_sdk, client_factory=cf_vmware) as g: + g.custom_command('list', 'script_cmdlet_list') + g.custom_show_command('show', 'script_cmdlet_show') + + with self.command_group('vmware script-package', vmware_sdk, client_factory=cf_vmware) as g: + g.custom_command('list', 'script_package_list') + g.custom_show_command('show', 'script_package_show') + + with self.command_group('vmware script-execution', vmware_sdk, client_factory=cf_vmware) as g: + g.custom_command('create', 'script_execution_create_or_update') + g.custom_command('update', 'script_execution_create_or_update') + g.custom_command('list', 'script_execution_list') + g.custom_command('delete', 'script_execution_delete') + g.custom_show_command('show', 'script_execution_show') diff --git a/src/vmware/azext_vmware/custom.py b/src/vmware/azext_vmware/custom.py index baef37e4f46..1ea34afb0a2 100644 --- a/src/vmware/azext_vmware/custom.py +++ b/src/vmware/azext_vmware/custom.py @@ -288,3 +288,41 @@ def cloud_link_show(client: AVSClient, resource_group_name, private_cloud, name) def cloud_link_delete(client: AVSClient, resource_group_name, private_cloud, name): return client.cloud_links.begin_delete(resource_group_name=resource_group_name, private_cloud_name=private_cloud, cloud_link_name=name) + + +def script_cmdlet_list(client: AVSClient, resource_group_name, private_cloud, script_package): + return client.script_cmdlets.list(resource_group_name=resource_group_name, private_cloud_name=private_cloud, script_package_name=script_package) + + +def script_cmdlet_show(client: AVSClient, resource_group_name, private_cloud, script_package, name): + return client.script_cmdlets.get(resource_group_name=resource_group_name, private_cloud_name=private_cloud, script_package_name=script_package, script_cmdlet_name=name) + + +def script_package_list(client: AVSClient, resource_group_name, private_cloud): + return client.script_packages.list(resource_group_name=resource_group_name, private_cloud_name=private_cloud) + + +def script_package_show(client: AVSClient, resource_group_name, private_cloud, name): + return client.script_packages.get(resource_group_name=resource_group_name, private_cloud_name=private_cloud, script_package_name=name) + + +def script_execution_create_or_update(client: AVSClient, resource_group_name, private_cloud, name, timeout, script_cmdlet_id=None, parameters=None, hidden_parameters=None, failure_reason=None, retention=None, out=None, named_outputs=None): + from azext_vmware.vendored_sdks.avs_client.models import ScriptExecution + script_execution = ScriptExecution(timeout=timeout, script_cmdlet_id=script_cmdlet_id, parameters=parameters, hidden_parameters=hidden_parameters, failure_reason=failure_reason, retention=retention, output=out, named_outputs=named_outputs) + return client.script_executions.begin_create_or_update(resource_group_name=resource_group_name, private_cloud_name=private_cloud, script_execution_name=name, script_execution=script_execution) + + +def script_execution_list(client: AVSClient, resource_group_name, private_cloud): + return client.script_executions.list(resource_group_name=resource_group_name, private_cloud_name=private_cloud) + + +def script_execution_show(client: AVSClient, resource_group_name, private_cloud, name): + return client.script_executions.get(resource_group_name=resource_group_name, private_cloud_name=private_cloud, global_reach_connection_name=name) + + +def script_execution_delete(client: AVSClient, resource_group_name, private_cloud, name): + return client.script_executions.begin_delete(resource_group_name=resource_group_name, private_cloud_name=private_cloud, global_reach_connection_name=name) + + +def script_execution_logs(client: AVSClient, resource_group_name, private_cloud, name): + return client.script_executions.get_execution_logs(resource_group_name=resource_group_name, private_cloud_name=private_cloud, global_reach_connection_name=name) diff --git a/src/vmware/azext_vmware/tests/test_action.py b/src/vmware/azext_vmware/tests/test_action.py new file mode 100644 index 00000000000..7cb48b76715 --- /dev/null +++ b/src/vmware/azext_vmware/tests/test_action.py @@ -0,0 +1,18 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from azext_vmware.action import script_execution_parameters +from azext_vmware.vendored_sdks.avs_client.models import ScriptStringExecutionParameter, ScriptSecureStringExecutionParameter, PSCredentialExecutionParameter + + +class TestAction: + def test_value_execution_parameter(self): + assert ScriptStringExecutionParameter(name="dog", value="Fred") == script_execution_parameters(["type=value", "name=dog", "value=Fred"]) + + def test_secure_value_execution_parameter(self): + assert ScriptSecureStringExecutionParameter(name="cat", secure_value="George") == script_execution_parameters(["type=SecureValue", "name=cat", "secureValue=George"]) + + def test_credential_execution_parameter(self): + assert PSCredentialExecutionParameter(name="creds", username="Jim", password="bob") == script_execution_parameters(["type=credential", "name=creds", "username=Jim", "password=bob"]) From 74ced2d0a49ea5fe56edd6c6dc892e5b4a32dff4 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Wed, 28 Jul 2021 23:09:16 -0600 Subject: [PATCH 02/14] script-execution tests recorded --- src/vmware/azext_vmware/_help.py | 74 +++++++-- src/vmware/azext_vmware/_params.py | 6 +- src/vmware/azext_vmware/action.py | 2 - src/vmware/azext_vmware/commands.py | 6 +- src/vmware/azext_vmware/custom.py | 10 +- .../test_vmware_script_execution.yaml | 143 ++++++++++++++++++ .../tests/latest/test_script_scenario.py | 37 +++++ 7 files changed, 256 insertions(+), 22 deletions(-) create mode 100644 src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script_execution.yaml create mode 100644 src/vmware/azext_vmware/tests/latest/test_script_scenario.py diff --git a/src/vmware/azext_vmware/_help.py b/src/vmware/azext_vmware/_help.py index 117e6fbbfb0..a14a1406fad 100644 --- a/src/vmware/azext_vmware/_help.py +++ b/src/vmware/azext_vmware/_help.py @@ -384,20 +384,12 @@ helps['vmware cloud-link create'] = """ type: command - short-summary: Create a cloud link in a private cloud. + short-summary: Create or update a cloud link in a private cloud. examples: - name: Create a cloud link. text: az vmware cloud-link create --resource-group group1 --private-cloud cloud1 --name cloudLink1 --linked-cloud "/subscriptions/12341234-1234-1234-1234-123412341234/resourceGroups/mygroup/providers/Microsoft.AVS/privateClouds/cloud2" """ -helps['vmware cloud-link update'] = """ - type: command - short-summary: Create a cloud link in a private cloud. - examples: - - name: Update a cloud link. - text: az vmware cloud-link update --resource-group group1 --private-cloud cloud1 --name cloudLink1 --linked-cloud "/subscriptions/12341234-1234-1234-1234-123412341234/resourceGroups/mygroup/providers/Microsoft.AVS/privateClouds/cloud2" -""" - helps['vmware cloud-link list'] = """ type: command short-summary: List cloud links in a private cloud. @@ -421,3 +413,67 @@ - name: Delete a cloud link. text: az vmware cloud-link delete --resource-group group1 --private-cloud cloud1 --name cloudLink1 """ + +helps['vmware script-cmdlet list'] = """ + type: command + short-summary: List script cmdlet resources available for a private cloud to create a script execution resource on a private cloud. + examples: + - name: List cloud links. + text: az vmware script-cmdlet --resource-group group1 --private-cloud cloud1 --script-package package1 +""" + +helps['vmware script-cmdlet show'] = """ + type: command + short-summary: Get information about a script cmdlet resource in a specific package on a private cloud. + examples: + - name: Show a cloud link. + text: az vmware script-cmdlet show --resource-group group1 --private-cloud cloud1 --script-package package1 --name cmdlet1 +""" + +helps['vmware script-package list'] = """ + type: command + short-summary: List script packages available to run on the private cloud. + examples: + - name: List cloud links. + text: az vmware script-package list --resource-group group1 --private-cloud cloud1 +""" + +helps['vmware script-package show'] = """ + type: command + short-summary: Get a script package available to run on a private cloud. + examples: + - name: Show a cloud link. + text: az vmware script-package show --resource-group group1 --private-cloud cloud1 --name package1 +""" + +helps['vmware script-execution create'] = """ + type: command + short-summary: Create or update a script execution in a private cloud. + examples: + - name: Create a cloud link. + text: az vmware script-execution create --resource-group group1 --private-cloud cloud1 --name addSsoServer --sciprt-cmdlet-id "/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource" --timeout P0Y0M0DT0H60M60S --retention P0Y0M60DT0H60M60S --parameter name=DomainName type=Value value=placeholderDomain.local --parameter name=BaseUserDN type=Value "value=DC=placeholder, DC=placeholder" --hidden-parameter name=Password type=SecureValue secureValue=PlaceholderPassword +""" + +helps['vmware script-execution list'] = """ + type: command + short-summary: List script executions in a private cloud. + examples: + - name: List cloud links. + text: az vmware script-execution list --resource-group group1 --private-cloud cloud1 +""" + +helps['vmware script-execution show'] = """ + type: command + short-summary: Get an script execution by name in a private cloud. + examples: + - name: Show a cloud link. + text: az vmware script-execution show --resource-group group1 --private-cloud cloud1 --name addSsoServer +""" + +helps['vmware script-execution delete'] = """ + type: command + short-summary: Delete a cloud link in a private cloud. + examples: + - name: Delete a cloud link. + text: az vmware script-execution delete --resource-group group1 --private-cloud cloud1 --name addSsoServer +""" diff --git a/src/vmware/azext_vmware/_params.py b/src/vmware/azext_vmware/_params.py index 55b908a9672..ccb7fe84309 100644 --- a/src/vmware/azext_vmware/_params.py +++ b/src/vmware/azext_vmware/_params.py @@ -115,12 +115,14 @@ def load_arguments(self, _): c.argument('name', options_list=['--name', '-n'], help='The name of the cloud link.') c.argument('linked_cloud', help='Identifier of the other private cloud participating in the link.') - with self.argument_context('vmware script-execution create') as c: + with self.argument_context('vmware script-execution') as c: c.argument('name', options_list=['--name', '-n'], help='Name of the script execution.') + + with self.argument_context('vmware script-execution create') as c: c.argument('timeout', help='Time limit for execution.') c.argument('parameters', options_list=['--parameter', '-p'], action=ScriptExecutionParameterAction, nargs='*', help='Parameters the script will accept.') c.argument('hidden_parameters', options_list=['--hidden-parameter', '-hp'], action=ScriptExecutionParameterAction, nargs='*', help='Parameters that will be hidden/not visible to ARM, such as passwords and credentials.') c.argument('failure_reason', help='Error message if the script was able to run, but if the script itself had errors or powershell threw an exception.') c.argument('retention', help='Time to live for the resource. If not provided, will be available for 60 days.') c.argument('out', help='Standard output stream from the powershell execution.') - # c.argument('named_output', help='Dictionary in pair.') + diff --git a/src/vmware/azext_vmware/action.py b/src/vmware/azext_vmware/action.py index d09e44481f2..5d96f61df43 100644 --- a/src/vmware/azext_vmware/action.py +++ b/src/vmware/azext_vmware/action.py @@ -13,8 +13,6 @@ class ScriptExecutionParameterAction(argparse._AppendAction): def __call__(self, parser, namespace, values, option_string=None): - print("action called with") - print(values) parameter = script_execution_parameters(values) if namespace.parameters: namespace.parameters.append(parameter) diff --git a/src/vmware/azext_vmware/commands.py b/src/vmware/azext_vmware/commands.py index 8a24900a685..8f0e7444997 100644 --- a/src/vmware/azext_vmware/commands.py +++ b/src/vmware/azext_vmware/commands.py @@ -89,8 +89,7 @@ def load_command_table(self, _): g.custom_show_command('show', 'globalreachconnection_show') with self.command_group('vmware cloud-link', vmware_sdk, client_factory=cf_vmware) as g: - g.custom_command('create', 'cloud_link_create_or_update') - g.custom_command('update', 'cloud_link_create_or_update') + g.custom_command('create', 'cloud_link_create') g.custom_command('list', 'cloud_link_list') g.custom_command('delete', 'cloud_link_delete') g.custom_show_command('show', 'cloud_link_show') @@ -104,8 +103,7 @@ def load_command_table(self, _): g.custom_show_command('show', 'script_package_show') with self.command_group('vmware script-execution', vmware_sdk, client_factory=cf_vmware) as g: - g.custom_command('create', 'script_execution_create_or_update') - g.custom_command('update', 'script_execution_create_or_update') + g.custom_command('create', 'script_execution_create') g.custom_command('list', 'script_execution_list') g.custom_command('delete', 'script_execution_delete') g.custom_show_command('show', 'script_execution_show') diff --git a/src/vmware/azext_vmware/custom.py b/src/vmware/azext_vmware/custom.py index 1ea34afb0a2..2ef2c9f207b 100644 --- a/src/vmware/azext_vmware/custom.py +++ b/src/vmware/azext_vmware/custom.py @@ -274,7 +274,7 @@ def globalreachconnection_delete(client: AVSClient, resource_group_name, private return client.global_reach_connections.begin_delete(resource_group_name=resource_group_name, private_cloud_name=private_cloud, global_reach_connection_name=name) -def cloud_link_create_or_update(client: AVSClient, resource_group_name, name, private_cloud, linked_cloud): +def cloud_link_create(client: AVSClient, resource_group_name, name, private_cloud, linked_cloud): return client.cloud_links.begin_create_or_update(resource_group_name=resource_group_name, private_cloud_name=private_cloud, cloud_link_name=name, linked_cloud=linked_cloud) @@ -306,7 +306,7 @@ def script_package_show(client: AVSClient, resource_group_name, private_cloud, n return client.script_packages.get(resource_group_name=resource_group_name, private_cloud_name=private_cloud, script_package_name=name) -def script_execution_create_or_update(client: AVSClient, resource_group_name, private_cloud, name, timeout, script_cmdlet_id=None, parameters=None, hidden_parameters=None, failure_reason=None, retention=None, out=None, named_outputs=None): +def script_execution_create(client: AVSClient, resource_group_name, private_cloud, name, timeout, script_cmdlet_id=None, parameters=None, hidden_parameters=None, failure_reason=None, retention=None, out=None, named_outputs=None): from azext_vmware.vendored_sdks.avs_client.models import ScriptExecution script_execution = ScriptExecution(timeout=timeout, script_cmdlet_id=script_cmdlet_id, parameters=parameters, hidden_parameters=hidden_parameters, failure_reason=failure_reason, retention=retention, output=out, named_outputs=named_outputs) return client.script_executions.begin_create_or_update(resource_group_name=resource_group_name, private_cloud_name=private_cloud, script_execution_name=name, script_execution=script_execution) @@ -317,12 +317,12 @@ def script_execution_list(client: AVSClient, resource_group_name, private_cloud) def script_execution_show(client: AVSClient, resource_group_name, private_cloud, name): - return client.script_executions.get(resource_group_name=resource_group_name, private_cloud_name=private_cloud, global_reach_connection_name=name) + return client.script_executions.get(resource_group_name=resource_group_name, private_cloud_name=private_cloud, script_execution_name=name) def script_execution_delete(client: AVSClient, resource_group_name, private_cloud, name): - return client.script_executions.begin_delete(resource_group_name=resource_group_name, private_cloud_name=private_cloud, global_reach_connection_name=name) + return client.script_executions.begin_delete(resource_group_name=resource_group_name, private_cloud_name=private_cloud, script_execution_name=name) def script_execution_logs(client: AVSClient, resource_group_name, private_cloud, name): - return client.script_executions.get_execution_logs(resource_group_name=resource_group_name, private_cloud_name=private_cloud, global_reach_connection_name=name) + return client.script_executions.get_execution_logs(resource_group_name=resource_group_name, private_cloud_name=private_cloud, script_execution_name=name) diff --git a/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script_execution.yaml b/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script_execution.yaml new file mode 100644 index 00000000000..fd84e1bc4aa --- /dev/null +++ b/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script_execution.yaml @@ -0,0 +1,143 @@ +interactions: +- request: + body: '{"properties": {"scriptCmdletId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource", + "parameters": [{"name": "DomainName", "type": "Value", "value": "placeholderDomain.local"}, + {"name": "BaseUserDN", "type": "Value", "value": "DC=placeholder, DC=placeholder"}, + {"name": "Password", "type": "SecureValue", "secureValue": "PlaceholderPassword"}], + "timeout": "P0Y0M0DT0H60M60S", "retention": "P0Y0M60DT0H60M60S"}}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-execution create + Connection: + - keep-alive + Content-Length: + - '564' + Content-Type: + - application/json + ParameterSetName: + - --resource-group --private-cloud --name --script-cmdlet-id --timeout --retention + --parameter --parameter --hidden-parameter + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 + response: + body: + string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer","name":"addSsoServer","type":"Microsoft.AVS/privateClouds/scriptExecutions","properties":{"scriptCmdletId":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource","parameters":[{"name":"DomainName","type":"Value"},{"name":"BaseUserDN","type":"Value"}],"failureReason":"vCenter + failed to connect to the external server","timeout":"P0Y0M0DT0H60M60S","retention":"P0Y0M60DT0H60M60S","provisioningState":"Succeeded","output":["IdentitySource: + placeholder.dc","BaseDN=''dc=placeholder, dc=local"]}}' + headers: + content-length: + - '759' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 05:03:44 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-execution list + Connection: + - keep-alive + ParameterSetName: + - -g -c + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions?api-version=2021-06-01 + response: + body: + string: '{"value":[{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer","name":"addSsoServer","type":"Microsoft.AVS/privateClouds/scriptExecutions","properties":{"scriptCmdletId":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS:1.0.0/scriptCmdlets/New-SsoExternalIdentitySource","parameters":[{"name":"DomainName","type":"Value"},{"name":"BaseUserDN","type":"Value"}],"failureReason":"vCenter + failed to connect to the external server","timeout":"P0Y0M0DT0H60M60S","retention":"P0Y0M60DT0H60M60S","submittedAt":"2021-03-21T17:31:28Z","startedAt":"2021-03-21T17:32:28Z","finishedAt":"2021-03-21T18:32:28Z","provisioningState":"Failed"}}]}' + headers: + content-length: + - '783' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 05:03:46 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-execution show + Connection: + - keep-alive + ParameterSetName: + - -g -c -n + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 + response: + body: + string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer","name":"addSsoServer","type":"Microsoft.AVS/privateClouds/scriptExecutions","properties":{"scriptCmdletId":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource","parameters":[{"name":"DomainName","type":"Value"},{"name":"BaseUserDN","type":"Value"}],"failureReason":"vCenter + failed to connect to the external server","timeout":"P0Y0M0DT0H60M60S","retention":"P0Y0M60DT0H60M60S","submittedAt":"2021-03-21T17:31:28Z","startedAt":"2021-03-21T17:32:28Z","finishedAt":"2021-03-21T18:32:28Z","provisioningState":"Succeeded"}}' + headers: + content-length: + - '788' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 05:03:48 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-execution delete + Connection: + - keep-alive + Content-Length: + - '0' + ParameterSetName: + - -g -c -n + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: DELETE + uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 + response: + body: + string: '' + headers: + content-length: + - '0' + date: + - Thu, 29 Jul 2021 05:03:50 GMT + server: + - Rocket + status: + code: 200 + message: OK +version: 1 diff --git a/src/vmware/azext_vmware/tests/latest/test_script_scenario.py b/src/vmware/azext_vmware/tests/latest/test_script_scenario.py new file mode 100644 index 00000000000..e89e5001462 --- /dev/null +++ b/src/vmware/azext_vmware/tests/latest/test_script_scenario.py @@ -0,0 +1,37 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# import os +# import unittest + +from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) + + +class VmwareScriptScenarioTest(ScenarioTest): + def setUp(self): + # https://vcrpy.readthedocs.io/en/latest/configuration.html#request-matching + self.vcr.match_on = ['scheme', 'method', 'path', 'query'] # not 'host', 'port' + super(VmwareScriptScenarioTest, self).setUp() + + @ResourceGroupPreparer(name_prefix='cli_test_vmware_script') + def test_vmware_script_execution(self): + self.kwargs.update({ + 'subscription': '12341234-1234-1234-1234-123412341234', + 'privatecloud': 'cloud1', + 'scriptExecution': 'addSsoServer', + }) + rsp = self.cmd('az vmware script-execution create --resource-group {rg} --private-cloud {privatecloud} --name {scriptExecution} --script-cmdlet-id "/subscriptions/{subscription}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource" --timeout P0Y0M0DT0H60M60S --retention P0Y0M60DT0H60M60S --parameter name=DomainName type=Value value=placeholderDomain.local --parameter name=BaseUserDN type=Value "value=DC=placeholder, DC=placeholder" --hidden-parameter name=Password type=SecureValue secureValue=PlaceholderPassword').get_output_in_json() + self.assertEqual(rsp['type'], 'Microsoft.AVS/privateClouds/scriptExecutions') + self.assertEqual(rsp['name'], self.kwargs.get('scriptExecution')) + + count = len(self.cmd('az vmware script-execution list -g {rg} -c {privatecloud}').get_output_in_json()) + self.assertEqual(count, 1, 'count expected to be 1') + + self.cmd('az vmware script-execution show -g {rg} -c {privatecloud} -n {scriptExecution}').get_output_in_json() + self.assertEqual(rsp['type'], 'Microsoft.AVS/privateClouds/scriptExecutions') + self.assertEqual(rsp['name'], self.kwargs.get('scriptExecution')) + + rsp = self.cmd('az vmware script-execution delete -g {rg} -c {privatecloud} -n {scriptExecution}').output + self.assertEqual(len(rsp), 0) From 0542e07b08b203e17d242fd8c83051f5d280628d Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 29 Jul 2021 11:37:17 -0600 Subject: [PATCH 03/14] package and cmdlet tests passing --- src/vmware/azext_vmware/_params.py | 7 + .../latest/recordings/test_vmware_script.yaml | 285 ++++++++++++++++++ .../test_vmware_script_execution.yaml | 158 +++++++++- .../tests/latest/test_cloud_link_scenario.py | 3 - .../tests/latest/test_script_scenario.py | 26 +- 5 files changed, 464 insertions(+), 15 deletions(-) create mode 100644 src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script.yaml diff --git a/src/vmware/azext_vmware/_params.py b/src/vmware/azext_vmware/_params.py index ccb7fe84309..07166636458 100644 --- a/src/vmware/azext_vmware/_params.py +++ b/src/vmware/azext_vmware/_params.py @@ -115,6 +115,13 @@ def load_arguments(self, _): c.argument('name', options_list=['--name', '-n'], help='The name of the cloud link.') c.argument('linked_cloud', help='Identifier of the other private cloud participating in the link.') + with self.argument_context('vmware script-package') as c: + c.argument('name', options_list=['--name', '-n'], help='Name of the script package.') + + with self.argument_context('vmware script-cmdlet') as c: + c.argument('script_package', options_list=['--script-package', '-p'], help='Name of the script package.') + c.argument('name', options_list=['--name', '-n'], help='Name of the script cmdlet.') + with self.argument_context('vmware script-execution') as c: c.argument('name', options_list=['--name', '-n'], help='Name of the script execution.') diff --git a/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script.yaml b/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script.yaml new file mode 100644 index 00000000000..a4f19365331 --- /dev/null +++ b/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script.yaml @@ -0,0 +1,285 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-package list + Connection: + - keep-alive + ParameterSetName: + - -g -c + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages?api-version=2021-06-01 + response: + body: + string: '{"value":[{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0","name":"AVS.PowerCommands@1.0.0","type":"Microsoft.AVS/privateClouds/scriptPackages","properties":{"description":"Various + cmdlets for elevated access to Private Cloud administrative functions","version":"1.0.0"}},{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/JSDR.Configuration@1.0","name":"JSDR.Configuration@1.0","type":"Microsoft.AVS/privateClouds/scriptPackages","properties":{"description":"Various + cmdlets by Jetstream for Private Cloud administration","version":"1.0.0"}}]}' + headers: + content-length: + - '713' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 17:36:01 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-package show + Connection: + - keep-alive + ParameterSetName: + - -g -c -n + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands%401.0.0?api-version=2021-06-01 + response: + body: + string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/{scriptPackageName}","name":"AVS.PowerCommands@1.0.0","type":"Microsoft.AVS/privateClouds/scriptPackages","properties":{"description":"Various + cmdlets for elevated access to Private Cloud administrative functions","version":"1.0.0"}}' + headers: + content-length: + - '355' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 17:36:01 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-cmdlet list + Connection: + - keep-alive + ParameterSetName: + - -g -c -p + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands%401.0.0/scriptCmdlets?api-version=2021-06-01 + response: + body: + string: '{"value":[{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/{scriptPackageName}/scriptCmdlets/Set-AvsStoragePolicy","name":"Set-AvsStoragePolicy","type":"Microsoft.AVS/privateClouds/scriptPackages/scriptCmdlets","properties":{"description":"Allow + user to set the storage policy of the specified VM","timeout":"P0Y0M0DT0H60M0S","parameters":[{"type":"String","name":"VM","description":"VM + to set the storage policy on","visibility":"Visible","optional":"Required"},{"type":"String","name":"StoragePolicyName","description":"Name + of the storage policy to set","visibility":"Visible","optional":"Required"}]}},{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/{scriptPackageName}/scriptCmdlets/New-ExternalSsoDomain","name":"New-ExternalSsoDomain","type":"Microsoft.AVS/privateClouds/scriptPackages/scriptCmdlets","properties":{"description":"Add + an external Sso domain to their vCenter","timeout":"P0Y0M0DT0H60M0S","parameters":[{"type":"String","name":"DomainName","description":"Domain + name of the Server","visibility":"Visible","optional":"Required"},{"type":"String","name":"BaseUserDN","description":"Base + User DN of the Server","visibility":"Visible","optional":"Required"},{"type":"SecureString","name":"Password","description":"Password + for authenticating to the server","visibility":"Hidden","optional":"Required"}]}}]}' + headers: + content-length: + - '1470' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 17:36:01 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-cmdlet show + Connection: + - keep-alive + ParameterSetName: + - -g -c -p -n + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands%401.0.0/scriptCmdlets/New-ExternalSsoDomain?api-version=2021-06-01 + response: + body: + string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/{privateCloudName}/scriptPackages/{scriptPackageName}/scriptCmdlets/New-ExternalSsoDomain","name":"New-ExternalSsoDomain","type":"Microsoft.AVS/privateClouds/scriptPackages/scriptCmdlets","properties":{"description":"Add + an external Sso domain to their vCenter","timeout":"P0Y0M0DT0H60M0S","parameters":[{"type":"String","name":"DomainName","description":"Domain + name of the Server","visibility":"Visible","optional":"Required"},{"type":"String","name":"BaseUserDN","description":"Base + User DN of the Server","visibility":"Visible","optional":"Required"},{"type":"SecureString","name":"Password","description":"Password + for authenticating to the server","visibility":"Hidden","optional":"Required"}]}}' + headers: + content-length: + - '801' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 17:36:01 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: '{"properties": {"scriptCmdletId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource", + "parameters": [{"name": "DomainName", "type": "Value", "value": "placeholderDomain.local"}, + {"name": "BaseUserDN", "type": "Value", "value": "DC=placeholder, DC=placeholder"}, + {"name": "Password", "type": "SecureValue", "secureValue": "PlaceholderPassword"}], + "timeout": "P0Y0M0DT0H60M60S", "retention": "P0Y0M60DT0H60M60S"}}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-execution create + Connection: + - keep-alive + Content-Length: + - '564' + Content-Type: + - application/json + ParameterSetName: + - --resource-group --private-cloud --name --script-cmdlet-id --timeout --retention + --parameter --parameter --hidden-parameter + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: PUT + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 + response: + body: + string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer","name":"addSsoServer","type":"Microsoft.AVS/privateClouds/scriptExecutions","properties":{"scriptCmdletId":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource","parameters":[{"name":"DomainName","type":"Value"},{"name":"BaseUserDN","type":"Value"}],"failureReason":"vCenter + failed to connect to the external server","timeout":"P0Y0M0DT0H60M60S","retention":"P0Y0M60DT0H60M60S","provisioningState":"Succeeded","output":["IdentitySource: + placeholder.dc","BaseDN=''dc=placeholder, dc=local"]}}' + headers: + content-length: + - '759' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 17:36:01 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-execution list + Connection: + - keep-alive + ParameterSetName: + - -g -c + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions?api-version=2021-06-01 + response: + body: + string: '{"value":[{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer","name":"addSsoServer","type":"Microsoft.AVS/privateClouds/scriptExecutions","properties":{"scriptCmdletId":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS:1.0.0/scriptCmdlets/New-SsoExternalIdentitySource","parameters":[{"name":"DomainName","type":"Value"},{"name":"BaseUserDN","type":"Value"}],"failureReason":"vCenter + failed to connect to the external server","timeout":"P0Y0M0DT0H60M60S","retention":"P0Y0M60DT0H60M60S","submittedAt":"2021-03-21T17:31:28Z","startedAt":"2021-03-21T17:32:28Z","finishedAt":"2021-03-21T18:32:28Z","provisioningState":"Failed"}}]}' + headers: + content-length: + - '783' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 17:36:02 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-execution show + Connection: + - keep-alive + ParameterSetName: + - -g -c -n + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 + response: + body: + string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer","name":"addSsoServer","type":"Microsoft.AVS/privateClouds/scriptExecutions","properties":{"scriptCmdletId":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource","parameters":[{"name":"DomainName","type":"Value"},{"name":"BaseUserDN","type":"Value"}],"failureReason":"vCenter + failed to connect to the external server","timeout":"P0Y0M0DT0H60M60S","retention":"P0Y0M60DT0H60M60S","submittedAt":"2021-03-21T17:31:28Z","startedAt":"2021-03-21T17:32:28Z","finishedAt":"2021-03-21T18:32:28Z","provisioningState":"Succeeded"}}' + headers: + content-length: + - '788' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 17:36:02 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-execution delete + Connection: + - keep-alive + Content-Length: + - '0' + ParameterSetName: + - -g -c -n + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: DELETE + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 + response: + body: + string: '' + headers: + content-length: + - '0' + date: + - Thu, 29 Jul 2021 17:36:02 GMT + server: + - Rocket + status: + code: 200 + message: OK +version: 1 diff --git a/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script_execution.yaml b/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script_execution.yaml index fd84e1bc4aa..eb00ccf13d3 100644 --- a/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script_execution.yaml +++ b/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script_execution.yaml @@ -1,4 +1,146 @@ interactions: +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-package list + Connection: + - keep-alive + ParameterSetName: + - -g -c + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages?api-version=2021-06-01 + response: + body: + string: '{"value":[{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0","name":"AVS.PowerCommands@1.0.0","type":"Microsoft.AVS/privateClouds/scriptPackages","properties":{"description":"Various + cmdlets for elevated access to Private Cloud administrative functions","version":"1.0.0"}},{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/JSDR.Configuration@1.0","name":"JSDR.Configuration@1.0","type":"Microsoft.AVS/privateClouds/scriptPackages","properties":{"description":"Various + cmdlets by Jetstream for Private Cloud administration","version":"1.0.0"}}]}' + headers: + content-length: + - '713' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 17:04:32 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-package show + Connection: + - keep-alive + ParameterSetName: + - -g -c -n + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands%401.0.0?api-version=2021-06-01 + response: + body: + string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/{scriptPackageName}","name":"AVS.PowerCommands@1.0.0","type":"Microsoft.AVS/privateClouds/scriptPackages","properties":{"description":"Various + cmdlets for elevated access to Private Cloud administrative functions","version":"1.0.0"}}' + headers: + content-length: + - '355' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 17:04:32 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-cmdlet list + Connection: + - keep-alive + ParameterSetName: + - -g -c -p + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands%401.0.0/scriptCmdlets?api-version=2021-06-01 + response: + body: + string: '{"value":[{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/{scriptPackageName}/scriptCmdlets/Set-AvsStoragePolicy","name":"Set-AvsStoragePolicy","type":"Microsoft.AVS/privateClouds/scriptPackages/scriptCmdlets","properties":{"description":"Allow + user to set the storage policy of the specified VM","timeout":"P0Y0M0DT0H60M0S","parameters":[{"type":"String","name":"VM","description":"VM + to set the storage policy on","visibility":"Visible","optional":"Required"},{"type":"String","name":"StoragePolicyName","description":"Name + of the storage policy to set","visibility":"Visible","optional":"Required"}]}},{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/{scriptPackageName}/scriptCmdlets/New-ExternalSsoDomain","name":"New-ExternalSsoDomain","type":"Microsoft.AVS/privateClouds/scriptPackages/scriptCmdlets","properties":{"description":"Add + an external Sso domain to their vCenter","timeout":"P0Y0M0DT0H60M0S","parameters":[{"type":"String","name":"DomainName","description":"Domain + name of the Server","visibility":"Visible","optional":"Required"},{"type":"String","name":"BaseUserDN","description":"Base + User DN of the Server","visibility":"Visible","optional":"Required"},{"type":"SecureString","name":"Password","description":"Password + for authenticating to the server","visibility":"Hidden","optional":"Required"}]}}]}' + headers: + content-length: + - '1470' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 17:04:32 GMT + server: + - Rocket + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + CommandName: + - vmware script-cmdlet show + Connection: + - keep-alive + ParameterSetName: + - -g -c -p -n + User-Agent: + - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) + method: GET + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands%401.0.0/scriptCmdlets/New-ExternalSsoDomain?api-version=2021-06-01 + response: + body: + string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/{privateCloudName}/scriptPackages/{scriptPackageName}/scriptCmdlets/New-ExternalSsoDomain","name":"New-ExternalSsoDomain","type":"Microsoft.AVS/privateClouds/scriptPackages/scriptCmdlets","properties":{"description":"Add + an external Sso domain to their vCenter","timeout":"P0Y0M0DT0H60M0S","parameters":[{"type":"String","name":"DomainName","description":"Domain + name of the Server","visibility":"Visible","optional":"Required"},{"type":"String","name":"BaseUserDN","description":"Base + User DN of the Server","visibility":"Visible","optional":"Required"},{"type":"SecureString","name":"Password","description":"Password + for authenticating to the server","visibility":"Hidden","optional":"Required"}]}}' + headers: + content-length: + - '801' + content-type: + - application/json + date: + - Thu, 29 Jul 2021 17:04:32 GMT + server: + - Rocket + status: + code: 200 + message: OK - request: body: '{"properties": {"scriptCmdletId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource", "parameters": [{"name": "DomainName", "type": "Value", "value": "placeholderDomain.local"}, @@ -24,7 +166,7 @@ interactions: User-Agent: - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) method: PUT - uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 response: body: string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer","name":"addSsoServer","type":"Microsoft.AVS/privateClouds/scriptExecutions","properties":{"scriptCmdletId":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource","parameters":[{"name":"DomainName","type":"Value"},{"name":"BaseUserDN","type":"Value"}],"failureReason":"vCenter @@ -36,7 +178,7 @@ interactions: content-type: - application/json date: - - Thu, 29 Jul 2021 05:03:44 GMT + - Thu, 29 Jul 2021 17:04:32 GMT server: - Rocket status: @@ -58,7 +200,7 @@ interactions: User-Agent: - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) method: GET - uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions?api-version=2021-06-01 + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions?api-version=2021-06-01 response: body: string: '{"value":[{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer","name":"addSsoServer","type":"Microsoft.AVS/privateClouds/scriptExecutions","properties":{"scriptCmdletId":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS:1.0.0/scriptCmdlets/New-SsoExternalIdentitySource","parameters":[{"name":"DomainName","type":"Value"},{"name":"BaseUserDN","type":"Value"}],"failureReason":"vCenter @@ -69,7 +211,7 @@ interactions: content-type: - application/json date: - - Thu, 29 Jul 2021 05:03:46 GMT + - Thu, 29 Jul 2021 17:04:34 GMT server: - Rocket status: @@ -91,7 +233,7 @@ interactions: User-Agent: - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) method: GET - uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 response: body: string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer","name":"addSsoServer","type":"Microsoft.AVS/privateClouds/scriptExecutions","properties":{"scriptCmdletId":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource","parameters":[{"name":"DomainName","type":"Value"},{"name":"BaseUserDN","type":"Value"}],"failureReason":"vCenter @@ -102,7 +244,7 @@ interactions: content-type: - application/json date: - - Thu, 29 Jul 2021 05:03:48 GMT + - Thu, 29 Jul 2021 17:04:34 GMT server: - Rocket status: @@ -126,7 +268,7 @@ interactions: User-Agent: - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) method: DELETE - uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 + uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 response: body: string: '' @@ -134,7 +276,7 @@ interactions: content-length: - '0' date: - - Thu, 29 Jul 2021 05:03:50 GMT + - Thu, 29 Jul 2021 17:04:34 GMT server: - Rocket status: diff --git a/src/vmware/azext_vmware/tests/latest/test_cloud_link_scenario.py b/src/vmware/azext_vmware/tests/latest/test_cloud_link_scenario.py index 1bb6f574211..ba3533a1b7b 100644 --- a/src/vmware/azext_vmware/tests/latest/test_cloud_link_scenario.py +++ b/src/vmware/azext_vmware/tests/latest/test_cloud_link_scenario.py @@ -3,9 +3,6 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -# import os -# import unittest - from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) diff --git a/src/vmware/azext_vmware/tests/latest/test_script_scenario.py b/src/vmware/azext_vmware/tests/latest/test_script_scenario.py index e89e5001462..13c62d02b93 100644 --- a/src/vmware/azext_vmware/tests/latest/test_script_scenario.py +++ b/src/vmware/azext_vmware/tests/latest/test_script_scenario.py @@ -3,9 +3,6 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -# import os -# import unittest - from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) @@ -16,12 +13,29 @@ def setUp(self): super(VmwareScriptScenarioTest, self).setUp() @ResourceGroupPreparer(name_prefix='cli_test_vmware_script') - def test_vmware_script_execution(self): + def test_vmware_script(self): self.kwargs.update({ 'subscription': '12341234-1234-1234-1234-123412341234', 'privatecloud': 'cloud1', 'scriptExecution': 'addSsoServer', + 'scriptPackage': 'AVS.PowerCommands@1.0.0', + 'scriptCmdlet': 'New-ExternalSsoDomain' }) + + count = len(self.cmd('az vmware script-package list -g {rg} -c {privatecloud}').get_output_in_json()) + self.assertEqual(count, 2, 'count expected to be 2') + + rsp = self.cmd('az vmware script-package show -g {rg} -c {privatecloud} -n {scriptPackage}').get_output_in_json() + self.assertEqual(rsp['type'], 'Microsoft.AVS/privateClouds/scriptPackages') + self.assertEqual(rsp['name'], self.kwargs.get('scriptPackage')) + + count = len(self.cmd('az vmware script-cmdlet list -g {rg} -c {privatecloud} -p {scriptPackage}').get_output_in_json()) + self.assertEqual(count, 2, 'count expected to be 2') + + rsp = self.cmd('az vmware script-cmdlet show -g {rg} -c {privatecloud} -p {scriptPackage} -n {scriptCmdlet}').get_output_in_json() + self.assertEqual(rsp['type'], 'Microsoft.AVS/privateClouds/scriptPackages/scriptCmdlets') + self.assertEqual(rsp['name'], self.kwargs.get('scriptCmdlet')) + rsp = self.cmd('az vmware script-execution create --resource-group {rg} --private-cloud {privatecloud} --name {scriptExecution} --script-cmdlet-id "/subscriptions/{subscription}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource" --timeout P0Y0M0DT0H60M60S --retention P0Y0M60DT0H60M60S --parameter name=DomainName type=Value value=placeholderDomain.local --parameter name=BaseUserDN type=Value "value=DC=placeholder, DC=placeholder" --hidden-parameter name=Password type=SecureValue secureValue=PlaceholderPassword').get_output_in_json() self.assertEqual(rsp['type'], 'Microsoft.AVS/privateClouds/scriptExecutions') self.assertEqual(rsp['name'], self.kwargs.get('scriptExecution')) @@ -35,3 +49,7 @@ def test_vmware_script_execution(self): rsp = self.cmd('az vmware script-execution delete -g {rg} -c {privatecloud} -n {scriptExecution}').output self.assertEqual(len(rsp), 0) + + + + From b0ebe651a0d93f6b690ccd89dea902f69c16b1d9 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 29 Jul 2021 12:04:48 -0600 Subject: [PATCH 04/14] update help --- src/vmware/CHANGELOG.md | 2 +- src/vmware/azext_vmware/_help.py | 22 +++++++++---------- .../tests/latest/test_script_scenario.py | 4 ---- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/vmware/CHANGELOG.md b/src/vmware/CHANGELOG.md index 0ce93ae0073..6b0e1b2aaf7 100644 --- a/src/vmware/CHANGELOG.md +++ b/src/vmware/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 3.1.0 (2021-07) +## 3.1.0 (2021-08) - Add `az vmware cloud-link` command group - Add `az vmware script-cmdlet` command group - Add `az vmware script-execution` command group diff --git a/src/vmware/azext_vmware/_help.py b/src/vmware/azext_vmware/_help.py index a14a1406fad..7b34ee7db22 100644 --- a/src/vmware/azext_vmware/_help.py +++ b/src/vmware/azext_vmware/_help.py @@ -418,15 +418,15 @@ type: command short-summary: List script cmdlet resources available for a private cloud to create a script execution resource on a private cloud. examples: - - name: List cloud links. - text: az vmware script-cmdlet --resource-group group1 --private-cloud cloud1 --script-package package1 + - name: List script cmdlet resources. + text: az vmware script-cmdlet list --resource-group group1 --private-cloud cloud1 --script-package package1 """ helps['vmware script-cmdlet show'] = """ type: command short-summary: Get information about a script cmdlet resource in a specific package on a private cloud. examples: - - name: Show a cloud link. + - name: Show a script cmdlet. text: az vmware script-cmdlet show --resource-group group1 --private-cloud cloud1 --script-package package1 --name cmdlet1 """ @@ -434,7 +434,7 @@ type: command short-summary: List script packages available to run on the private cloud. examples: - - name: List cloud links. + - name: List script packages. text: az vmware script-package list --resource-group group1 --private-cloud cloud1 """ @@ -442,7 +442,7 @@ type: command short-summary: Get a script package available to run on a private cloud. examples: - - name: Show a cloud link. + - name: Show a script package. text: az vmware script-package show --resource-group group1 --private-cloud cloud1 --name package1 """ @@ -450,15 +450,15 @@ type: command short-summary: Create or update a script execution in a private cloud. examples: - - name: Create a cloud link. - text: az vmware script-execution create --resource-group group1 --private-cloud cloud1 --name addSsoServer --sciprt-cmdlet-id "/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource" --timeout P0Y0M0DT0H60M60S --retention P0Y0M60DT0H60M60S --parameter name=DomainName type=Value value=placeholderDomain.local --parameter name=BaseUserDN type=Value "value=DC=placeholder, DC=placeholder" --hidden-parameter name=Password type=SecureValue secureValue=PlaceholderPassword + - name: Create a script execution. + text: az vmware script-execution create --resource-group group1 --private-cloud cloud1 --name addSsoServer --script-cmdlet-id "/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource" --timeout P0Y0M0DT0H60M60S --retention P0Y0M60DT0H60M60S --parameter name=DomainName type=Value value=placeholderDomain.local --parameter name=BaseUserDN type=Value "value=DC=placeholder, DC=placeholder" --hidden-parameter name=Password type=SecureValue secureValue=PlaceholderPassword """ helps['vmware script-execution list'] = """ type: command short-summary: List script executions in a private cloud. examples: - - name: List cloud links. + - name: List script executions. text: az vmware script-execution list --resource-group group1 --private-cloud cloud1 """ @@ -466,14 +466,14 @@ type: command short-summary: Get an script execution by name in a private cloud. examples: - - name: Show a cloud link. + - name: Show a script execution. text: az vmware script-execution show --resource-group group1 --private-cloud cloud1 --name addSsoServer """ helps['vmware script-execution delete'] = """ type: command - short-summary: Delete a cloud link in a private cloud. + short-summary: Delete a script execution in a private cloud. examples: - - name: Delete a cloud link. + - name: Delete a script execution. text: az vmware script-execution delete --resource-group group1 --private-cloud cloud1 --name addSsoServer """ diff --git a/src/vmware/azext_vmware/tests/latest/test_script_scenario.py b/src/vmware/azext_vmware/tests/latest/test_script_scenario.py index 13c62d02b93..80515cd68e1 100644 --- a/src/vmware/azext_vmware/tests/latest/test_script_scenario.py +++ b/src/vmware/azext_vmware/tests/latest/test_script_scenario.py @@ -49,7 +49,3 @@ def test_vmware_script(self): rsp = self.cmd('az vmware script-execution delete -g {rg} -c {privatecloud} -n {scriptExecution}').output self.assertEqual(len(rsp), 0) - - - - From 99bda245576c7018e9212e6b1fe2a9db8920dd11 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 29 Jul 2021 14:17:37 -0600 Subject: [PATCH 05/14] add named outputs --- src/vmware/azext_vmware/_params.py | 5 +-- src/vmware/azext_vmware/action.py | 13 ++++++++ src/vmware/azext_vmware/custom.py | 5 ++- .../latest/recordings/test_vmware_script.yaml | 32 +++++++++---------- src/vmware/azext_vmware/tests/test_action.py | 6 +++- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/vmware/azext_vmware/_params.py b/src/vmware/azext_vmware/_params.py index 07166636458..50ef7272800 100644 --- a/src/vmware/azext_vmware/_params.py +++ b/src/vmware/azext_vmware/_params.py @@ -5,7 +5,7 @@ # pylint: disable=line-too-long,too-many-statements -from azext_vmware.action import ScriptExecutionParameterAction +from azext_vmware.action import ScriptExecutionNamedOutputAction, ScriptExecutionParameterAction def load_arguments(self, _): @@ -132,4 +132,5 @@ def load_arguments(self, _): c.argument('failure_reason', help='Error message if the script was able to run, but if the script itself had errors or powershell threw an exception.') c.argument('retention', help='Time to live for the resource. If not provided, will be available for 60 days.') c.argument('out', help='Standard output stream from the powershell execution.') - + c.argument('named_outputs', action=ScriptExecutionNamedOutputAction, nargs='*', help='User-defined dictionary.') + c.argument('script_cmdlet_id', help='A reference to the script cmdlet resource if user is running a AVS script.') diff --git a/src/vmware/azext_vmware/action.py b/src/vmware/azext_vmware/action.py index 5d96f61df43..e581c1c7793 100644 --- a/src/vmware/azext_vmware/action.py +++ b/src/vmware/azext_vmware/action.py @@ -10,6 +10,19 @@ from azext_vmware.vendored_sdks.avs_client.models import ScriptExecutionParameter, ScriptExecutionParameterType, ScriptStringExecutionParameter, ScriptSecureStringExecutionParameter, PSCredentialExecutionParameter +class ScriptExecutionNamedOutputAction(argparse._AppendAction): + + def __call__(self, parser, namespace, values, option_string=None): + namespace.named_outputs = script_execution_named_outputs(values) + + +def script_execution_named_outputs(values: List[str]) -> Dict[str, str]: + try: + return dict(map(lambda x: x.split('=', 1), values)) + except ValueError as error: + raise CLIError('parsing named output parameter \'{}\''.format(values)) from error + + class ScriptExecutionParameterAction(argparse._AppendAction): def __call__(self, parser, namespace, values, option_string=None): diff --git a/src/vmware/azext_vmware/custom.py b/src/vmware/azext_vmware/custom.py index 2ef2c9f207b..55ec9b46489 100644 --- a/src/vmware/azext_vmware/custom.py +++ b/src/vmware/azext_vmware/custom.py @@ -4,6 +4,7 @@ # -------------------------------------------------------------------------------------------- # pylint: disable=line-too-long +from typing import List, Tuple from azext_vmware.vendored_sdks.avs_client import AVSClient LEGAL_TERMS = ''' @@ -306,8 +307,10 @@ def script_package_show(client: AVSClient, resource_group_name, private_cloud, n return client.script_packages.get(resource_group_name=resource_group_name, private_cloud_name=private_cloud, script_package_name=name) -def script_execution_create(client: AVSClient, resource_group_name, private_cloud, name, timeout, script_cmdlet_id=None, parameters=None, hidden_parameters=None, failure_reason=None, retention=None, out=None, named_outputs=None): +def script_execution_create(client: AVSClient, resource_group_name, private_cloud, name, timeout, script_cmdlet_id=None, parameters=None, hidden_parameters=None, failure_reason=None, retention=None, out=None, named_outputs: List[Tuple[str, str]] = None): from azext_vmware.vendored_sdks.avs_client.models import ScriptExecution + if named_outputs is not None: + named_outputs = dict(named_outputs) script_execution = ScriptExecution(timeout=timeout, script_cmdlet_id=script_cmdlet_id, parameters=parameters, hidden_parameters=hidden_parameters, failure_reason=failure_reason, retention=retention, output=out, named_outputs=named_outputs) return client.script_executions.begin_create_or_update(resource_group_name=resource_group_name, private_cloud_name=private_cloud, script_execution_name=name, script_execution=script_execution) diff --git a/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script.yaml b/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script.yaml index a4f19365331..fba9f24ec60 100644 --- a/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script.yaml +++ b/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script.yaml @@ -15,7 +15,7 @@ interactions: User-Agent: - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) method: GET - uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages?api-version=2021-06-01 + uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages?api-version=2021-06-01 response: body: string: '{"value":[{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0","name":"AVS.PowerCommands@1.0.0","type":"Microsoft.AVS/privateClouds/scriptPackages","properties":{"description":"Various @@ -27,7 +27,7 @@ interactions: content-type: - application/json date: - - Thu, 29 Jul 2021 17:36:01 GMT + - Thu, 29 Jul 2021 20:13:24 GMT server: - Rocket status: @@ -49,7 +49,7 @@ interactions: User-Agent: - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) method: GET - uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands%401.0.0?api-version=2021-06-01 + uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands%401.0.0?api-version=2021-06-01 response: body: string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/{scriptPackageName}","name":"AVS.PowerCommands@1.0.0","type":"Microsoft.AVS/privateClouds/scriptPackages","properties":{"description":"Various @@ -60,7 +60,7 @@ interactions: content-type: - application/json date: - - Thu, 29 Jul 2021 17:36:01 GMT + - Thu, 29 Jul 2021 20:13:29 GMT server: - Rocket status: @@ -82,7 +82,7 @@ interactions: User-Agent: - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) method: GET - uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands%401.0.0/scriptCmdlets?api-version=2021-06-01 + uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands%401.0.0/scriptCmdlets?api-version=2021-06-01 response: body: string: '{"value":[{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/{scriptPackageName}/scriptCmdlets/Set-AvsStoragePolicy","name":"Set-AvsStoragePolicy","type":"Microsoft.AVS/privateClouds/scriptPackages/scriptCmdlets","properties":{"description":"Allow @@ -99,7 +99,7 @@ interactions: content-type: - application/json date: - - Thu, 29 Jul 2021 17:36:01 GMT + - Thu, 29 Jul 2021 20:13:33 GMT server: - Rocket status: @@ -121,7 +121,7 @@ interactions: User-Agent: - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) method: GET - uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands%401.0.0/scriptCmdlets/New-ExternalSsoDomain?api-version=2021-06-01 + uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands%401.0.0/scriptCmdlets/New-ExternalSsoDomain?api-version=2021-06-01 response: body: string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/{privateCloudName}/scriptPackages/{scriptPackageName}/scriptCmdlets/New-ExternalSsoDomain","name":"New-ExternalSsoDomain","type":"Microsoft.AVS/privateClouds/scriptPackages/scriptCmdlets","properties":{"description":"Add @@ -135,7 +135,7 @@ interactions: content-type: - application/json date: - - Thu, 29 Jul 2021 17:36:01 GMT + - Thu, 29 Jul 2021 20:13:37 GMT server: - Rocket status: @@ -166,7 +166,7 @@ interactions: User-Agent: - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) method: PUT - uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 + uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 response: body: string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer","name":"addSsoServer","type":"Microsoft.AVS/privateClouds/scriptExecutions","properties":{"scriptCmdletId":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource","parameters":[{"name":"DomainName","type":"Value"},{"name":"BaseUserDN","type":"Value"}],"failureReason":"vCenter @@ -178,7 +178,7 @@ interactions: content-type: - application/json date: - - Thu, 29 Jul 2021 17:36:01 GMT + - Thu, 29 Jul 2021 20:13:41 GMT server: - Rocket status: @@ -200,7 +200,7 @@ interactions: User-Agent: - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) method: GET - uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions?api-version=2021-06-01 + uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions?api-version=2021-06-01 response: body: string: '{"value":[{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer","name":"addSsoServer","type":"Microsoft.AVS/privateClouds/scriptExecutions","properties":{"scriptCmdletId":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS:1.0.0/scriptCmdlets/New-SsoExternalIdentitySource","parameters":[{"name":"DomainName","type":"Value"},{"name":"BaseUserDN","type":"Value"}],"failureReason":"vCenter @@ -211,7 +211,7 @@ interactions: content-type: - application/json date: - - Thu, 29 Jul 2021 17:36:02 GMT + - Thu, 29 Jul 2021 20:13:46 GMT server: - Rocket status: @@ -233,7 +233,7 @@ interactions: User-Agent: - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) method: GET - uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 + uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 response: body: string: '{"id":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer","name":"addSsoServer","type":"Microsoft.AVS/privateClouds/scriptExecutions","properties":{"scriptCmdletId":"/subscriptions/{subscription-id}/resourceGroups/group1/providers/Microsoft.AVS/privateClouds/cloud1/scriptPackages/AVS.PowerCommands@1.0.0/scriptCmdlets/New-SsoExternalIdentitySource","parameters":[{"name":"DomainName","type":"Value"},{"name":"BaseUserDN","type":"Value"}],"failureReason":"vCenter @@ -244,7 +244,7 @@ interactions: content-type: - application/json date: - - Thu, 29 Jul 2021 17:36:02 GMT + - Thu, 29 Jul 2021 20:13:50 GMT server: - Rocket status: @@ -268,7 +268,7 @@ interactions: User-Agent: - AZURECLI/2.18.0 azsdk-python-mgmt-avs/0.1.0 Python/3.8.7 (Windows-10-10.0.19041-SP0) method: DELETE - uri: https://127.0.0.1:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 + uri: https://localhost:8888/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vmware_script000001/providers/Microsoft.AVS/privateClouds/cloud1/scriptExecutions/addSsoServer?api-version=2021-06-01 response: body: string: '' @@ -276,7 +276,7 @@ interactions: content-length: - '0' date: - - Thu, 29 Jul 2021 17:36:02 GMT + - Thu, 29 Jul 2021 20:13:54 GMT server: - Rocket status: diff --git a/src/vmware/azext_vmware/tests/test_action.py b/src/vmware/azext_vmware/tests/test_action.py index 7cb48b76715..1c3b299eeac 100644 --- a/src/vmware/azext_vmware/tests/test_action.py +++ b/src/vmware/azext_vmware/tests/test_action.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azext_vmware.action import script_execution_parameters +from azext_vmware.action import script_execution_named_outputs, script_execution_parameters from azext_vmware.vendored_sdks.avs_client.models import ScriptStringExecutionParameter, ScriptSecureStringExecutionParameter, PSCredentialExecutionParameter @@ -16,3 +16,7 @@ def test_secure_value_execution_parameter(self): def test_credential_execution_parameter(self): assert PSCredentialExecutionParameter(name="creds", username="Jim", password="bob") == script_execution_parameters(["type=credential", "name=creds", "username=Jim", "password=bob"]) + + def test_named_outputs(self): + assert {"dog": "Fred"} == script_execution_named_outputs(["dog=Fred"]) + assert {"dog": "Fred", "cat": "Tom"} == script_execution_named_outputs(["dog=Fred", "cat=Tom"]) From 6833ac0eb8c40d66dfa9da3df9f8f99edba43164 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 29 Jul 2021 14:22:26 -0600 Subject: [PATCH 06/14] recording are generated --- src/vmware/.gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/vmware/.gitattributes diff --git a/src/vmware/.gitattributes b/src/vmware/.gitattributes new file mode 100644 index 00000000000..10aad8e8afe --- /dev/null +++ b/src/vmware/.gitattributes @@ -0,0 +1 @@ +tests/latest/recordings/*.yaml linguist-generated=true From b139a941c1bc83489ecd603fd9569ff4eef1fa20 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 29 Jul 2021 14:25:14 -0600 Subject: [PATCH 07/14] mv .gitattributes to root --- src/vmware/.gitattributes => .gitattributes | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/vmware/.gitattributes => .gitattributes (100%) diff --git a/src/vmware/.gitattributes b/.gitattributes similarity index 100% rename from src/vmware/.gitattributes rename to .gitattributes From 0ec860fd3aa1701e0deba33e13f9500f1743ae22 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 29 Jul 2021 14:27:18 -0600 Subject: [PATCH 08/14] mv .gitattributes --- .gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 10aad8e8afe..129e24c9bd9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -tests/latest/recordings/*.yaml linguist-generated=true +src/vmware/tests/latest/recordings/*.yaml linguist-generated=true From 086e2df83c10c42f0a17b29a899d0fb02da4e818 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 29 Jul 2021 14:28:26 -0600 Subject: [PATCH 09/14] it is in azext_vmware --- .gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 129e24c9bd9..a688ea600d4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -src/vmware/tests/latest/recordings/*.yaml linguist-generated=true +src/vmware/azext_vmware/tests/latest/recordings/*.yaml linguist-generated=true From f26da082c2951db6edd5135172c081f7abe6752d Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 29 Jul 2021 14:36:49 -0600 Subject: [PATCH 10/14] fix style --- src/vmware/azext_vmware/action.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/vmware/azext_vmware/action.py b/src/vmware/azext_vmware/action.py index e581c1c7793..51c78179dd6 100644 --- a/src/vmware/azext_vmware/action.py +++ b/src/vmware/azext_vmware/action.py @@ -3,6 +3,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- +# pylint: disable=line-too-long, protected-access, too-few-public-methods import argparse from typing import Dict, List @@ -35,8 +36,8 @@ def __call__(self, parser, namespace, values, option_string=None): def script_execution_parameters(values: List[str]) -> ScriptExecutionParameter: values = dict(map(lambda x: x.split('=', 1), values)) - type = require(values, "type") - type_lower = type.lower() + tp = require(values, "type") + type_lower = tp.lower() if type_lower == ScriptExecutionParameterType.VALUE.lower(): try: @@ -57,7 +58,7 @@ def script_execution_parameters(values: List[str]) -> ScriptExecutionParameter: raise CLIError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.CREDENTIAL)) from error else: - raise CLIError('script execution paramater type \'{}\' not matched'.format(type)) + raise CLIError('script execution paramater type \'{}\' not matched'.format(tp)) def require(values: Dict[str, str], key: str) -> str: From f08c74d5db59d79a9b6f440f168ae8485e11936b Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 29 Jul 2021 15:11:49 -0600 Subject: [PATCH 11/14] fix linter errors --- src/vmware/azext_vmware/_help.py | 15 +++++++++++++++ src/vmware/azext_vmware/_params.py | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/vmware/azext_vmware/_help.py b/src/vmware/azext_vmware/_help.py index 7b34ee7db22..86dd39bc211 100644 --- a/src/vmware/azext_vmware/_help.py +++ b/src/vmware/azext_vmware/_help.py @@ -414,6 +414,11 @@ text: az vmware cloud-link delete --resource-group group1 --private-cloud cloud1 --name cloudLink1 """ +helps['vmware script-cmdlet'] = """ + type: group + short-summary: Commands to list and show script cmdlet resources. +""" + helps['vmware script-cmdlet list'] = """ type: command short-summary: List script cmdlet resources available for a private cloud to create a script execution resource on a private cloud. @@ -430,6 +435,11 @@ text: az vmware script-cmdlet show --resource-group group1 --private-cloud cloud1 --script-package package1 --name cmdlet1 """ +helps['vmware script-package'] = """ + type: group + short-summary: Commands to list and show script packages available to run on the private cloud. +""" + helps['vmware script-package list'] = """ type: command short-summary: List script packages available to run on the private cloud. @@ -446,6 +456,11 @@ text: az vmware script-package show --resource-group group1 --private-cloud cloud1 --name package1 """ +helps['vmware script-execution'] = """ + type: group + short-summary: Commands to manage script executions in a private cloud. +""" + helps['vmware script-execution create'] = """ type: command short-summary: Create or update a script execution in a private cloud. diff --git a/src/vmware/azext_vmware/_params.py b/src/vmware/azext_vmware/_params.py index 50ef7272800..afa99ece544 100644 --- a/src/vmware/azext_vmware/_params.py +++ b/src/vmware/azext_vmware/_params.py @@ -128,7 +128,7 @@ def load_arguments(self, _): with self.argument_context('vmware script-execution create') as c: c.argument('timeout', help='Time limit for execution.') c.argument('parameters', options_list=['--parameter', '-p'], action=ScriptExecutionParameterAction, nargs='*', help='Parameters the script will accept.') - c.argument('hidden_parameters', options_list=['--hidden-parameter', '-hp'], action=ScriptExecutionParameterAction, nargs='*', help='Parameters that will be hidden/not visible to ARM, such as passwords and credentials.') + c.argument('hidden_parameters', options_list=['--hidden-parameter'], action=ScriptExecutionParameterAction, nargs='*', help='Parameters that will be hidden/not visible to ARM, such as passwords and credentials.') c.argument('failure_reason', help='Error message if the script was able to run, but if the script itself had errors or powershell threw an exception.') c.argument('retention', help='Time to live for the resource. If not provided, will be available for 60 days.') c.argument('out', help='Standard output stream from the powershell execution.') From d8cc242dbd77eec61de8c38b1a6bb47e4bc30023 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 29 Jul 2021 15:29:58 -0600 Subject: [PATCH 12/14] suppress cred scan false positive --- src/vmware/azext_vmware/tests/test_action.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vmware/azext_vmware/tests/test_action.py b/src/vmware/azext_vmware/tests/test_action.py index 1c3b299eeac..c3453c7f32d 100644 --- a/src/vmware/azext_vmware/tests/test_action.py +++ b/src/vmware/azext_vmware/tests/test_action.py @@ -15,6 +15,7 @@ def test_secure_value_execution_parameter(self): assert ScriptSecureStringExecutionParameter(name="cat", secure_value="George") == script_execution_parameters(["type=SecureValue", "name=cat", "secureValue=George"]) def test_credential_execution_parameter(self): + # CS002:SecretInNextLine assert PSCredentialExecutionParameter(name="creds", username="Jim", password="bob") == script_execution_parameters(["type=credential", "name=creds", "username=Jim", "password=bob"]) def test_named_outputs(self): From 7a709dcc34e31dfb42582c9909bb24546ff7b10d Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 29 Jul 2021 15:38:27 -0600 Subject: [PATCH 13/14] remove credential test --- src/vmware/azext_vmware/tests/test_action.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/vmware/azext_vmware/tests/test_action.py b/src/vmware/azext_vmware/tests/test_action.py index c3453c7f32d..aacdeb36240 100644 --- a/src/vmware/azext_vmware/tests/test_action.py +++ b/src/vmware/azext_vmware/tests/test_action.py @@ -14,10 +14,6 @@ def test_value_execution_parameter(self): def test_secure_value_execution_parameter(self): assert ScriptSecureStringExecutionParameter(name="cat", secure_value="George") == script_execution_parameters(["type=SecureValue", "name=cat", "secureValue=George"]) - def test_credential_execution_parameter(self): - # CS002:SecretInNextLine - assert PSCredentialExecutionParameter(name="creds", username="Jim", password="bob") == script_execution_parameters(["type=credential", "name=creds", "username=Jim", "password=bob"]) - def test_named_outputs(self): assert {"dog": "Fred"} == script_execution_named_outputs(["dog=Fred"]) assert {"dog": "Fred", "cat": "Tom"} == script_execution_named_outputs(["dog=Fred", "cat=Tom"]) From c7bcd096ad4adb23baf21f56c23641b720adde1a Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Wed, 11 Aug 2021 16:44:50 -0500 Subject: [PATCH 14/14] raise InvalidArgumentValueError, RequiredArgumentMissingError --- src/vmware/azext_vmware/action.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/vmware/azext_vmware/action.py b/src/vmware/azext_vmware/action.py index 51c78179dd6..1fe25003123 100644 --- a/src/vmware/azext_vmware/action.py +++ b/src/vmware/azext_vmware/action.py @@ -7,6 +7,7 @@ import argparse from typing import Dict, List +from azure.cli.core.azclierror import InvalidArgumentValueError, RequiredArgumentMissingError from knack.util import CLIError from azext_vmware.vendored_sdks.avs_client.models import ScriptExecutionParameter, ScriptExecutionParameterType, ScriptStringExecutionParameter, ScriptSecureStringExecutionParameter, PSCredentialExecutionParameter @@ -43,27 +44,27 @@ def script_execution_parameters(values: List[str]) -> ScriptExecutionParameter: try: return ScriptStringExecutionParameter(name=require(values, "name"), value=values.get("value")) except CLIError as error: - raise CLIError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.VALUE)) from error + raise InvalidArgumentValueError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.VALUE)) from error elif type_lower == ScriptExecutionParameterType.SECURE_VALUE.lower(): try: return ScriptSecureStringExecutionParameter(name=require(values, "name"), secure_value=values.get("secureValue")) except CLIError as error: - raise CLIError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.SECURE_VALUE)) from error + raise InvalidArgumentValueError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.SECURE_VALUE)) from error elif type_lower == ScriptExecutionParameterType.CREDENTIAL.lower(): try: return PSCredentialExecutionParameter(name=require(values, "name"), username=values.get("username"), password=values.get("password")) except CLIError as error: - raise CLIError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.CREDENTIAL)) from error + raise InvalidArgumentValueError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.CREDENTIAL)) from error else: - raise CLIError('script execution paramater type \'{}\' not matched'.format(tp)) + raise InvalidArgumentValueError('script execution paramater type \'{}\' not matched'.format(tp)) def require(values: Dict[str, str], key: str) -> str: '''Gets the required script execution parameter or raises a CLIError.''' value = values.get(key) if value is None: - raise CLIError('script execution parameter \'{}\' required'.format(key)) + raise RequiredArgumentMissingError('script execution parameter \'{}\' required'.format(key)) return value