Skip to content

Commit 2f9cb41

Browse files
authored
[Virtual-Wan] add command "update" for "az network vhub connection" and "az network vpn-gateway connection" (Azure#2829)
* virtual-wan * verison * pylint * test * help * pylint * pylint * review fix * add support_no_wait and live test * test * test * test * test
1 parent 215e547 commit 2f9cb41

15 files changed

+34296
-36322
lines changed

src/virtual-wan/azext_vwan/_help.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from knack.help_files import helps
77

8-
98
# region VirtualHub
109
helps['network vhub'] = """
1110
type: group
@@ -93,6 +92,21 @@
9392
az network vhub connection delete -n MyConnection --vhub-name MyHub -g MyRG
9493
"""
9594

95+
helps['network vhub connection update'] = """
96+
type: command
97+
short-summary: Update settings of a virtual hub connection.
98+
examples:
99+
- name: Add labels of a virtual hub connection.
100+
text: |
101+
az network vhub connection update -n MyConnection --vhub-name MyHub -g MyRG --labels Newlabel1 Newlabel2
102+
- name: Add labels for propagatedRouteTables of a virtual hub connection.
103+
text: |
104+
az network vhub connection update -n MyConnection --vhub-name MyHub -g MyRG --add routingConfiguration.propagatedRouteTables.labels Newlabel1 Newlabel2
105+
- name: Reset labels of a virtual hub connection.
106+
text: |
107+
az network vhub connection update -n MyConnection --vhub-name MyHub -g MyRG --set routingConfiguration.propagatedRouteTables.labels[0]=Newlabel
108+
"""
109+
96110
helps['network vhub connection wait'] = """
97111
type: command
98112
short-summary: Place the CLI in a waiting state until a condition of virtual hub VNet connection is met.
@@ -314,6 +328,21 @@
314328
az network vpn-gateway connection delete -g MyRG -n MyConnection --gateway-name MyGateway
315329
"""
316330

331+
helps['network vpn-gateway connection update'] = """
332+
type: command
333+
short-summary: Update settings of VPN gateway connection.
334+
examples:
335+
- name: Update settings of VPN gateway connection.
336+
text: |
337+
az network vpn-gateway connection update -g MyRG -n MyConnection --gateway-name MyGateway --labels NewLabel1 NewLabels2
338+
- name: Add labels of VPN gateway connection.
339+
text: |
340+
az network vpn-gateway connection update -g MyRG -n MyConnection --gateway-name MyGateway --add routingConfiguration.propagatedRouteTables.labels Newlabel1 Newlabel2
341+
- name: Reset labels of VPN gateway connection.
342+
text: |
343+
az network vpn-gateway connection update -g MyRG -n MyConnection --gateway-name MyGateway --set routingConfiguration.propagatedRouteTables.labels[0]=Newlabel1
344+
"""
345+
317346
helps['network vpn-gateway connection wait'] = """
318347
type: command
319348
short-summary: Place the CLI in a waiting state until a condition of the site-to-site VPN gateway connection is met.
@@ -478,6 +507,10 @@
478507
helps['network p2s-vpn-gateway update'] = """
479508
type: command
480509
short-summary: Update settings of a point-to-site VPN gateway.
510+
examples:
511+
- name: Update settings of a point-to-site VPN gateway with routing configuration.
512+
text: |
513+
az network p2s-vpn-gateway update -g MyRG -n MyP2SVPNGateway --labels Newlabel1 Newlabel2 Newlabel3
481514
"""
482515

483516
helps['network p2s-vpn-gateway delete'] = """

src/virtual-wan/azext_vwan/commands.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def load_command_table(self, _):
114114
g.command('delete', 'delete', supports_no_wait=True, confirmation=True)
115115
g.show_command('show')
116116
g.command('list', 'list')
117+
g.generic_update_command('update', custom_func_name='update_hub_vnet_connection', setter_arg_name='hub_virtual_network_connection_parameters', supports_no_wait=True)
117118
g.wait_command('wait')
118119

119120
with self.command_group('network vhub route', network_vhub_sdk) as g:
@@ -150,6 +151,8 @@ def load_command_table(self, _):
150151
g.command('list', 'list_by_vpn_gateway')
151152
g.show_command('show', 'get')
152153
g.command('delete', 'delete')
154+
g.generic_update_command('update', custom_func_name='update_vpn_gateway_connection',
155+
setter_arg_name='vpn_connection_parameters', supports_no_wait=True)
153156
g.wait_command('wait')
154157

155158
with self.command_group('network vpn-gateway connection ipsec-policy', network_vpn_gateway_sdk) as g:

src/virtual-wan/azext_vwan/custom.py

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ def update_param(self, prop, value, allow_clear):
3737
elif value is not None:
3838
setattr(self.instance, prop, value)
3939

40+
def set_param(self, prop, value, allow_clear=True, curr_obj=None):
41+
curr_obj = curr_obj or self.instance
42+
if '.' in prop:
43+
prop, path = prop.split('.', 1)
44+
curr_obj = getattr(curr_obj, prop)
45+
self.set_param(path, value, allow_clear=allow_clear, curr_obj=curr_obj)
46+
elif value == '' and allow_clear:
47+
setattr(curr_obj, prop, None)
48+
elif value is not None:
49+
setattr(curr_obj, prop, value)
50+
4051

4152
def _generic_list(cli_ctx, operation_name, resource_group_name):
4253
ncf = network_client_factory(cli_ctx)
@@ -153,6 +164,20 @@ def list_virtual_hubs(cmd, resource_group_name=None):
153164
return _generic_list(cmd.cli_ctx, 'virtual_hubs', resource_group_name)
154165

155166

167+
def update_hub_vnet_connection(instance, cmd, associated_route_table=None, propagated_route_tables=None, labels=None):
168+
SubResource = cmd.get_models('SubResource')
169+
170+
ids = [SubResource(id=propagated_route_table) for propagated_route_table in
171+
propagated_route_tables] if propagated_route_tables else None # pylint: disable=line-too-long
172+
associated_route_table = SubResource(id=associated_route_table) if associated_route_table else None
173+
with UpdateContext(instance) as c:
174+
c.set_param('routing_configuration.associated_route_table', associated_route_table, False)
175+
c.set_param('routing_configuration.propagated_route_tables.labels', labels, False)
176+
c.set_param('routing_configuration.propagated_route_tables.ids', ids, False)
177+
178+
return instance
179+
180+
156181
# pylint: disable=too-many-locals
157182
def create_hub_vnet_connection(cmd, resource_group_name, virtual_hub_name, connection_name,
158183
remote_virtual_network, allow_hub_to_remote_vnet_transit=None,
@@ -472,6 +497,21 @@ def update_vpn_gateway(instance, cmd, virtual_hub=None, tags=None, scale_unit=No
472497
return instance
473498

474499

500+
def update_vpn_gateway_connection(instance, cmd, associated_route_table=None, propagated_route_tables=None,
501+
labels=None):
502+
SubResource = cmd.get_models('SubResource')
503+
504+
ids = [SubResource(id=propagated_route_table) for propagated_route_table in
505+
propagated_route_tables] if propagated_route_tables else None
506+
associated_route_table = SubResource(id=associated_route_table) if associated_route_table else None
507+
with UpdateContext(instance) as c:
508+
c.set_param('routing_configuration.associated_route_table', associated_route_table, False)
509+
c.set_param('routing_configuration.propagated_route_tables.labels', labels, False)
510+
c.set_param('routing_configuration.propagated_route_tables.ids', ids, False)
511+
512+
return instance
513+
514+
475515
def create_vpn_gateway_connection(cmd, resource_group_name, gateway_name, connection_name,
476516
remote_vpn_site, routing_weight=None, protocol_type=None,
477517
connection_bandwidth=None, shared_key=None, enable_bgp=None,
@@ -822,14 +862,20 @@ def update_p2s_vpn_gateway(instance, cmd, tags=None, scale_unit=None,
822862
associated_route_table=None, propagated_route_tables=None, labels=None):
823863
SubResource = cmd.get_models('SubResource')
824864
with UpdateContext(instance) as c:
825-
c.update_param('tags', tags, True)
826-
c.update_param('vpn_gateway_scale_unit', scale_unit, False)
827-
c.update_param('vpn_server_configuration', SubResource(id=vpn_server_config) if vpn_server_config else None, True)
828-
c.update_param('p2_sconnection_configurations.vpn_client_address_pool.address_prefixes', address_space, False)
829-
c.update_param('p2_sconnection_configurations.name', p2s_conn_config_name, False)
830-
c.update_param('p2_sconnection_configurations.routing_configuration.associated_route_table', SubResource(id=associated_route_table) if associated_route_table else None, True)
831-
c.update_param('p2_sconnection_configurations.routing_configuration.propagated_route_tables.labels', labels, True)
832-
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)
865+
c.set_param('tags', tags, True)
866+
c.set_param('vpn_gateway_scale_unit', scale_unit, False)
867+
c.set_param('vpn_server_configuration', SubResource(id=vpn_server_config) if vpn_server_config else None, True)
868+
p2_sconnection_configurations = getattr(instance, 'p2_sconnection_configurations')
869+
if p2_sconnection_configurations:
870+
with UpdateContext(p2_sconnection_configurations[0]) as c:
871+
c.set_param('vpn_client_address_pool.address_prefixes', address_space, False)
872+
c.set_param('name', p2s_conn_config_name, False)
873+
c.set_param('routing_configuration.associated_route_table',
874+
SubResource(id=associated_route_table) if associated_route_table else None, False)
875+
c.set_param('routing_configuration.propagated_route_tables.labels', labels, False)
876+
c.set_param('routing_configuration.propagated_route_tables.ids',
877+
[SubResource(id=propagated_route_table) for propagated_route_table in
878+
propagated_route_tables] if propagated_route_tables else None, False)
833879

834880
return instance
835881

0 commit comments

Comments
 (0)