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

VNET extension #176

Merged
merged 22 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e6b2d2f
VNET extension
rahulgouthamDOTgs May 10, 2018
e25f366
fixing indentation
rahulgouthamDOTgs May 10, 2018
11bc3b1
fixing more flake8 reported issues
rahulgouthamDOTgs May 11, 2018
e06f1c1
Fixing Review comments and formatting issues.
rahulgouthamDOTgs May 11, 2018
f15a7cb
Fixing some more issues with source static and bug fixes
rahulgouthamDOTgs May 11, 2018
bebd263
Merge branch 'master' into master
rahulgouthamDOTgs May 11, 2018
3e1ff25
Renaming _client_factory to _client_vnet_factory
rahulgouthamDOTgs May 11, 2018
8f9dad9
Reverting the last change
rahulgouthamDOTgs May 11, 2018
eb80f8b
Renaming to azext_rdbms_vnet
rahulgouthamDOTgs May 11, 2018
b1babff
More formatting issue fix
rahulgouthamDOTgs May 11, 2018
81a8a29
adding code owners
rahulgouthamDOTgs May 11, 2018
e5ef37e
Adding my email id
rahulgouthamDOTgs May 11, 2018
79d3d6a
Merge branch 'master' into master
rohit-joy May 11, 2018
0cfda9e
Merge branch 'master' into master
rohit-joy May 14, 2018
1bd5236
Merge branch 'master' into master
rohit-joy May 14, 2018
bad76af
Merge branch 'master' into master
rohit-joy May 17, 2018
9876498
Merge branch 'master' into master
rohit-joy May 22, 2018
8504656
Adding extension to index.json
rahulgouthamDOTgs May 22, 2018
6f09d16
Merge branch 'master' of https://github.com/rahulgouthamDOTgs/azure-c…
rahulgouthamDOTgs May 22, 2018
592fba6
Merge branch 'master' into master
rahulgouthamDOTgs May 22, 2018
ec79eeb
fixing index-verify
rahulgouthamDOTgs May 22, 2018
233b695
Merge branch 'master' of https://github.com/rahulgouthamDOTgs/azure-c…
rahulgouthamDOTgs May 22, 2018
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
1 change: 1 addition & 0 deletions src/rdbms_vnet/azext_rdbms/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ def get_postgresql_management_client(cli_ctx, **_):
def cf_mysql_virtual_network_rules_operations(cli_ctx, _):
return get_mysql_management_client(cli_ctx).virtual_network_rules


def cf_postgres_virtual_network_rules_operations(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).virtual_network_rules
40 changes: 17 additions & 23 deletions src/rdbms_vnet/azext_rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# pylint: disable=line-too-long

from azure.cli.core.commands.parameters import get_three_state_flag,get_resource_name_completion_list, tags_type, get_location_type, get_enum_type # pylint: disable=line-too-long
from azure.cli.core.commands.parameters import get_three_state_flag, get_resource_name_completion_list, tags_type, get_location_type, get_enum_type # pylint: disable=line-too-long
from azext_rdbms import mysql, postgresql
from azure.cli.command_modules.sql._validators import validate_subnet

Expand All @@ -14,27 +14,21 @@

def load_arguments(self, _): # pylint: disable=too-many-statements

server_completers = {
'mysql': get_resource_name_completion_list('Microsoft.DBForMySQL/servers'),
'postgres': get_resource_name_completion_list('Microsoft.DBForPostgreSQL/servers')
}

for scope in ['mysql server vnet-rule', 'postgres server vnet-rule']:
with self.argument_context(scope) as c:
c.argument('server_name', options_list=['--server-name', '-s'])
c.argument('virtual_network_rule_name', options_list=['--name', '-n'], id_part='child_name_1', help='The name of the vnet rule.')
c.argument('virtual_network_subnet_id', options_list=['--subnet'], help='Name or ID of the subnet that allows access to an Azure Postgres Server. If subnet name is provided, --vnet-name must be provided.')
c.argument('ignore_missing_vnet_service_endpoint', options_list=['--ignore-missing-endpoint', '-i'], help='Create vnet rule before virtual network has vnet service endpoint enabled', arg_type=get_three_state_flag())

with self.argument_context('postgres server vnet-rule create') as c:
c.extra('vnet_name', options_list=['--vnet-name'], help='The virtual network name', validator=validate_subnet)

with self.argument_context('postgres server vnet-rule update') as c:
c.extra('vnet_name', options_list=['--vnet-name'], help='The virtual network name', validator=validate_subnet)

