Skip to content
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

[RDBMS] Support Private Endpoint Connections #12394

Merged
merged 30 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,27 @@ def cf_mysql_replica(cli_ctx, _):

def cf_postgres_replica(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).replicas


def cf_mariadb_private_endpoint_connections_operations(cli_ctx, _):
return get_mariadb_management_client(cli_ctx).private_endpoint_connections


def cf_mariadb_private_link_resources_operations(cli_ctx, _):
return get_mariadb_management_client(cli_ctx).private_link_resources


def cf_mysql_private_endpoint_connections_operations(cli_ctx, _):
return get_mysql_management_client(cli_ctx).private_endpoint_connections


def cf_mysql_private_link_resources_operations(cli_ctx, _):
return get_mysql_management_client(cli_ctx).private_link_resources


def cf_postgres_private_endpoint_connections_operations(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).private_endpoint_connections


def cf_postgres_private_link_resources_operations(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).private_link_resources
105 changes: 105 additions & 0 deletions src/azure-cli/azure/cli/command_modules/rdbms/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,41 @@
text: az mariadb server-logs list -g testgroup -s testsvr --max-file-size 30
"""

helps['mariadb server private-endpoint-connection'] = """
type: group
short-summary: Manage MariaDB server private endpoint connections.
"""

helps['mariadb server private-endpoint-connection approve'] = """
type: command
short-summary: Approve the specified private endpoint connection associated with a MariaDB server.
"""

helps['mariadb server private-endpoint-connection reject'] = """
type: command
short-summary: Reject the specified private endpoint connection associated with a MariaDB server.
"""

helps['mariadb server private-endpoint-connection delete'] = """
type: command
short-summary: Delete the specified private endpoint connection associated with a MariaDB server.
"""

helps['mariadb server private-endpoint-connection show'] = """
type: command
short-summary: Show details of a private endpoint connection associated with a MariaDB server.
"""

helps['mariadb server private-link-resource'] = """
type: group
short-summary: Manage MariaDB server private link resources.
"""

helps['mariadb server private-link-resource list'] = """
type: command
short-summary: List the private link resources supported for a MariaDB server.
"""

helps['mysql'] = """
type: group
short-summary: Manage Azure Database for MySQL servers.
Expand Down Expand Up @@ -619,6 +654,41 @@
text: az mysql server-logs list -g testgroup -s testsvr --max-file-size 30
"""

helps['mysql server private-endpoint-connection'] = """
type: group
short-summary: Manage MySQL server private endpoint connections.
"""

helps['mysql server private-endpoint-connection approve'] = """
type: command
short-summary: Approve the specified private endpoint connection associated with a MySQL server.
"""

helps['mysql server private-endpoint-connection reject'] = """
type: command
short-summary: Reject the specified private endpoint connection associated with a MySQL server.
"""

helps['mysql server private-endpoint-connection delete'] = """
type: command
short-summary: Delete the specified private endpoint connection associated with a MySQL server.
"""

helps['mysql server private-endpoint-connection show'] = """
type: command
short-summary: Show details of a private endpoint connection associated with a MySQL server.
"""

helps['mysql server private-link-resource'] = """
type: group
short-summary: Manage MySQL server private link resources.
"""

helps['mysql server private-link-resource list'] = """
type: command
short-summary: List the private link resources supported for a MySQL server.
"""

helps['postgres'] = """
type: group
short-summary: Manage Azure Database for PostgreSQL servers.
Expand Down Expand Up @@ -921,3 +991,38 @@
- name: List log files for 'testsvr' less than 30Kb in size.
text: az postgres server-logs list -g testgroup -s testsvr --max-file-size 30
"""

helps['postgres server private-endpoint-connection'] = """
type: group
short-summary: Manage PostgreSQL server private endpoint connections.
"""

helps['postgres server private-endpoint-connection approve'] = """
type: command
short-summary: Approve the specified private endpoint connection associated with a PostgreSQL server.
"""

helps['postgres server private-endpoint-connection reject'] = """
type: command
short-summary: Reject the specified private endpoint connection associated with a PostgreSQL server.
"""

helps['postgres server private-endpoint-connection delete'] = """
type: command
short-summary: Delete the specified private endpoint connection associated with a PostgreSQL server.
"""

helps['postgres server private-endpoint-connection show'] = """
type: command
short-summary: Show details of a private endpoint connection associated with a PostgreSQL server.
"""

helps['postgres server private-link-resource'] = """
type: group
short-summary: Manage PostgreSQL server private link resources.
"""

helps['postgres server private-link-resource list'] = """
type: command
short-summary: List the private link resources supported for a PostgreSQL server.
"""
21 changes: 21 additions & 0 deletions src/azure-cli/azure/cli/command_modules/rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,24 @@ def _complex_params(command_group):
for scope in ['mariadb server replica list', 'mysql server replica list', 'postgres server replica list']:
with self.argument_context(scope) as c:
c.argument('server_name', options_list=['--server-name', '-s'], help='Name of the master server.')

for scope in ['mariadb server private-endpoint-connection', 'mysql server private-endpoint-connection', 'postgres server private-endpoint-connection']:
with self.argument_context(scope) as c:
c.argument('approval_description', help='Comments for the approval.')
c.argument('private_endpoint_connection_name', options_list=['--name', '-n'], required=False,
help='The name of the private endpoint connection associated with the Server. '
'Required if --id is not specified')
c.argument('server_name', options_list=['--server-name', '-s'], required=False,
help='Name of the Server. Required if --id is not specified')
c.argument('rejection_description', help='Comments for the rejection.')

for item in ['approve', 'reject', 'delete', 'show']:
mmyyrroonn marked this conversation as resolved.
Show resolved Hide resolved
for scope in ['mariadb server private-endpoint-connection {}', 'mysql server private-endpoint-connection {}', 'postgres server private-endpoint-connection {}']:
with self.argument_context(scope.format(item)) as c:
c.extra('connection_id', options_list=['--id'], required=False,
help='The ID of the private endpoint connection associated with the Server. '
'If specified --server-name and --name/-n, this should be omitted.')

for scope in ['mariadb server private-link-resource', 'mysql server private-link-resource', 'postgres server private-link-resource']:
with self.argument_context(scope) as c:
c.argument('server_name', options_list=['--server-name', '-s'], required=True, help='Name of the Server.')
93 changes: 92 additions & 1 deletion src/azure-cli/azure/cli/command_modules/rdbms/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands import CliCommandType
from azure.cli.core.profiles import ResourceType

from azure.cli.command_modules.rdbms.validators import (
validate_private_endpoint_connection_id)

from azure.cli.command_modules.rdbms._client_factory import (
cf_mariadb_servers,
Expand All @@ -13,20 +17,26 @@
cf_mariadb_config,
cf_mariadb_log,
cf_mariadb_replica,
cf_mariadb_private_endpoint_connections_operations,
cf_mariadb_private_link_resources_operations,
cf_mysql_servers,
cf_mysql_db,
cf_mysql_firewall_rules,
cf_mysql_virtual_network_rules_operations,
cf_mysql_config,
cf_mysql_log,
cf_mysql_replica,
cf_mysql_private_endpoint_connections_operations,
cf_mysql_private_link_resources_operations,
cf_postgres_servers,
cf_postgres_db,
cf_postgres_firewall_rules,
cf_postgres_virtual_network_rules_operations,
cf_postgres_config,
cf_postgres_log,
cf_postgres_replica)
cf_postgres_replica,
cf_postgres_private_endpoint_connections_operations,
cf_postgres_private_link_resources_operations)


# pylint: disable=too-many-locals, too-many-statements, line-too-long
Expand Down Expand Up @@ -139,6 +149,42 @@ def load_command_table(self, _):
client_factory=cf_postgres_db
)

mariadb_private_endpoint_connections_sdk = CliCommandType(
operations_tmpl='azure.mgmt.rdbms.mariadb.operations#PrivateEndpointConnectionsOperations.{}',
client_factory=cf_mariadb_private_endpoint_connections_operations,
resource_type=ResourceType.MGMT_RDBMS
)

mariadb_private_link_resources_sdk = CliCommandType(
operations_tmpl='azure.mgmt.rdbms.mariadb.operations#PrivateLinkResourcesOperations.{}',
client_factory=cf_mariadb_private_link_resources_operations,
resource_type=ResourceType.MGMT_RDBMS
)

mysql_private_endpoint_connections_sdk = CliCommandType(
operations_tmpl='azure.mgmt.rdbms.mysql.operations#PrivateEndpointConnectionsOperations.{}',
client_factory=cf_mysql_private_endpoint_connections_operations,
resource_type=ResourceType.MGMT_RDBMS
)

mysql_private_link_resources_sdk = CliCommandType(
operations_tmpl='azure.mgmt.rdbms.mysql.operations#PrivateLinkResourcesOperations.{}',
client_factory=cf_mysql_private_link_resources_operations,
resource_type=ResourceType.MGMT_RDBMS
)

postgres_private_endpoint_connections_sdk = CliCommandType(
operations_tmpl='azure.mgmt.rdbms.postgresql.operations#PrivateEndpointConnectionsOperations.{}',
client_factory=cf_postgres_private_endpoint_connections_operations,
resource_type=ResourceType.MGMT_RDBMS
)

postgres_private_link_resources_sdk = CliCommandType(
operations_tmpl='azure.mgmt.rdbms.postgresql.operations#PrivateLinkResourcesOperations.{}',
client_factory=cf_postgres_private_link_resources_operations,
resource_type=ResourceType.MGMT_RDBMS
)

with self.command_group('mariadb server', mariadb_servers_sdk, client_factory=cf_mariadb_servers) as g:
g.custom_command('create', '_server_create')
g.custom_command('restore', '_server_restore', supports_no_wait=True)
Expand Down Expand Up @@ -297,3 +343,48 @@ def load_command_table(self, _):
g.command('delete', 'delete', confirmation=True)
g.show_command('show', 'get')
g.command('list', 'list_by_server')

with self.command_group('mariadb server private-endpoint-connection',
mariadb_private_endpoint_connections_sdk,
client_factory=cf_mariadb_private_endpoint_connections_operations) as g:
g.custom_command('approve', 'approve_private_endpoint_connection',
validator=validate_private_endpoint_connection_id)
g.custom_command('reject', 'reject_private_endpoint_connection',
validator=validate_private_endpoint_connection_id)
g.command('delete', 'delete', validator=validate_private_endpoint_connection_id)
g.show_command('show', 'get', validator=validate_private_endpoint_connection_id)

with self.command_group('mariadb server private-link-resource',
mariadb_private_link_resources_sdk,
client_factory=cf_mariadb_private_link_resources_operations) as g:
g.show_command('list', 'list_by_server')

with self.command_group('mysql server private-endpoint-connection',
mysql_private_endpoint_connections_sdk,
client_factory=cf_mysql_private_endpoint_connections_operations) as g:
g.custom_command('approve', 'approve_private_endpoint_connection',
ramnov marked this conversation as resolved.
Show resolved Hide resolved
validator=validate_private_endpoint_connection_id)
g.custom_command('reject', 'reject_private_endpoint_connection',
validator=validate_private_endpoint_connection_id)
g.command('delete', 'delete', validator=validate_private_endpoint_connection_id)
g.show_command('show', 'get', validator=validate_private_endpoint_connection_id)

with self.command_group('mysql server private-link-resource',
mysql_private_link_resources_sdk,
client_factory=cf_mysql_private_link_resources_operations) as g:
g.show_command('list', 'list_by_server')

with self.command_group('postgres server private-endpoint-connection',
postgres_private_endpoint_connections_sdk,
client_factory=cf_postgres_private_endpoint_connections_operations) as g:
g.custom_command('approve', 'approve_private_endpoint_connection',
validator=validate_private_endpoint_connection_id)
g.custom_command('reject', 'reject_private_endpoint_connection',
validator=validate_private_endpoint_connection_id)
g.command('delete', 'delete', validator=validate_private_endpoint_connection_id)
g.show_command('show', 'get', validator=validate_private_endpoint_connection_id)

with self.command_group('postgres server private-link-resource',
postgres_private_link_resources_sdk,
client_factory=cf_postgres_private_link_resources_operations) as g:
g.show_command('list', 'list_by_server')
47 changes: 45 additions & 2 deletions src/azure-cli/azure/cli/command_modules/rdbms/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
from msrestazure.azure_exceptions import CloudError
from msrestazure.tools import resource_id, is_valid_resource_id, parse_resource_id # pylint: disable=import-error
from azure.cli.core.commands.client_factory import get_subscription_id
from azure.cli.core.profiles import ResourceType
from azure.cli.core.util import CLIError, sdk_no_wait
from azure.mgmt.rdbms.mysql.operations.servers_operations import ServersOperations as MySqlServersOperations
from azure.mgmt.rdbms.mariadb.operations.servers_operations import ServersOperations as MariaDBServersOperations
from azure.mgmt.rdbms.mysql.operations._servers_operations import ServersOperations as MySqlServersOperations
from azure.mgmt.rdbms.mariadb.operations._servers_operations import ServersOperations as MariaDBServersOperations
from ._client_factory import get_mariadb_management_client, get_mysql_management_client, get_postgresql_management_client

SKU_TIER_MAP = {'Basic': 'b', 'GeneralPurpose': 'gp', 'MemoryOptimized': 'mo'}
Expand Down Expand Up @@ -425,3 +426,45 @@ def _server_list_custom_func(client, resource_group_name=None):
if resource_group_name:
return client.list_by_resource_group(resource_group_name)
return client.list()


# region private_endpoint
def _update_private_endpoint_connection_status(cmd, client, resource_group_name, server_name,
private_endpoint_connection_name, is_approved=True, description=None,
connection_id=None): # pylint: disable=unused-argument
PrivateEndpointServiceConnectionStatus = cmd.get_models('PrivateEndpointServiceConnectionStatus',
resource_type=ResourceType.MGMT_RDBMS)

private_endpoint_connection = client.get(resource_group_name=resource_group_name, server_name=server_name,
private_endpoint_connection_name=private_endpoint_connection_name)

new_status = PrivateEndpointServiceConnectionStatus.approved \
if is_approved else PrivateEndpointServiceConnectionStatus.rejected
private_endpoint_connection.private_link_service_connection_state.status = new_status
private_endpoint_connection.private_link_service_connection_state.description = description

return client.put(resource_group_name=resource_group_name,
server_name=server_name,
private_endpoint_connection_name=private_endpoint_connection_name,
properties=private_endpoint_connection)


def approve_private_endpoint_connection(cmd, client, resource_group_name, server_name, private_endpoint_connection_name,
approval_description=None, connection_id=None):
ramnov marked this conversation as resolved.
Show resolved Hide resolved
"""Approve a private endpoint connection request for a server."""

return _update_private_endpoint_connection_status(
cmd, client, resource_group_name, server_name, private_endpoint_connection_name, is_approved=True,
description=approval_description, connection_id=connection_id
)


def reject_private_endpoint_connection(cmd, client, resource_group_name, server_name, private_endpoint_connection_name,
rejection_description=None, connection_id=None):
"""Reject a private endpoint connection request for a server."""

return _update_private_endpoint_connection_status(
cmd, client, resource_group_name, server_name, private_endpoint_connection_name, is_approved=False,
description=rejection_description, connection_id=connection_id
)
# endregion
Loading