From 972eb709f3c9014511c686ed681bf73d1247e468 Mon Sep 17 00:00:00 2001 From: Jim Minter Date: Fri, 13 Dec 2019 12:08:20 -0600 Subject: [PATCH] check in autogenerated aro-preview extension stub --- docs/az-client-extension.md | 51 ----------------- python/az/aro/HISTORY.rst | 8 +++ python/az/aro/README.rst | 5 ++ python/az/aro/azext_aro/__init__.py | 27 +++++++++ python/az/aro/azext_aro/_client_factory.py | 7 +++ python/az/aro/azext_aro/_help.py | 34 +++++++++++ python/az/aro/azext_aro/_params.py | 19 +++++++ python/az/aro/azext_aro/_validators.py | 14 +++++ python/az/aro/azext_aro/azext_metadata.json | 5 ++ python/az/aro/azext_aro/commands.py | 23 ++++++++ python/az/aro/azext_aro/custom.py | 15 +++++ python/az/aro/azext_aro/tests/__init__.py | 0 .../az/aro/azext_aro/tests/latest/__init__.py | 0 .../tests/latest/test_aro_scenario.py | 35 ++++++++++++ python/az/aro/setup.cfg | 2 + python/az/aro/setup.py | 56 +++++++++++++++++++ 16 files changed, 250 insertions(+), 51 deletions(-) delete mode 100644 docs/az-client-extension.md create mode 100644 python/az/aro/HISTORY.rst create mode 100644 python/az/aro/README.rst create mode 100644 python/az/aro/azext_aro/__init__.py create mode 100644 python/az/aro/azext_aro/_client_factory.py create mode 100644 python/az/aro/azext_aro/_help.py create mode 100644 python/az/aro/azext_aro/_params.py create mode 100644 python/az/aro/azext_aro/_validators.py create mode 100644 python/az/aro/azext_aro/azext_metadata.json create mode 100644 python/az/aro/azext_aro/commands.py create mode 100644 python/az/aro/azext_aro/custom.py create mode 100644 python/az/aro/azext_aro/tests/__init__.py create mode 100644 python/az/aro/azext_aro/tests/latest/__init__.py create mode 100644 python/az/aro/azext_aro/tests/latest/test_aro_scenario.py create mode 100644 python/az/aro/setup.cfg create mode 100644 python/az/aro/setup.py diff --git a/docs/az-client-extension.md b/docs/az-client-extension.md deleted file mode 100644 index d78acc14e..000000000 --- a/docs/az-client-extension.md +++ /dev/null @@ -1,51 +0,0 @@ -# Azure Red Hat OpenShift CLI preview extension - -ARO CLI extension code - -## Configure & generate extensions - -All these steps assumes you read throuth documents in useful links sections -and you are already familiar with terminology - -1. Clone required dev repositories: -``` -git clone https://github.com/Azure/azure-cli -git clone https://github.com/Azure/azure-cli-extensions -``` - -1. Setup virtual env in the repository which will unify all projects, -including `rp`. I do this on `$GOPATH/src/github.com` level. -``` -python3 -m venv env -source env/bin/activate -``` - -1. Install pre-requisited -``` -pip install azdev -azdev setup -``` - -1. Add external extension repistory -``` -azdev extension repo add /home/mjudeiki/go/src/github.com/mjudeikis/azure-cli-aro -``` - -From this point, if you want develop existing extension - add extension to az: -client. Otherwise generate new from the template -``` -azdev extension add aro-preview -``` - -### Generate extension template - -1. Generate extension template -``` -azdev extension create aro-preview --client-name AzureRedHatOpenShiftClient --operation-name OpenShiftClustersOperations --local-sdk /home/mjudeiki/go/src/github.com/jim-minter/rp/az/azure-python-sdk/2019-12-31-preview/redhatopenshift/ --sdk-property=resource_name --github-alias=mjudeikis --repo-name /home/mjudeiki/go/src/github.com/mjudeikis/azure-cli-aro -``` - -## Useful links - -* https://github.com/Azure/azure-cli-dev-tools - -* https://github.com/Azure/azure-cli/blob/master/doc/extensions/authoring.md diff --git a/python/az/aro/HISTORY.rst b/python/az/aro/HISTORY.rst new file mode 100644 index 000000000..1c139576b --- /dev/null +++ b/python/az/aro/HISTORY.rst @@ -0,0 +1,8 @@ +.. :changelog: + +Release History +=============== + +0.1.0 +++++++ +* Initial release. diff --git a/python/az/aro/README.rst b/python/az/aro/README.rst new file mode 100644 index 000000000..6971c6bc0 --- /dev/null +++ b/python/az/aro/README.rst @@ -0,0 +1,5 @@ +Microsoft Azure CLI 'aro' Extension +========================================== + +This package is for the 'aro' extension. +i.e. 'az aro' diff --git a/python/az/aro/azext_aro/__init__.py b/python/az/aro/azext_aro/__init__.py new file mode 100644 index 000000000..1ce7351bb --- /dev/null +++ b/python/az/aro/azext_aro/__init__.py @@ -0,0 +1,27 @@ +from azure.cli.core import AzCommandsLoader + +from azext_aro._help import helps # pylint: disable=unused-import + + +class AroCommandsLoader(AzCommandsLoader): + + def __init__(self, cli_ctx=None): + from azure.cli.core.commands import CliCommandType + from azext_aro._client_factory import cf_aro + aro_custom = CliCommandType( + operations_tmpl='azext_aro.custom#{}', + client_factory=cf_aro) + super(AroCommandsLoader, self).__init__(cli_ctx=cli_ctx, + custom_command_type=aro_custom) + + def load_command_table(self, args): + from azext_aro.commands import load_command_table + load_command_table(self, args) + return self.command_table + + def load_arguments(self, command): + from azext_aro._params import load_arguments + load_arguments(self, command) + + +COMMAND_LOADER_CLS = AroCommandsLoader diff --git a/python/az/aro/azext_aro/_client_factory.py b/python/az/aro/azext_aro/_client_factory.py new file mode 100644 index 000000000..aba5fc5b9 --- /dev/null +++ b/python/az/aro/azext_aro/_client_factory.py @@ -0,0 +1,7 @@ +def cf_aro(cli_ctx, *_): + + from azure.cli.core.commands.client_factory import get_mgmt_service_client + # TODO: Replace CONTOSO with the appropriate label and uncomment + # from azure.mgmt.CONTOSO import CONTOSOManagementClient + # return get_mgmt_service_client(cli_ctx, CONTOSOManagementClient) + return None diff --git a/python/az/aro/azext_aro/_help.py b/python/az/aro/azext_aro/_help.py new file mode 100644 index 000000000..d92524800 --- /dev/null +++ b/python/az/aro/azext_aro/_help.py @@ -0,0 +1,34 @@ +# coding=utf-8 + +from knack.help_files import helps # pylint: disable=unused-import + + +helps['aro'] = """ + type: group + short-summary: Commands to manage Aros. +""" + +helps['aro create'] = """ + type: command + short-summary: Create a Aro. +""" + +helps['aro list'] = """ + type: command + short-summary: List Aros. +""" + +# helps['aro delete'] = """ +# type: command +# short-summary: Delete a Aro. +# """ + +# helps['aro show'] = """ +# type: command +# short-summary: Show details of a Aro. +# """ + +# helps['aro update'] = """ +# type: command +# short-summary: Update a Aro. +# """ diff --git a/python/az/aro/azext_aro/_params.py b/python/az/aro/azext_aro/_params.py new file mode 100644 index 000000000..f56322c51 --- /dev/null +++ b/python/az/aro/azext_aro/_params.py @@ -0,0 +1,19 @@ +# pylint: disable=line-too-long + +from knack.arguments import CLIArgumentType + + +def load_arguments(self, _): + + from azure.cli.core.commands.parameters import tags_type + from azure.cli.core.commands.validators import get_default_location_from_resource_group + + aro_name_type = CLIArgumentType(options_list='--aro-name-name', help='Name of the Aro.', id_part='name') + + with self.argument_context('aro') as c: + c.argument('tags', tags_type) + c.argument('location', validator=get_default_location_from_resource_group) + c.argument('aro_name', aro_name_type, options_list=['--name', '-n']) + + with self.argument_context('aro list') as c: + c.argument('aro_name', aro_name_type, id_part=None) diff --git a/python/az/aro/azext_aro/_validators.py b/python/az/aro/azext_aro/_validators.py new file mode 100644 index 000000000..3ff7d0a54 --- /dev/null +++ b/python/az/aro/azext_aro/_validators.py @@ -0,0 +1,14 @@ +def example_name_or_id_validator(cmd, namespace): + # Example of a storage account name or ID validator. + # See: https://github.com/Azure/azure-cli/blob/dev/doc/authoring_command_modules/authoring_commands.md#supporting-name-or-id-parameters + from azure.cli.core.commands.client_factory import get_subscription_id + from msrestazure.tools import is_valid_resource_id, resource_id + if namespace.storage_account: + if not is_valid_resource_id(namespace.RESOURCE): + namespace.storage_account = resource_id( + subscription=get_subscription_id(cmd.cli_ctx), + resource_group=namespace.resource_group_name, + namespace='Microsoft.Storage', + type='storageAccounts', + name=namespace.storage_account + ) diff --git a/python/az/aro/azext_aro/azext_metadata.json b/python/az/aro/azext_aro/azext_metadata.json new file mode 100644 index 000000000..89d62dfaa --- /dev/null +++ b/python/az/aro/azext_aro/azext_metadata.json @@ -0,0 +1,5 @@ +{ + "azext.isPreview": true, + "azext.minCliCoreVersion": "2.0.67", + "azext.maxCliCoreVersion": "2.1.0" +} diff --git a/python/az/aro/azext_aro/commands.py b/python/az/aro/azext_aro/commands.py new file mode 100644 index 000000000..7acbea666 --- /dev/null +++ b/python/az/aro/azext_aro/commands.py @@ -0,0 +1,23 @@ +# pylint: disable=line-too-long +from azure.cli.core.commands import CliCommandType +from azext_aro._client_factory import cf_aro + + +def load_command_table(self, _): + + # TODO: Add command type here + # aro_sdk = CliCommandType( + # operations_tmpl='.operations#None.{}', + # client_factory=cf_aro) + + + with self.command_group('aro') as g: + g.custom_command('create', 'create_aro') + # g.command('delete', 'delete') + g.custom_command('list', 'list_aro') + # g.show_command('show', 'get') + # g.generic_update_command('update', setter_name='update', custom_func_name='update_aro') + + + with self.command_group('aro', is_preview=True): + pass diff --git a/python/az/aro/azext_aro/custom.py b/python/az/aro/azext_aro/custom.py new file mode 100644 index 000000000..610368642 --- /dev/null +++ b/python/az/aro/azext_aro/custom.py @@ -0,0 +1,15 @@ +from knack.util import CLIError + + +def create_aro(cmd, resource_group_name, aro_name, location=None, tags=None): + raise CLIError('TODO: Implement `aro create`') + + +def list_aro(cmd, resource_group_name=None): + raise CLIError('TODO: Implement `aro list`') + + +def update_aro(cmd, instance, tags=None): + with cmd.update_context(instance) as c: + c.set_param('tags', tags) + return instance diff --git a/python/az/aro/azext_aro/tests/__init__.py b/python/az/aro/azext_aro/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/python/az/aro/azext_aro/tests/latest/__init__.py b/python/az/aro/azext_aro/tests/latest/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/python/az/aro/azext_aro/tests/latest/test_aro_scenario.py b/python/az/aro/azext_aro/tests/latest/test_aro_scenario.py new file mode 100644 index 000000000..2a3de03b6 --- /dev/null +++ b/python/az/aro/azext_aro/tests/latest/test_aro_scenario.py @@ -0,0 +1,35 @@ +import os +import unittest + +from azure_devtools.scenario_tests import AllowLargeResponse +from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) + + +TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) + + +class AroScenarioTest(ScenarioTest): + + @ResourceGroupPreparer(name_prefix='cli_test_aro') + def test_aro(self, resource_group): + + self.kwargs.update({ + 'name': 'test1' + }) + + self.cmd('aro create -g {rg} -n {name} --tags foo=doo', checks=[ + self.check('tags.foo', 'doo'), + self.check('name', '{name}') + ]) + self.cmd('aro update -g {rg} -n {name} --tags foo=boo', checks=[ + self.check('tags.foo', 'boo') + ]) + count = len(self.cmd('aro list').get_output_in_json()) + self.cmd('aro show - {rg} -n {name}', checks=[ + self.check('name', '{name}'), + self.check('resourceGroup', '{rg}'), + self.check('tags.foo', 'boo') + ]) + self.cmd('aro delete -g {rg} -n {name}') + final_count = len(self.cmd('aro list').get_output_in_json()) + self.assertTrue(final_count, count - 1) diff --git a/python/az/aro/setup.cfg b/python/az/aro/setup.cfg new file mode 100644 index 000000000..3c6e79cf3 --- /dev/null +++ b/python/az/aro/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal=1 diff --git a/python/az/aro/setup.py b/python/az/aro/setup.py new file mode 100644 index 000000000..afc79ba93 --- /dev/null +++ b/python/az/aro/setup.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +from codecs import open +from setuptools import setup, find_packages +try: + from azure_bdist_wheel import cmdclass +except ImportError: + from distutils import log as logger + logger.warn("Wheel is not available, disabling bdist_wheel hook") + +# TODO: Confirm this is the right version number you want and it matches your +# HISTORY.rst entry. +VERSION = '0.1.0' + +# The full list of classifiers is available at +# https://pypi.python.org/pypi?%3Aaction=list_classifiers +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 :: Apache Software License', +] + +# TODO: Add any additional SDK dependencies here +DEPENDENCIES = [ + 'azure-cli-core' +] + +with open('README.rst', 'r', encoding='utf-8') as f: + README = f.read() +with open('HISTORY.rst', 'r', encoding='utf-8') as f: + HISTORY = f.read() + +setup( + name='aro', + version=VERSION, + description='Microsoft Azure Command-Line Tools Aro Extension', + # TODO: Update author and email, if applicable + author='Microsoft Corporation', + author_email='azpycli@microsoft.com', + # TODO: consider pointing directly to your source code instead of the generic repo + url='https://github.com/Azure/azure-cli-extensions', + long_description=README + '\n\n' + HISTORY, + license='Apache', + classifiers=CLASSIFIERS, + packages=find_packages(), + install_requires=DEPENDENCIES, + package_data={'azext_aro': ['azext_metadata.json']}, +)