Hello community, here is the log from the commit of package azure-cli-lab for openSUSE:Factory checked in at 2018-02-14 09:31:25 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/azure-cli-lab (Old) and /work/SRC/openSUSE:Factory/.azure-cli-lab.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "azure-cli-lab" Wed Feb 14 09:31:25 2018 rev:2 rq:574817 version:0.0.16 Changes: -------- --- /work/SRC/openSUSE:Factory/azure-cli-lab/azure-cli-lab.changes 2017-11-10 14:54:11.531033789 +0100 +++ /work/SRC/openSUSE:Factory/.azure-cli-lab.new/azure-cli-lab.changes 2018-02-14 09:31:27.131849213 +0100 @@ -1,0 +2,9 @@ +Thu Feb 8 12:29:54 UTC 2018 - [email protected] + +- New upstream release + + Version 0.0.16 + + For detailed information about changes see the + HISTORY.rst file provided with this package +- Install HISTORY.rst into doc directory + +------------------------------------------------------------------- Old: ---- azure-cli-lab-0.0.11.tar.gz New: ---- azure-cli-lab-0.0.16.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ azure-cli-lab.spec ++++++ --- /var/tmp/diff_new_pack.CbqTRH/_old 2018-02-14 09:31:28.219809790 +0100 +++ /var/tmp/diff_new_pack.CbqTRH/_new 2018-02-14 09:31:28.219809790 +0100 @@ -1,7 +1,7 @@ # # spec file for package azure-cli-lab # -# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -15,8 +15,9 @@ # Please submit bugfixes or comments via http://bugs.opensuse.org/ # + Name: azure-cli-lab -Version: 0.0.11 +Version: 0.0.16 Release: 0 Summary: Microsoft Azure CLI 'DevTestLabs' Command Module License: MIT @@ -24,17 +25,17 @@ Url: https://github.com/Azure/azure-cli Source: https://files.pythonhosted.org/packages/source/a/azure-cli-lab/azure-cli-lab-%{version}.tar.gz Source1: LICENSE.txt -BuildRequires: python3-devel -BuildRequires: python3-setuptools -BuildRequires: unzip BuildRequires: azure-cli-command-modules-nspkg BuildRequires: azure-cli-nspkg BuildRequires: python3-azure-nspkg +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: unzip Requires: azure-cli-command-modules-nspkg -Requires: azure-cli-nspkg -Requires: python3-azure-nspkg Requires: azure-cli-core +Requires: azure-cli-nspkg Requires: python3-azure-graphrbac >= 0.31.0 +Requires: python3-azure-nspkg Conflicts: azure-cli < 2.0.0 BuildArch: noarch @@ -63,7 +64,8 @@ %files %defattr(-,root,root,-) -%doc LICENSE.txt README.rst +%doc HISTORY.rst LICENSE.txt README.rst %{python3_sitelib}/azure/cli/command_modules/lab %{python3_sitelib}/azure_cli_lab-*.egg-info + %changelog ++++++ azure-cli-lab-0.0.11.tar.gz -> azure-cli-lab-0.0.16.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/HISTORY.rst new/azure-cli-lab-0.0.16/HISTORY.rst --- old/azure-cli-lab-0.0.11/HISTORY.rst 2017-09-23 01:47:00.000000000 +0200 +++ new/azure-cli-lab-0.0.16/HISTORY.rst 2018-01-26 17:12:24.000000000 +0100 @@ -2,6 +2,27 @@ Release History =============== + +0.0.16 +++++++ +* Performance fixes. + +0.0.15 +++++++ +* Update helpfile + +0.0.14 +++++++ +* Update for CLI core changes. + +0.0.13 +++++++ +* Minor fixes. + +0.0.12 +++++++ +* minor fixes + 0.0.11 (2017-09-22) +++++++++++++++++++ * minor fixes diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/PKG-INFO new/azure-cli-lab-0.0.16/PKG-INFO --- old/azure-cli-lab-0.0.11/PKG-INFO 2017-09-23 01:48:29.000000000 +0200 +++ new/azure-cli-lab-0.0.16/PKG-INFO 2018-01-26 17:12:47.000000000 +0100 @@ -1,12 +1,11 @@ Metadata-Version: 1.1 Name: azure-cli-lab -Version: 0.0.11 +Version: 0.0.16 Summary: Microsoft Azure Command-Line Tools DevTestLabs Command Module Home-page: https://github.com/Azure/azure-cli Author: Microsoft Corporation Author-email: [email protected] License: MIT -Description-Content-Type: UNKNOWN Description: Microsoft Azure CLI 'DevTestLabs' Command Module ================================================ @@ -15,6 +14,27 @@ Release History =============== + + 0.0.16 + ++++++ + * Performance fixes. + + 0.0.15 + ++++++ + * Update helpfile + + 0.0.14 + ++++++ + * Update for CLI core changes. + + 0.0.13 + ++++++ + * Minor fixes. + + 0.0.12 + ++++++ + * minor fixes + 0.0.11 (2017-09-22) +++++++++++++++++++ * minor fixes diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/__init__.py new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/__init__.py --- old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/__init__.py 2017-09-23 01:47:00.000000000 +0200 +++ new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/__init__.py 2018-01-26 17:12:24.000000000 +0100 @@ -3,12 +3,27 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- +from azure.cli.core import AzCommandsLoader + import azure.cli.command_modules.lab._help # pylint: disable=unused-import -def load_params(_): - import azure.cli.command_modules.lab.params # pylint: disable=redefined-outer-name, unused-variable +class DevTestLabCommandsLoader(AzCommandsLoader): + + def __init__(self, cli_ctx=None): + from azure.cli.core.commands import CliCommandType + lab_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.lab.custom#{}') + super(DevTestLabCommandsLoader, self).__init__(cli_ctx=cli_ctx, custom_command_type=lab_custom, + min_profile='2017-03-10-profile') + + def load_command_table(self, args): + from azure.cli.command_modules.lab.commands import load_command_table + load_command_table(self, args) + return self.command_table + + def load_arguments(self, command): + from azure.cli.command_modules.lab._params import load_arguments + load_arguments(self, command) -def load_commands(): - import azure.cli.command_modules.lab.commands # pylint: disable=redefined-outer-name, unused-variable +COMMAND_LOADER_CLS = DevTestLabCommandsLoader diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/_client_factory.py new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/_client_factory.py --- old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/_client_factory.py 2017-09-23 01:47:00.000000000 +0200 +++ new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/_client_factory.py 2018-01-26 17:12:24.000000000 +0100 @@ -5,51 +5,51 @@ # MANAGEMENT CLIENT FACTORIES -def get_devtestlabs_management_client(_): +def get_devtestlabs_management_client(cli_ctx, _): from azure.mgmt.devtestlabs import DevTestLabsClient from azure.cli.core.commands.client_factory import get_mgmt_service_client - return get_mgmt_service_client(DevTestLabsClient) + return get_mgmt_service_client(cli_ctx, DevTestLabsClient) -def get_devtestlabs_virtual_machine_operation(kwargs): - return get_devtestlabs_management_client(kwargs).virtual_machines +def get_devtestlabs_virtual_machine_operation(cli_ctx, _): + return get_devtestlabs_management_client(cli_ctx, _).virtual_machines -def get_devtestlabs_lab_operation(kwargs): - return get_devtestlabs_management_client(kwargs).labs +def get_devtestlabs_lab_operation(cli_ctx, _): + return get_devtestlabs_management_client(cli_ctx, _).labs -def get_devtestlabs_custom_image_operation(kwargs): - return get_devtestlabs_management_client(kwargs).custom_images +def get_devtestlabs_custom_image_operation(cli_ctx, _): + return get_devtestlabs_management_client(cli_ctx, _).custom_images -def get_devtestlabs_gallery_image_operation(kwargs): - return get_devtestlabs_management_client(kwargs).gallery_images +def get_devtestlabs_gallery_image_operation(cli_ctx, _): + return get_devtestlabs_management_client(cli_ctx, _).gallery_images -def get_devtestlabs_artifact_operation(kwargs): - return get_devtestlabs_management_client(kwargs).artifacts +def get_devtestlabs_artifact_operation(cli_ctx, _): + return get_devtestlabs_management_client(cli_ctx, _).artifacts -def get_devtestlabs_artifact_source_operation(kwargs): - return get_devtestlabs_management_client(kwargs).artifact_sources +def get_devtestlabs_artifact_source_operation(cli_ctx, _): + return get_devtestlabs_management_client(cli_ctx, _).artifact_sources -def get_devtestlabs_virtual_network_operation(kwargs): - return get_devtestlabs_management_client(kwargs).virtual_networks +def get_devtestlabs_virtual_network_operation(cli_ctx, _): + return get_devtestlabs_management_client(cli_ctx, _).virtual_networks -def get_devtestlabs_formula_operation(kwargs): - return get_devtestlabs_management_client(kwargs).formulas +def get_devtestlabs_formula_operation(cli_ctx, _): + return get_devtestlabs_management_client(cli_ctx, _).formulas -def get_devtestlabs_secret_operation(kwargs): - return get_devtestlabs_management_client(kwargs).secrets +def get_devtestlabs_secret_operation(cli_ctx, _): + return get_devtestlabs_management_client(cli_ctx, _).secrets -def get_devtestlabs_environment_operation(kwargs): - return get_devtestlabs_management_client(kwargs).environments +def get_devtestlabs_environment_operation(cli_ctx, _): + return get_devtestlabs_management_client(cli_ctx, _).environments -def get_devtestlabs_arm_template_operation(kwargs): - return get_devtestlabs_management_client(kwargs).arm_templates +def get_devtestlabs_arm_template_operation(cli_ctx, _): + return get_devtestlabs_management_client(cli_ctx, _).arm_templates diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/_format.py new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/_format.py --- old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/_format.py 1970-01-01 01:00:00.000000000 +0100 +++ new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/_format.py 2018-01-26 17:12:24.000000000 +0100 @@ -0,0 +1,60 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + + +def export_artifacts(formula): + """ Exports artifacts from the given formula. This method removes some of the properties of the + artifact model as they do not play important part for users in create or read context. + """ + artifacts = [] + if formula and formula.formula_content and formula.formula_content.artifacts: + artifacts = formula.formula_content.artifacts + for artifact in formula.formula_content.artifacts: + del artifact.status + del artifact.deployment_status_message + del artifact.vm_extension_status_message + del artifact.install_time + return artifacts + + +def transform_artifact_source_list(artifact_source_list): + return [transform_artifact_source(v) for v in artifact_source_list] + + +def transform_artifact_source(result): + from collections import OrderedDict + return OrderedDict([('name', result['name']), + ('sourceType', result['sourceType']), + ('status', result.get('status')), + ('uri', result.get('uri'))]) + + +def transform_arm_template_list(arm_template_list): + return [transform_arm_template(v) for v in arm_template_list] + + +def transform_arm_template(result): + from collections import OrderedDict + return OrderedDict([('name', result['name']), + ('resourceGroup', result['resourceGroup']), + ('publisher', result.get('publisher'))]) + + +def transform_vm_list(vm_list): + return [_transform_vm_dict(v) for v in vm_list] + + +def _transform_vm_dict(result): + from collections import OrderedDict + return OrderedDict([('name', result['name']), + ('location', result['location']), + ('osType', result['osType'])]) + + +def transform_vm(result): + from collections import OrderedDict + return OrderedDict([('name', result.name), + ('location', result.location), + ('osType', result.os_type)]) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/_help.py new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/_help.py --- old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/_help.py 2017-09-23 01:47:00.000000000 +0200 +++ new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/_help.py 2018-01-26 17:12:24.000000000 +0100 @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure.cli.core.help_files import helps +from knack.help_files import helps helps['lab'] = """ @@ -55,10 +55,10 @@ short-summary: 'Type of IP configuration to use for the VM. Allowed values are: shared, public, private.' long-summary: If omitted, will be selected based on the VM's vnet. - name: --artifacts - short-summary: JSON encoded array of artifacts to be applied. Use @{file} to load from a file. + short-summary: JSON encoded array of artifacts to be applied. Use '@{file}' to load from a file. - name: --tags short-summary: Space separated tags in `key[=value]` format. - long-summary: Tags may be cleared by assigning the empty value `""` to them. + long-summary: Tags may be cleared by assigning the empty value "" to them. - name: --allow-claim short-summary: Flag indicating if the VM should be created as claimable. - name: --disk-type @@ -70,25 +70,25 @@ examples: - name: Create a VM in the lab from a gallery image. text: > - az lab vm create --lab-name MyLab -g MyRG --name MyVM --image "Ubuntu Server 16.04 LTS" --image-type gallery --size Standard_DS1_v2 + az lab vm create --lab-name {LabName} -g {ResourceGroup} --name {VMName} --image "Ubuntu Server 16.04 LTS" --image-type gallery --size Standard_DS1_v2 - name: Create a VM in the lab from a gallery image with SSH authentication. text: > - az lab vm create --lab-name MyLab -g MyRG --name MyVM --image "Ubuntu Server 16.04 LTS" --image-type gallery --size Standard_DS1_v2 --authentication-type ssh + az lab vm create --lab-name {LabName} -g {ResourceGroup} --name {VMName} --image "Ubuntu Server 16.04 LTS" --image-type gallery --size Standard_DS1_v2 --authentication-type ssh - name: Create a claimable VM in the lab from a gallery image with password authentication. text: > - az lab vm create --lab-name MyLab -g MyRG --name MyVM --image "Ubuntu Server 16.04 LTS" --image-type gallery --size Standard_DS1_v2 --allow-claim + az lab vm create --lab-name {LabName} -g {ResourceGroup} --name {VMName} --image "Ubuntu Server 16.04 LTS" --image-type gallery --size Standard_DS1_v2 --allow-claim - name: Create a windows VM in the lab from a gallery image with password authentication. text: > - az lab vm create --lab-name MyLab -g MyRG --name MyVM --image "Windows Server 2008 R2 SP1" --image-type gallery --size Standard_DS1_v2 + az lab vm create --lab-name {LabName} -g {ResourceGroup} --name {VMName} --image "Windows Server 2008 R2 SP1" --image-type gallery --size Standard_DS1_v2 - name: Create a VM in the lab from a custom image. text: > - az lab vm create --lab-name MyLab -g MyRG --name MyVM --image "jenkins_custom" --image-type custom --size Standard_DS1_v2 + az lab vm create --lab-name {LabName} -g {ResourceGroup} --name {VMName} --image "jenkins_custom" --image-type custom --size Standard_DS1_v2 - name: Create a VM in the lab with a public IP. text: > - az lab vm create --lab-name MyLab -g MyRG --name MyVM --image "Ubuntu Server 16.04 LTS" --image-type gallery --size Standard_DS1_v2 --ip-configuration public + az lab vm create --lab-name {LabName} -g {ResourceGroup} --name {VMName} --image "Ubuntu Server 16.04 LTS" --image-type gallery --size Standard_DS1_v2 --ip-configuration public - name: Create a VM from a formula. text: > - az lab vm create --lab-name MyLab -g MyRG --name MyVM --formula MyFormula --artifacts @/artifacts.json + az lab vm create --lab-name {LabName} -g {ResourceGroup} --name {VMName} --formula MyFormula --artifacts '@artifacts.json' """ helps['lab vm list'] = """ type: command @@ -124,7 +124,7 @@ - name: --name -n short-summary: Name of the virtual machine. - name: --artifacts - short-summary: JSON encoded array of artifacts to be applied. Use @{file} to load from a file. + short-summary: JSON encoded array of artifacts to be applied. Use '@{file}' to load from a file. """ helps['lab vm claim'] = """ type: command @@ -141,15 +141,15 @@ examples: - name: Claim any available virtual machine in the lab. text: > - az lab vm claim -g MyRG --lab-name MyLab + az lab vm claim -g {ResourceGroup} --lab-name {LabName} - name: Claim a specific virtual machine in the lab. text: > - az lab vm claim -g MyRG --lab-name MyLab --name MyVM - - name: Claim multiple virtual machines in the lab using `--ids`. + az lab vm claim -g {ResourceGroup} --lab-name {LabName} --name {VMName} + - name: Claim multiple virtual machines in the lab by IDs. text: | az lab vm claim --ids \\ - /subscriptions/{SubID}/resourcegroups/{MyRG}/providers/microsoft.devtestlab/labs/{MyLab}/virtualmachines/{MyVM1} \\ - /subscriptions/{SubID}/resourcegroups/{MyRG}/providers/microsoft.devtestlab/labs/{MyLab}/virtualmachines/{MyVM2} + /subscriptions/{SubID}/resourcegroups/{ResourceGroup}/providers/microsoft.devtestlab/labs/{LabName}/virtualmachines/{VMName1} \\ + /subscriptions/{SubID}/resourcegroups/{ResourceGroup}/providers/microsoft.devtestlab/labs/{LabName}/virtualmachines/{VMName2} """ helps['lab custom-image'] = """ type: group @@ -175,13 +175,13 @@ short-summary: The current state of the virtual machine. long-summary: > For Windows virtual machines: NonSysprepped, SysprepRequested, SysprepApplied - For Linux virtual machines - NonDeprovisioned, DeprovisionRequested, DeprovisionApplied + For Linux virtual machines: NonDeprovisioned, DeprovisionRequested, DeprovisionApplied examples: - name: Create a custom image in the lab from a running Windows virtual machine without applying sysprep. text: | - az lab custom-image create --lab-name MyLab -g MyRG --name MyVM \\ + az lab custom-image create --lab-name {LabName} -g {ResourceGroup} --name {VMName} \\ --os-type Windows --os-state NonSysprepped \\ - --source-vm-id "/subscriptions/{SubID}/resourcegroups/{MyRG}/microsoft.devtestlab/labs/{MyLab}/virtualmachines/{MyVM}" + --source-vm-id "/subscriptions/{SubID}/resourcegroups/{ResourceGroup}/microsoft.devtestlab/labs/{LabName}/virtualmachines/{VMName}" """ helps['lab gallery-image'] = """ type: group @@ -276,7 +276,7 @@ populator-commands: - az lab artifact-source list - name: --parameters - short-summary: JSON encoded list of parameters. Use @{file} to load from a file. + short-summary: JSON encoded list of parameters. Use '@{file}' to load from a file. - name: --tags short-summary: The tags for the resource. """ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/_params.py new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/_params.py --- old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/_params.py 1970-01-01 01:00:00.000000000 +0100 +++ new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/_params.py 2018-01-26 17:12:24.000000000 +0100 @@ -0,0 +1,80 @@ +# -------------------------------------------------------------------------------------------- +# 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.command_modules.lab.validators import validate_artifacts, validate_template_id +from azure.cli.core.util import get_json_object + + +def load_arguments(self, _): + with self.argument_context('lab custom-image create') as c: + c.argument('name', options_list=['--name', '-n']) + + with self.argument_context('lab vm create') as c: + c.argument('name', options_list=['--name', '-n']) + + # Authentication related arguments + for arg_name in ['admin_username', 'admin_password', 'authentication_type', 'ssh_key', 'generate_ssh_keys', + 'saved_secret']: + c.argument(arg_name, arg_group='Authentication') + c.argument('generate_ssh_keys', action='store_true') + + # Add Artifacts from json object + c.argument('artifacts', type=get_json_object) + + # Image related arguments + c.ignore('os_type', 'gallery_image_reference', 'custom_image_id') + + # Network related arguments + for arg_name in ['ip_configuration', 'subnet', 'vnet_name']: + c.argument(arg_name, arg_group='Network') + + c.ignore('lab_subnet_name', 'lab_virtual_network_id', 'disallow_public_ip_address', 'network_interface') + + # Creating VM in the different location then lab is an officially unsupported scenario + c.ignore('location') + c.argument('allow_claim', action='store_true') + + with self.argument_context('lab vm list') as c: + for arg_name in ['filters', 'all', 'claimable', 'environment']: + c.argument(arg_name, arg_group='Filter') + + for arg_name in ['all', 'claimable']: + c.argument(arg_name, action='store_true') + + with self.argument_context('lab vm claim') as c: + c.argument('name', options_list=['--name', '-n'], id_part='child_name_1') + c.argument('lab_name', id_part='name') + + with self.argument_context('lab vm apply-artifacts') as c: + c.argument('artifacts', type=get_json_object, validator=validate_artifacts) + c.argument('name', options_list=['--name', '-n']) + + with self.argument_context('lab formula') as c: + c.argument('name', options_list=['--name', '-n']) + + with self.argument_context('lab secret') as c: + from azure.mgmt.devtestlabs.models.secret import Secret + + c.argument('name', options_list=['--name', '-n']) + c.argument('secret', options_list=['--value'], type=lambda x: Secret(value=x)) + c.ignore('user_name') + + with self.argument_context('lab formula export-artifacts') as c: + # Exporting artifacts does not need expand filter + c.ignore('expand') + + with self.argument_context('lab environment') as c: + c.argument('name', options_list=['--name', '-n']) + c.ignore('user_name') + + with self.argument_context('lab environment create') as c: + c.argument('arm_template', validator=validate_template_id) + c.argument('parameters', type=get_json_object) + + with self.argument_context('lab arm-template') as c: + c.argument('name', options_list=['--name', '-n']) + + with self.argument_context('lab arm-template show') as c: + c.argument('export_parameters', action='store_true') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/commands.py new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/commands.py --- old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/commands.py 2017-09-23 01:47:00.000000000 +0200 +++ new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/commands.py 2018-01-26 17:12:24.000000000 +0100 @@ -3,9 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from collections import OrderedDict -from azure.cli.core.profiles import supported_api_version, PROFILE_TYPE -from azure.cli.core.sdk.util import (ServiceGroup, create_service_adapter) +from azure.cli.core.commands import CliCommandType from ._client_factory import (get_devtestlabs_virtual_machine_operation, get_devtestlabs_custom_image_operation, get_devtestlabs_gallery_image_operation, @@ -17,205 +15,138 @@ get_devtestlabs_secret_operation, get_devtestlabs_environment_operation, get_devtestlabs_arm_template_operation) - -if not supported_api_version(PROFILE_TYPE, max_api='2017-03-09-profile'): - custom_path = 'azure.cli.command_modules.lab.custom' - mgmt_operations_path = 'azure.mgmt.devtestlabs.operations.{}' - - def _export_artifacts(formula): - """ Exports artifacts from the given formula. This method removes some of the properties of the - artifact model as they do not play important part for users in create or read context. - """ - artifacts = [] - if formula and formula.formula_content and formula.formula_content.artifacts: - artifacts = formula.formula_content.artifacts - for artifact in formula.formula_content.artifacts: - del artifact.status - del artifact.deployment_status_message - del artifact.vm_extension_status_message - del artifact.install_time - return artifacts - - def transform_artifact_source_list(artifact_source_list): - return [transform_artifact_source(v) for v in artifact_source_list] - - def transform_artifact_source(result): - return OrderedDict([('name', result['name']), - ('sourceType', result['sourceType']), - ('status', result.get('status')), - ('uri', result.get('uri'))]) - - def transform_arm_template_list(arm_template_list): - return [transform_arm_template(v) for v in arm_template_list] - - def transform_arm_template(result): - return OrderedDict([('name', result['name']), - ('resourceGroup', result['resourceGroup']), - ('publisher', result.get('publisher'))]) - - def transform_vm_list(vm_list): - return [transform_vm(v) for v in vm_list] - - def transform_vm(result): - return OrderedDict([('name', result['name']), - ('location', result['location']), - ('osType', result['osType'])]) - - # Custom Command's service adapter - custom_operations = create_service_adapter(custom_path) +from .validators import validate_lab_vm_create, validate_lab_vm_list, validate_claim_vm, validate_user_name +from ._format import (transform_artifact_source_list, transform_artifact_source, transform_arm_template_list, + transform_arm_template, transform_vm_list, transform_vm, export_artifacts) + + +# pylint: disable=too-many-locals, too-many-statements +def load_command_table(self, _): + + virtual_machine_operations = CliCommandType( + operations_tmpl='azure.mgmt.devtestlabs.operations.virtual_machines_operations#VirtualMachinesOperations.{}', + client_factory=get_devtestlabs_virtual_machine_operation + ) + + lab_operations = CliCommandType( + operations_tmpl='azure.mgmt.devtestlabs.operations.labs_operations#LabsOperations.{}', + client_factory=get_devtestlabs_lab_operation + ) + + custom_image_operations = CliCommandType( + operations_tmpl='azure.mgmt.devtestlabs.operations.custom_images_operations#CustomImagesOperations.{}', + client_factory=get_devtestlabs_custom_image_operation + ) + + gallery_image_operations = CliCommandType( + operations_tmpl='azure.mgmt.devtestlabs.operations.gallery_images_operations#GalleryImagesOperations.{}', + client_factory=get_devtestlabs_gallery_image_operation + ) + + artifact_operations = CliCommandType( + operations_tmpl='azure.mgmt.devtestlabs.operations.artifacts_operations#ArtifactsOperations.{}', + client_factory=get_devtestlabs_artifact_operation + ) + + artifact_source_operations = CliCommandType( + operations_tmpl='azure.mgmt.devtestlabs.operations.artifact_sources_operations#ArtifactSourcesOperations.{}', + client_factory=get_devtestlabs_artifact_source_operation + ) + + virtual_network_operations = CliCommandType( + operations_tmpl='azure.mgmt.devtestlabs.operations.virtual_networks_operations#VirtualNetworksOperations.{}', + client_factory=get_devtestlabs_virtual_network_operation + ) + + formula_operations = CliCommandType( + operations_tmpl='azure.mgmt.devtestlabs.operations.formulas_operations#FormulasOperations.{}', + client_factory=get_devtestlabs_formula_operation + ) + + secret_operations = CliCommandType( + operations_tmpl='azure.mgmt.devtestlabs.operations.secrets_operations#SecretsOperations.{}', + client_factory=get_devtestlabs_secret_operation, + validator=validate_user_name + ) + + environment_operations = CliCommandType( + operations_tmpl='azure.mgmt.devtestlabs.operations.environments_operations#EnvironmentsOperations.{}', + client_factory=get_devtestlabs_environment_operation, + validator=validate_user_name + ) + + arm_template_operations = CliCommandType( + operations_tmpl='azure.mgmt.devtestlabs.operations.arm_templates_operations#ArmTemplatesOperations.{}', + client_factory=get_devtestlabs_arm_template_operation + ) # Virtual Machine Operations Commands - virtual_machine_operations = create_service_adapter( - mgmt_operations_path.format('virtual_machines_operations'), - 'VirtualMachinesOperations') - - with ServiceGroup(__name__, get_devtestlabs_virtual_machine_operation, - virtual_machine_operations) as s: - with s.group('lab vm') as c: - c.command('show', 'get', table_transformer=transform_vm) - c.command('delete', 'delete') - c.command('start', 'start') - c.command('stop', 'stop') - c.command('apply-artifacts', 'apply_artifacts') - - # Virtual Machine Operations Custom Commands - with ServiceGroup(__name__, get_devtestlabs_virtual_machine_operation, - custom_operations) as s: - with s.group('lab vm') as c: - c.command('list', 'list_vm', table_transformer=transform_vm_list) - c.command('claim', 'claim_vm') - - # Lab Operations Custom Commands - with ServiceGroup(__name__, get_devtestlabs_lab_operation, - custom_operations) as s: - with s.group('lab vm') as c: - c.command('create', 'create_lab_vm') - - lab_operations = create_service_adapter(mgmt_operations_path.format('labs_operations'), - 'LabsOperations') + with self.command_group('lab vm', virtual_machine_operations, + client_factory=get_devtestlabs_virtual_machine_operation) as g: + g.command('show', 'get', transform=transform_vm) + g.command('delete', 'delete') + g.command('start', 'start') + g.command('stop', 'stop') + g.command('apply-artifacts', 'apply_artifacts') + g.custom_command('list', 'list_vm', validator=validate_lab_vm_list, table_transformer=transform_vm_list) + g.custom_command('claim', 'claim_vm', validator=validate_claim_vm) + g.custom_command('create', 'create_lab_vm', client_factory=get_devtestlabs_lab_operation, + validator=validate_lab_vm_create) # Lab Operations Commands - with ServiceGroup(__name__, get_devtestlabs_lab_operation, - lab_operations) as s: - with s.group('lab') as c: - c.command('get', 'get') - c.command('delete', 'delete') + with self.command_group('lab', lab_operations) as g: + g.command('get', 'get') + g.command('delete', 'delete') # Custom Image Operations Commands - custom_image_operations = create_service_adapter( - mgmt_operations_path.format('custom_images_operations'), - 'CustomImagesOperations') - - with ServiceGroup(__name__, get_devtestlabs_custom_image_operation, - custom_image_operations) as s: - with s.group('lab custom-image') as c: - c.command('show', 'get') - c.command('list', 'list') - c.command('delete', 'delete') - - with ServiceGroup(__name__, get_devtestlabs_custom_image_operation, custom_operations) as s: - with s.group('lab custom-image') as c: - c.command('create', 'create_custom_image') + with self.command_group('lab custom-image', custom_image_operations) as g: + g.command('show', 'get') + g.command('list', 'list') + g.command('delete', 'delete') + g.custom_command('create', 'create_custom_image', client_factory=get_devtestlabs_custom_image_operation) # Gallery Image Operations Commands - gallery_image_operations = create_service_adapter( - mgmt_operations_path.format('gallery_images_operations'), - 'GalleryImagesOperations') - - with ServiceGroup(__name__, get_devtestlabs_gallery_image_operation, - gallery_image_operations) as s: - with s.group('lab gallery-image') as c: - c.command('list', 'list') + with self.command_group('lab gallery-image', gallery_image_operations) as g: + g.command('list', 'list') # Artifact Operations Commands - artifact_operations = create_service_adapter( - mgmt_operations_path.format('artifacts_operations'), - 'ArtifactsOperations') - - with ServiceGroup(__name__, get_devtestlabs_artifact_operation, - artifact_operations) as s: - with s.group('lab artifact') as c: - c.command('list', 'list') + with self.command_group('lab artifact', artifact_operations) as g: + g.command('list', 'list') # Artifact Source Operations Commands - artifact_source_operations = create_service_adapter( - mgmt_operations_path.format('artifact_sources_operations'), - 'ArtifactSourcesOperations') - - with ServiceGroup(__name__, get_devtestlabs_artifact_source_operation, - artifact_source_operations) as s: - with s.group('lab artifact-source') as c: - c.command('list', 'list', table_transformer=transform_artifact_source_list) - c.command('show', 'get', table_transformer=transform_artifact_source) + with self.command_group('lab artifact-source', artifact_source_operations) as g: + g.command('list', 'list', table_transformer=transform_artifact_source_list) + g.command('show', 'get', transform=transform_artifact_source) # Virtual Network Operations Commands - virtual_network_operations = create_service_adapter( - mgmt_operations_path.format('virtual_networks_operations'), - 'VirtualNetworksOperations') - - with ServiceGroup(__name__, get_devtestlabs_virtual_network_operation, - virtual_network_operations) as s: - with s.group('lab vnet') as c: - c.command('list', 'list') - c.command('get', 'get') + with self.command_group('lab vnet', virtual_network_operations) as g: + g.command('list', 'list') + g.command('get', 'get') # Formula Operations Commands - formula_operations = create_service_adapter( - mgmt_operations_path.format('formulas_operations'), - 'FormulasOperations') - - with ServiceGroup(__name__, get_devtestlabs_formula_operation, - formula_operations) as s: - with s.group('lab formula') as c: - c.command('show', 'get') - c.command('list', 'list') - c.command('delete', 'delete') - c.command('export-artifacts', 'get', transform=_export_artifacts) + with self.command_group('lab formula', formula_operations) as g: + g.command('show', 'get') + g.command('list', 'list') + g.command('delete', 'delete') + g.command('export-artifacts', 'get', transform=export_artifacts) # Secret Operations Commands - secret_operations = create_service_adapter( - mgmt_operations_path.format('secrets_operations'), - 'SecretsOperations') - - with ServiceGroup(__name__, get_devtestlabs_secret_operation, - secret_operations) as s: - with s.group('lab secret') as c: - c.command('set', 'create_or_update') - c.command('show', 'get') - c.command('list', 'list') - c.command('delete', 'delete') + with self.command_group('lab secret', secret_operations) as g: + g.command('set', 'create_or_update') + g.command('show', 'get') + g.command('list', 'list') + g.command('delete', 'delete') # Environment Operations Commands - environment_operations = create_service_adapter( - mgmt_operations_path.format('environments_operations'), - 'EnvironmentsOperations') - - with ServiceGroup(__name__, get_devtestlabs_environment_operation, - environment_operations) as s: - with s.group('lab environment') as c: - c.command('show', 'get') - c.command('list', 'list') - c.command('delete', 'delete') - c.command('create', 'create_or_update') - - # Environment Operations Custom Commands - with ServiceGroup(__name__, get_devtestlabs_environment_operation, - custom_operations) as s: - with s.group('lab environment') as c: - c.command('create', 'create_environment') + with self.command_group('lab environment', environment_operations) as g: + g.command('show', 'get') + g.command('list', 'list') + g.command('delete', 'delete') + g.command('create', 'create_or_update') + g.custom_command('create', 'create_environment', client_factory=get_devtestlabs_environment_operation) # ARM Templates Operations Commands - arm_template_operations = create_service_adapter( - mgmt_operations_path.format('arm_templates_operations'), - 'ArmTemplatesOperations') - - with ServiceGroup(__name__, get_devtestlabs_arm_template_operation, - arm_template_operations) as s: - with s.group('lab arm-template') as c: - c.command('list', 'list', table_transformer=transform_arm_template_list) - - # ARM Templates Operations Custom Commands - with ServiceGroup(__name__, get_devtestlabs_arm_template_operation, - custom_operations) as s: - with s.group('lab arm-template') as c: - c.command('show', 'show_arm_template', table_transformer=transform_arm_template) + with self.command_group('lab arm-template', arm_template_operations) as g: + g.command('list', 'list', table_transformer=transform_arm_template_list) + g.custom_command('show', 'show_arm_template', transform=transform_arm_template, + client_factory=get_devtestlabs_arm_template_operation) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/custom.py new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/custom.py --- old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/custom.py 2017-09-23 01:47:00.000000000 +0200 +++ new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/custom.py 2018-01-26 17:12:24.000000000 +0100 @@ -2,19 +2,17 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import getpass -from azure.mgmt.devtestlabs.models.custom_image_properties_from_vm import CustomImagePropertiesFromVm -from azure.mgmt.devtestlabs.models import CustomImage -from azure.mgmt.devtestlabs.models import WindowsOsInfo -from azure.mgmt.devtestlabs.models import LinuxOsInfo +import getpass # pylint: disable=too-many-locals, unused-argument, too-many-statements -def create_custom_image(client, resource_group, lab_name, name, source_vm_id, os_type, os_state, +def create_custom_image(client, resource_group_name, lab_name, name, source_vm_id, os_type, os_state, author=None, description=None): """ Command to create a custom image from a source VM, managed image, or VHD """ + from azure.mgmt.devtestlabs.models import ( + CustomImagePropertiesFromVm, CustomImage, WindowsOsInfo, LinuxOsInfo) if source_vm_id is not None: payload = CustomImagePropertiesFromVm( @@ -27,10 +25,10 @@ author=author, description=description) - return client.create_or_update(resource_group, lab_name, name, customImage) + return client.create_or_update(resource_group_name, lab_name, name, customImage) -def create_lab_vm(client, resource_group, lab_name, name, notes=None, image=None, image_type=None, +def create_lab_vm(client, resource_group_name, lab_name, name, notes=None, image=None, image_type=None, size=None, admin_username=getpass.getuser(), admin_password=None, ssh_key=None, authentication_type='password', vnet_name=None, subnet=None, disallow_public_ip_address=None, artifacts=None, @@ -64,31 +62,30 @@ allow_claim=allow_claim, storage_type=disk_type, expiration_date=expiration_date) - - return client.create_environment(resource_group, lab_name, lab_virtual_machine) + return client.create_environment(resource_group_name, lab_name, lab_virtual_machine) # pylint: disable=redefined-builtin -def list_vm(client, resource_group, lab_name, order_by=None, top=None, +def list_vm(client, resource_group_name, lab_name, order_by=None, top=None, filters=None, all=None, claimable=None, environment=None, expand=None, object_id=None): """ Command to list vms by resource group in the Azure DevTest Lab """ - return client.list(resource_group, lab_name, + return client.list(resource_group_name, lab_name, expand=expand, filter=filters, top=top, order_by=order_by) -def claim_vm(client, lab_name=None, name=None, resource_group=None): +def claim_vm(cmd, client, lab_name=None, name=None, resource_group_name=None): """ Command to claim a VM in the Azure DevTest Lab""" if name is not None: - return client.claim(resource_group, lab_name, name) + return client.claim(resource_group_name, lab_name, name) from ._client_factory import get_devtestlabs_lab_operation - return get_devtestlabs_lab_operation(None).claim_any_vm(resource_group, lab_name) + return get_devtestlabs_lab_operation(cmd.cli_ctx, None).claim_any_vm(resource_group_name, lab_name) # pylint: disable=too-many-locals, unused-argument -def create_environment(client, resource_group, lab_name, name, arm_template, parameters=None, +def create_environment(client, resource_group_name, lab_name, name, arm_template, parameters=None, artifact_source_name=None, user_name=None, tags=None): """ Command to create an environment the Azure DevTest Lab """ @@ -100,14 +97,14 @@ dtl_environment = DtlEnvironment(tags=tags, deployment_properties=environment_deployment_properties) - return client.create_or_update(resource_group, lab_name, user_name, name, dtl_environment) + return client.create_or_update(resource_group_name, lab_name, user_name, name, dtl_environment) -def show_arm_template(client, resource_group, lab_name, name, +def show_arm_template(client, resource_group_name, lab_name, name, artifact_source_name, export_parameters=False): """ Command to show azure resource manager template in the Azure DevTest Lab """ - arm_template = client.get(resource_group, lab_name, artifact_source_name, name) + arm_template = client.get(resource_group_name, lab_name, artifact_source_name, name) if export_parameters: return _export_parameters(arm_template) return arm_template diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/params.py new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/params.py --- old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/params.py 2017-09-23 01:47:00.000000000 +0200 +++ new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/params.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,118 +0,0 @@ -# -------------------------------------------------------------------------------------------- -# 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.command_modules.lab.validators import (validate_lab_vm_create, - validate_lab_vm_list, - validate_user_name, - validate_template_id, - validate_claim_vm, - _validate_artifacts) -from azure.cli.core.commands.parameters import resource_group_name_type -from azure.cli.core.sdk.util import ParametersContext -from azure.cli.core.util import get_json_object - - -with ParametersContext(command='lab') as c: - c.argument('resource_group', arg_type=resource_group_name_type, - help='Name of lab\'s resource group. You can configure the default group ' - 'using \'az configure --defaults group=<name>\'') - -with ParametersContext(command='lab custom-image create') as c: - c.register_alias('resource_group', ('--resource-group', '-g')) - c.register_alias('name', ('--name', '-n')) - -with ParametersContext(command='lab vm create') as c: - c.register_alias('resource_group', ('--resource-group', '-g'), validator=validate_lab_vm_create) - c.register_alias('name', ('--name', '-n')) - - # Authentication related arguments - authentication_group_name = 'Authentication' - c.argument('admin_username', arg_group=authentication_group_name) - c.argument('admin_password', arg_group=authentication_group_name) - c.argument('authentication_type', arg_group=authentication_group_name) - c.argument('ssh_key', arg_group=authentication_group_name) - c.argument('generate_ssh_keys', action='store_true', arg_group=authentication_group_name) - c.argument('saved_secret', arg_group=authentication_group_name) - - # Add Artifacts from json object - c.argument('artifacts', type=get_json_object) - - # Image related arguments - c.ignore('os_type') - c.ignore('gallery_image_reference') - c.ignore('custom_image_id') - c.argument('image') - - # Network related arguments - network_group_name = 'Network' - c.argument('ip_configuration', arg_group=network_group_name) - c.argument('subnet', arg_group=network_group_name) - c.argument('vnet_name', arg_group=network_group_name) - c.ignore('lab_subnet_name') - c.ignore('lab_virtual_network_id') - c.ignore('disallow_public_ip_address') - c.ignore('network_interface') - - # Creating VM in the different location then lab is an officially unsupported scenario - c.ignore('location') - - c.argument('expiration_date') - c.argument('formula') - c.argument('allow_claim', action='store_true') - - -with ParametersContext(command='lab vm list') as c: - filter_arg_group_name = 'Filter' - c.argument('filters', arg_group=filter_arg_group_name) - c.argument('all', action='store_true', arg_group=filter_arg_group_name) - c.argument('claimable', action='store_true', arg_group=filter_arg_group_name) - c.argument('environment', arg_group=filter_arg_group_name) - c.register_alias('resource_group', ('--resource-group', '-g'), validator=validate_lab_vm_list) - - -with ParametersContext(command='lab vm claim') as c: - c.register_alias('resource_group', ('--resource-group', '-g'), validator=validate_claim_vm) - c.register_alias('name', ('--name', '-n'), id_part='child_name') - c.argument('lab_name', id_part='name') - - -with ParametersContext(command='lab vm apply-artifacts') as c: - c.register('artifacts', ('--artifacts',), type=get_json_object, validator=_validate_artifacts) - c.register_alias('name', ('--name', '-n')) - - -with ParametersContext(command='lab formula') as c: - c.register_alias('name', ('--name', '-n')) - - -with ParametersContext(command='lab secret') as c: - from azure.mgmt.devtestlabs.models.secret import Secret - - c.register_alias('name', ('--name', '-n')) - c.register_alias('secret', ('--value', ), type=lambda x: Secret(value=x)) - c.ignore('user_name') - c.argument('lab_name', validator=validate_user_name) - - -with ParametersContext(command='lab formula export-artifacts') as c: - # Exporting artifacts does not need expand filter - c.ignore('expand') - - -with ParametersContext(command='lab environment') as c: - c.register_alias('name', ('--name', '-n')) - c.ignore('user_name') - c.argument('lab_name', validator=validate_user_name) - - -with ParametersContext(command='lab environment create') as c: - c.argument('arm_template', validator=validate_template_id) - c.argument('parameters', type=get_json_object) - -with ParametersContext(command='lab arm-template') as c: - c.register_alias('name', ('--name', '-n')) - -with ParametersContext(command='lab arm-template show') as c: - c.argument('export_parameters', action='store_true') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/validators.py new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/validators.py --- old/azure-cli-lab-0.0.11/azure/cli/command_modules/lab/validators.py 2017-09-23 01:47:00.000000000 +0200 +++ new/azure-cli-lab-0.0.16/azure/cli/command_modules/lab/validators.py 2018-01-26 17:12:24.000000000 +0100 @@ -3,32 +3,20 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os -import datetime -import dateutil.parser -from msrestazure.azure_exceptions import CloudError -from azure.cli.core.util import CLIError -from azure.cli.core.commands.arm import resource_id, is_valid_resource_id -from azure.mgmt.devtestlabs.models.gallery_image_reference import GalleryImageReference -from azure.mgmt.devtestlabs.models.network_interface_properties import NetworkInterfaceProperties -from azure.mgmt.devtestlabs.models.shared_public_ip_address_configuration import \ - SharedPublicIpAddressConfiguration -from azure.mgmt.devtestlabs.models.inbound_nat_rule import InboundNatRule -from azure.graphrbac import GraphRbacManagementClient -import azure.cli.core.azlogging as azlogging -from ._client_factory import (get_devtestlabs_management_client) +from knack.util import CLIError +from knack.log import get_logger -logger = azlogging.get_az_logger(__name__) +from azure.cli.command_modules.lab._client_factory import get_devtestlabs_management_client +logger = get_logger(__name__) # Odata filter for name ODATA_NAME_FILTER = "name eq '{}'" -def validate_lab_vm_create(namespace): +def validate_lab_vm_create(cmd, namespace): """ Validates parameters for lab vm create and updates namespace. """ formula = None - collection = [namespace.image, namespace.formula] if not _single(collection): raise CLIError("usage error: [--image name --image-type type | --formula name]") @@ -36,19 +24,20 @@ raise CLIError("usage error: [--image name --image-type type | --formula name]") if namespace.formula: - formula = _get_formula(namespace) + formula = _get_formula(cmd.cli_ctx, namespace) - _validate_location(namespace) + _validate_location(cmd.cli_ctx, namespace) _validate_expiration_date(namespace) _validate_other_parameters(namespace, formula) - _validate_artifacts(namespace) - _validate_image_argument(namespace, formula) - _validate_network_parameters(namespace, formula) + validate_artifacts(cmd, namespace) + _validate_image_argument(cmd.cli_ctx, namespace, formula) + _validate_network_parameters(cmd.cli_ctx, namespace, formula) validate_authentication_type(namespace, formula) -def validate_lab_vm_list(namespace): +def validate_lab_vm_list(cmd, namespace): """ Validates parameters for lab vm list and updates namespace. """ + from msrestazure.tools import resource_id, is_valid_resource_id collection = [namespace.filters, namespace.all, namespace.claimable] if _any(collection) and not _single(collection): raise CLIError("usage error: [--filters FILTER | [[--all | --claimable][--environment ENVIRONMENT]]") @@ -70,20 +59,20 @@ else: # Find out owner object id if not namespace.object_id: - namespace.filters = "Properties/ownerObjectId eq '{}'".format(_get_owner_object_id()) + namespace.filters = "Properties/ownerObjectId eq '{}'".format(_get_owner_object_id(cmd.cli_ctx)) if namespace.environment: if not is_valid_resource_id(namespace.environment): from azure.cli.core.commands.client_factory import get_subscription_id - namespace.environment = resource_id(subscription=get_subscription_id(), - resource_group=namespace.resource_group, + namespace.environment = resource_id(subscription=get_subscription_id(cmd.cli_ctx), + resource_group=namespace.resource_group_name, namespace='Microsoft.DevTestLab', type='labs', name=namespace.lab_name, - child_type='users', - child_name=_get_owner_object_id(), - grandchild_type='environments', - grandchild_name=namespace.environment) + child_type_1='users', + child_name_1=_get_owner_object_id(cmd.cli_ctx), + child_type_2='environments', + child_name_2=namespace.environment) if namespace.filters is None: namespace.filters = "Properties/environmentId eq '{}'".format(namespace.environment) else: @@ -95,39 +84,41 @@ namespace.user_name = "@me" -def validate_template_id(namespace): +def validate_template_id(cmd, namespace): + from msrestazure.tools import resource_id, is_valid_resource_id from azure.cli.core.commands.client_factory import get_subscription_id if not is_valid_resource_id(namespace.arm_template): if not namespace.artifact_source_name: raise CLIError("--artifact-source-name is required when name is " "provided for --arm-template") - namespace.arm_template = resource_id(subscription=get_subscription_id(), - resource_group=namespace.resource_group, + namespace.arm_template = resource_id(subscription=get_subscription_id(cmd.cli_ctx), + resource_group=namespace.resource_group_name, namespace='Microsoft.DevTestLab', type='labs', name=namespace.lab_name, - child_type='artifactSources', - child_name=namespace.artifact_source_name, - grandchild_type='armTemplates', - grandchild_name=namespace.arm_template) + child_type_1='artifactSources', + child_name_1=namespace.artifact_source_name, + child_type_2='armTemplates', + child_name_2=namespace.arm_template) def validate_claim_vm(namespace): - if namespace.name is None and namespace.lab_name is None or namespace.resource_group is None: + if namespace.name is None and namespace.lab_name is None or namespace.resource_group_name is None: raise CLIError("usage error: --ids IDs | --lab-name LabName --resource-group ResourceGroup --name VMName" " | --lab-name LabName --resource-group ResourceGroup") -def _get_owner_object_id(): - from azure.cli.core._profile import Profile, CLOUD +def _get_owner_object_id(cli_ctx): + from azure.cli.core._profile import Profile from azure.graphrbac.models import GraphErrorException - profile = Profile() + from azure.graphrbac import GraphRbacManagementClient + profile = Profile(cli_ctx=cli_ctx) cred, _, tenant_id = profile.get_login_credentials( - resource=CLOUD.endpoints.active_directory_graph_resource_id) + resource=cli_ctx.cloud.endpoints.active_directory_graph_resource_id) graph_client = GraphRbacManagementClient(cred, tenant_id, - base_url=CLOUD.endpoints.active_directory_graph_resource_id) + base_url=cli_ctx.cloud.endpoints.active_directory_graph_resource_id) subscription = profile.get_subscription() try: return _get_current_user_object_id(graph_client) @@ -136,13 +127,13 @@ # pylint: disable=no-member -def _validate_location(namespace): +def _validate_location(cli_ctx, namespace): """ Selects the default location of the lab when location is not provided. """ if namespace.location is None: - lab_operation = get_devtestlabs_management_client(None).labs - lab = lab_operation.get(namespace.resource_group, namespace.lab_name) + lab_operation = get_devtestlabs_management_client(cli_ctx, None).labs + lab = lab_operation.get(namespace.resource_group_name, namespace.lab_name) namespace.location = lab.location @@ -150,14 +141,16 @@ """ Validates expiration date if provided. """ if namespace.expiration_date: + import datetime + import dateutil.parser if datetime.datetime.utcnow().date() >= dateutil.parser.parse(namespace.expiration_date).date(): raise CLIError("Expiration date '{}' must be in future.".format(namespace.expiration_date)) # pylint: disable=no-member -def _validate_network_parameters(namespace, formula=None): +def _validate_network_parameters(cli_ctx, namespace, formula=None): """ Updates namespace for virtual network and subnet parameters """ - vnet_operation = get_devtestlabs_management_client(None).virtual_networks + vnet_operation = get_devtestlabs_management_client(cli_ctx, None).virtual_networks lab_vnet = None if formula and formula.formula_content: @@ -173,7 +166,7 @@ # User did not provide vnet and not selected from formula if not namespace.vnet_name: - lab_vnets = list(vnet_operation.list(namespace.resource_group, namespace.lab_name, top=1)) + lab_vnets = list(vnet_operation.list(namespace.resource_group_name, namespace.lab_name, top=1)) if not lab_vnets: err = "Unable to find any virtual network in the '{}' lab.".format(namespace.lab_name) raise CLIError(err) @@ -183,7 +176,7 @@ namespace.lab_virtual_network_id = lab_vnet.id # User did provide vnet or has been selected from formula else: - lab_vnet = vnet_operation.get(namespace.resource_group, namespace.lab_name, namespace.vnet_name) + lab_vnet = vnet_operation.get(namespace.resource_group_name, namespace.lab_name, namespace.vnet_name) namespace.lab_virtual_network_id = lab_vnet.id # User did not provide subnet and not selected from formula @@ -196,6 +189,7 @@ # pylint: disable=no-member def _validate_ip_configuration(namespace, lab_vnet=None): """ Updates namespace with network_interface & disallow_public_ip_address """ + from azure.mgmt.devtestlabs.models import NetworkInterfaceProperties, SharedPublicIpAddressConfiguration # case 1: User selecting "shared" ip configuration if namespace.ip_configuration == 'shared': @@ -233,6 +227,7 @@ def _inbound_rule_from_os(namespace): + from azure.mgmt.devtestlabs.models import InboundNatRule if namespace.os_type == 'Linux': return InboundNatRule(transport_protocol='Tcp', backend_port=22) @@ -240,8 +235,9 @@ # pylint: disable=no-member -def _validate_image_argument(namespace, formula=None): +def _validate_image_argument(cli_ctx, namespace, formula=None): """ Update namespace for image based on image or formula """ + from azure.mgmt.devtestlabs.models import GalleryImageReference if formula and formula.formula_content: if formula.formula_content.gallery_image_reference: gallery_image_reference = formula.formula_content.gallery_image_reference @@ -259,20 +255,21 @@ namespace.image_type = 'custom' if namespace.image_type == 'gallery': - _use_gallery_image(namespace) + _use_gallery_image(cli_ctx, namespace) elif namespace.image_type == 'custom': - _use_custom_image(namespace) + _use_custom_image(cli_ctx, namespace) else: raise CLIError("incorrect value for image-type: '{}'. Allowed values: gallery or custom" .format(namespace.image_type)) # pylint: disable=no-member -def _use_gallery_image(namespace): +def _use_gallery_image(cli_ctx, namespace): """ Retrieve gallery image from lab and update namespace """ - gallery_image_operation = get_devtestlabs_management_client(None).gallery_images + from azure.mgmt.devtestlabs.models import GalleryImageReference + gallery_image_operation = get_devtestlabs_management_client(cli_ctx, None).gallery_images odata_filter = ODATA_NAME_FILTER.format(namespace.image) - gallery_images = list(gallery_image_operation.list(namespace.resource_group, + gallery_images = list(gallery_image_operation.list(namespace.resource_group_name, namespace.lab_name, filter=odata_filter)) @@ -294,14 +291,15 @@ # pylint: disable=no-member -def _use_custom_image(namespace): +def _use_custom_image(cli_ctx, namespace): """ Retrieve custom image from lab and update namespace """ + from msrestazure.tools import is_valid_resource_id if is_valid_resource_id(namespace.image): namespace.custom_image_id = namespace.image else: - custom_image_operation = get_devtestlabs_management_client(None).custom_images + custom_image_operation = get_devtestlabs_management_client(cli_ctx, None).custom_images odata_filter = ODATA_NAME_FILTER.format(namespace.image) - custom_images = list(custom_image_operation.list(namespace.resource_group, + custom_images = list(custom_image_operation.list(namespace.resource_group_name, namespace.lab_name, filter=odata_filter)) if not custom_images: @@ -326,11 +324,11 @@ namespace.os_type = os_type -def _get_formula(namespace): +def _get_formula(cli_ctx, namespace): """ Retrieve formula image from lab """ - formula_operation = get_devtestlabs_management_client(None).formulas + formula_operation = get_devtestlabs_management_client(cli_ctx, None).formulas odata_filter = ODATA_NAME_FILTER.format(namespace.formula) - formula_images = list(formula_operation.list(namespace.resource_group, + formula_images = list(formula_operation.list(namespace.resource_group_name, namespace.lab_name, filter=odata_filter)) if not formula_images: @@ -355,7 +353,8 @@ namespace.os_type = formula.os_type -def _validate_artifacts(namespace): +def validate_artifacts(cmd, namespace): + from msrestazure.tools import resource_id if namespace.artifacts: from azure.cli.core.commands.client_factory import get_subscription_id if hasattr(namespace, 'resource_group'): @@ -364,7 +363,7 @@ # some SDK methods have parameter name as 'resource_group_name' resource_group = namespace.resource_group_name - lab_resource_id = resource_id(subscription=get_subscription_id(), + lab_resource_id = resource_id(subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group, namespace='Microsoft.DevTestLab', type='labs', @@ -390,6 +389,7 @@ def _update_artifact_id(artifact_id, lab_resource_id): + from msrestazure.tools import is_valid_resource_id if not is_valid_resource_id(artifact_id): return "{}{}".format(lab_resource_id, artifact_id) return artifact_id @@ -420,7 +420,7 @@ if not namespace.admin_password: # prompt for admin password if not supplied - from azure.cli.core.prompting import prompt_pass, NoTTYException + from knack.prompting import prompt_pass, NoTTYException try: namespace.admin_password = prompt_pass('Admin Password: ', confirm=True) except NoTTYException: @@ -449,6 +449,8 @@ def validate_ssh_key(namespace): + import os + string_or_file = (namespace.ssh_key or os.path.join(os.path.expanduser('~'), '.ssh/id_rsa.pub')) content = string_or_file @@ -475,6 +477,7 @@ def _generate_ssh_keys(private_key_filepath, public_key_filepath): + import os import paramiko ssh_dir, _ = os.path.split(private_key_filepath) @@ -524,12 +527,14 @@ def _get_current_user_object_id(graph_client): + from msrestazure.azure_exceptions import CloudError try: current_user = graph_client.objects.get_current_user() if current_user and current_user.object_id: # pylint:disable=no-member return current_user.object_id # pylint:disable=no-member except CloudError: pass + return None def _get_object_id(graph_client, subscription=None, spn=None, upn=None): @@ -551,6 +556,7 @@ else: logger.warning('Current credentials are not from a user or service principal. ' 'Azure DevTest Lab does not work with certificate credentials.') + return None def _get_object_id_by_spn(graph_client, spn): @@ -558,11 +564,11 @@ filter="servicePrincipalNames/any(c:c eq '{}')".format(spn))) if not accounts: logger.warning("Unable to find user with spn '%s'", spn) - return + return None if len(accounts) > 1: logger.warning("Multiple service principals found with spn '%s'. " "You can avoid this by specifying object id.", spn) - return + return None return accounts[0].object_id @@ -570,9 +576,9 @@ accounts = list(graph_client.users.list(filter="userPrincipalName eq '{}'".format(upn))) if not accounts: logger.warning("Unable to find user with upn '%s'", upn) - return + return None if len(accounts) > 1: logger.warning("Multiple users principals found with upn '%s'. " "You can avoid this by specifying object id.", upn) - return + return None return accounts[0].object_id diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/azure_cli_lab.egg-info/PKG-INFO new/azure-cli-lab-0.0.16/azure_cli_lab.egg-info/PKG-INFO --- old/azure-cli-lab-0.0.11/azure_cli_lab.egg-info/PKG-INFO 2017-09-23 01:48:29.000000000 +0200 +++ new/azure-cli-lab-0.0.16/azure_cli_lab.egg-info/PKG-INFO 2018-01-26 17:12:47.000000000 +0100 @@ -1,12 +1,11 @@ Metadata-Version: 1.1 Name: azure-cli-lab -Version: 0.0.11 +Version: 0.0.16 Summary: Microsoft Azure Command-Line Tools DevTestLabs Command Module Home-page: https://github.com/Azure/azure-cli Author: Microsoft Corporation Author-email: [email protected] License: MIT -Description-Content-Type: UNKNOWN Description: Microsoft Azure CLI 'DevTestLabs' Command Module ================================================ @@ -15,6 +14,27 @@ Release History =============== + + 0.0.16 + ++++++ + * Performance fixes. + + 0.0.15 + ++++++ + * Update helpfile + + 0.0.14 + ++++++ + * Update for CLI core changes. + + 0.0.13 + ++++++ + * Minor fixes. + + 0.0.12 + ++++++ + * minor fixes + 0.0.11 (2017-09-22) +++++++++++++++++++ * minor fixes diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/azure_cli_lab.egg-info/SOURCES.txt new/azure-cli-lab-0.0.16/azure_cli_lab.egg-info/SOURCES.txt --- old/azure-cli-lab-0.0.11/azure_cli_lab.egg-info/SOURCES.txt 2017-09-23 01:48:29.000000000 +0200 +++ new/azure-cli-lab-0.0.16/azure_cli_lab.egg-info/SOURCES.txt 2018-01-26 17:12:47.000000000 +0100 @@ -8,10 +8,11 @@ azure/cli/command_modules/__init__.py azure/cli/command_modules/lab/__init__.py azure/cli/command_modules/lab/_client_factory.py +azure/cli/command_modules/lab/_format.py azure/cli/command_modules/lab/_help.py +azure/cli/command_modules/lab/_params.py azure/cli/command_modules/lab/commands.py azure/cli/command_modules/lab/custom.py -azure/cli/command_modules/lab/params.py azure/cli/command_modules/lab/validators.py azure_cli_lab.egg-info/PKG-INFO azure_cli_lab.egg-info/SOURCES.txt diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/azure_cli_lab.egg-info/requires.txt new/azure-cli-lab-0.0.16/azure_cli_lab.egg-info/requires.txt --- old/azure-cli-lab-0.0.11/azure_cli_lab.egg-info/requires.txt 2017-09-23 01:48:29.000000000 +0200 +++ new/azure-cli-lab-0.0.16/azure_cli_lab.egg-info/requires.txt 2018-01-26 17:12:47.000000000 +0100 @@ -1,4 +1,3 @@ azure-cli-core azure-graphrbac==0.31.0 azure-mgmt-devtestlabs==2.0.0 -azure-cli-command-modules-nspkg>=2.0.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/azure-cli-lab-0.0.11/setup.py new/azure-cli-lab-0.0.16/setup.py --- old/azure-cli-lab-0.0.11/setup.py 2017-09-23 01:48:28.000000000 +0200 +++ new/azure-cli-lab-0.0.16/setup.py 2018-01-26 17:12:24.000000000 +0100 @@ -12,7 +12,7 @@ logger.warn("Wheel is not available, disabling bdist_wheel hook") cmdclass = {} -VERSION = "0.0.11" +VERSION = "0.0.16" CLASSIFIERS = [ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers',
