-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Network] Add new commands to manage flow-log and deprecate old configure command #12350
Changes from 13 commits
e9f3e05
de655bb
020ba1c
1a7726f
fc3dc06
66ddc4d
e68c120
f3f18ad
2c23c57
fa70fd2
dc1cd48
c1c05b5
369ea7d
b61df69
3903194
00b5057
3cb7cb5
f366a87
b80c2df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
cf_express_route_circuit_connections, cf_express_route_gateways, cf_express_route_connections, | ||
cf_express_route_ports, cf_express_route_port_locations, cf_express_route_links, cf_app_gateway_waf_policy, | ||
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_virtual_router, cf_virtual_router_peering, cf_service_aliases, cf_bastion_hosts, cf_flow_logs) | ||
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 ( | ||
|
@@ -50,7 +50,7 @@ | |
process_nw_cm_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_show_namespace, | ||
process_nw_flow_log_set_namespace, process_nw_flow_log_create_namespace, process_nw_flow_log_show_namespace, | ||
process_nw_packet_capture_create_namespace, process_nw_test_connectivity_namespace, process_nw_topology_namespace, | ||
process_nw_troubleshooting_start_namespace, process_nw_troubleshooting_show_namespace, | ||
process_public_ip_create_namespace, process_tm_endpoint_create_namespace, | ||
|
@@ -300,6 +300,16 @@ def load_command_table(self, _): | |
client_factory=cf_connection_monitor | ||
) | ||
|
||
network_watcher_flow_log_sdk = CliCommandType( | ||
operations_tmpl='azure.mgmt.network.operations#FlowLogsOperations.{}', | ||
client_factory=cf_flow_logs, | ||
) | ||
|
||
network_watcher_flow_log_update_sdk = CliCommandType( | ||
operations_tmpl='azure.cli.command_modules.network.custom#{}', | ||
client_factory=cf_flow_logs, | ||
) | ||
|
||
network_watcher_pc_sdk = CliCommandType( | ||
operations_tmpl='azure.mgmt.network.operations#PacketCapturesOperations.{}', | ||
client_factory=cf_packet_capture | ||
|
@@ -910,9 +920,33 @@ def _make_singular(value): | |
g.command('list', 'list') | ||
|
||
with self.command_group('network watcher flow-log', client_factory=cf_network_watcher, min_api='2016-09-01') as g: | ||
g.custom_command('configure', 'set_nsg_flow_logging', validator=process_nw_flow_log_set_namespace) | ||
g.custom_command('configure', | ||
'set_nsg_flow_logging', | ||
validator=process_nw_flow_log_set_namespace, | ||
deprecate_info=self.deprecate(redirect='network watcher flow-log create', hide=False)) | ||
g.custom_show_command('show', 'show_nsg_flow_logging', validator=process_nw_flow_log_show_namespace) | ||
|
||
with self.command_group('network watcher flow-log', network_watcher_flow_log_sdk, min_api='2019-11-01') as g: | ||
g.custom_command('create', | ||
'create_nw_flow_log', | ||
client_factory=cf_flow_logs, | ||
validator=process_nw_flow_log_create_namespace) | ||
# show command implementation is substituted by show_nsg_flow_logging() | ||
haroldrandom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# after old show command's parameter is deprecated and removed, should refactor this show command implementation | ||
# g.custom_show_command('show', | ||
# 'show_nw_flow_log', | ||
# client_factory=cf_flow_logs, | ||
# validator=process_nw_flow_log_show_namespace) | ||
g.command('list', 'list') | ||
g.command('delete', 'delete') | ||
g.generic_update_command('update', | ||
getter_name='update_nw_flow_log_getter', | ||
getter_type=network_watcher_flow_log_update_sdk, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Answered in next question. |
||
setter_name='update_nw_flow_log_setter', | ||
setter_type=network_watcher_flow_log_update_sdk, | ||
custom_func_name='update_nw_flow_log', | ||
validator=process_nw_flow_log_create_namespace) | ||
|
||
with self.command_group('network watcher troubleshooting', client_factory=cf_network_watcher, min_api='2016-09-01') as g: | ||
g.custom_command('start', 'start_nw_troubleshooting', supports_no_wait=True, validator=process_nw_troubleshooting_start_namespace) | ||
g.custom_show_command('show', 'show_nw_troubleshooting_result', validator=process_nw_troubleshooting_show_namespace) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4381,10 +4381,131 @@ def set_nsg_flow_logging(cmd, client, watcher_rg, watcher_name, nsg, storage_acc | |
return client.set_flow_log_configuration(watcher_rg, watcher_name, config) | ||
|
||
|
||
def show_nsg_flow_logging(client, watcher_rg, watcher_name, nsg, resource_group_name=None): | ||
# why need 2 different names (watcher_name and network_watcher_name) for watcher? | ||
# It's temporary solution for compatible with old show command's parameter. | ||
# After old show command's parameter is deprecated, those parameters for should be removed. | ||
def show_nsg_flow_logging(cmd, client, watcher_rg, watcher_name, resource_group_name=None, nsg=None, | ||
network_watcher_name=None, flow_log_name=None): | ||
# new approach to show flow log | ||
if all([resource_group_name, network_watcher_name, flow_log_name]): | ||
from ._client_factory import cf_flow_logs | ||
client = cf_flow_logs(cmd.cli_ctx, None) | ||
return client.get(resource_group_name, network_watcher_name, flow_log_name) | ||
|
||
# deprecated approach to show flow log | ||
return client.get_flow_log_status(watcher_rg, watcher_name, nsg) | ||
|
||
|
||
def create_nw_flow_log(cmd, | ||
client, | ||
watcher_rg, | ||
watcher_name, | ||
flow_log_name, | ||
nsg, | ||
storage_account=None, | ||
resource_group_name=None, | ||
location=None, | ||
enabled=None, | ||
retention=0, | ||
log_format=None, | ||
log_version=None, | ||
traffic_analytics_workspace=None, | ||
traffic_analytics_interval=60, | ||
traffic_analytics_enabled=None, | ||
tags=None): | ||
FlowLog = cmd.get_models('FlowLog') | ||
flow_log = FlowLog(location=location, | ||
target_resource_id=nsg, | ||
storage_id=storage_account, | ||
enabled=enabled, | ||
tags=tags) | ||
|
||
if retention > 0: | ||
RetentionPolicyParameters = cmd.get_models('RetentionPolicyParameters') | ||
retention_policy = RetentionPolicyParameters(days=retention, enabled=(retention > 0)) | ||
flow_log.retention_policy = retention_policy | ||
|
||
if log_format is not None or log_version is not None: | ||
FlowLogFormatParameters = cmd.get_models('FlowLogFormatParameters') | ||
format_config = FlowLogFormatParameters(type=log_format, version=log_version) | ||
flow_log.format = format_config | ||
|
||
if traffic_analytics_workspace is not None: | ||
TrafficAnalyticsProperties, TrafficAnalyticsConfigurationProperties = \ | ||
cmd.get_models('TrafficAnalyticsProperties', 'TrafficAnalyticsConfigurationProperties') | ||
|
||
from azure.cli.core.commands.arm import get_arm_resource_by_id | ||
workspace = get_arm_resource_by_id(cmd.cli_ctx, traffic_analytics_workspace) | ||
if not workspace: | ||
raise CLIError('Name or ID of workspace is invalid') | ||
|
||
traffic_analytics_config = TrafficAnalyticsConfigurationProperties( | ||
enabled=traffic_analytics_enabled, | ||
workspace_id=workspace.properties['customerId'], | ||
workspace_region=workspace.location, | ||
workspace_resource_id=workspace.id, | ||
traffic_analytics_interval=traffic_analytics_interval | ||
) | ||
traffic_analytics = TrafficAnalyticsProperties( | ||
network_watcher_flow_analytics_configuration=traffic_analytics_config | ||
) | ||
|
||
flow_log.flow_analytics_configuration = traffic_analytics | ||
|
||
return client.create_or_update(watcher_rg, watcher_name, flow_log_name, flow_log) | ||
|
||
|
||
def update_nw_flow_log_getter(client, watcher_rg, network_watcher_name, flow_log_name): | ||
return client.get(watcher_rg, network_watcher_name, flow_log_name) | ||
|
||
|
||
def update_nw_flow_log_setter(client, watcher_rg, network_watcher_name, flow_log_name, parameters): | ||
return client.create_or_update(watcher_rg, network_watcher_name, flow_log_name, parameters) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's just a wrapper? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the network_watcher_name for the |
||
|
||
|
||
def update_nw_flow_log(cmd, | ||
instance, | ||
location=None, # dummy parameter to let it appear in command | ||
resource_group_name=None, # dummy parameter to let it appear in command | ||
enabled=None, | ||
storage_account=None, | ||
retention=0, | ||
log_format=None, | ||
log_version=None, | ||
traffic_analytics_workspace=None, | ||
traffic_analytics_interval=60, | ||
traffic_analytics_enabled=None, | ||
tags=None): | ||
with cmd.update_context(instance) as c: | ||
c.set_param('enabled', enabled) | ||
c.set_param('tags', tags) | ||
c.set_param('storage_id', storage_account) | ||
|
||
with cmd.update_context(instance.retention_policy) as c: | ||
c.set_param('days', retention) | ||
c.set_param('enabled', retention > 0) | ||
|
||
with cmd.update_context(instance.format) as c: | ||
c.set_param('type', log_format) | ||
c.set_param('version', log_version) | ||
|
||
if traffic_analytics_workspace is not None: | ||
from azure.cli.core.commands.arm import get_arm_resource_by_id | ||
workspace = get_arm_resource_by_id(cmd.cli_ctx, traffic_analytics_workspace) | ||
if not workspace: | ||
raise CLIError('Name or ID of workspace is invalid') | ||
|
||
with cmd.update_context( | ||
instance.flow_analytics_configuration.network_watcher_flow_analytics_configuration) as c: | ||
c.set_param('enabled', traffic_analytics_enabled) | ||
c.set_param('workspace_id', workspace.properties['customerId']) | ||
c.set_param('workspace_region', workspace.location) | ||
c.set_param('workspace_resource_id', workspace.id) | ||
c.set_param('traffic_analytics_interval', traffic_analytics_interval) | ||
|
||
return instance | ||
|
||
|
||
def start_nw_troubleshooting(cmd, client, watcher_name, watcher_rg, resource, storage_account, | ||
storage_path, resource_type=None, resource_group_name=None, | ||
no_wait=False): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a little bit confusing to me. What's the meaning of
Azure Resource Management formatted
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure. Just want user to know the output is different from the older one. Any suggestion to do this?