Skip to content

Commit

Permalink
Network Traffic Manager commands (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
BurtBiel authored Aug 18, 2016
1 parent e456c98 commit 511a72a
Show file tree
Hide file tree
Showing 31 changed files with 2,053 additions and 18 deletions.
25 changes: 25 additions & 0 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,25 @@
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_route_table\lib\version.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_route_table\lib\__init__.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_route_table\__init__.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\credentials.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\exceptions.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\models\basic_dependency.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\models\dependency.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\models\deployment_extended.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\models\deployment_properties_extended.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\models\deployment_traffic_manager_profile.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\models\parameters_link.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\models\provider.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\models\provider_resource_type.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\models\template_link.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\models\traffic_manager_profile_creation_client_enums.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\models\__init__.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\operations\traffic_manager_profile_operations.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\operations\__init__.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\traffic_manager_profile_creation_client.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\version.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\__init__.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\__init__.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_vnet\lib\vnet_creation_client.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_vnet_gateway\lib\credentials.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_vnet_gateway\lib\exceptions.py" />
Expand Down Expand Up @@ -615,6 +634,9 @@
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_route_table\lib\" />
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_route_table\lib\models\" />
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_route_table\lib\operations\" />
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\" />
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\models\" />
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\lib\operations\" />
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_vnet_gateway\" />
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_vnet_gateway\lib\" />
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_vnet_gateway\lib\models\" />
Expand All @@ -627,6 +649,7 @@
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_vpn_connection\lib\operations\" />
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_express_route_circuit\" />
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_express_route_peering\" />
<Folder Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\" />
<Folder Include="command_modules\azure-cli-redis\" />
<Folder Include="command_modules\azure-cli-redis\azure\" />
<Folder Include="command_modules\azure-cli-redis\azure\cli\" />
Expand Down Expand Up @@ -748,6 +771,8 @@
<Content Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_public_ip\swagger_create_public_ip.json" />
<Content Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_route_table\azuredeploy.json" />
<Content Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_route_table\swagger_create_route_table.json" />
<Content Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\azuredeploy.json" />
<Content Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_traffic_manager_profile\swagger_create_traffic_manager_profile.json" />
<Content Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_vnet\azuredeploy.json" />
<Content Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_vnet\azuredeploy_empty.json" />
<Content Include="command_modules\azure-cli-network\azure\cli\command_modules\network\mgmt_vnet\swagger_create_vnet.json" />
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ adal==0.4.0
applicationinsights==0.10.0
argcomplete==1.3.0
azure==2.0.0rc5
azure-mgmt-trafficmanager==0.30.0rc5
colorama==0.3.7
jmespath
mock==1.3.0
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
'applicationinsights',
'argcomplete>=1.3.0',
'azure==2.0.0rc5',
'azure-mgmt-trafficmanager==0.30.0rc5',
'colorama',
'jmespath',
'msrest>=0.4.0',
Expand Down
5 changes: 5 additions & 0 deletions src/azure/cli/commands/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def completer(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-a
return list(enum_type.__dict__[ENUM_MAPPING_KEY].keys())
return completer

def get_generic_completion_list(generic_list):
def completer(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument
return generic_list
return completer

def get_enum_choices(enum_type):
return [x.value for x in enum_type]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

from azure.cli.commands import CliArgumentType, register_cli_argument, register_extra_cli_argument
from azure.cli.commands.parameters import (location_type, get_resource_name_completion_list,
get_enum_type_completion_list, tags_type, get_enum_choices)
get_enum_type_completion_list, tags_type, get_enum_choices,
get_generic_completion_list)
from azure.cli.commands.validators import MarkSpecifiedAction
from azure.cli.commands.template_create import register_folded_cli_argument
from azure.cli.command_modules.network._factory import _network_client_factory
Expand All @@ -32,6 +33,9 @@
from azure.cli.command_modules.network.mgmt_nic.lib.models.nic_creation_client_enums import privateIpAddressVersion
from azure.cli.command_modules.network.mgmt_vnet_gateway.lib.models.vnet_gateway_creation_client_enums import \
(gatewayType, sku, vpnType)
from azure.cli.command_modules.network.mgmt_traffic_manager_profile.lib.models.traffic_manager_profile_creation_client_enums \
import routingMethod
from azure.cli.command_modules.network.custom import list_traffic_manager_endpoints

# COMPLETERS

Expand Down Expand Up @@ -87,6 +91,13 @@ def completer(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-a
return [r.name for r in url_map.path_rules]
return completer

def get_tm_endpoint_completion_list():
def completer(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument
return list_traffic_manager_endpoints(parsed_args.resource_group_name, parsed_args.profile_name) \
if parsed_args.resource_group_name and parsed_args.profile_name \
else []
return completer

# BASIC PARAMETER CONFIGURATION

name_arg_type = CliArgumentType(options_list=('--name', '-n'), metavar='NAME')
Expand Down Expand Up @@ -351,6 +362,8 @@ def completer(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-a
register_cli_argument('network vpn-gateway root-cert create', 'public_cert_data', help='Base64 contents of the root certificate file or file path.', validator=load_cert_file('public_cert_data'))
register_cli_argument('network vpn-gateway revoked-cert create', 'thumbprint', help='Certificate thumbprint.')
register_extra_cli_argument('network vpn-gateway update', 'address_prefixes', options_list=('--address-prefixes',), help='List of address prefixes for the VPN gateway. Prerequisite for uploading certificates.', nargs='+')
register_cli_argument('network vpn-gateway root-cert create', 'cert_name', help='Root certificate name', options_list=('--name', '-n'))
register_cli_argument('network vpn-gateway root-cert create', 'gateway_name', help='Virtual network gateway name')

# VPN connection
register_cli_argument('network vpn-connection', 'virtual_network_gateway_connection_name', CliArgumentType(options_list=('--name', '-n'), metavar='NAME', id_part='name'))
Expand All @@ -360,3 +373,16 @@ def completer(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-a
# VPN connection shared key
register_cli_argument('network vpn-connection shared-key', 'connection_shared_key_name', CliArgumentType(options_list=('--name', '-n')), id_part='name')
register_cli_argument('network vpn-connection shared-key', 'virtual_network_gateway_connection_name', CliArgumentType(options_list=('--connection-name',), metavar='NAME'), id_part='name')

# Traffic manager profiles
register_cli_argument('network traffic-manager profile', 'traffic_manager_profile_name', name_arg_type, id_part='name', completer=get_resource_name_completion_list('Microsoft.Network/trafficManagerProfiles'))
register_cli_argument('network traffic-manager profile', 'profile_name', name_arg_type, id_part='name', completer=get_resource_name_completion_list('Microsoft.Network/trafficManagerProfiles'))
register_cli_argument('network traffic-manager profile create', 'routing_method', choices=get_enum_choices(routingMethod), completer=get_enum_type_completion_list(routingMethod))
register_cli_argument('network traffic-manager profile check-dns', 'name', name_arg_type, help='DNS prefix to verify availability for.', required=True)
register_cli_argument('network traffic-manager profile check-dns', 'type', help=argparse.SUPPRESS, default='Microsoft.Network/trafficManagerProfiles')

# Traffic manager endpoints
register_cli_argument('network traffic-manager endpoint', 'endpoint_name', name_arg_type, id_part='name', help='Endpoint name.', completer=get_tm_endpoint_completion_list())
endpoint_types = ['azureEndpoints', 'externalEndpoints', 'nestedEndpoints']
register_cli_argument('network traffic-manager endpoint', 'endpoint_type', options_list=('--type',), help='Endpoint type. Values include: {}.'.format(', '.join(endpoint_types)), completer=get_generic_completion_list(endpoint_types))
register_cli_argument('network traffic-manager endpoint', 'profile_name', help='Name of parent profile.', completer=get_resource_name_completion_list('Microsoft.Network/trafficManagerProfiles'))
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
from azure.cli.command_modules.network.mgmt_app_gateway.lib.operations.app_gateway_operations \
import AppGatewayOperations

from azure.cli.commands.client_factory import get_mgmt_service_client
from ._factory import _network_client_factory
from azure.cli.command_modules.network.mgmt_nic.lib.operations.nic_operations import NicOperations
from azure.mgmt.trafficmanager import TrafficManagerManagementClient
from azure.mgmt.trafficmanager.models import Endpoint

#region Network subresource factory methods

Expand Down Expand Up @@ -98,6 +101,7 @@ def list_route_tables(resource_group_name=None):

def list_application_gateways(resource_group_name=None):
return _generic_list('application_gateways', resource_group_name)

#endregion

#region Application Gateway subresource commands
Expand Down Expand Up @@ -721,22 +725,6 @@ def update_subnet(resource_group_name, virtual_network_name, subnet_name,

update_nsg_rule.__doc__ = SecurityRule.__doc__

def create_route(resource_group_name, route_table_name, route_name, next_hop_type, address_prefix,
next_hop_ip_address=None):
route = Route(next_hop_type, None, address_prefix, next_hop_ip_address, None, route_name)
ncf = _network_client_factory()
return ncf.routes.create_or_update(resource_group_name, route_table_name, route_name, route)

create_route.__doc__ = Route.__doc__

def create_vpn_gateway_root_cert(resource_group_name, gateway_name, public_cert_data, cert_name):
config, gateway, ncf = _prep_cert_create(gateway_name, resource_group_name)

cert = VpnClientRootCertificate(name=cert_name, public_cert_data=public_cert_data)
config.vpn_client_root_certificates.append(cert)

return ncf.create_or_update(resource_group_name, gateway_name, gateway)

def delete_vpn_gateway_root_cert(resource_group_name, gateway_name, cert_name):
ncf = _network_client_factory().virtual_network_gateways
gateway = ncf.get(resource_group_name, gateway_name)
Expand Down Expand Up @@ -807,4 +795,59 @@ def create_express_route_auth(resource_group_name, circuit_name, authorization_n
ncf = _network_client_factory().express_route_circuit_authorizations
auth = ExpressRouteCircuitAuthorization(authorization_key=authorization_key)
return ncf.create_or_update(resource_group_name, circuit_name, authorization_name, auth)

def create_route(resource_group_name, route_table_name, route_name, next_hop_type, address_prefix,
next_hop_ip_address=None):
route = Route(next_hop_type, None, address_prefix, next_hop_ip_address, None, route_name)
ncf = _network_client_factory()
return ncf.routes.create_or_update(resource_group_name, route_table_name, route_name, route)

create_route.__doc__ = Route.__doc__

def create_vpn_gateway_root_cert(resource_group_name, gateway_name, public_cert_data, cert_name):
ncf = _network_client_factory().virtual_network_gateways
gateway = ncf.get(resource_group_name, gateway_name)
if not gateway.vpn_client_configuration:
gateway.vpn_client_configuration = VpnClientConfiguration()
config = gateway.vpn_client_configuration

if config.vpn_client_root_certificates is None:
config.vpn_client_root_certificates = []

cert = VpnClientRootCertificate(name=cert_name, public_cert_data=public_cert_data)
config.vpn_client_root_certificates.append(cert)

return ncf.create_or_update(resource_group_name, gateway_name, gateway)
#endregion

#region Traffic Manager Commands
def list_traffic_manager_profiles(resource_group_name=None):
ncf = get_mgmt_service_client(TrafficManagerManagementClient).profiles
if resource_group_name:
return ncf.list_all_in_resource_group(resource_group_name)
else:
return ncf.list_all()

def create_traffic_manager_endpoint(resource_group_name, profile_name, endpoint_type, endpoint_name,
target_resource_id=None, target=None,
endpoint_status=None, weight=None, priority=None,
endpoint_location=None, endpoint_monitor_status=None,
min_child_endpoints=None):
ncf = get_mgmt_service_client(TrafficManagerManagementClient).endpoints

endpoint = Endpoint(target_resource_id=target_resource_id, target=target,
endpoint_status=endpoint_status, weight=weight, priority=priority,
endpoint_location=endpoint_location,
endpoint_monitor_status=endpoint_monitor_status,
min_child_endpoints=min_child_endpoints)

return ncf.create_or_update(resource_group_name, profile_name, endpoint_type, endpoint_name,
endpoint)

create_traffic_manager_endpoint.__doc__ = Endpoint.__doc__

def list_traffic_manager_endpoints(resource_group_name, profile_name, endpoint_type=None):
ncf = get_mgmt_service_client(TrafficManagerManagementClient).profiles
profile = ncf.get(resource_group_name, profile_name)
return [e for e in profile.endpoints if not endpoint_type or e.type.endswith(endpoint_type)]
#endregion
Loading

0 comments on commit 511a72a

Please sign in to comment.