diff --git a/src/dev-spaces-preview/azext_dev_spaces_preview/__init__.py b/src/dev-spaces-preview/azext_dev_spaces_preview/__init__.py index 8158947a5f6..28e3fe344e2 100644 --- a/src/dev-spaces-preview/azext_dev_spaces_preview/__init__.py +++ b/src/dev-spaces-preview/azext_dev_spaces_preview/__init__.py @@ -21,21 +21,8 @@ def __init__(self, cli_ctx=None): def load_command_table(self, _): with self.command_group('ads') as g: - g.custom_command('use', 'ads_use_dev_spaces') - g.custom_command('remove', 'ads_remove_dev_spaces') + g.custom_command('upgrade-tools', 'ads_upgrade_dev_spaces_tools') return self.command_table - def load_arguments(self, _): - with self.argument_context('ads use') as c: - c.argument('cluster_name', options_list=['--name', '-n']) - c.argument('resource_group_name', options_list=['--resource-group', '-g']) - c.argument('space_name', options_list=['--space', '-s']) - c.argument('parent_space_name', options_list=['--parent-space', '-p']) - - with self.argument_context('ads remove') as c: - c.argument('cluster_name', options_list=['--name', '-n']) - c.argument('resource_group_name', options_list=['--resource-group', '-g']) - c.argument('prompt', options_list=['--yes', '-y'], action='store_true') - COMMAND_LOADER_CLS = DevspacesExtCommandLoader diff --git a/src/dev-spaces-preview/azext_dev_spaces_preview/_help.py b/src/dev-spaces-preview/azext_dev_spaces_preview/_help.py index 74b506a7684..01e8ccaa482 100644 --- a/src/dev-spaces-preview/azext_dev_spaces_preview/_help.py +++ b/src/dev-spaces-preview/azext_dev_spaces_preview/_help.py @@ -13,35 +13,7 @@ short-summary: (PREVIEW) Manage Azure Dev Spaces. """ -helps['ads use'] = """ +helps['ads upgrade-tools'] = """ type: command - short-summary: (PREVIEW) Use Azure Dev Spaces with a managed Kubernetes cluster. - parameters: - - name: --name -n - type: string - short-summary: Name of the managed cluster. - - name: --resource-group -g - type: string - short-summary: Name of resource group. You can configure the default group using 'az configure --defaults group='. - - name: --space -s - type: string - short-summary: Name of the dev space to use. - - name: --parent-space -p - type: string - short-summary: Name of a parent dev space to inherit from when creating a new dev space. By default, if there is already a single dev space with no parent, the new space inherits from this one. -""" - -helps['ads remove'] = """ - type: command - short-summary: (PREVIEW) Remove Azure Dev Spaces from a managed Kubernetes cluster. - parameters: - - name: --name -n - type: string - short-summary: Name of the managed cluster. - - name: --resource-group -g - type: string - short-summary: Name of resource group. You can configure the default group using 'az configure --defaults group='. - - name: --yes -y - type: bool - short-summary: Do not prompt for confirmation. + short-summary: (PREVIEW) Upgrade Azure Dev Spaces tools. """ diff --git a/src/dev-spaces-preview/azext_dev_spaces_preview/custom.py b/src/dev-spaces-preview/azext_dev_spaces_preview/custom.py index 606739008fe..16068cdd49d 100644 --- a/src/dev-spaces-preview/azext_dev_spaces_preview/custom.py +++ b/src/dev-spaces-preview/azext_dev_spaces_preview/custom.py @@ -15,10 +15,10 @@ logger = get_logger(__name__) -# pylint:disable=no-member,too-many-lines,too-many-locals,too-many-statements +# pylint:disable=no-member,too-many-lines,too-many-locals,too-many-statements,too-few-public-methods -def ads_use_dev_spaces(cluster_name, resource_group_name, space_name='default', parent_space_name=None): # pylint: disable=line-too-long +def ads_use_dev_spaces(cluster_name, resource_group_name, space_name='default', parent_space_name=None): """ Use Azure Dev Spaces with a managed Kubernetes cluster. @@ -34,40 +34,42 @@ def ads_use_dev_spaces(cluster_name, resource_group_name, space_name='default', :type parent_space_name: String """ - azds_cli = _install_dev_spaces_cli() + azds_cli = _install_dev_spaces_cli(False) from subprocess import PIPE should_create_resource = False + create_resource_ret_code = 0 retCode = subprocess.call( [azds_cli, 'resource', 'select', '-n', cluster_name, '-g', resource_group_name], stderr=PIPE) if retCode == 1: should_create_resource = True + create_resource_ret_code = 1 if should_create_resource: - retCode = subprocess.call( + create_resource_ret_code = subprocess.call( [azds_cli, 'resource', 'create', '--aks-name', cluster_name, '--aks-resource-group', resource_group_name, '--name', cluster_name, '--resource-group', resource_group_name], universal_newlines=True) - if retCode == 0: - should_create_spaces = False - create_space_arguments = [azds_cli, 'space', 'select', '--name', space_name] - if parent_space_name is not None: - create_space_arguments.append('--parent') - create_space_arguments.append(parent_space_name) - retCode = subprocess.call( - create_space_arguments, stderr=PIPE) - if retCode == 1: - should_create_spaces = True + if create_resource_ret_code == 0: + should_create_spaces = False + create_space_arguments = [azds_cli, 'space', 'select', '--name', space_name] + if parent_space_name is not None: + create_space_arguments.append('--parent') + create_space_arguments.append(parent_space_name) + retCode = subprocess.call( + create_space_arguments, stderr=PIPE) + if retCode == 1: + should_create_spaces = True - if should_create_spaces: - subprocess.call( - [azds_cli, 'space', 'create', '--name', space_name], - universal_newlines=True) + if should_create_spaces: + subprocess.call( + [azds_cli, 'space', 'create', '--name', space_name], + universal_newlines=True) -def ads_remove_dev_spaces(cluster_name, resource_group_name, prompt=False): # pylint: disable=line-too-long +def ads_remove_dev_spaces(cluster_name, resource_group_name, prompt=False): """ Remove Azure Dev Spaces from a managed Kubernetes cluster. @@ -80,7 +82,7 @@ def ads_remove_dev_spaces(cluster_name, resource_group_name, prompt=False): # p :type prompt: bool """ - azds_cli = _install_dev_spaces_cli() + azds_cli = _install_dev_spaces_cli(False) remove_command_arguments = [azds_cli, 'resource', 'rm', '--name', cluster_name, '--resource-group', resource_group_name] @@ -90,6 +92,13 @@ def ads_remove_dev_spaces(cluster_name, resource_group_name, prompt=False): # p remove_command_arguments, universal_newlines=True) +def ads_upgrade_dev_spaces_tools(): + """ + Upgrade Azure Dev Spaces tools. + """ + _install_dev_spaces_cli(True) + + def _create_tmp_dir(): tmp_dir = tempfile.mkdtemp() return tmp_dir @@ -104,7 +113,7 @@ def _is_dev_spaces_installed(vsce_cli): return True -def _install_dev_spaces_cli(): +def _install_dev_spaces_cli(force_install): azds_tool = 'Azure Dev Spaces CLI' should_install_azds = False system = platform.system() @@ -132,7 +141,7 @@ def _install_dev_spaces_cli(): else: raise CLIError('Platform not supported: {}.'.format(system)) - should_install_azds = not _is_dev_spaces_installed(azds_cli) + should_install_azds = force_install | (not _is_dev_spaces_installed(azds_cli)) if should_install_azds: # Install AZDS diff --git a/src/dev-spaces-preview/setup.py b/src/dev-spaces-preview/setup.py index 4b492c16c52..ae3fc2187ab 100644 --- a/src/dev-spaces-preview/setup.py +++ b/src/dev-spaces-preview/setup.py @@ -7,7 +7,7 @@ from setuptools import setup, find_packages -VERSION = "0.1.1" +VERSION = "0.1.2" CLASSIFIERS = [ 'Development Status :: 4 - Beta', diff --git a/src/index.json b/src/index.json index ae3f558c5d0..eedb0735db8 100644 --- a/src/index.json +++ b/src/index.json @@ -326,9 +326,9 @@ ], "dev-spaces-preview": [ { - "filename": "dev_spaces_preview-0.1.1-py2.py3-none-any.whl", - "sha256Digest": "59557d90999178dddbdcb14590202efe3d4d016186484ce33cfe0984a312c73b", - "downloadUrl": "https://azuredevspacestools.blob.core.windows.net/azdssetup/LKS/dev_spaces_preview-0.1.1-py2.py3-none-any.whl", + "filename": "dev_spaces_preview-0.1.2-py2.py3-none-any.whl", + "sha256Digest": "8ce34d6d78059e14099100e9e7d466d0a098412367d4915d266c8971b38685e4", + "downloadUrl": "https://azuredevspacestools.blob.core.windows.net/azdssetup/LKS/dev_spaces_preview-0.1.2-py2.py3-none-any.whl", "metadata": { "azext.isPreview": true, "azext.minCliCoreVersion": "2.0.32", @@ -367,7 +367,7 @@ "metadata_version": "2.0", "name": "dev-spaces-preview", "summary": "Dev Spaces provides a rapid, iterative Kubernetes development experience for teams.", - "version": "0.1.1" + "version": "0.1.2" } } ],