Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ def cf_virtual_router(cli_ctx, _):
return network_client_factory(cli_ctx).virtual_routers


def cf_virtual_hub(cli_ctx, _):
return network_client_factory(cli_ctx).virtual_hubs


def cf_virtual_hub_bgp_connection(cli_ctx, _):
return network_client_factory(cli_ctx).virtual_hub_bgp_connection


def cf_virtual_hub_bgp_connections(cli_ctx, _):
return network_client_factory(cli_ctx).virtual_hub_bgp_connections


def cf_virtual_router_peering(cli_ctx, _):
return network_client_factory(cli_ctx).virtual_router_peerings

Expand Down
79 changes: 79 additions & 0 deletions src/azure-cli/azure/cli/command_modules/network/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5803,6 +5803,85 @@
short-summary: Delete a virtual router peering.
"""

helps['network routeserver'] = """
type: group
short-summary: Manage the virtual hub router.
"""

helps['network routeserver create'] = """
type: command
short-summary: Create a virtual hub router.
examples:
- name: Create a virtual hub router.
text: |
az network routeserver create --resource-group myresourcegroup --name myvirtualrouter --hosted-subnet my_subnet_id
"""

helps['network routeserver update'] = """
type: command
short-summary: Update a virtual hub router.
examples:
- name: Update a virtual hub router. (autogenerated)
text: |
az network routeserver update --name myvirtualrouter --resource-group myresourcegroup --tags super_secure no_80 no_22
crafted: true
"""

helps['network routeserver show'] = """
type: command
short-summary: Show a virtual hub router.
"""

helps['network routeserver list'] = """
type: command
short-summary: List all virtual hub routers under a subscription or a resource group.
"""

helps['network routeserver delete'] = """
type: command
short-summary: Delete a virtual hub router under a resource group.
"""

helps['network routeserver peering'] = """
type: group
short-summary: Manage the virtual hub router peering.
"""

helps['network routeserver peering create'] = """
type: command
short-summary: Create a virtual hub router peering.
"""

helps['network routeserver peering update'] = """
type: command
short-summary: Update a virtual hub router peering.
"""

helps['network routeserver peering list'] = """
type: command
short-summary: List all virtual hub router peerings under a resource group.
"""

helps['network routeserver peering show'] = """
type: command
short-summary: Show a virtual hub router peering
"""

helps['network routeserver peering delete'] = """
type: command
short-summary: Delete a virtual hub router peering.
"""

helps['network routeserver peering list-learned-routes'] = """
type: command
short-summary: List all routes the virtual hub bgp connection has learned.
"""

helps['network routeserver peering list-advertised-routes'] = """
type: command
short-summary: List all routes the virtual hub bgp connection is advertising to the specified peer.
"""

helps['network watcher'] = """
type: group
short-summary: Manage the Azure Network Watcher.
Expand Down
25 changes: 25 additions & 0 deletions src/azure-cli/azure/cli/command_modules/network/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,31 @@ def load_arguments(self, _):
c.argument('peer_asn', type=int, help='Peer ASN. Its range is from 1 to 4294967295.')
c.argument('peer_ip', help='Peer IP address.')

with self.argument_context('network routeserver') as c:
c.argument('virtual_hub_name', options_list=['--name', '-n'], id_part='name',
help='The name of the Virtual Hub Router.')
c.argument('hosted_subnet', help='The ID of a subnet where Virtual Hub Router would be deployed')
c.argument('allow_branch_to_branch_traffic', options_list=['--allow-b2b-traffic'],
arg_type=get_three_state_flag(), help='Allow branch to branch traffic.')

with self.argument_context('network routeserver create') as c:
c.argument('virtual_hub_name', id_part=None)

