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

Updating the dev-spaces command from aks group to ads group #183

Merged
merged 4 commits into from
May 17, 2018
Merged
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
11 changes: 6 additions & 5 deletions src/dev-spaces-preview/azext_dev_spaces_preview/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from azure.cli.core import AzCommandsLoader

import azext_dev_spaces_preview._help # pylint: disable=unused-import
import azext_dev_spaces_preview.custom # pylint: disable=unused-import


class DevspacesExtCommandLoader(AzCommandsLoader):
Expand All @@ -19,19 +20,19 @@ def __init__(self, cli_ctx=None):
min_profile='2017-03-10-profile')

def load_command_table(self, _):
with self.command_group('aks') as g:
g.custom_command('use-dev-spaces', 'aks_use_dev_spaces')
g.custom_command('remove-dev-spaces', 'aks_remove_dev_spaces')
with self.command_group('ads') as g:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the plan was to make these internal (so they don't appear as actual commands in az).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the next update when we have other commands. Right not the extension should have some exposed commands to work with.

g.custom_command('use', 'ads_use_dev_spaces')
g.custom_command('remove', 'ads_remove_dev_spaces')
return self.command_table

def load_arguments(self, _):
with self.argument_context('aks use-dev-spaces') as c:
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('aks remove-dev-spaces') as c:
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')
Expand Down
11 changes: 9 additions & 2 deletions src/dev-spaces-preview/azext_dev_spaces_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
from knack.help_files import helps # pylint: disable=import-error


helps['aks use-dev-spaces'] = """
# ADS command help

helps['ads'] = """
type: group
short-summary: (PREVIEW) Manage Azure Dev Spaces.
"""

helps['ads use'] = """
type: command
short-summary: (PREVIEW) Use Azure Dev Spaces with a managed Kubernetes cluster.
parameters:
Expand All @@ -24,7 +31,7 @@
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['aks remove-dev-spaces'] = """
helps['ads remove'] = """
type: command
short-summary: (PREVIEW) Remove Azure Dev Spaces from a managed Kubernetes cluster.
parameters:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"azext.minCliCoreVersion": "2.0.27",
"azext.minCliCoreVersion": "2.0.32",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR relies on the CLI's next release right?
If so, change this to 2.0.33.dev0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this extn doesnot depend on cli update but it definitely goes the other way round.

"azext.isPreview": true
}
142 changes: 67 additions & 75 deletions src/dev-spaces-preview/azext_dev_spaces_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# pylint:disable=no-member,too-many-lines,too-many-locals,too-many-statements


def aks_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): # pylint: disable=line-too-long
"""
Use Azure Dev Spaces with a managed Kubernetes cluster.

Expand All @@ -34,49 +34,7 @@ def aks_use_dev_spaces(cluster_name, resource_group_name, space_name='default',
:type parent_space_name: String
"""

azds_tool = 'Azure Dev Spaces CLI (Preview)'
should_install_vsce = False
system = platform.system()
if system == 'Windows':
# Windows
# Dev Connect Install Path (WinX)
azds_cli = os.path.join(os.environ["ProgramW6432"],
"Microsoft SDKs", "Azure",
"Azure Dev Spaces CLI (Preview)", "azds.exe")
setup_file = os.path.join(_create_tmp_dir(), 'azds-winx-setup.exe')
setup_url = "https://aka.ms/get-azds-windows-az"
setup_args = [setup_file]
elif system == 'Darwin':
# OSX
azds_cli = 'azds'
setup_file = os.path.join(_create_tmp_dir(), 'azds-osx-setup.sh')
setup_url = "https://aka.ms/get-azds-osx-az"
setup_args = ['bash', setup_file]
elif system == 'Linux':
# OSX
azds_cli = 'azds'
setup_file = os.path.join(_create_tmp_dir(), 'azds-linux-setup.sh')
setup_url = "https://aka.ms/get-azds-linux-az"
setup_args = ['bash', setup_file]
else:
raise CLIError('Platform not supported: {}.'.format(system))

should_install_vsce = not _is_dev_spaces_installed(azds_cli)

