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
1 change: 0 additions & 1 deletion src/azure-cli-core/azure/cli/core/profiles/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ def default_api_version(self):
AD_HOC_API_VERSIONS = {
ResourceType.MGMT_NETWORK: {
'vm_default_target_network': '2018-01-01',
'nw_connection_monitor': '2019-06-01',
'container_network': '2018-08-01',
'appservice_network': '2020-04-01',
'appservice_ensure_subnet': '2019-02-01'
Expand Down
17 changes: 1 addition & 16 deletions src/azure-cli/azure/cli/command_modules/network/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -6274,23 +6274,8 @@
helps['network watcher connection-monitor create'] = """
type: command
short-summary: Create a connection monitor.
long-summary: |
This extension allow to create V1 and V2 version of connection monitor.
V1 connection monitor supports single source and destination endpoint which comes with V1 argument groups as usual.
V2 connection monitor supports multiple endpoints and several test protocol which comes with V2 argument groups.
parameters:
- name: --source-resource
short-summary: >
Currently only Virtual Machines are supported.
- name: --dest-resource
short-summary: >
Currently only Virtual Machines are supported.
examples:
- name: Create a connection monitor for a virtual machine.
text: |
az network watcher connection-monitor create -g MyResourceGroup -n MyConnectionMonitorName \\
--source-resource MyVM
- name: Create a V2 connection monitor
- name: Create a connection monitor
text: >
az network watcher connection-monitor create
--name MyV2ConnectionMonitor
Expand Down
13 changes: 0 additions & 13 deletions src/azure-cli/azure/cli/command_modules/network/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,19 +1348,6 @@ def load_arguments(self, _):
c.argument('network_watcher_name', arg_type=ignore_type, options_list=['--__NETWORK_WATCHER_NAME'])
c.argument('connection_monitor_name', name_arg_type, help='Connection monitor name.')

# connection monitor V1 parameter set
with self.argument_context('network watcher connection-monitor', arg_group='V1 Endpoint') as c:
c.argument('source_resource', help='Name or ID of the resource from which to originate traffic. '
'Currently only Virtual Machines are supported.')
c.argument('source_port', help='Port number from which to originate traffic.')
c.argument('dest_resource', help='Name of ID of the resource to receive traffic. '
'Currently only Virtual Machines are supported.')
c.argument('dest_port', help='Port number on which to receive traffic.')
c.argument('dest_address', help='The IP address or URI at which to receive traffic.')
c.argument('monitoring_interval', help='Monitoring interval in seconds.', type=int, default=60)
c.argument('do_not_start', action='store_true',
help='Create the connection monitor but do not start it immediately.')

nw_validator = get_network_watcher_from_location(remove=True, watcher_name='network_watcher_name', rg_name='resource_group_name')
for scope in ['list', 'show', 'start', 'stop', 'delete', 'query']:
with self.argument_context('network watcher connection-monitor {}'.format(scope)) as c:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1375,15 +1375,6 @@ def process_nw_cm_v2_create_namespace(cmd, namespace):
return get_network_watcher_from_location()(cmd, namespace)


def process_nw_cm_create_namespace(cmd, namespace):
# V2 parameter set
if namespace.source_resource is None:
return process_nw_cm_v2_create_namespace(cmd, namespace)

# V1 parameter set
return process_nw_cm_v1_create_namespace(cmd, namespace)


def process_nw_cm_v2_endpoint_namespace(cmd, namespace):
if hasattr(namespace, 'filter_type') or hasattr(namespace, 'filter_items'):
filter_type, filter_items = namespace.filter_type, namespace.filter_items
Expand Down
5 changes: 2 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 @@ -48,8 +48,7 @@
process_ag_create_namespace, process_ag_http_listener_create_namespace, process_ag_listener_create_namespace, process_ag_settings_create_namespace, process_ag_http_settings_create_namespace,
process_ag_rule_create_namespace, process_ag_routing_rule_create_namespace, process_ag_ssl_policy_set_namespace, process_ag_url_path_map_create_namespace,
process_ag_url_path_map_rule_create_namespace, process_auth_create_namespace, process_nic_create_namespace,
process_lb_create_namespace, process_lb_frontend_ip_namespace,
process_nw_cm_create_namespace,
process_lb_create_namespace, process_lb_frontend_ip_namespace, process_nw_cm_v2_create_namespace,
process_nw_cm_v2_endpoint_namespace, process_nw_cm_v2_test_configuration_namespace,
process_nw_cm_v2_test_group, process_nw_cm_v2_output_namespace,
process_nw_flow_log_set_namespace, process_nw_flow_log_create_namespace, process_nw_flow_log_show_namespace,
Expand Down Expand Up @@ -1077,7 +1076,7 @@ def _make_singular(value):
g.custom_command('run-configuration-diagnostic', 'run_network_configuration_diagnostic', client_factory=cf_network_watcher, min_api='2018-06-01', validator=process_nw_config_diagnostic_namespace)

with self.command_group('network watcher connection-monitor', network_watcher_cm_sdk, client_factory=cf_connection_monitor, min_api='2018-01-01') as g:
g.custom_command('create', 'create_nw_connection_monitor', validator=process_nw_cm_create_namespace)
g.custom_command('create', 'create_nw_connection_monitor', validator=process_nw_cm_v2_create_namespace)
g.command('delete', 'begin_delete')
g.show_command('show', 'get')
g.command('stop', 'begin_stop')
Expand Down
150 changes: 33 additions & 117 deletions src/azure-cli/azure/cli/command_modules/network/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5384,14 +5384,7 @@ def create_nw_connection_monitor(cmd,
watcher_name,
resource_group_name=None,
location=None,
source_resource=None,
source_port=None,
dest_resource=None,
dest_port=None,
dest_address=None,
tags=None,
do_not_start=None,
monitoring_interval=None,
endpoint_source_name=None,
endpoint_source_resource_id=None,
endpoint_source_address=None,
Expand Down Expand Up @@ -5422,120 +5415,43 @@ def create_nw_connection_monitor(cmd,
output_type=None,
workspace_ids=None,
notes=None):
v1_required_parameter_set = [
source_resource, source_port,
dest_resource, dest_address, dest_port
]

v2_required_parameter_set = [
endpoint_source_name, endpoint_source_resource_id, endpoint_source_type, endpoint_source_coverage_level,
endpoint_dest_name, endpoint_dest_address, endpoint_dest_type, endpoint_dest_coverage_level,
test_config_name, test_config_protocol,
output_type, workspace_ids,
]

if any(v1_required_parameter_set): # V1 creation
connection_monitor = _create_nw_connection_monitor_v1(cmd,
connection_monitor_name,
watcher_rg,
watcher_name,
source_resource,
resource_group_name,
source_port,
location,
dest_resource,
dest_port,
dest_address,
tags,
do_not_start,
monitoring_interval)
from azure.cli.core.profiles._shared import AD_HOC_API_VERSIONS
client = get_mgmt_service_client(
cmd.cli_ctx,
ResourceType.MGMT_NETWORK,
api_version=AD_HOC_API_VERSIONS[ResourceType.MGMT_NETWORK]['nw_connection_monitor']
).connection_monitors
elif any(v2_required_parameter_set): # V2 creation
connection_monitor = _create_nw_connection_monitor_v2(cmd,
location,
tags,
endpoint_source_name,
endpoint_source_resource_id,
endpoint_source_address,
endpoint_source_type,
endpoint_source_coverage_level,
endpoint_dest_name,
endpoint_dest_resource_id,
endpoint_dest_address,
endpoint_dest_type,
endpoint_dest_coverage_level,
test_config_name,
test_config_frequency,
test_config_protocol,
test_config_preferred_ip_version,
test_config_threshold_failed_percent,
test_config_threshold_round_trip_time,
test_config_tcp_port,
test_config_tcp_port_behavior,
test_config_tcp_disable_trace_route,
test_config_icmp_disable_trace_route,
test_config_http_port,
test_config_http_method,
test_config_http_path,
test_config_http_valid_status_codes,
test_config_http_prefer_https,
test_group_name,
test_group_disable,
output_type,
workspace_ids,
notes)
else:
raise CLIError('Unknown operation')
connection_monitor = _create_nw_connection_monitor_v2(cmd,
location,
tags,
endpoint_source_name,
endpoint_source_resource_id,
endpoint_source_address,
endpoint_source_type,
endpoint_source_coverage_level,
endpoint_dest_name,
endpoint_dest_resource_id,
endpoint_dest_address,
endpoint_dest_type,
endpoint_dest_coverage_level,
test_config_name,
test_config_frequency,
test_config_protocol,
test_config_preferred_ip_version,
test_config_threshold_failed_percent,
test_config_threshold_round_trip_time,
test_config_tcp_port,
test_config_tcp_port_behavior,
test_config_tcp_disable_trace_route,
test_config_icmp_disable_trace_route,
test_config_http_port,
test_config_http_method,
test_config_http_path,
test_config_http_valid_status_codes,
test_config_http_prefer_https,
test_group_name,
test_group_disable,
output_type,
workspace_ids,
notes)

return client.begin_create_or_update(watcher_rg, watcher_name, connection_monitor_name, connection_monitor)


def _create_nw_connection_monitor_v1(cmd,
connection_monitor_name,
watcher_rg,
watcher_name,
source_resource,
resource_group_name=None,
source_port=None,
location=None,
dest_resource=None,
dest_port=None,
dest_address=None,
tags=None,
do_not_start=None,
monitoring_interval=60):
ConnectionMonitor, ConnectionMonitorSource, ConnectionMonitorDestination = cmd.get_models(
'ConnectionMonitor', 'ConnectionMonitorSource', 'ConnectionMonitorDestination')

cmv1 = ConnectionMonitor(
location=location,
tags=tags,
source=ConnectionMonitorSource(
resource_id=source_resource,
port=source_port
),
destination=ConnectionMonitorDestination(
resource_id=dest_resource,
port=dest_port,
address=dest_address
),
auto_start=not do_not_start,
monitoring_interval_in_seconds=monitoring_interval,
endpoints=None,
test_configurations=None,
test_groups=None,
outputs=None,
notes=None
)

return cmv1


def _create_nw_connection_monitor_v2(cmd,
location=None,
tags=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1878,29 +1878,6 @@ def _network_watcher_troubleshooting(self):
self.cmd('network watcher troubleshooting start --resource vgw1 -t vnetGateway -g {rg} --storage-account {sa} --storage-path {storage_path}')
self.cmd('network watcher troubleshooting show --resource vgw1 -t vnetGateway -g {rg}')

def _network_watcher_connection_monitor(self):
import time
self.kwargs.update({
'vm2': 'vm2',
'vm3': 'vm3',
'cm': 'cm1'
})
self.cmd('vm create -g {rg} -n {vm2} --image UbuntuLTS --authentication-type password --admin-username deploy --admin-password PassPass10!) --nsg {vm2}')
self.cmd('vm extension set -g {rg} --vm-name {vm2} -n NetworkWatcherAgentLinux --publisher Microsoft.Azure.NetworkWatcher')
self.cmd('vm create -g {rg} -n {vm3} --image UbuntuLTS --authentication-type password --admin-username deploy --admin-password PassPass10!) --nsg {vm3}')
self.cmd('vm extension set -g {rg} --vm-name {vm3} -n NetworkWatcherAgentLinux --publisher Microsoft.Azure.NetworkWatcher')
time.sleep(20)
self.cmd('network watcher connection-monitor create -n {cm} --source-resource {vm2} -g {rg} --dest-resource {vm3} --dest-port 80 --tags foo=doo')
self.cmd('network watcher connection-monitor list -l {loc}')
self.cmd('network watcher connection-monitor show -l {loc} -n {cm}')
try:
self.cmd('network watcher connection-monitor stop -l {loc} -n {cm}')
self.cmd('network watcher connection-monitor start -l {loc} -n {cm}')
except CLIError:
pass
self.cmd('network watcher connection-monitor query -l {loc} -n {cm}')
self.cmd('network watcher connection-monitor delete -l {loc} -n {cm}')

@mock.patch('azure.cli.command_modules.vm._actions._get_thread_count', _mock_thread_count)
@ResourceGroupPreparer(name_prefix='cli_test_network_watcher', location='westcentralus')
@StorageAccountPreparer(name_prefix='clitestnw', location='westcentralus')
Expand All @@ -1914,7 +1891,6 @@ def test_network_watcher(self, resource_group, storage_account):
'capture': 'capture1'
})
self._network_watcher_configure()
self._network_watcher_connection_monitor()
self._network_watcher_vm()
self._network_watcher_flow_log()
self._network_watcher_packet_capture()
Expand Down
Loading