Skip to content

Commit

Permalink
[Virtual-Wan] add command "update" for "az network vhub connection" a…
Browse files Browse the repository at this point in the history
…nd "az network vpn-gateway connection" (#2829)

* virtual-wan

* verison

* pylint

* test

* help

* pylint

* pylint

* review fix

* add support_no_wait and live test

* test

* test

* test

* test
  • Loading branch information
msyyc authored Jan 22, 2021
1 parent 215e547 commit 2f9cb41
Show file tree
Hide file tree
Showing 15 changed files with 34,296 additions and 36,322 deletions.
35 changes: 34 additions & 1 deletion src/virtual-wan/azext_vwan/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from knack.help_files import helps


# region VirtualHub
helps['network vhub'] = """
type: group
Expand Down Expand Up @@ -93,6 +92,21 @@
az network vhub connection delete -n MyConnection --vhub-name MyHub -g MyRG
"""

helps['network vhub connection update'] = """
type: command
short-summary: Update settings of a virtual hub connection.
examples:
- name: Add labels of a virtual hub connection.
text: |
az network vhub connection update -n MyConnection --vhub-name MyHub -g MyRG --labels Newlabel1 Newlabel2
- name: Add labels for propagatedRouteTables of a virtual hub connection.
text: |
az network vhub connection update -n MyConnection --vhub-name MyHub -g MyRG --add routingConfiguration.propagatedRouteTables.labels Newlabel1 Newlabel2
- name: Reset labels of a virtual hub connection.
text: |
az network vhub connection update -n MyConnection --vhub-name MyHub -g MyRG --set routingConfiguration.propagatedRouteTables.labels[0]=Newlabel
"""

helps['network vhub connection wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of virtual hub VNet connection is met.
Expand Down Expand Up @@ -314,6 +328,21 @@
az network vpn-gateway connection delete -g MyRG -n MyConnection --gateway-name MyGateway
"""

helps['network vpn-gateway connection update'] = """
type: command
short-summary: Update settings of VPN gateway connection.
examples:
- name: Update settings of VPN gateway connection.
text: |
az network vpn-gateway connection update -g MyRG -n MyConnection --gateway-name MyGateway --labels NewLabel1 NewLabels2
- name: Add labels of VPN gateway connection.
text: |
az network vpn-gateway connection update -g MyRG -n MyConnection --gateway-name MyGateway --add routingConfiguration.propagatedRouteTables.labels Newlabel1 Newlabel2
- name: Reset labels of VPN gateway connection.
text: |
az network vpn-gateway connection update -g MyRG -n MyConnection --gateway-name MyGateway --set routingConfiguration.propagatedRouteTables.labels[0]=Newlabel1
"""

helps['network vpn-gateway connection wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of the site-to-site VPN gateway connection is met.
Expand Down Expand Up @@ -478,6 +507,10 @@
helps['network p2s-vpn-gateway update'] = """
type: command
short-summary: Update settings of a point-to-site VPN gateway.
examples:
- name: Update settings of a point-to-site VPN gateway with routing configuration.
text: |
az network p2s-vpn-gateway update -g MyRG -n MyP2SVPNGateway --labels Newlabel1 Newlabel2 Newlabel3
"""

helps['network p2s-vpn-gateway delete'] = """
Expand Down
3 changes: 3 additions & 0 deletions src/virtual-wan/azext_vwan/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def load_command_table(self, _):
g.command('delete', 'delete', supports_no_wait=True, confirmation=True)
g.show_command('show')
g.command('list', 'list')
g.generic_update_command('update', custom_func_name='update_hub_vnet_connection', setter_arg_name='hub_virtual_network_connection_parameters', supports_no_wait=True)
g.wait_command('wait')

with self.command_group('network vhub route', network_vhub_sdk) as g:
Expand Down Expand Up @@ -150,6 +151,8 @@ def load_command_table(self, _):
g.command('list', 'list_by_vpn_gateway')
g.show_command('show', 'get')
g.command('delete', 'delete')
g.generic_update_command('update', custom_func_name='update_vpn_gateway_connection',
setter_arg_name='vpn_connection_parameters', supports_no_wait=True)
g.wait_command('wait')

with self.command_group('network vpn-gateway connection ipsec-policy', network_vpn_gateway_sdk) as g:
Expand Down
62 changes: 54 additions & 8 deletions src/virtual-wan/azext_vwan/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ def update_param(self, prop, value, allow_clear):
elif value is not None:
setattr(self.instance, prop, value)

def set_param(self, prop, value, allow_clear=True, curr_obj=None):
curr_obj = curr_obj or self.instance
if '.' in prop:
prop, path = prop.split('.', 1)
curr_obj = getattr(curr_obj, prop)
self.set_param(path, value, allow_clear=allow_clear, curr_obj=curr_obj)
elif value == '' and allow_clear:
setattr(curr_obj, prop, None)
elif value is not None:
setattr(curr_obj, prop, value)


def _generic_list(cli_ctx, operation_name, resource_group_name):
ncf = network_client_factory(cli_ctx)
Expand Down Expand Up @@ -153,6 +164,20 @@ def list_virtual_hubs(cmd, resource_group_name=None):
return _generic_list(cmd.cli_ctx, 'virtual_hubs', resource_group_name)


def update_hub_vnet_connection(instance, cmd, associated_route_table=None, propagated_route_tables=None, labels=None):
SubResource = cmd.get_models('SubResource')

ids = [SubResource(id=propagated_route_table) for propagated_route_table in
propagated_route_tables] if propagated_route_tables else None # pylint: disable=line-too-long
associated_route_table = SubResource(id=associated_route_table) if associated_route_table else None
with UpdateContext(instance) as c:
c.set_param('routing_configuration.associated_route_table', associated_route_table, False)
c.set_param('routing_configuration.propagated_route_tables.labels', labels, False)
c.set_param('routing_configuration.propagated_route_tables.ids', ids, False)

return instance


# pylint: disable=too-many-locals
def create_hub_vnet_connection(cmd, resource_group_name, virtual_hub_name, connection_name,
remote_virtual_network, allow_hub_to_remote_vnet_transit=None,
Expand Down Expand Up @@ -472,6 +497,21 @@ def update_vpn_gateway(instance, cmd, virtual_hub=None, tags=None, scale_unit=No
return instance


def update_vpn_gateway_connection(instance, cmd, associated_route_table=None, propagated_route_tables=None,
labels=None):
SubResource = cmd.get_models('SubResource')

ids = [SubResource(id=propagated_route_table) for propagated_route_table in
propagated_route_tables] if propagated_route_tables else None
associated_route_table = SubResource(id=associated_route_table) if associated_route_table else None
with UpdateContext(instance) as c:
c.set_param('routing_configuration.associated_route_table', associated_route_table, False)
c.set_param('routing_configuration.propagated_route_tables.labels', labels, False)
c.set_param('routing_configuration.propagated_route_tables.ids', ids, False)

return instance


def create_vpn_gateway_connection(cmd, resource_group_name, gateway_name, connection_name,
remote_vpn_site, routing_weight=None, protocol_type=None,
connection_bandwidth=None, shared_key=None, enable_bgp=None,
Expand Down Expand Up @@ -822,14 +862,20 @@ def update_p2s_vpn_gateway(instance, cmd, tags=None, scale_unit=None,
associated_route_table=None, propagated_route_tables=None, labels=None):
SubResource = cmd.get_models('SubResource')
with UpdateContext(instance) as c:
c.update_param('tags', tags, True)
c.update_param('vpn_gateway_scale_unit', scale_unit, False)
c.update_param('vpn_server_configuration', SubResource(id=vpn_server_config) if vpn_server_config else None, True)
c.update_param('p2_sconnection_configurations.vpn_client_address_pool.address_prefixes', address_space, False)
c.update_param('p2_sconnection_configurations.name', p2s_conn_config_name, False)
c.update_param('p2_sconnection_configurations.routing_configuration.associated_route_table', SubResource(id=associated_route_table) if associated_route_table else None, True)
c.update_param('p2_sconnection_configurations.routing_configuration.propagated_route_tables.labels', labels, True)
c.update_param('p2_sconnection_configurations.routing_configuration.propagated_route_tables.ids', [SubResource(id=propagated_route_table) for propagated_route_table in propagated_route_tables] if propagated_route_tables else None, True)
c.set_param('tags', tags, True)
c.set_param('vpn_gateway_scale_unit', scale_unit, False)
c.set_param('vpn_server_configuration', SubResource(id=vpn_server_config) if vpn_server_config else None, True)
p2_sconnection_configurations = getattr(instance, 'p2_sconnection_configurations')
if p2_sconnection_configurations:
with UpdateContext(p2_sconnection_configurations[0]) as c:
c.set_param('vpn_client_address_pool.address_prefixes', address_space, False)
c.set_param('name', p2s_conn_config_name, False)
c.set_param('routing_configuration.associated_route_table',
SubResource(id=associated_route_table) if associated_route_table else None, False)
c.set_param('routing_configuration.propagated_route_tables.labels', labels, False)
c.set_param('routing_configuration.propagated_route_tables.ids',
[SubResource(id=propagated_route_table) for propagated_route_table in
propagated_route_tables] if propagated_route_tables else None, False)

return instance

Expand Down
Loading

0 comments on commit 2f9cb41

Please sign in to comment.