with self.argument_context('network routeserver peering') as c:
c.argument('virtual_hub_name', options_list=['--vrouter-name'], id_part='name',
help='The name of the Virtual Hub Router.')
c.argument('connection_name', options_list=['--name', '-n'], id_part='child_name_1',
help='The name of the Virtual Hub Router Peering')
c.argument('peer_asn', type=int, help='Peer ASN. Its range is from 1 to 4294967295.')
c.argument('peer_ip', help='Peer IP address.')

with self.argument_context('network routeserver peering create') as c:
c.argument('virtual_hub_name', id_part=None)
c.argument('connection_name', id_part=None)

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

param_map = {
'dh_group': 'DhGroup',
'ike_encryption': 'IkeEncryption',
Expand Down
77 changes: 74 additions & 3 deletions src/azure-cli/azure/cli/command_modules/network/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
cf_service_tags, cf_private_link_services, cf_private_endpoint_types, cf_peer_express_route_circuit_connections,
cf_virtual_router, cf_virtual_router_peering, cf_service_aliases, cf_bastion_hosts, cf_flow_logs,
cf_private_dns_zone_groups, cf_security_partner_providers, cf_load_balancer_backend_pools,
cf_network_virtual_appliances, cf_virtual_appliance_skus, cf_virtual_appliance_sites)
cf_network_virtual_appliances, cf_virtual_appliance_skus, cf_virtual_appliance_sites, cf_virtual_hub,
cf_virtual_hub_bgp_connection, cf_virtual_hub_bgp_connections)
from azure.cli.command_modules.network._util import (
list_network_resource_property, get_network_resource_property_entry, delete_network_resource_property_entry)
from azure.cli.command_modules.network._format import (
Expand Down Expand Up @@ -63,6 +64,8 @@
process_appgw_waf_policy_update, process_cross_region_lb_frontend_ip_namespace, process_cross_region_lb_create_namespace)

ROUTE_TABLE_DEPRECATION_INFO = 'network vhub route-table'
NETWORK_VROUTER_DEPRECATION_INFO = 'network routeserver'
NETWORK_VROUTER_PEERING_DEPRECATION_INFO = 'network routeserver peering'


# pylint: disable=too-many-locals, too-many-statements
Expand Down Expand Up @@ -345,6 +348,42 @@ def load_command_table(self, _):
min_api='2018-07-01'
)

network_virtual_hub_sdk = CliCommandType(
operations_tmpl='azure.mgmt.network.operations#VirtualHubsOperations.{}',
client_factory=cf_virtual_hub,
min_api='2020-07-01'
)

network_virtual_hub_update_sdk = CliCommandType(
operations_tmpl='azure.cli.command_modules.network.custom#{}',
client_factory=cf_virtual_hub,
min_api='2020-07-01'
)

network_virtual_hub_bgp_connection_sdk = CliCommandType(
operations_tmpl='azure.mgmt.network.operations#VirtualHubBgpConnectionOperations.{}',
client_factory=cf_virtual_hub_bgp_connection,
min_api='2020-07-01'
)

network_virtual_hub_bgp_connection_update_sdk = CliCommandType(
operations_tmpl='azure.cli.command_modules.network.custom#{}',
client_factory=cf_virtual_hub_bgp_connection,
min_api='2020-07-01'
)

network_virtual_hub_bgp_connections_sdk = CliCommandType(
operations_tmpl='azure.mgmt.network.operations#VirtualHubBgpConnectionsOperations.{}',
client_factory=cf_virtual_hub_bgp_connections,
min_api='2020-07-01'
)

network_virtual_hub_bgp_connections_update_sdk = CliCommandType(
operations_tmpl='azure.cli.command_modules.network.custom#{}',
client_factory=cf_virtual_hub_bgp_connections,
min_api='2020-07-01'
)

