Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add az vmware script* #3722

Merged
merged 15 commits into from
Aug 12, 2021
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/vmware/azext_vmware/tests/latest/recordings/*.yaml linguist-generated=true
cataggar marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 4 additions & 1 deletion src/vmware/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
89 changes: 80 additions & 9 deletions src/vmware/azext_vmware/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
"""
23 changes: 23 additions & 0 deletions src/vmware/azext_vmware/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.')
69 changes: 69 additions & 0 deletions src/vmware/azext_vmware/action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

# --------------------------------------------------------------------------------------------
# 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 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
cataggar marked this conversation as resolved.
Show resolved Hide resolved


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 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(tp))
cataggar marked this conversation as resolved.
Show resolved Hide resolved


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))
cataggar marked this conversation as resolved.
Show resolved Hide resolved
return value
17 changes: 15 additions & 2 deletions src/vmware/azext_vmware/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
43 changes: 42 additions & 1 deletion src/vmware/azext_vmware/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '''
Expand Down Expand Up @@ -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)


Expand All @@ -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)
Loading