Skip to content

Commit

Permalink
Transfer VTAP from private to public. (Azure#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott authored Sep 22, 2018
1 parent 17ace77 commit 1d2f2a2
Show file tree
Hide file tree
Showing 681 changed files with 65,420 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@
/src/find/ @albaloo

/src/resource-graph/ @demyanenko @amirhbk @chiragg4u

/src/virtual-network-tap/ @trpresco
35 changes: 35 additions & 0 deletions src/virtual-network-tap/azext_vnettap/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader
from azure.cli.core.profiles import register_resource_type

import azext_vnettap._help # pylint: disable=unused-import


class VirtualNetworkTapCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from .profiles import CUSTOM_VNET_TAP
register_resource_type('latest', CUSTOM_VNET_TAP, '2018-08-01')

super(VirtualNetworkTapCommandsLoader, self).__init__(
cli_ctx=cli_ctx,
custom_command_type=CliCommandType(operations_tmpl='azext_vnettap.custom#{}'),
resource_type=CUSTOM_VNET_TAP
)

def load_command_table(self, args):
from .commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, args):
from ._params import load_arguments
load_arguments(self, args)


COMMAND_LOADER_CLS = VirtualNetworkTapCommandsLoader
27 changes: 27 additions & 0 deletions src/virtual-network-tap/azext_vnettap/_client_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


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_VNET_TAP
return get_mgmt_service_client(cli_ctx, CUSTOM_VNET_TAP, aux_subscriptions=aux_subscriptions,
api_version='2018-08-01')


def cf_virtual_network_taps(cli_ctx, _):
return network_client_factory(cli_ctx).virtual_network_taps


def cf_load_balancers(cli_ctx, _):
return network_client_factory(cli_ctx).load_balancers


def cf_nics(cli_ctx, _):
return network_client_factory(cli_ctx).network_interfaces


def cf_nic_tap_config(cli_ctx, _):
return network_client_factory(cli_ctx).network_interface_tap_configurations
62 changes: 62 additions & 0 deletions src/virtual-network-tap/azext_vnettap/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.help_files import helps


helps['network vnet tap'] = """
type: group
short-summary: Manage virtual network taps.
"""

helps['network vnet tap create'] = """
type: command
short-summary: Create a virtual network tap.
"""

helps['network vnet tap list'] = """
type: command
short-summary: List virtual network taps.
"""

helps['network vnet tap show'] = """
type: command
short-summary: Get the details of a virtual network tap.
"""

helps['network vnet tap update'] = """
type: command
short-summary: Update settings of a virtual network tap.
"""

helps['network vnet tap delete'] = """
type: command
short-summary: Delete a virtual network tap.
"""

helps['network nic vtap-config'] = """
type: group
short-summary: Manage virtual network tap configurations.
"""

helps['network nic vtap-config create'] = """
type: command
short-summary: Create a virtual network tap configuration.
"""

helps['network nic vtap-config delete'] = """
type: command
short-summary: Delete a virtual network tap configuration.
"""

helps['network nic vtap-config list'] = """
type: command
short-summary: List virtual network tap configurations.
"""

helps['network nic vtap-config show'] = """
type: command
short-summary: Get details of a virtual network tap configuration.
"""
34 changes: 34 additions & 0 deletions src/virtual-network-tap/azext_vnettap/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
from knack.arguments import CLIArgumentType

from azure.cli.core.commands.parameters import (
get_resource_name_completion_list, tags_type)
from azure.cli.core.commands.validators import get_default_location_from_resource_group

from ._validators import validate_vnet_tap


# pylint: disable=too-many-locals, too-many-branches, too-many-statements
def load_arguments(self, _):

tap_name_arg_type = CLIArgumentType(options_list='--tap-name', metavar='NAME', help='Name of the VNet TAP.', id_part='name', completer=get_resource_name_completion_list('Microsoft.Network/virtualNetworkTaps'))

with self.argument_context('network vnet tap') as c:
c.argument('tap_name', tap_name_arg_type, options_list=['--name', '-n'])
c.argument('tags', tags_type)
c.argument('location', validator=get_default_location_from_resource_group)

with self.argument_context('network vnet tap create', arg_group='Destination') as c:
c.argument('destination', help='ID of the ILB or NIC IP configuration to receive the tap.')
c.argument('port', help='The VXLAN port that will receive the tapped traffic.')

with self.argument_context('network nic vtap-config') as c:
c.argument('network_interface_name', options_list='--nic-name', help='Name of the network interface (NIC).', id_part='name')
c.argument('vnet_tap', help='Name or ID of the virtual network tap.', validator=validate_vnet_tap)
for dest in ['vtap_config_name', 'tap_configuration_name']:
c.argument(dest, options_list=['--name', '-n'], help='Name of the virtual network tap configuration.', id_part='child_name_1')
18 changes: 18 additions & 0 deletions src/virtual-network-tap/azext_vnettap/_validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands.client_factory import get_subscription_id