with self.argument_context('mysql server vnet-rule create') as c:
c.extra('vnet_name', options_list=['--vnet-name'], help='The virtual network name', validator=validate_subnet)

with self.argument_context('mysql server vnet-rule update') as c:
c.extra('vnet_name', options_list=['--vnet-name'], help='The virtual network name', validator=validate_subnet)
with self.argument_context(scope) as c:
c.argument('server_name', options_list=['--server-name', '-s'])
c.argument('virtual_network_rule_name', options_list=['--name', '-n'], id_part='child_name_1', help='The name of the vnet rule.')
c.argument('virtual_network_subnet_id', options_list=['--subnet'], help='Name or ID of the subnet that allows access to an Azure Postgres Server. If subnet name is provided, --vnet-name must be provided.')
c.argument('ignore_missing_vnet_service_endpoint', options_list=['--ignore-missing-endpoint', '-i'], help='Create vnet rule before virtual network has vnet service endpoint enabled', arg_type=get_three_state_flag())

with self.argument_context('postgres server vnet-rule create') as c:
c.extra('vnet_name', options_list=['--vnet-name'], help='The virtual network name', validator=validate_subnet)

with self.argument_context('postgres server vnet-rule update') as c:
c.extra('vnet_name', options_list=['--vnet-name'], help='The virtual network name', validator=validate_subnet)

with self.argument_context('mysql server vnet-rule create') as c:
c.extra('vnet_name', options_list=['--vnet-name'], help='The virtual network name', validator=validate_subnet)

with self.argument_context('mysql server vnet-rule update') as c:
c.extra('vnet_name', options_list=['--vnet-name'], help='The virtual network name', validator=validate_subnet)
32 changes: 15 additions & 17 deletions src/rdbms_vnet/azext_rdbms/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from azext_rdbms._client_factory import (
cf_mysql_virtual_network_rules_operations,
cf_postgres_virtual_network_rules_operations)
cf_postgres_virtual_network_rules_operations)


# pylint: disable=too-many-locals, too-many-statements, line-too-long
Expand All @@ -27,22 +27,20 @@ def load_command_table(self, _):
client_factory=cf_postgres_virtual_network_rules_operations
)
with self.command_group('mysql server vnet-rule', mysql_vnet_sdk) as g:
g.command('create', 'create_or_update')
g.command('delete', 'delete', confirmation=True)
g.command('show', 'get')
g.command('list', 'list_by_server')
#g.generic_update_command('update')
g.generic_update_command('update', getter_name='_custom_vnet_update_get', getter_type=rdbms_custom,
g.command('create', 'create_or_update')
g.command('delete', 'delete', confirmation=True)
g.command('show', 'get')
g.command('list', 'list_by_server')
# g.generic_update_command('update')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the commented lines.

g.generic_update_command('update', getter_name='_custom_vnet_update_get', getter_type=rdbms_custom,
setter_name='_custom_vnet_update_set', setter_type=rdbms_custom, setter_arg_name='parameters')

with self.command_group('postgres server vnet-rule', postgres_vnet_sdk) as g:
g.command('create', 'create_or_update')
g.command('delete', 'delete', confirmation=True)
g.command('show', 'get')
g.command('list', 'list_by_server')
#g.generic_update_command('update')
g.generic_update_command('update',
getter_name='_custom_vnet_update_get', getter_type=rdbms_custom,
setter_name='_custom_vnet_update_set', setter_type=rdbms_custom, setter_arg_name='parameters')
#custom_func_name='_custom_vnet_update', custom_func_type=rdbms_custom)
#g.custom_command('update', '_custom_vnet_update')
g.command('create', 'create_or_update')
g.command('delete', 'delete', confirmation=True)
g.command('show', 'get')
g.command('list', 'list_by_server')
# g.generic_update_command('update')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the commented lines.

g.generic_update_command('update',
getter_name='_custom_vnet_update_get', getter_type=rdbms_custom,
setter_name='_custom_vnet_update_set', setter_type=rdbms_custom, setter_arg_name='parameters')
2 changes: 1 addition & 1 deletion src/rdbms_vnet/azext_rdbms/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from ._client_factory import get_mysql_management_client, get_postgresql_management_client



def _custom_vnet_update_get(client, resource_group_name, server_name, virtual_network_rule_name):
return client.get(resource_group_name, server_name, virtual_network_rule_name)


def _custom_vnet_update_set(client, resource_group_name, server_name, virtual_network_rule_name, virtual_network_subnet_id, ignore_missing_vnet_service_endpoint=None, parameters=None):
return client.create_or_update(resource_group_name, server_name, virtual_network_rule_name, virtual_network_subnet_id, ignore_missing_vnet_service_endpoint)
33 changes: 16 additions & 17 deletions src/rdbms_vnet/azext_rdbms/tests/test_rdbms_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,50 +354,50 @@ def _test_vnet_firewall_mgmt(self, resource_group, server, database_engine):

subnet_name_1 = 'clitestsubnet1'
subnet_prefix_1 = '10.0.0.0/24'

subnet_name_2 = 'clitestsubnet2'
subnet_prefix_2 = '10.0.1.0/24'

# pre create the dependent resources here
# pre create the dependent resources here
# create vnet and subnet
execute(self.cli_ctx, 'az network vnet create -n {} -g {} -l {} '
'--address-prefix {} --subnet-name {} --subnet-prefix {}'.format(vnet_name, resource_group, location, address_prefix, subnet_name_1,
subnet_prefix_1))
'--address-prefix {} --subnet-name {} --subnet-prefix {}'.format(vnet_name, resource_group, location, address_prefix, subnet_name_1,
subnet_prefix_1))
# add one more subnet
execute(self.cli_ctx, 'az network vnet subnet create --vnet-name {} -g {} '
'--address-prefix {} -n {}'.format(vnet_name, resource_group, subnet_prefix_2, subnet_name_2))
'--address-prefix {} -n {}'.format(vnet_name, resource_group, subnet_prefix_2, subnet_name_2))
# test vnet-rule create
self.cmd('{} server vnet-rule create -n {} -g {} -s {} '
'--vnet-name {} --subnet {} --ignore-missing-endpoint {}'
.format(database_engine, vnet_firewall_rule_1, resource_group, server,
vnet_name, subnet_name_1, ignore_missing_endpoint),
checks=[
JMESPathCheck('name', vnet_firewall_rule_1),
JMESPathCheck('resourceGroup', resource_group),
JMESPathCheck('state', 'Ready')])
JMESPathCheck('name', vnet_firewall_rule_1),
JMESPathCheck('resourceGroup', resource_group),
JMESPathCheck('state', 'Ready')])

