Skip to content

Commit

Permalink
[VirtualWan] Add new command group az network vhub bgpconnection (#…
Browse files Browse the repository at this point in the history
…3888)

* vhub support bgpconnection
  • Loading branch information
00Kai0 authored Sep 27, 2021
1 parent dd83107 commit c50c077
Show file tree
Hide file tree
Showing 255 changed files with 175,567 additions and 2,549 deletions.
4 changes: 4 additions & 0 deletions src/virtual-wan/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.2.10
++++++
* add new command group: `az network vhub bgpconnection`.

0.2.9
++++++
* bugfix: `az network vpn-gateway connection ipsec-policy add/remove` doesn't migrate to track2.
Expand Down
15 changes: 15 additions & 0 deletions src/virtual-wan/azext_vwan/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def network_client_factory(cli_ctx, aux_subscriptions=None, **_):
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')


def cf_virtual_wans(cli_ctx, _):
return network_client_factory(cli_ctx).virtual_wans

Expand All @@ -23,6 +30,14 @@ def cf_virtual_hub_connection(cli_ctx, _):
return network_client_factory(cli_ctx).hub_virtual_network_connections


def cf_virtual_hub_bgpconnection(cli_ctx, _):
return network_client_factory_2021_03_01(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


def cf_virtual_hub_route_table_v2s(cli_ctx, _):
return network_client_factory(cli_ctx).virtual_hub_route_table_v2_s

Expand Down
56 changes: 56 additions & 0 deletions src/virtual-wan/azext_vwan/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,62 @@
short-summary: Place the CLI in a waiting state until a condition of virtual hub VNet connection is met.
"""

helps['network vhub bgpconnection'] = """
type: group
short-summary: Manage virtual hub bgpconnections.
"""

helps['network vhub bgpconnection create'] = """
type: command
short-summary: Create a virtual hub bgpconnection.
examples:
- name: Create a virtual hub bgpconnection.
text: |
az network vhub bgpconnection create -n MyConnection -g MyRG --vhub-name MyHub --peer-asn 20000 --peer-ip "10.5.0.3"
--vhub-conn <vhub_connection_resource_id>
"""

helps['network vhub bgpconnection list'] = """
type: command
short-summary: List virtual hub bgpconnections.
examples:
- name: List bgpconnections in a given virtual hub.
text: |
az network vhub bgpconnection list --vhub-name MyHub -g MyRG
"""

helps['network vhub bgpconnection show'] = """
type: command
short-summary: Get the details of a virtual hub bgpconnection.
examples:
- name: Get the details of a virtual hub bgpconnection.
text: |
az network vhub bgpconnection show -n MyConnection --vhub-name MyHub -g MyRG
"""

helps['network vhub bgpconnection delete'] = """
type: command
short-summary: Delete a virtual hub bgpconnection.
examples:
- name: Delete a virtual hub bgpconnection.
text: |
az network vhub bgpconnection delete -n MyConnection --vhub-name MyHub -g MyRG
"""

helps['network vhub bgpconnection update'] = """
type: command
short-summary: Update settings of a virtual hub bgpconnection.
examples:
- name: Update a virtual hub bgpconnection.
text: |
az network vhub bgpconnection update -n MyConnection --vhub-name MyHub -g MyRG --peer-asn 15000
"""

helps['network vhub bgpconnection wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of virtual hub bgpconnection is met.
"""

helps['network vhub route'] = """
type: group
short-summary: Manage entries in the virtual hub route table.
Expand Down
10 changes: 10 additions & 0 deletions src/virtual-wan/azext_vwan/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def load_arguments(self, _):
c.argument('next_hop_ip_address', options_list='--next-hop', help='The ip address of the next hop.')
c.argument('route_name', help='The name of the Static Route that is unique within a Vnet Route.')

with self.argument_context('network vhub bgpconnection') as c:
c.argument('virtual_hub_name', vhub_name_type)
c.argument('connection_name', help='Name of the bgpconnection.', options_list=['--name', '-n'], id_part='child_name_1')
c.argument('peer_asn', help='Peer ASN', type=int)
c.argument('peer_ip', help='Peer IP')
c.argument('virtual_hub_connection', options_list='--vhub-conn', help='The resource id of vhub connection.')

with self.argument_context('network vhub bgpconnection list') as c:
c.argument('virtual_hub_name', id_part=None)

with self.argument_context('network vhub route') as c:
c.argument('virtual_hub_name', vhub_name_type, id_part=None)
c.argument('address_prefixes', nargs='+', help='Space-separated list of CIDR prefixes.')
Expand Down
18 changes: 16 additions & 2 deletions src/virtual-wan/azext_vwan/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

# pylint: disable=line-too-long
from azure.cli.core.commands import CliCommandType
from .profiles import CUSTOM_VWAN
from .profiles import CUSTOM_VWAN, CUSTOM_VWAN_2021_03_01

from ._client_factory import (
cf_virtual_wans, cf_virtual_hubs, cf_vpn_sites, cf_vpn_site_configs,
cf_vpn_gateways, cf_vpn_gateway_connection, cf_virtual_hub_route_table_v2s, cf_vpn_server_config,
cf_p2s_vpn_gateways, cf_virtual_hub_connection)
cf_p2s_vpn_gateways, cf_virtual_hub_connection, cf_virtual_hub_bgpconnection)
from ._util import (
list_network_resource_property,
get_network_resource_property_entry
Expand All @@ -37,6 +37,12 @@ def load_command_table(self, _):
min_api='2020-05-01'
)

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

network_vhub_route_table_sdk = CliCommandType(
operations_tmpl='azext_vwan.vendored_sdks.v2020_05_01.operations#VirtualHubRouteTableV2SOperations.{}',
client_factory=cf_virtual_hub_route_table_v2s,
Expand Down Expand Up @@ -120,6 +126,14 @@ def load_command_table(self, _):
g.generic_update_command('update', custom_func_name='update_hub_vnet_connection', setter_name="begin_create_or_update", setter_arg_name='hub_virtual_network_connection_parameters', supports_no_wait=True)
g.wait_command('wait')

with self.command_group('network vhub bgpconnection', network_vhub_bgpconnection_sdk, client_factory=cf_virtual_hub_bgpconnection) as g:
g.custom_command('create', 'create_hub_vnet_bgpconnection', supports_no_wait=True)
g.command('delete', 'begin_delete', supports_no_wait=True, confirmation=True)
g.show_command('show')
g.custom_command('list', 'list_hub_vnet_bgpconnection')
g.generic_update_command('update', custom_func_name='update_hub_vnet_bgpconnection', setter_name="begin_create_or_update", supports_no_wait=True)
g.wait_command('wait')

with self.command_group('network vhub route', network_vhub_sdk, deprecate_info=self.deprecate(redirect=ROUTE_TABLE_DEPRECATION_INFO, hide=False)) as g:
g.custom_command('add', 'add_hub_route', supports_no_wait=True)
g.custom_command('list', 'list_hub_routes')
Expand Down
37 changes: 36 additions & 1 deletion src/virtual-wan/azext_vwan/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from azure.cli.core.util import sdk_no_wait

from ._client_factory import network_client_factory
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 @@ -256,6 +256,41 @@ def create_hub_vnet_connection(cmd, resource_group_name, virtual_hub_name, conne
virtual_hub_name, connection_name, connection)


def _bgp_connections_client(cli_ctx):
return cf_virtual_hub_bgpconnections(cli_ctx=cli_ctx, _=None)


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
connection = BgpConnection(
name=connection_name,
peer_asn=peer_asn,
peer_ip=peer_ip,
hub_virtual_network_connection=SubResource(id=virtual_hub_connection) if virtual_hub_connection else None
)
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name,
virtual_hub_name, connection_name, connection)


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):
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


def list_hub_vnet_bgpconnection(cmd, client, resource_group_name, virtual_hub_name):
client = _bgp_connections_client(cmd.cli_ctx)
return client.list(resource_group_name=resource_group_name, virtual_hub_name=virtual_hub_name)


# pylint: disable=inconsistent-return-statements
def add_hub_route(cmd, resource_group_name, virtual_hub_name, address_prefixes, next_hop_ip_address, no_wait=False):
VirtualHubRoute = cmd.get_models('VirtualHubRoute')
Expand Down
1 change: 1 addition & 0 deletions src/virtual-wan/azext_vwan/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,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')
Loading

0 comments on commit c50c077

Please sign in to comment.