-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Initial PR for SignalR Service preview CLI extension #142
Changes from all commits
9e3273e
6d7d235
19bb400
5bbae84
40dfded
c0f0746
814646d
0140f1c
e2b0038
be75de4
c1177b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,6 @@ | |
|
||
/src/managementpartner/ @jeffrey-ace | ||
|
||
/src/dns/ @muwaqar | ||
/src/dns/ @muwaqar | ||
|
||
/src/signalr/ @zackliu |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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_signalr._help # pylint: disable=unused-import | ||
|
||
|
||
class SignalRCommandsLoader(AzCommandsLoader): | ||
|
||
def __init__(self, cli_ctx=None): | ||
super(SignalRCommandsLoader, self).__init__(cli_ctx=cli_ctx, | ||
min_profile='2017-03-10-profile') | ||
|
||
def load_command_table(self, args): | ||
from .commands import load_command_table | ||
load_command_table(self, args) | ||
return self.command_table | ||
|
||
def load_arguments(self, command): | ||
from ._params import load_arguments | ||
load_arguments(self, command) | ||
|
||
|
||
COMMAND_LOADER_CLS = SignalRCommandsLoader |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
|
||
def _signalr_client_factory(cli_ctx, *_): | ||
from azext_signalr.signalr import SignalRManagementClient | ||
from azure.cli.core.commands.client_factory import get_mgmt_service_client | ||
return get_mgmt_service_client(cli_ctx, SignalRManagementClient) | ||
|
||
|
||
def cf_signalr(cli_ctx, *_): | ||
return _signalr_client_factory(cli_ctx).signal_r |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
|
||
SIGNALR_SKU = ['Basic_DS2'] | ||
SIGNALR_RESOURCE_TYPE = 'Microsoft.SignalRService/SignalR' | ||
SIGNALR_KEY_TYPE = ['primary', 'secondary'] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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['signalr'] = """ | ||
type: group | ||
short-summary: Manage Azure SignalR Service. | ||
""" | ||
|
||
helps['signalr key'] = """ | ||
type: group | ||
short-summary: Manage keys for Azure SignalR Service. | ||
""" | ||
|
||
helps['signalr list'] = """ | ||
type: command | ||
short-summary: Lists all the SignalR Service under the current subscription. | ||
examples: | ||
- name: List SignalR Service and show the results in a table. | ||
text: > | ||
az signalr list -o table | ||
- name: List SignalR Service in a resource group and show the results in a table. | ||
text: > | ||
az signalr list -g MySignalR -o table | ||
""" | ||
|
||
helps['signalr create'] = """ | ||
type: command | ||
short-summary: Creates a SignalR Service. | ||
examples: | ||
- name: Create a SignalR Service with the Basic SKU. | ||
text: > | ||
az signalr create -n MySignalR -g MyResourceGroup --sku Basic_DS2 --unit-count 1 | ||
""" | ||
|
||
helps['signalr delete'] = """ | ||
type: command | ||
short-summary: Deletes a SignalR Service. | ||
examples: | ||
- name: Delete a SignalR Service. | ||
text: > | ||
az signalr delete -n MySignalR -g MyResourceGroup | ||
""" | ||
|
||
helps['signalr show'] = """ | ||
type: command | ||
short-summary: Get the details of a SignalR Service. | ||
examples: | ||
- name: Get the sku for a SignalR Service. | ||
text: > | ||
az signalr show -n MySignalR -g MyResourceGroup --query sku | ||
""" | ||
|
||
helps['signalr key list'] = """ | ||
type: command | ||
short-summary: List the access keys for a SignalR Service. | ||
examples: | ||
- name: Get the primary key for a SignalR Service. | ||
text: > | ||
az signalr key list -n MySignalR -g MyResourceGroup --query primaryKey -o tsv | ||
""" | ||
|
||
helps['signalr key renew'] = """ | ||
type: command | ||
short-summary: Regenerate the access key for a SignalR Service. | ||
examples: | ||
- name: Renew the secondary key for a SignalR Service. | ||
text: > | ||
az signalr key renew -n MySignalR -g MyResourceGroup --key-type secondary | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# pylint: disable=line-too-long | ||
# -------------------------------------------------------------------------------------------- | ||
# 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.commands.validators import get_default_location_from_resource_group | ||
|
||
from knack.log import get_logger | ||
|
||
from azure.cli.core.commands.parameters import ( | ||
resource_group_name_type, | ||
get_location_type, | ||
get_resource_name_completion_list, | ||
tags_type | ||
) | ||
|
||
from ._constants import ( | ||
SIGNALR_SKU, | ||
SIGNALR_RESOURCE_TYPE, | ||
SIGNALR_KEY_TYPE | ||
) | ||
|
||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
def load_arguments(self, _): | ||
with self.argument_context('signalr') as c: | ||
c.argument('resource_group_name', arg_type=resource_group_name_type) | ||
c.argument('location', | ||
arg_type=get_location_type(self.cli_ctx), | ||
validator=get_default_location_from_resource_group) | ||
c.argument('signalr_name', options_list=['--name', '-n'], | ||
completer=get_resource_name_completion_list(SIGNALR_RESOURCE_TYPE), | ||
help='Name of signalr service.') | ||
c.argument('tags', arg_type=tags_type) | ||
|
||
with self.argument_context('signalr create') as c: | ||
c.argument('sku', help='The sku name of the signalr service', choices=SIGNALR_SKU) | ||
c.argument('unit_count', help='The number of signalr service unit count', type=int) | ||
|
||
with self.argument_context('signalr key renew') as c: | ||
c.argument('key_type', help='The name of access key to regenerate', choices=SIGNALR_KEY_TYPE) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"azext.minCliCoreVersion": "2.0.32.dev0", | ||
"azext.isPreview": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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.commands import CliCommandType | ||
|
||
from ._client_factory import cf_signalr | ||
from azure.cli.core.util import empty_on_404 | ||
|
||
|
||
def load_command_table(self, _): | ||
|
||
signalr_custom_util = CliCommandType( | ||
operations_tmpl='azext_signalr.custom#{}', | ||
client_factory=cf_signalr | ||
) | ||
|
||
signalr_key_utils = CliCommandType( | ||
operations_tmpl='azext_signalr.key#{}', | ||
client_factory=cf_signalr | ||
) | ||
|
||
with self.command_group('signalr', signalr_custom_util) as g: | ||
g.command('create', 'signalr_create') | ||
g.command('delete', 'signalr_delete') | ||
g.command('list', 'signalr_list') | ||
g.command('show', 'signalr_show', exception_handler=empty_on_404) | ||
|
||
with self.command_group('signalr key', signalr_key_utils) as g: | ||
g.command('list', 'signalr_key_list') | ||
g.command('renew', 'signalr_key_renew') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
|
||
from azext_signalr.signalr.models import (ResourceSku, SignalRCreateOrUpdateProperties, SignalRCreateParameters) | ||
|
||
|
||
def signalr_create(client, signalr_name, resource_group_name, sku, unit_count=1, location=None, tags=None): | ||
sku = ResourceSku(name=sku, capacity=unit_count) | ||
properties = SignalRCreateOrUpdateProperties(host_name_prefix=signalr_name) | ||
|
||
parameter = SignalRCreateParameters(tags=tags, | ||
sku=sku, | ||
properties=properties, | ||
location=location) | ||
|
||
return client.create_or_update(resource_group_name, signalr_name, parameter) | ||
|
||
|
||
def signalr_delete(client, signalr_name, resource_group_name): | ||
return client.delete(resource_group_name, signalr_name) | ||
|
||
|
||
def signalr_list(client, resource_group_name=None): | ||
if not resource_group_name: | ||
return client.list_by_subscription() | ||
return client.list_by_resource_group(resource_group_name) | ||
|
||
|
||
def signalr_show(client, signalr_name, resource_group_name): | ||
return client.get(resource_group_name, signalr_name) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
|
||
from azext_signalr.signalr.models import KeyType | ||
|
||
|
||
def signalr_key_list(client, resource_group_name, signalr_name): | ||
return client.list_keys(resource_group_name, signalr_name) | ||
|
||
|
||
def signalr_key_renew(client, resource_group_name, signalr_name, key_type): | ||
if key_type == 'primary': | ||
key_type = KeyType.primary | ||
else: | ||
key_type = KeyType.secondary | ||
return client.regenerate_key(resource_group_name, signalr_name, key_type, polling=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to:
https://github.com/Azure/azure-cli/blob/dev/src/azure-cli-core/azure/cli/core/util.py#L251 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I use sdk_no_wait, the output will be raw. Thus, when I run |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is | ||
# regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from .signal_rmanagement_client import SignalRManagementClient | ||
from .version import VERSION | ||
|
||
__all__ = ['SignalRManagementClient'] | ||
|
||
__version__ = VERSION | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems unnecessary to have this function as the only reference is in
cf_signalr
. These two methods can be merged.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the general pattern though used in other modules. Makes it easy to add new client factories later.