Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
upgrade az search to use the latest sdk version with new features suc…
…h as public ip rules, private endpoints, private link resources and msi; also add search provider in 'az network private-link-resource list'
  • Loading branch information
Bolun Huang committed Jan 27, 2021
commit 045ea3d288acdcb3a27484552f4af0ed86821892
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def register_providers():
_register_one_provider('Microsoft.Network/applicationGateways', '2020-05-01', True)
_register_one_provider('Microsoft.Compute/diskAccesses', '2020-05-01', False, support_connection_operation=False)
_register_one_provider('Microsoft.AppConfiguration/configurationStores', '2020-06-01', True)
_register_one_provider('Microsoft.Search/searchServices', '2020-08-01', True)


def _register_one_provider(provider, api_version, support_list_or_not, resource_get_api_version=None, support_connection_operation=True): # pylint: disable=line-too-long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ def cf_search(cli_ctx, **_):
def cf_search_services(cli_ctx, _):
return cf_search(cli_ctx).services

def cf_search_private_endpoint_connections(cli_ctx, _):
return cf_search(cli_ctx).private_endpoint_connections

def cf_search_private_link_resources(cli_ctx, _):
return cf_search(cli_ctx).private_link_resources

def cf_search_shared_private_link_resources(cli_ctx, _):
return cf_search(cli_ctx).shared_private_link_resources

def cf_search_admin_keys(cli_ctx, _):
return cf_search(cli_ctx).admin_keys
Expand Down
15 changes: 15 additions & 0 deletions src/azure-cli/azure/cli/command_modules/search/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@
short-summary: Manage Azure Search services.
"""

helps['search privateendpointconnection'] = """
type: group
short-summary: Manage Azure Search private endpoint connections.
"""

helps['search privatelinkresource'] = """
type: group
short-summary: Manage Azure Search private link resources.
"""

helps['search sharedprivatelinkresource'] = """
type: group
short-summary: Manage Azure Search shared private link resources.
"""

helps['search service create'] = """
type: command
short-summary: Creates a Search service in the given resource group.
Expand Down
12 changes: 12 additions & 0 deletions src/azure-cli/azure/cli/command_modules/search/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ def load_arguments(self, _):
c.ignore('search_management_request_options')
c.argument('sku', help='Search Service SKU', arg_type=get_enum_type(["Free", "Basic", "Standard", "Standard2", "Standard3"]))

with self.argument_context('search privateendpointconnection') as c:
c.ignore('search_management_request_options')
c.argument('search_service_name', options_list=['--service-name'], help='The name of the search service.')

with self.argument_context('search privatelinkresource') as c:
c.ignore('search_management_request_options')
c.argument('search_service_name', options_list=['--service-name'], help='The name of the search service.')

with self.argument_context('search sharedprivatelinkresource') as c:
c.ignore('search_management_request_options')
c.argument('search_service_name', options_list=['--service-name'], help='The name of the search service.')

with self.argument_context('search query-key') as c:
c.ignore('search_management_request_options')
c.argument('search_service_name', options_list=['--service-name'], help='The name of the search service.')
Expand Down
34 changes: 32 additions & 2 deletions src/azure-cli/azure/cli/command_modules/search/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,29 @@

def load_command_table(self, _):
from azure.cli.core.commands import CliCommandType
from azure.cli.command_modules.search._client_factory import cf_search_services, cf_search_admin_keys, \
cf_search_query_keys
from azure.cli.command_modules.search._client_factory import cf_search_services, cf_search_private_endpoint_connections, \
cf_search_private_link_resources, cf_search_shared_private_link_resources, cf_search_admin_keys, cf_search_query_keys

search_services_sdk = CliCommandType(
operations_tmpl='azure.mgmt.search.operations#ServicesOperations.{}',
client_factory=cf_search_services
)

search_private_endpoint_connections_sdk = CliCommandType(
operations_tmpl='azure.mgmt.search.operations#PrivateEndpointConnectionsOperations.{}',
client_factory=cf_search_private_endpoint_connections
)

search_private_link_resources_sdk = CliCommandType(
operations_tmpl='azure.mgmt.search.operations#PrivateLinkResourcesOperations.{}',
client_factory=cf_search_private_link_resources
)

search_shared_private_link_resources_sdk = CliCommandType(
operations_tmpl='azure.mgmt.search.operations#SharedPrivateLinkResourcesOperations.{}',
client_factory=cf_search_shared_private_link_resources
)

