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

Added upgrade-tools commands #190

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions src/dev-spaces-preview/azext_dev_spaces_preview/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 2 additions & 30 deletions src/dev-spaces-preview/azext_dev_spaces_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>'.
- 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>'.
- name: --yes -y
type: bool
short-summary: Do not prompt for confirmation.
short-summary: (PREVIEW) Upgrade Azure Dev Spaces tools.
"""
53 changes: 31 additions & 22 deletions src/dev-spaces-preview/azext_dev_spaces_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/dev-spaces-preview/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from setuptools import setup, find_packages

VERSION = "0.1.1"
VERSION = "0.1.2"

CLASSIFIERS = [
'Development Status :: 4 - Beta',
Expand Down
8 changes: 4 additions & 4 deletions src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
],
Expand Down