# test vnet-rule show
self.cmd('{} server vnet-rule show -n {} -g {} -s {}'
.format(database_engine, vnet_firewall_rule_1, resource_group, server),
checks=[
JMESPathCheck('name', vnet_firewall_rule_1),
JMESPathCheck('resourceGroup', resource_group),
JMESPathCheck('state', 'Ready')])
JMESPathCheck('name', vnet_firewall_rule_1),
JMESPathCheck('resourceGroup', resource_group),
JMESPathCheck('state', 'Ready')])

# test create one more vnet rule .
self.cmd('{} server vnet-rule create -n {} -g {} -s {} '
'--vnet-name {} --subnet {} --ignore-missing-endpoint {}'
.format(database_engine, vnet_firewall_rule_2, resource_group, server,
vnet_name, subnet_name_2, ignore_missing_endpoint),
checks=[
JMESPathCheck('name', vnet_firewall_rule_2),
JMESPathCheck('resourceGroup', resource_group),
JMESPathCheck('state', 'Ready')])
JMESPathCheck('name', vnet_firewall_rule_2),
JMESPathCheck('resourceGroup', resource_group),
JMESPathCheck('state', 'Ready')])

# test vnet-rule list
self.cmd('{} server vnet-rule list -g {} -s {}'
.format(database_engine, resource_group, server),
checks=[JMESPathCheck('length(@)', 2)])
checks=[JMESPathCheck('length(@)', 2)])

self.cmd('{} server vnet-rule delete --name {} -g {} --server {} --yes'
.format(database_engine, vnet_firewall_rule_1, resource_group, server), checks=NoneCheck())
Expand All @@ -406,8 +406,7 @@ def _test_vnet_firewall_mgmt(self, resource_group, server, database_engine):
self.cmd('{} server vnet-rule delete -n {} -g {} -s {} --yes'
.format(database_engine, vnet_firewall_rule_2, resource_group, server), checks=NoneCheck())
self.cmd('{} server vnet-rule list -g {} --server {}'
.format(database_engine, resource_group, server), checks=[NoneCheck()])

.format(database_engine, resource_group, server), checks=[NoneCheck()])

def _test_db_mgmt(self, resource_group, server, database_engine):
self.cmd('{} db list -g {} -s {}'.format(database_engine, resource_group, server),
Expand Down