search_admin_keys_sdk = CliCommandType(
operations_tmpl='azure.mgmt.search.operations#AdminKeysOperations.{}',
client_factory=cf_search_admin_keys
Expand All @@ -34,6 +49,21 @@ def load_command_table(self, _):
g.generic_update_command('update', custom_func_name='update_search_service', setter_arg_name='service')
g.custom_command('create', 'create_search_service')

with self.command_group('search privateendpointconnection', search_private_endpoint_connections_sdk) as g:
g.command('list', 'list_by_service')
g.show_command('show', 'get')
g.command('delete', 'delete', confirmation=True)
g.custom_command('update', 'update_private_endpoint_connection')

with self.command_group('search privatelinkresource', search_private_link_resources_sdk) as g:
g.command('list', 'list_supported')

with self.command_group('search sharedprivatelinkresource', search_shared_private_link_resources_sdk) as g:
g.command('list', 'list_by_service')
g.show_command('show', 'get')
g.command('delete', 'begin_delete', confirmation=True)
g.custom_command('createorupdate', 'create_or_update_shared_private_link_resource')

with self.command_group('search admin-key', search_admin_keys_sdk) as g:
g.show_command('show', 'get')
g.command('renew', 'regenerate')
Expand Down
124 changes: 117 additions & 7 deletions src/azure-cli/azure/cli/command_modules/search/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.log import get_logger

logger = get_logger(__name__)
Expand All @@ -15,9 +14,8 @@ def _get_resource_group_location(cli_ctx, resource_group_name):
# pylint: disable=no-member
return client.resource_groups.get(resource_group_name).location


def create_search_service(cmd, resource_group_name, search_service_name, sku, location=None, partition_count=0,
replica_count=0,):
replica_count=0, public_network_access="enabled", ip_rules=None, identity_type=None):
"""
Creates a Search service in the given resource group.

Expand All @@ -27,35 +25,147 @@ def create_search_service(cmd, resource_group_name, search_service_name, sku, lo
:param location: Geographic location of the resource.
:param partition_count: Number of partitions in the search service.
:param replica_count: Number of replicas in the search service.
:param public_network_access: Public accessibility to the search service;
allowed values are "enabled" or "disabled".
:param ip_rules: Public IP(v4) addresses or CIDR ranges to the search service, seperated by comma or semicolon;
These IP rules are applicable only when public_network_access is "enabled".
:param identity_type: The identity type. Possible values include: "None", "SystemAssigned".
"""
from azure.mgmt.search.models import SearchService, Sku
from azure.mgmt.search.models import SearchService, Sku, NetworkRuleSet, IpRule, Identity
from azure.cli.command_modules.search._client_factory import cf_search_services
import re

_client = cf_search_services(cmd.cli_ctx, None)
if location is None:
location = _get_resource_group_location(cmd.cli_ctx, resource_group_name)

_search = SearchService(location=location, sku=Sku(name=sku))
_search = SearchService(location=location, sku=Sku(name=sku.lower()))

replica_count = int(replica_count)
partition_count = int(partition_count)
if replica_count > 0:
_search.replica_count = replica_count
if partition_count > 0:
_search.partition_count = partition_count
return _client.create_or_update(resource_group_name, search_service_name, _search)
if (public_network_access.lower() not in ["enabled", "disabled"]):
raise ValueError("SearchService.PublicNetworkAccess: only [""enabled"", ""disabled""] are allowed")
_search.public_network_access = public_network_access

if ip_rules:
_ip_rules = []
_ip_rules_array = re.split(';|,', ip_rules)
for _ip_rule in _ip_rules_array:
_ip_rules.append(IpRule(value=_ip_rule))
_search.network_rule_set = NetworkRuleSet(ip_rules=_ip_rules)
if identity_type:
_identity = Identity(type=identity_type)
_search.identity = _identity

def update_search_service(instance, partition_count=0, replica_count=0):
return _client.begin_create_or_update(resource_group_name, search_service_name, _search)

def update_search_service(instance, partition_count=0, replica_count=0, public_network_access="enabled",
ip_rules=None, identity_type=None):
"""
Update partition and replica of the given search service.

:param partition_count: Number of partitions in the search service.
:param replica_count: Number of replicas in the search service.
:param public_network_access: Public accessibility to the search service;
allowed values are "enabled" or "disabled".
:param ip_rules: Public IP(v4) addresses or CIDR ranges to the search service, seperated by comma or semicolon;
These IP rules are applicable only when public_network_access is "enabled".
:param identity_type: The identity type. Possible values include: "None", "SystemAssigned".
"""
from azure.mgmt.search.models import NetworkRuleSet, IpRule, Identity
import re

