Skip to content
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] Improve NSG rule table output format #6184

Merged
merged 1 commit into from
Apr 23, 2018
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 @@ -120,6 +120,24 @@ def transform_nsg_create_output(result):
return {'NewNSG': result.result()}


def transform_nsg_rule_table_output(result):
item = OrderedDict()
item['Name'] = result['name']
item['ResourceGroup'] = result['resourceGroup']
item['Priority'] = result['priority']
item['SourcePortRanges'] = result['sourcePortRange'] or ' '.join(result['sourcePortRanges'])
item['SourceAddressPrefixes'] = result['sourceAddressPrefix'] or ' '.join(result['sourceAddressPrefixes'])
item['SourceASG'] = result['sourceApplicationSecurityGroups'] or 'None'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume returning a string 'None' is the pattern for output, instead of a plain None to be serialized as null eventually

Copy link
Contributor

@yugangw-msft yugangw-msft Apr 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i got it now, that using the string 'None' would preventing the column from missing if the value is None

item['Access'] = result['access']
item['Protocol'] = result['protocol']
item['Direction'] = result['direction']
item['DestinationPortRanges'] = result['destinationPortRange'] or ' '.join(result['destinationPortRanges'])
item['DestinationAddressPrefixes'] = result['destinationAddressPrefix'] or \
' '.join(result['destinationAddressPrefixes'])
item['DestinationASG'] = result['destinationApplicationSecurityGroups'] or 'None'
return item


def transform_vnet_gateway_create_output(result):
result = {'vnetGateway': result.result()} if result else result
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
transform_vpn_connection, transform_vpn_connection_list,
transform_geographic_hierachy_table_output,
transform_service_community_table_output, transform_waf_rule_sets_table_output,
transform_network_usage_list, transform_network_usage_table)
transform_network_usage_list, transform_network_usage_table, transform_nsg_rule_table_output)
from azure.cli.command_modules.network._validators import (
process_ag_create_namespace, process_ag_listener_create_namespace, process_ag_http_settings_create_namespace,
process_ag_rule_create_namespace, process_ag_ssl_policy_set_namespace, process_ag_url_path_map_create_namespace,
Expand Down Expand Up @@ -488,8 +488,8 @@ def _make_singular(value):

with self.command_group('network nsg rule', network_nsg_rule_sdk) as g:
g.command('delete', 'delete')
g.command('show', 'get', exception_handler=empty_on_404)
g.command('list', 'list')
g.command('show', 'get', exception_handler=empty_on_404, table_transformer=transform_nsg_rule_table_output)
g.command('list', 'list', table_transformer=lambda x: [transform_nsg_rule_table_output(i) for i in x])
g.custom_command('create', 'create_nsg_rule_2017_06_01', min_api='2017-06-01')
g.generic_update_command('update', setter_arg_name='security_rule_parameters', min_api='2017-06-01',
custom_func_name='update_nsg_rule_2017_06_01', doc_string_source='SecurityRule')
Expand Down