network_vrouter_sdk = CliCommandType(
operations_tmpl='azure.mgmt.network.operations#VirtualRoutersOperations.{}',
client_factory=cf_virtual_router,
Expand Down Expand Up @@ -1309,7 +1348,8 @@ def _make_singular(value):
# endregion

# region VirtualRouter
with self.command_group('network vrouter', network_vrouter_sdk) as g:
with self.command_group('network vrouter', network_vrouter_sdk,
deprecate_info=self.deprecate(redirect=NETWORK_VROUTER_DEPRECATION_INFO, hide=True)) as g:
g.custom_command('create', 'create_virtual_router')
g.generic_update_command('update',
getter_name='virtual_router_update_getter',
Expand All @@ -1321,7 +1361,9 @@ def _make_singular(value):
g.custom_show_command('show', 'show_virtual_router')
g.custom_command('list', 'list_virtual_router')

with self.command_group('network vrouter peering', network_vrouter_peering_sdk) as g:
with self.command_group(
'network vrouter peering', network_vrouter_peering_sdk,
deprecate_info=self.deprecate(redirect=NETWORK_VROUTER_PEERING_DEPRECATION_INFO, hide=True)) as g:
g.custom_command('create', 'create_virtual_router_peering')
g.generic_update_command('update',
getter_name='virtual_router_peering_update_getter',
Expand All @@ -1334,6 +1376,35 @@ def _make_singular(value):
g.custom_command('list', 'list_virtual_router_peering')
# endregion

# region VirtualHub
with self.command_group('network routeserver', network_virtual_hub_sdk,
custom_command_type=network_virtual_hub_update_sdk) as g:
g.custom_command('create', 'create_virtual_hub')
g.generic_update_command('update',
setter_name='virtual_hub_update_setter',
setter_type=network_virtual_hub_update_sdk,
custom_func_name='update_virtual_hub')
g.custom_command('delete', 'delete_virtual_hub', supports_no_wait=True, confirmation=True)
g.show_command('show', 'get')
g.custom_command('list', 'list_virtual_hub')

with self.command_group('network routeserver peering', network_virtual_hub_bgp_connection_sdk,
custom_command_type=network_virtual_hub_bgp_connection_update_sdk) as g:
g.custom_command('create', 'create_virtual_hub_bgp_connection', supports_no_wait=True)
g.generic_update_command('update',
setter_name='virtual_hub_bgp_connection_update_setter',
setter_type=network_virtual_hub_bgp_connection_update_sdk,
custom_func_name='update_virtual_hub_bgp_connection')
g.custom_command('delete', 'delete_virtual_hub_bgp_connection', supports_no_wait=True, confirmation=True)
g.show_command('show', 'get')

with self.command_group('network routeserver peering', network_virtual_hub_bgp_connections_sdk,
custom_command_type=network_virtual_hub_bgp_connections_update_sdk) as g:
g.command('list', 'list')
g.custom_command('list-learned-routes', 'list_virtual_hub_bgp_connection_learned_routes')
g.custom_command('list-advertised-routes', 'list_virtual_hub_bgp_connection_advertised_routes')
# endregion

# region Bastion
with self.command_group('network bastion', network_bastion_hosts_sdk, is_preview=True) as g:
g.custom_command('create', 'create_bastion_host')
Expand Down
107 changes: 107 additions & 0 deletions src/azure-cli/azure/cli/command_modules/network/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6496,6 +6496,113 @@ def remove_vnet_gateway_aad(cmd, resource_group_name, gateway_name, no_wait=Fals
# endregion


# region VirtualHub
def create_virtual_hub(cmd, client,
resource_group_name,
virtual_hub_name,
hosted_subnet=None,
location=None,
tags=None):
from azure.core.exceptions import HttpResponseError
from azure.cli.core.commands import LongRunningOperation

try:
client.get(resource_group_name, virtual_hub_name)
raise CLIError('The VirtualHub "{}" under resource group "{}" exists'.format(
virtual_hub_name, resource_group_name))
except HttpResponseError:
pass

SubResource = cmd.get_models('SubResource')

VirtualHub, HubIpConfiguration = cmd.get_models('VirtualHub', 'HubIpConfiguration')

hub = VirtualHub(tags=tags, location=location,
virtual_wan=None,
sku='Standard')
vhub_poller = client.begin_create_or_update(resource_group_name, virtual_hub_name, hub)
LongRunningOperation(cmd.cli_ctx)(vhub_poller)

ip_config = HubIpConfiguration(subnet=SubResource(id=hosted_subnet))
vhub_ip_config_client = network_client_factory(cmd.cli_ctx).virtual_hub_ip_configuration
try:
vhub_ip_poller = vhub_ip_config_client.begin_create_or_update(
resource_group_name, virtual_hub_name, 'Default', ip_config)
LongRunningOperation(cmd.cli_ctx)(vhub_ip_poller)
except Exception as ex:
logger.error(ex)
try:
vhub_ip_config_client.begin_delete(resource_group_name, virtual_hub_name, 'Default')
except HttpResponseError:
pass
client.begin_delete(resource_group_name, virtual_hub_name)
raise ex

return client.get(resource_group_name, virtual_hub_name)


def virtual_hub_update_setter(client, resource_group_name, virtual_hub_name, parameters):
return client.begin_create_or_update(resource_group_name, virtual_hub_name, parameters)


def update_virtual_hub(cmd, instance,
tags=None,
allow_branch_to_branch_traffic=None):
with cmd.update_context(instance) as c:
c.set_param('tags', tags)
c.set_param('allow_branch_to_branch_traffic', allow_branch_to_branch_traffic)
return instance


def delete_virtual_hub(cmd, client, resource_group_name, virtual_hub_name, no_wait=False):
from azure.cli.core.commands import LongRunningOperation
vhub_ip_config_client = network_client_factory(cmd.cli_ctx).virtual_hub_ip_configuration
poller = vhub_ip_config_client.begin_delete(resource_group_name, virtual_hub_name, 'Default')
LongRunningOperation(cmd.cli_ctx)(poller)
return sdk_no_wait(no_wait, client.begin_delete, resource_group_name, virtual_hub_name)


def list_virtual_hub(client, resource_group_name=None):
if resource_group_name is not None:
return client.list_by_resource_group(resource_group_name)
return client.list()


def create_virtual_hub_bgp_connection(cmd, client, resource_group_name, virtual_hub_name, connection_name,
peer_asn, peer_ip, no_wait=False):
BgpConnection = cmd.get_models('BgpConnection')
vhub_bgp_conn = BgpConnection(name=connection_name, peer_asn=peer_asn, peer_ip=peer_ip)
return sdk_no_wait(no_wait, client.begin_create_or_update, resource_group_name,
virtual_hub_name, connection_name, vhub_bgp_conn)


def virtual_hub_bgp_connection_update_setter(client, resource_group_name,
virtual_hub_name, connection_name,
parameters):
return client.begin_create_or_update(resource_group_name, virtual_hub_name, connection_name, parameters)


def update_virtual_hub_bgp_connection(cmd, instance, peer_asn=None, peer_ip=None):
with cmd.update_context(instance) as c:
c.set_param('peer_asn', peer_asn)
c.set_param('peer_ip', peer_ip)
return instance


def delete_virtual_hub_bgp_connection(client, resource_group_name,
virtual_hub_name, connection_name, no_wait=False):
return sdk_no_wait(no_wait, client.begin_delete, resource_group_name, virtual_hub_name, connection_name)


def list_virtual_hub_bgp_connection_learned_routes(client, resource_group_name, virtual_hub_name, connection_name):
return client.begin_list_learned_routes(resource_group_name, virtual_hub_name, connection_name)


def list_virtual_hub_bgp_connection_advertised_routes(client, resource_group_name, virtual_hub_name, connection_name):
return client.begin_list_advertised_routes(resource_group_name, virtual_hub_name, connection_name)
# endregion


# region VirtualRouter
def create_virtual_router(cmd,
resource_group_name,
Expand Down
Loading