if should_install_vsce:
# Install VSCE
logger.info('Installing Dev Spaces (Preview) commands...')
urlretrieve(setup_url, setup_file)
try:
subprocess.call(
setup_args, universal_newlines=True, stdin=None, stdout=None, stderr=None, shell=False)
except OSError as ex:
raise CLIError('Installing {} tooling needs permissions: {}'.format(azds_tool, ex))
finally:
os.remove(setup_file)
if not _is_dev_spaces_installed(azds_cli):
raise CLIError("{} not installed properly. Visit 'https://aka.ms/get-azds' for Azure Dev Spaces."
.format(azds_tool))
azds_cli = _install_dev_spaces_cli()

from subprocess import PIPE
should_create_resource = False
Expand All @@ -87,28 +45,29 @@ def aks_use_dev_spaces(cluster_name, resource_group_name, space_name='default',
should_create_resource = True

if should_create_resource:
subprocess.call(
retCode = 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)

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 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 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 aks_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): # pylint: disable=line-too-long
"""
Remove Azure Dev Spaces from a managed Kubernetes cluster.

Expand All @@ -121,22 +80,7 @@ def aks_remove_dev_spaces(cluster_name, resource_group_name, prompt=False): # p
:type prompt: bool
"""

azds_tool = 'Azure Dev Spaces CLI'
system = platform.system()
if system == 'Windows':
# Windows
azds_cli = os.path.join(os.environ["ProgramW6432"],
"Microsoft SDKs", "Azure",
"Azure Dev Spaces CLI (Preview)", "azds.exe")
elif system == 'Darwin':
# OSX
azds_cli = 'azds'
else:
raise CLIError('Platform not supported: {}.'.format(system))

if not _is_dev_spaces_installed(azds_cli):
raise CLIError("{} not installed properly. Use 'az aks use-dev-spaces' commands for Azure Dev Spaces."
.format(azds_tool))
azds_cli = _install_dev_spaces_cli()

remove_command_arguments = [azds_cli, 'resource', 'rm', '--name',
cluster_name, '--resource-group', resource_group_name]
Expand All @@ -158,3 +102,51 @@ def _is_dev_spaces_installed(vsce_cli):
except OSError:
return False
return True


def _install_dev_spaces_cli():
azds_tool = 'Azure Dev Spaces CLI'
should_install_azds = False
system = platform.system()
if system == 'Windows':
# Windows
# Dev Spaces Install Path (WinX)
azds_cli = os.path.join(os.environ["ProgramW6432"],
"Microsoft SDKs", "Azure",
"Azure Dev Spaces CLI (Preview)", "azds.exe")
setup_file = os.path.join(_create_tmp_dir(), 'azds-winx-setup.exe')
setup_url = "https://aka.ms/get-azds-windows-az"
setup_args = [setup_file]
elif system == 'Darwin':
# OSX
azds_cli = 'azds'
setup_file = os.path.join(_create_tmp_dir(), 'azds-osx-setup.sh')
setup_url = "https://aka.ms/get-azds-osx-az"
setup_args = ['bash', setup_file]
elif system == 'Linux':
# Linux
azds_cli = 'azds'
setup_file = os.path.join(_create_tmp_dir(), 'azds-linux-setup.sh')
setup_url = "https://aka.ms/get-azds-linux-az"
setup_args = ['bash', setup_file]
else:
raise CLIError('Platform not supported: {}.'.format(system))

should_install_azds = not _is_dev_spaces_installed(azds_cli)

if should_install_azds:
# Install AZDS
logger.info('Installing Dev Spaces (Preview) commands...')
urlretrieve(setup_url, setup_file)
try:
subprocess.call(
setup_args, universal_newlines=True, stdin=None, stdout=None, stderr=None, shell=False)
except OSError as ex:
raise CLIError('Installing {} tooling needs permissions: {}'.format(azds_tool, ex))
finally:
os.remove(setup_file)
if not _is_dev_spaces_installed(azds_cli):
raise CLIError("{} not installed properly. Visit 'https://aka.ms/get-azds' for Azure Dev Spaces."
.format(azds_tool))

return azds_cli