Skip to content

Commit

Permalink
Merge Knack-based extensions with updated index (#28)
Browse files Browse the repository at this point in the history
* Ignore SDK models/operations and KnackConversion testsdk (#22)

* Ignore SDK models/operations and KnackConversion testsdk

* Install from KnackConversion branch

* Fix new pylint

* Ignore knack and other azure.cli modules from pylint import errors (#23)

* Ignore _management_client.py from SDK also (#25)

* Image-copy: knack conversion (#26)

* knack conversion

* fixing some lint warnings

* fix number displayed in progress reporting

* fix more lint issues

* fix mroe lint issues

* image-copy: fix lint issue

* Update IoT Extension index data for new release. (#27)

* Update IoT Extension index data for new release.

* Tweak dependency format.

* minCLiVersion->minCliCoreVersion

* Checksum must be lowercase.

* Update minCliCoreVersion.

* Add new hash.

* image copy: add version 0.0.4 back to index (#29)

* image copy: add version 0.0.4 back to index

* image copy: fix json object
  • Loading branch information
tjprescott authored and derekbekoe committed Jan 8, 2018
1 parent 9e6b525 commit 76a4dad
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 172 deletions.
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ disable=missing-docstring,locally-disabled,fixme,cyclic-import,too-many-argument

[TYPECHECK]
# For Azure CLI extensions, we ignore some import errors as they'll be available in the environment of the CLI
ignored-modules=azure,azure.cli
ignored-modules=azure,azure.cli,azure.cli.core,azure.cli.core.commands,knack

[FORMAT]
max-line-length=120
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import hashlib
import shutil
import subprocess
from util import get_repo_root
from wheel.install import WHEEL_INFO_RE
from util import get_repo_root

INDEX_PATH = os.path.join(get_repo_root(), 'src', 'index.json')
SRC_PATH = os.path.join(get_repo_root(), 'src')
Expand Down
5 changes: 3 additions & 2 deletions scripts/ci/test_source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ set -ex

# Install CLI & CLI testsdk
echo "Installing azure-cli-testsdk and azure-cli..."
# TODO Update the git commit when we need a new version of azure-cli-testsdk
pip install "git+https://github.com/Azure/azure-cli@68460748e47f20cba462686c9fd20d2c720cf98c#egg=azure-cli-testsdk&subdirectory=src/azure-cli-testsdk" -q
# TODO Update the git commit or branch when we need a new version of azure-cli-testsdk
pip install "git+https://github.com/Azure/azure-cli@KnackConversion#egg=azure-cli-testsdk&subdirectory=src/azure-cli-testsdk" -q
pip install knack==0.3.0 -q
echo "Installed."


Expand Down
9 changes: 7 additions & 2 deletions scripts/ci/test_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
set -e

proc_number=`python -c 'import multiprocessing; print(multiprocessing.cpu_count())'`
pylint ./src/*/azext_*/ --rcfile=./pylintrc -j $proc_number
flake8 --statistics --append-config=./.flake8 ./src/*/azext_*/

# Run pylint/flake8 on extensions
# - We ignore 'models', 'operations' and files with suffix '_management_client.py' as they typically come from vendored Azure SDKs
pylint ./src/*/azext_*/ --ignore=models,operations,service_bus_management_client --ignore-patterns=[a-zA-Z_]+_management_client.py --rcfile=./pylintrc -j $proc_number
flake8 --statistics --exclude=models,operations,*_management_client.py --append-config=./.flake8 ./src/*/azext_*/

# Run pylint/flake8 on CI files
pylint ./scripts/ci/*.py --rcfile=./pylintrc
flake8 --append-config=./.flake8 ./scripts/ci/*.py

# Other static checks
python ./scripts/ci/verify_codeowners.py
python ./scripts/ci/verify_license.py
80 changes: 39 additions & 41 deletions src/image-copy/azext_imagecopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,42 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.help_files import helps
from azure.cli.core.sdk.util import ParametersContext

helps['image copy'] = """
type: command
short-summary: Copy a managed image (or vm) to other regions
long-summary: >
Allows to copy a managed image (or vm) to other regions.
Keep in mind that it requires the source disk to be available.
examples:
- name: Copy an image to several regions and cleanup at the end.
text: >
az image copy --source-resource-group mySources-rg --source-object-name myImage \\
--target-location uksouth northeurope --target-resource-group "images-repo-rg" --cleanup
- name: Use an already generalized vm to create images in other regions.
text: >
az image copy --source-resource-group mySources-rg --source-object-name myVm \\
--source-type vm --target-location uksouth northeurope --target-resource-group "images-repo-rg"
"""


def load_params(_):
with ParametersContext('image copy') as c:
c.register('source_resource_group_name', '--source-resource-group',
help='Name of the resource group of the source resource')
c.register('source_object_name', '--source-object-name',
help='The name of the image or vm resource')
c.register('target_location', '--target-location', nargs='+',
help='Space separated location list to create the image in (e.g. westeurope etc.)')
c.register('source_type', '--source-type', default='image', choices=['image', 'vm'], help='image or vm')
c.register('target_resource_group_name', '--target-resource-group',
help='Name of the resource group to create images in')
c.register('parallel_degree', '--parallel-degree', type=int, default=-1,
help='Number of parallel copy operations')
c.register('cleanup', '--cleanup', action='store_true', default=False,
help='Include this switch to delete temporary resources upon completion')


def load_commands():
from azure.cli.core.commands import cli_command
cli_command(__name__, 'image copy', 'azext_imagecopy.custom#imagecopy')
from azure.cli.core import AzCommandsLoader

import azext_imagecopy._help # pylint: disable=unused-import


class ImageCopyCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
imagecopy_custom = CliCommandType(
operations_tmpl='azext_imagecopy.custom#{}')
super(ImageCopyCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=imagecopy_custom)

def load_command_table(self, _):
with self.command_group('image') as g:
g.custom_command('copy', 'imagecopy')

return self.command_table

def load_arguments(self, _):
with self.argument_context('image copy') as c:
c.argument('source_resource_group_name', options_list=['--source-resource-group'],
help='Name of the resource group of the source resource')
c.argument('source_object_name', options_list=['--source-object-name'],
help='The name of the image or vm resource')
c.argument('target_location', options_list=['--target-location'], nargs='+',
help='Space separated location list to create the image in (e.g. westeurope etc.)')
c.argument('source_type', options_list=[
'--source-type'], default='image', choices=['image', 'vm'], help='image or vm')
c.argument('target_resource_group_name', options_list=['--target-resource-group'],
help='Name of the resource group to create images in')
c.argument('parallel_degree', options_list=['--parallel-degree'], type=int, default=-1,
help='Number of parallel copy operations')
c.argument('cleanup', options_list=['--cleanup'], action='store_true', default=False,
help='Include this switch to delete temporary resources upon completion')


COMMAND_LOADER_CLS = ImageCopyCommandsLoader
24 changes: 24 additions & 0 deletions src/image-copy/azext_imagecopy/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# --------------------------------------------------------------------------------------------
# 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


helps['image copy'] = """
type: command
short-summary: Copy a managed image (or vm) to other regions
long-summary: >
Allows to copy a managed image (or vm) to other regions.
Keep in mind that it requires the source disk to be available.
examples:
- name: Copy an image to several regions and cleanup at the end.
text: >
az image copy --source-resource-group mySources-rg --source-object-name myImage \\
--target-location uksouth northeurope --target-resource-group "images-repo-rg" --cleanup
- name: Use an already generalized vm to create images in other regions.
text: >
az image copy --source-resource-group mySources-rg --source-object-name myVm \\
--source-type vm --target-location uksouth northeurope --target-resource-group "images-repo-rg"
"""
1 change: 1 addition & 0 deletions src/image-copy/azext_imagecopy/azext_metadata.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{
"azext.minCliCoreVersion": "2.0.24"
}
9 changes: 5 additions & 4 deletions src/image-copy/azext_imagecopy/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
import json

from subprocess import check_output, STDOUT, CalledProcessError
from azure.cli.core.util import CLIError
import azure.cli.core.azlogging as azlogging
from knack.util import CLIError

logger = azlogging.get_az_logger(__name__)
from knack.log import get_logger
logger = get_logger(__name__)


# pylint: disable=inconsistent-return-statements
def run_cli_command(cmd, return_as_json=False):
try:
cmd_output = check_output(cmd, stderr=STDOUT, universal_newlines=True)
logger.debug('command: %s ended with output: %s', cmd, cmd_output)

if return_as_json is True:
if return_as_json:
if cmd_output:
json_output = json.loads(cmd_output)
return json_output
Expand Down
Loading

0 comments on commit 76a4dad

Please sign in to comment.