def validate_vnet_tap(cmd, namespace):
if namespace.vnet_tap:
from msrestazure.tools import is_valid_resource_id, resource_id
if not is_valid_resource_id(namespace.vnet_tap):
namespace.vnet_tap = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Network', type='virtualNetworkTaps',
name=namespace.vnet_tap
)
3 changes: 3 additions & 0 deletions src/virtual-network-tap/azext_vnettap/azext_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"azext.minCliCoreVersion": "2.0.41"
}
38 changes: 38 additions & 0 deletions src/virtual-network-tap/azext_vnettap/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

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

from ._client_factory import cf_virtual_network_taps, cf_nic_tap_config


# pylint: disable=too-many-locals, too-many-statements
def load_command_table(self, _):

network_vnet_tap_sdk = CliCommandType(
operations_tmpl='azext_vnettap.vendored_sdks.operations.virtual_network_taps_operations#VirtualNetworkTapsOperations.{}',
client_factory=cf_virtual_network_taps,
min_api='2018-08-01'
)

network_nic_tap_config_sdk = CliCommandType(
operations_tmpl='azext_vnettap.vendored_sdks.operations.network_interface_tap_configurations_operations#NetworkInterfaceTapConfigurationsOperations.{}',
client_factory=cf_nic_tap_config,
min_api='2018-08-01'
)

with self.command_group('network vnet tap', network_vnet_tap_sdk) as g:
g.custom_command('create', 'create_vnet_tap')
g.command('delete', 'delete')
g.custom_command('list', 'list_vnet_taps')
g.show_command('show', 'get')
g.generic_update_command('update')

with self.command_group('network nic vtap-config', network_nic_tap_config_sdk) as g:
g.custom_command('create', 'create_vtap_config')
g.command('delete', 'delete')
g.command('list', 'list')
g.show_command('show', 'get')
52 changes: 52 additions & 0 deletions src/virtual-network-tap/azext_vnettap/custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from ._client_factory import network_client_factory


def create_vnet_tap(cmd, resource_group_name, tap_name, destination, port=None, tags=None, location=None):
from msrestazure.tools import parse_resource_id
supported_types = ['loadBalancers', 'networkInterfaces']
client = network_client_factory(cmd.cli_ctx).virtual_network_taps
SubResource, VTAP = cmd.get_models('SubResource', 'VirtualNetworkTap')
dest_type = parse_resource_id(destination).get('type', None)
if not dest_type or dest_type not in supported_types:
from knack.util import CLIError
raise CLIError('Unable to parse destination resource ID. Supply an IP configuration ID '
'for one of the following resource types: {}'.format(supported_types))
vtap = VTAP(
tags=tags,
location=location,
destination_port=port,
destination_load_balancer_front_end_ip_configuration=SubResource(id=destination)
if dest_type == 'loadBalancers' else None,
destination_network_interface_ip_configuration=SubResource(id=destination)
if dest_type == 'networkInterfaces' else None
)
return client.create_or_update(resource_group_name, tap_name, vtap)


def list_vnet_taps(cmd, resource_group_name=None):
client = network_client_factory(cmd.cli_ctx).virtual_network_taps
if resource_group_name:
return client.list_by_resource_group(resource_group_name)
return client.list_all()


def create_vtap_config(cmd, resource_group_name, network_interface_name, vtap_config_name, vnet_tap):
client = network_client_factory(cmd.cli_ctx).network_interface_tap_configurations
SubResource, NetworkInterfaceTapConfiguration = cmd.get_models(
'SubResource', 'NetworkInterfaceTapConfiguration')
vtap_config = NetworkInterfaceTapConfiguration(
virtual_network_tap=SubResource(id=vnet_tap)
)
return client.create_or_update(resource_group_name, network_interface_name, vtap_config_name, vtap_config)


def list_nics(cmd, resource_group_name=None):
client = network_client_factory(cmd.cli_ctx).network_interfaces
if resource_group_name:
return client.list(resource_group_name)
return client.list_all()
8 changes: 8 additions & 0 deletions src/virtual-network-tap/azext_vnettap/profiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.profiles import CustomResourceType

CUSTOM_VNET_TAP = CustomResourceType('azext_vnettap.vendored_sdks', 'NetworkManagementClient')
17 changes: 17 additions & 0 deletions src/virtual-network-tap/azext_vnettap/vendored_sdks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from .network_management_client import NetworkManagementClient
from .version import VERSION

__all__ = ['NetworkManagementClient']

__version__ = VERSION
7 changes: 7 additions & 0 deletions src/virtual-network-tap/azext_vnettap/vendored_sdks/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
from .v2018_08_01.models import *
Loading

0 comments on commit 1d2f2a2

Please sign in to comment.