check in autogenerated aro-preview extension stub

This commit is contained in:
Jim Minter 2019-12-13 12:08:20 -06:00
Родитель 227f4e13dc
Коммит 972eb709f3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 0730CBDA10D1A2D3
16 изменённых файлов: 250 добавлений и 51 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -0,0 +1,8 @@
.. :changelog:
Release History
===============
0.1.0
++++++
* Initial release.

5
python/az/aro/README.rst Normal file
Просмотреть файл

@ -0,0 +1,5 @@
Microsoft Azure CLI 'aro' Extension
==========================================
This package is for the 'aro' extension.
i.e. 'az aro'

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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.
# """

Просмотреть файл

@ -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)

Просмотреть файл

@ -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
)

Просмотреть файл

@ -0,0 +1,5 @@
{
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.0.67",
"azext.maxCliCoreVersion": "2.1.0"
}

Просмотреть файл

@ -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='<PATH>.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

Просмотреть файл

@ -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

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -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)

2
python/az/aro/setup.cfg Normal file
Просмотреть файл

@ -0,0 +1,2 @@
[bdist_wheel]
universal=1

56
python/az/aro/setup.py Normal file
Просмотреть файл

@ -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']},
)