Skip to content

Commit

Permalink
[Virtual WAN] az network vhub: Add new parameter `--hub-routing-pre…
Browse files Browse the repository at this point in the history
…ference` (#4788)

* add new property of hub routing preference in virtual hub

* add vendored sdks

* refine changelog

* bump api version from 2020-05-01 to 2021-08-01

Co-authored-by: necusjz <necusjz@gmail.com>
  • Loading branch information
YuanyuanNi and necusjz authored May 16, 2022
1 parent deced1e commit e6f25f0
Show file tree
Hide file tree
Showing 52 changed files with 241,314 additions and 33,242 deletions.
6 changes: 6 additions & 0 deletions src/virtual-wan/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Release History
===============

0.2.12
++++++
* `az network vhub create`: Add new parameter `--hub-routing-preference`.
* `az network vhub update`: Add new parameter `--hub-routing-preference`.
* Bump api version from 2020-05-01 to 2021-08-01.

0.2.11
++++++
* add new command group: `az network vpn-gateway connection vpn-site-link-conn`.
Expand Down
2 changes: 1 addition & 1 deletion src/virtual-wan/azext_vwan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class VirtualWanCommandsLoader(AzCommandsLoader):
def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from .profiles import CUSTOM_VWAN
register_resource_type('latest', CUSTOM_VWAN, '2020-05-01')
register_resource_type('latest', CUSTOM_VWAN, '2021-08-01')

super(VirtualWanCommandsLoader, self).__init__(
cli_ctx=cli_ctx,
Expand Down
13 changes: 3 additions & 10 deletions src/virtual-wan/azext_vwan/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ def network_client_factory(cli_ctx, aux_subscriptions=None, **_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from .profiles import CUSTOM_VWAN
return get_mgmt_service_client(cli_ctx, CUSTOM_VWAN, aux_subscriptions=aux_subscriptions,
api_version='2020-05-01')


def network_client_factory_2021_03_01(cli_ctx, aux_subscriptions=None, **_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from .profiles import CUSTOM_VWAN_2021_03_01
return get_mgmt_service_client(cli_ctx, CUSTOM_VWAN_2021_03_01, aux_subscriptions=aux_subscriptions,
api_version='2021-03-01')
api_version='2021-08-01')


def cf_virtual_wans(cli_ctx, _):
Expand All @@ -31,11 +24,11 @@ def cf_virtual_hub_connection(cli_ctx, _):


def cf_virtual_hub_bgpconnection(cli_ctx, _):
return network_client_factory_2021_03_01(cli_ctx).virtual_hub_bgp_connection
return network_client_factory(cli_ctx).virtual_hub_bgp_connection


def cf_virtual_hub_bgpconnections(cli_ctx, _):
return network_client_factory_2021_03_01(cli_ctx).virtual_hub_bgp_connections
return network_client_factory(cli_ctx).virtual_hub_bgp_connections


def cf_virtual_hub_route_table_v2s(cli_ctx, _):
Expand Down
5 changes: 3 additions & 2 deletions src/virtual-wan/azext_vwan/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
def load_arguments(self, _):

(IpsecEncryption, IpsecIntegrity, IkeEncryption, IkeIntegrity, DhGroup, PfsGroup,
VirtualNetworkGatewayConnectionProtocol, AuthenticationMethod) = self.get_models(
VirtualNetworkGatewayConnectionProtocol, AuthenticationMethod, HubRoutingPreference) = self.get_models(
'IpsecEncryption', 'IpsecIntegrity', 'IkeEncryption', 'IkeIntegrity', 'DhGroup', 'PfsGroup',
'VirtualNetworkGatewayConnectionProtocol', 'AuthenticationMethod')
'VirtualNetworkGatewayConnectionProtocol', 'AuthenticationMethod', 'HubRoutingPreference')

(VpnGatewayTunnelingProtocol, VpnAuthenticationType) = self.get_models('VpnGatewayTunnelingProtocol', 'VpnAuthenticationType')

Expand Down Expand Up @@ -54,6 +54,7 @@ def load_arguments(self, _):
c.argument('virtual_wan', options_list='--vwan', help='Name or ID of the virtual WAN.', validator=get_network_resource_name_or_id('virtual_wan', 'virtualWans'))
c.argument('address_prefix', help='CIDR address prefix for the virtual hub.')
c.argument('sku', arg_type=get_enum_type(['Basic', 'Standard']), help='The sku of the VirtualHub.')
c.argument('hub_routing_preference', arg_type=get_enum_type(HubRoutingPreference), help='The hub routing preference gateway types')

with self.argument_context('network vhub', arg_group='Gateway') as c:
c.argument('express_route_gateway', help='Name or ID of an ExpressRoute gateway.', validator=get_network_resource_name_or_id('express_route_gateway', 'expressRouteGateways'))
Expand Down
2 changes: 1 addition & 1 deletion src/virtual-wan/azext_vwan/azext_metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.0.67"
"azext.minCliCoreVersion": "2.15.0"
}
28 changes: 14 additions & 14 deletions src/virtual-wan/azext_vwan/commands.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 import CliCommandType
from .profiles import CUSTOM_VWAN, CUSTOM_VWAN_2021_03_01
from .profiles import CUSTOM_VWAN

from ._client_factory import (
cf_virtual_wans, cf_virtual_hubs, cf_vpn_sites, cf_vpn_site_configs,
Expand All @@ -24,72 +24,72 @@
def load_command_table(self, _):

network_vhub_sdk = CliCommandType(
operations_tmpl='azext_vwan.vendored_sdks.v2020_05_01.operations#VirtualHubsOperations.{}',
operations_tmpl='azext_vwan.vendored_sdks.v2021_08_01.operations#VirtualHubsOperations.{}',
client_factory=cf_virtual_hubs,
resource_type=CUSTOM_VWAN,
min_api='2018-08-01'
)

network_vhub_connection_sdk = CliCommandType(
operations_tmpl='azext_vwan.vendored_sdks.v2020_05_01.operations#HubVirtualNetworkConnectionsOperations.{}',
operations_tmpl='azext_vwan.vendored_sdks.v2021_08_01.operations#HubVirtualNetworkConnectionsOperations.{}',
client_factory=cf_virtual_hub_connection,
resource_type=CUSTOM_VWAN,
min_api='2020-05-01'
)

network_vhub_bgpconnection_sdk = CliCommandType(
operations_tmpl='azext_vwan.vendored_sdks.v2021_03_01.v2021_03_01.operations#VirtualHubBgpConnectionOperations.{}',
operations_tmpl='azext_vwan.vendored_sdks.v2021_08_01.operations#VirtualHubBgpConnectionOperations.{}',
client_factory=cf_virtual_hub_bgpconnection,
resource_type=CUSTOM_VWAN_2021_03_01
resource_type=CUSTOM_VWAN
)

network_vhub_route_table_sdk = CliCommandType(
operations_tmpl='azext_vwan.vendored_sdks.v2020_05_01.operations#VirtualHubRouteTableV2SOperations.{}',
operations_tmpl='azext_vwan.vendored_sdks.v2021_08_01.operations#VirtualHubRouteTableV2SOperations.{}',
client_factory=cf_virtual_hub_route_table_v2s,
resource_type=CUSTOM_VWAN,
min_api='2019-09-01'
)

network_vwan_sdk = CliCommandType(
operations_tmpl='azext_vwan.vendored_sdks.v2020_05_01.operations#VirtualWansOperations.{}',
operations_tmpl='azext_vwan.vendored_sdks.v2021_08_01.operations#VirtualWansOperations.{}',
client_factory=cf_virtual_wans,
resource_type=CUSTOM_VWAN,
min_api='2018-08-01'
)

network_vpn_gateway_sdk = CliCommandType(
operations_tmpl='azext_vwan.vendored_sdks.v2020_05_01.operations#VpnGatewaysOperations.{}',
operations_tmpl='azext_vwan.vendored_sdks.v2021_08_01.operations#VpnGatewaysOperations.{}',
client_factory=cf_vpn_gateways,
min_api='2018-08-01'
)

network_vpn_gateway_connection_sdk = CliCommandType(
operations_tmpl='azext_vwan.vendored_sdks.v2020_05_01.operations#VpnConnectionsOperations.{}',
operations_tmpl='azext_vwan.vendored_sdks.v2021_08_01.operations#VpnConnectionsOperations.{}',
client_factory=cf_vpn_gateway_connection,
min_api='2020-05-01'
)

network_vpn_site_sdk = CliCommandType(
operations_tmpl='azext_vwan.vendored_sdks.v2020_05_01.operations#VpnSitesOperations.{}',
operations_tmpl='azext_vwan.vendored_sdks.v2021_08_01.operations#VpnSitesOperations.{}',
client_factory=cf_vpn_sites,
min_api='2018-08-01'
)

network_vpn_site_config_sdk = CliCommandType(
operations_tmpl='azext_vwan.vendored_sdks.v2020_05_01.operations#VpnSitesConfigurationOperations.{}',
operations_tmpl='azext_vwan.vendored_sdks.v2021_08_01.operations#VpnSitesConfigurationOperations.{}',
client_factory=cf_vpn_site_configs,
min_api='2018-08-01'
)

network_vpn_server_config_sdk = CliCommandType(
operations_tmpl='azext_vwan.vendored_sdks.v2020_05_01.operations#VpnServerConfigurationsOperations.{}',
operations_tmpl='azext_vwan.vendored_sdks.v2021_08_01.operations#VpnServerConfigurationsOperations.{}',
client_factory=cf_vpn_server_config,
resource_type=CUSTOM_VWAN,
min_api='2020-03-01'
)

network_p2s_vpn_gateway_sdk = CliCommandType(
operations_tmpl='azext_vwan.vendored_sdks.v2020_05_01.operations#P2SVpnGatewaysOperations.{}',
operations_tmpl='azext_vwan.vendored_sdks.v2021_08_01.operations#P2SVpnGatewaysOperations.{}',
client_factory=cf_p2s_vpn_gateways,
resource_type=CUSTOM_VWAN,
min_api='2020-03-01'
Expand All @@ -110,7 +110,7 @@ def load_command_table(self, _):
# endregion

# region VirtualHubs
with self.command_group('network vhub', network_vhub_sdk) as g:
with self.command_group('network vhub', network_vhub_sdk, client_factory=cf_virtual_hubs) as g:
g.custom_command('create', 'create_virtual_hub', supports_no_wait=True)
g.command('delete', 'begin_delete')
g.show_command('show')
Expand Down
18 changes: 10 additions & 8 deletions src/virtual-wan/azext_vwan/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from azure.cli.core.util import sdk_no_wait

from ._client_factory import network_client_factory, cf_virtual_hub_bgpconnections, cf_virtual_hub_connection

from ._util import _get_property

logger = get_logger(__name__)
Expand Down Expand Up @@ -135,16 +136,16 @@ def list_virtual_wans(cmd, resource_group_name=None):


# region VirtualHubs
def create_virtual_hub(cmd, resource_group_name, virtual_hub_name, address_prefix, virtual_wan,
location=None, tags=None, no_wait=False, sku=None):
client = network_client_factory(cmd.cli_ctx).virtual_hubs
VirtualHub, SubResource = cmd.get_models('VirtualHub', 'SubResource')
def create_virtual_hub(cmd, client, resource_group_name, virtual_hub_name, address_prefix, virtual_wan,
location=None, tags=None, no_wait=False, sku=None, hub_routing_preference=None):
(VirtualHub, SubResource) = cmd.get_models('VirtualHub', 'SubResource')
hub = VirtualHub(
tags=tags,
location=location,
address_prefix=address_prefix,
virtual_wan=SubResource(id=virtual_wan),
sku=sku
sku=sku,
hub_routing_preference=hub_routing_preference
)
return sdk_no_wait(no_wait, client.begin_create_or_update,
resource_group_name, virtual_hub_name, hub)
Expand Down Expand Up @@ -177,13 +178,14 @@ def raw(response, *_):
)


def update_virtual_hub(instance, cmd, address_prefix=None, virtual_wan=None, tags=None, sku=None):
def update_virtual_hub(cmd, instance, address_prefix=None, virtual_wan=None, tags=None, sku=None, hub_routing_preference=None):
SubResource = cmd.get_models('SubResource')
with UpdateContext(instance) as c:
c.update_param('tags', tags, True)
c.update_param('address_prefix', address_prefix, False)
c.update_param('virtual_wan', SubResource(id=virtual_wan) if virtual_wan else None, False)
c.update_param('sku', sku, False)
c.update_param('hub_routing_preference', hub_routing_preference, False)
return instance


Expand Down Expand Up @@ -263,7 +265,7 @@ def _bgp_connections_client(cli_ctx):
def create_hub_vnet_bgpconnection(cmd, client, resource_group_name, virtual_hub_name, connection_name,
virtual_hub_connection=None, peer_asn=None, peer_ip=None, no_wait=False):

from .vendored_sdks.v2021_03_01.models import BgpConnection, SubResource
(BgpConnection, SubResource) = cmd.get_models('BgpConnection', 'SubResource')
connection = BgpConnection(
name=connection_name,
peer_asn=peer_asn,
Expand All @@ -276,12 +278,12 @@ def create_hub_vnet_bgpconnection(cmd, client, resource_group_name, virtual_hub_

def update_hub_vnet_bgpconnection(cmd, instance, resource_group_name, virtual_hub_name, connection_name,
virtual_hub_connection=None, peer_asn=None, peer_ip=None):
SubResource = cmd.get_models('SubResource')
if peer_asn is not None:
instance.peer_asn = peer_asn
if peer_ip is not None:
instance.peer_ip = peer_ip
if virtual_hub_connection is not None:
from .vendored_sdks.v2021_03_01.models import SubResource
instance.hub_virtual_network_connection = SubResource(id=virtual_hub_connection)
return instance

Expand Down
3 changes: 1 addition & 2 deletions src/virtual-wan/azext_vwan/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@

from azure.cli.core.profiles import CustomResourceType

CUSTOM_VWAN = CustomResourceType('azext_vwan.vendored_sdks.v2020_05_01', 'NetworkManagementClient')
CUSTOM_VWAN_2021_03_01 = CustomResourceType('azext_vwan.vendored_sdks.v2021_03_01', 'NetworkManagementClient')
CUSTOM_VWAN = CustomResourceType('azext_vwan.vendored_sdks.v2021_08_01', 'NetworkManagementClient')
Loading

0 comments on commit e6f25f0

Please sign in to comment.