Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/webpubsub/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

1.4.0
+++++
* Add `az webpubsub replica create/delete/list/show` support for replica

1.3.0
+++++
* Add `kind` support for creating resource
Expand Down
4 changes: 4 additions & 0 deletions src/webpubsub/azext_webpubsub/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ def cf_webpubsubhub(cli_ctx, *_):

def cf_webpubsubhub_usage(cli_ctx, *_):
return _webpubsub_client_factory(cli_ctx).usages


def cf_webpubsub_replicas(cli_ctx, *_):
return _webpubsub_client_factory(cli_ctx).web_pub_sub_replicas
41 changes: 41 additions & 0 deletions src/webpubsub/azext_webpubsub/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
short-summary: Commands to manage Webpubsub service permissions.
"""

helps['webpubsub replica'] = """
type: group
short-summary: Manage replica settings.
"""

helps['webpubsub create'] = """
type: command
short-summary: Create a Webpubsub.
Expand Down Expand Up @@ -263,3 +268,39 @@
type: command
short-summary: Check if a connection has permission to the specified group.
"""

helps['webpubsub replica show'] = """
type: command
short-summary: Show the details of a replica
examples:
- name: Get the detail of a replica
text: >
az webpubsub replica show --replica-name MyReplica --name MyWebPubSub -g MyResourceGroup
"""

helps['webpubsub replica delete'] = """
type: command
short-summary: Delete a replica of WebPubSub Service.
examples:
- name: Delete a replica
text: >
az webpubsub replica delete --replica-name MyReplica --name MyWebPubSub -g MyResourceGroup
"""

helps['webpubsub replica list'] = """
type: command
short-summary: List replicas of Webpubsub Service.
examples:
- name: Get the detail of a replica
text: >
az webpubsub replica list --name MyWebPubSub -g MyResourceGroup -o table
"""

helps['webpubsub replica create'] = """
type: command
short-summary: Create a replica of Webpubsub Service.
examples:
- name: Get the detail of a replica
text: >
az webpubsub replica create --sku Premium_P1 -l eastus --replica-name MyReplica --name MyWebPubSub -g MyResourceGroup
"""
21 changes: 21 additions & 0 deletions src/webpubsub/azext_webpubsub/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def load_arguments(self, _):

webpubsub_name_type = CLIArgumentType(options_list='--webpubsub-name-name', help='Name of the Webpubsub.', id_part='name')
webpubsubhub_name_type = CLIArgumentType(help='Name of the hub.', id_part='child_name_1')
webpubsub_replica_name_type = CLIArgumentType(help='Name of the replica.', id_part='child_name_1')

with self.argument_context('webpubsub') as c:
c.argument('tags', tags_type)
Expand Down Expand Up @@ -100,3 +101,23 @@ def load_arguments(self, _):

with self.argument_context('webpubsub service permission') as c:
c.argument('permission', arg_type=get_enum_type(PERMISSION_TYPE), help='The permission')

# Replica
for scope in ['webpubsub replica create',
'webpubsub replica list',
'webpubsub replica delete',
'webpubsub replica show']:
with self.argument_context(scope) as c:
c.argument('sku', help='The sku name of the replica. Currently allowed values: Premium_P1')
c.argument('unit_count', help='The number of webpubsub service unit count', type=int)
c.argument('replica_name', webpubsub_replica_name_type)

for scope in ['webpubsub replica create',
'webpubsub replica list']:
with self.argument_context(scope) as c:
c.argument('webpubsub_name', webpubsub_name_type, options_list=['--name', '-n'], id_part=None)

for scope in ['webpubsub replica show',
'webpubsub replica delete']:
with self.argument_context(scope) as c:
c.argument('webpubsub_name', webpubsub_name_type, options_list=['--name', '-n'])
13 changes: 12 additions & 1 deletion src/webpubsub/azext_webpubsub/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# pylint: disable=line-too-long
from azure.cli.core.commands import CliCommandType
from azure.cli.core.util import empty_on_404
from ._client_factory import (cf_webpubsub, cf_webpubsubhub, cf_webpubsubhub_usage)
from ._client_factory import (cf_webpubsub, cf_webpubsubhub, cf_webpubsubhub_usage, cf_webpubsub_replicas)
from ._exception_handler import exception_handler


Expand Down Expand Up @@ -47,6 +47,11 @@ def load_command_table(self, _):
client_factory=cf_webpubsubhub_usage
)

webpubsub_replica_utils = CliCommandType(
operations_tmpl='azext_webpubsub.replica#{}',
client_factory=cf_webpubsub_replicas
)

with self.command_group('webpubsub', webpubsub_general_utils) as g:
g.command('create', 'webpubsub_create', exception_handler=exception_handler)
g.command('delete', 'webpubsub_delete')
Expand Down Expand Up @@ -100,3 +105,9 @@ def load_command_table(self, _):
g.command('grant', 'grant_permission')
g.command('revoke', 'revoke_permission')
g.command('check', 'check_permission')

with self.command_group('webpubsub replica', webpubsub_replica_utils) as g:
g.command('create', 'webpubsub_replica_create')
g.command('list', 'webpubsub_replica_list')
g.show_command('show', 'webpubsub_replica_show', exception_handler=empty_on_404)
g.show_command('delete', 'webpubsub_replica_delete')
38 changes: 38 additions & 0 deletions src/webpubsub/azext_webpubsub/replica.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long

from .vendored_sdks.azure_mgmt_webpubsub.models import (
ResourceSku,
Replica
)

from .vendored_sdks.azure_mgmt_webpubsub.operations import (
WebPubSubOperations
)


def webpubsub_replica_list(client: WebPubSubOperations, resource_group_name, webpubsub_name):
return client.list(resource_group_name, webpubsub_name)


def webpubsub_replica_show(client: WebPubSubOperations, webpubsub_name, replica_name, resource_group_name):
return client.get(resource_group_name=resource_group_name, resource_name=webpubsub_name, replica_name=replica_name)


def webpubsub_replica_delete(client: WebPubSubOperations, webpubsub_name, replica_name, resource_group_name):
return client.delete(resource_group_name=resource_group_name, resource_name=webpubsub_name, replica_name=replica_name)


def webpubsub_replica_create(client: WebPubSubOperations, webpubsub_name, replica_name, resource_group_name,
sku, unit_count=1, location=None, tags=None):
sku = ResourceSku(name=sku, capacity=unit_count)
parameter = Replica(tags=tags,
sku=sku,
location=location,
)

return client.begin_create_or_update(resource_group_name=resource_group_name, resource_name=webpubsub_name,
replica_name=replica_name, parameters=parameter)
Loading