replica_count = int(replica_count)
partition_count = int(partition_count)
if replica_count > 0:
instance.replica_count = replica_count
if partition_count > 0:
instance.partition_count = partition_count
if (public_network_access.lower() not in ["enabled", "disabled"]):
raise ValueError("SearchService.PublicNetworkAccess: only [""enabled"", ""disabled""] are allowed")
instance.public_network_access = public_network_access
if ip_rules:
_ip_rules = []
_ip_rules_array = re.split(';|,', ip_rules)
for _ip_rule in _ip_rules_array:
_ip_rules.append(IpRule(value=_ip_rule))
instance.network_rule_set = NetworkRuleSet(ip_rules=_ip_rules)
if identity_type:
_identity = Identity(type=identity_type)
instance.identity = _identity

return instance

def update_private_endpoint_connection(cmd, resource_group_name, search_service_name, private_endpoint_connection_name,
private_link_service_connection_status,
private_link_service_connection_description="N/A",
private_link_service_connection_actions_required="No action required"):
"""
Updates an existing private endpoint connection in a Search service in the given resource group.

:param resource_group_name: Name of resource group.
:param search_service_name: Name of the search service.
:param private_endpoint_connection_name: Name of the private endpoint connection resource.
Ex - {the name of the private endpoint resource}.{a guid}.
:param private_link_service_connection_status: The updated status of the private endpoint connection resource.
Possible values include: "Pending", "Approved", "Rejected", "Disconnected".
:param private_link_service_connection_description: Custom request description when updating
the private endpoint connection resource.
:param private_link_service_connection_actions_required: Custom 'actions required' message when updating
the private endpoint connection resource.
"""

from azure.mgmt.search.models import PrivateEndpointConnection, PrivateEndpointConnectionProperties, \
PrivateEndpointConnectionPropertiesPrivateLinkServiceConnectionState
from azure.cli.command_modules.search._client_factory import cf_search_private_endpoint_connections

_client = cf_search_private_endpoint_connections(cmd.cli_ctx, None)
_private_endpoint_connection = PrivateEndpointConnection()
_private_link_service_connection_state = PrivateEndpointConnectionPropertiesPrivateLinkServiceConnectionState(
status=private_link_service_connection_status,
description=private_link_service_connection_description,
actions_required=private_link_service_connection_actions_required
)
_private_endpoint_connection_properties = PrivateEndpointConnectionProperties(\
private_link_service_connection_state=_private_link_service_connection_state)
_private_endpoint_connection.id = private_endpoint_connection_name
_private_endpoint_connection.properties = _private_endpoint_connection_properties

return _client.update(resource_group_name, search_service_name, private_endpoint_connection_name, \
_private_endpoint_connection)

def create_or_update_shared_private_link_resource(cmd, resource_group_name, search_service_name,
shared_private_link_resource_name, shared_private_link_resource_id,
shared_private_link_resource_group_id,
shared_private_link_resource_request_message="Please approve"):
"""
Creates or updates shared privatelink resources in a Search service in the given resource group.

:param resource_group_name: Name of resource group.
:param search_service_name: Name of the search service.
:param shared_private_link_resource_name: Name of the shared private link resource.
:param shared_private_link_resource_id: Fully qualified resource ID for the resource.
Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/
{resourceProviderNamespace}/{resourceType}/{resourceName}.
:param shared_private_link_resource_group_id: The group id of the resource. Ex, blob, sql or vault.
:param shared_private_link_resource_request_message: Custom request message when creating or updating the shared
privatelink resources.
"""
from azure.mgmt.search.models import SharedPrivateLinkResource, SharedPrivateLinkResourceProperties
from azure.cli.command_modules.search._client_factory import cf_search_shared_private_link_resources

_client = cf_search_shared_private_link_resources(cmd.cli_ctx, None)
_shared_private_link_resource = SharedPrivateLinkResource()
_shared_private_link_resource.name = shared_private_link_resource_name
_shared_private_link_resource.properties = SharedPrivateLinkResourceProperties(
private_link_resource_id=shared_private_link_resource_id,
group_id=shared_private_link_resource_group_id,
request_message=shared_private_link_resource_request_message
)

return _client.begin_create_or_update(resource_group_name, search_service_name, shared_private_link_resource_name,
_shared_private_link_resource)
Loading