-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding dev-spaces extension under the aks module (#168)
* Adding dev-connect extension under the aks module * Update Windows Install Path * Update error message * Added space create/select functionality with --parent-space options * File Structure updated * Update * CR updates - Refactor - min AZ cli dependency * Update package name * Adding Linux support * CI build fix * Updating index - including dev-spaces-preview CI build fix * Fix CI * Reverting index changes * Updating PermissionError to OSError * Update * Updating CodeOwners
- Loading branch information
Showing
8 changed files
with
302 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,5 @@ | |
|
||
/src/storage-preview/ @williexu | ||
|
||
/src/dev-spaces-preview/ @saurabsa | ||
|
40 changes: 40 additions & 0 deletions
40
src/dev-spaces-preview/azext_dev_spaces_preview/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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.core import AzCommandsLoader | ||
|
||
import azext_dev_spaces_preview._help # pylint: disable=unused-import | ||
|
||
|
||
class DevspacesExtCommandLoader(AzCommandsLoader): | ||
|
||
def __init__(self, cli_ctx=None): | ||
from azure.cli.core.commands import CliCommandType | ||
dev_spaces_custom = CliCommandType( | ||
operations_tmpl='azext_dev_spaces_preview.custom#{}') | ||
super(DevspacesExtCommandLoader, self).__init__(cli_ctx=cli_ctx, | ||
custom_command_type=dev_spaces_custom, | ||
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') | ||
return self.command_table | ||
|
||
def load_arguments(self, _): | ||
with self.argument_context('aks use-dev-spaces') 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: | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from knack.help_files import helps # pylint: disable=import-error | ||
|
||
|
||
helps['aks use-dev-spaces'] = """ | ||
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['aks remove-dev-spaces'] = """ | ||
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. | ||
""" |
4 changes: 4 additions & 0 deletions
4
src/dev-spaces-preview/azext_dev_spaces_preview/azext_metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"azext.minCliCoreVersion": "2.0.27", | ||
"azext.isPreview": true | ||
} |
160 changes: 160 additions & 0 deletions
160
src/dev-spaces-preview/azext_dev_spaces_preview/custom.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from __future__ import print_function | ||
import os | ||
import platform | ||
import subprocess | ||
import tempfile | ||
from six.moves.urllib.request import urlretrieve # pylint: disable=import-error | ||
from knack.log import get_logger # pylint: disable=import-error | ||
from knack.util import CLIError # pylint: disable=import-error | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
# 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 | ||
""" | ||
Use Azure Dev Spaces with a managed Kubernetes cluster. | ||
:param cluster_name: Name of the managed cluster. | ||
:type cluster_name: String | ||
:param resource_group_name: Name of resource group. You can configure the default group. \ | ||
Using 'az configure --defaults group=<name>'. | ||
:type resource_group_name: String | ||
:param space_name: Name of the dev space to use. | ||
:type space_name: String | ||
:param parent_space_name: 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. | ||
: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)) | ||
|
||
from subprocess import PIPE | ||
should_create_resource = False | ||
retCode = subprocess.call( | ||
[azds_cli, 'resource', 'select', '-n', cluster_name, '-g', resource_group_name], | ||
stderr=PIPE) | ||
if retCode == 1: | ||
should_create_resource = True | ||
|
||
if should_create_resource: | ||
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 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 | ||
""" | ||
Remove Azure Dev Spaces from a managed Kubernetes cluster. | ||
:param cluster_name: Name of the managed cluster. | ||
:type cluster_name: String | ||
:param resource_group_name: Name of resource group. You can configure the default group. \ | ||
Using 'az configure --defaults group=<name>'. | ||
:type resource_group_name: String | ||
:param prompt: Do not prompt for confirmation. | ||
: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)) | ||
|
||
remove_command_arguments = [azds_cli, 'resource', 'rm', '--name', | ||
cluster_name, '--resource-group', resource_group_name] | ||
if prompt: | ||
remove_command_arguments.append('-y') | ||
subprocess.call( | ||
remove_command_arguments, universal_newlines=True) | ||
|
||
|
||
def _create_tmp_dir(): | ||
tmp_dir = tempfile.mkdtemp() | ||
return tmp_dir | ||
|
||
|
||
def _is_dev_spaces_installed(vsce_cli): | ||
try: | ||
from subprocess import PIPE, Popen | ||
Popen([vsce_cli], stdout=PIPE, stderr=PIPE) | ||
except OSError: | ||
return False | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Azure CLI Dev Spaces Preview Extension # | ||
This is a extension for dev spaces features. | ||
|
||
## How to use ## | ||
First, install the extension: | ||
``` | ||
az extension add --name dev-spaces-preview | ||
``` | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[bdist_wheel] | ||
universal=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python | ||
|
||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from setuptools import setup, find_packages | ||
|
||
VERSION = "0.1.0" | ||
|
||
CLASSIFIERS = [ | ||
'Development Status :: 4 - Beta', | ||
'Intended Audience :: Developers', | ||
'Intended Audience :: System Administrators', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 2', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
'License :: OSI Approved :: MIT License', | ||
] | ||
|
||
DEPENDENCIES = [] | ||
|
||
setup( | ||
name='dev-spaces-preview', | ||
version=VERSION, | ||
description='Dev Spaces provides a rapid, iterative Kubernetes development experience for teams.', | ||
long_description='Iteratively develop and debug containers in a Azure Kubernetes Service cluster using Dev Spaces. \ | ||
Share an AKS cluster with your team and collaborate together. You can test code end-to-end without replicating or \ | ||
mocking up dependencies. Onboard new team members faster by minimizing their local dev machine setup and have them \ | ||
work in a consistent dev environment.', | ||
license='MIT', | ||
author='Microsoft Corporation', | ||
author_email='azds-azcli@microsoft.com', | ||
url='https://github.com/Azure/azure-cli-extensions', | ||
classifiers=CLASSIFIERS, | ||
package_data={'azext_dev_spaces_preview': ['azext_metadata.json']}, | ||
packages=find_packages(exclude=["tests"]), | ||
install_requires=DEPENDENCIES | ||
) |