diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000000..a688ea600d4 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +src/vmware/azext_vmware/tests/latest/recordings/*.yaml linguist-generated=true diff --git a/src/vmware/CHANGELOG.md b/src/vmware/CHANGELOG.md index 610aa1dd767..6b0e1b2aaf7 100644 --- a/src/vmware/CHANGELOG.md +++ b/src/vmware/CHANGELOG.md @@ -1,7 +1,10 @@ # 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 +- 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/_help.py b/src/vmware/azext_vmware/_help.py index 117e6fbbfb0..86dd39bc211 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,82 @@ - name: Delete a cloud link. 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. + examples: + - 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 script cmdlet. + 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. + examples: + - name: List script packages. + 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 script package. + 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. + examples: + - 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 script executions. + 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 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 script execution in a private cloud. + examples: + - 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/_params.py b/src/vmware/azext_vmware/_params.py index db87f476b88..afa99ece544 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 ScriptExecutionNamedOutputAction, ScriptExecutionParameterAction + + def load_arguments(self, _): from azure.cli.core.commands.parameters import tags_type @@ -111,3 +114,23 @@ 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-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.') + + 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'], 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_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 new file mode 100644 index 00000000000..1fe25003123 --- /dev/null +++ b/src/vmware/azext_vmware/action.py @@ -0,0 +1,70 @@ + +# -------------------------------------------------------------------------------------------- +# 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 +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 + + +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): + 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)) + tp = require(values, "type") + type_lower = tp.lower() + + if type_lower == ScriptExecutionParameterType.VALUE.lower(): + try: + return ScriptStringExecutionParameter(name=require(values, "name"), value=values.get("value")) + except CLIError as 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 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 InvalidArgumentValueError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.CREDENTIAL)) from error + + else: + 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 RequiredArgumentMissingError('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..8f0e7444997 100644 --- a/src/vmware/azext_vmware/commands.py +++ b/src/vmware/azext_vmware/commands.py @@ -89,8 +89,21 @@ 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') + + 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') + 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..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 = ''' @@ -274,7 +275,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) @@ -288,3 +289,43 @@ 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(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) + + +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, 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, 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, script_execution_name=name) 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..fba9f24ec60 --- /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://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 + 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 20:13:24 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://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 + 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 20:13:29 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://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 + 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 20:13:33 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://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 + 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 20:13:37 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://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 20:13:41 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 20:13: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 20:13:50 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 20:13:54 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 new file mode 100644 index 00000000000..eb00ccf13d3 --- /dev/null +++ b/src/vmware/azext_vmware/tests/latest/recordings/test_vmware_script_execution.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: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"}, + {"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:04:32 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:04:34 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:04:34 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:04:34 GMT + server: + - Rocket + status: + code: 200 + message: OK +version: 1 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 new file mode 100644 index 00000000000..80515cd68e1 --- /dev/null +++ b/src/vmware/azext_vmware/tests/latest/test_script_scenario.py @@ -0,0 +1,51 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +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(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')) + + 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) 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..aacdeb36240 --- /dev/null +++ b/src/vmware/azext_vmware/tests/test_action.py @@ -0,0 +1,19 @@ +# -------------------------------------------------------------------------------------------- +# 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_named_outputs, 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_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"])