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

[CRM][DASH] Extend CRM utility to support DASH resources. #2800

Merged
merged 1 commit into from
May 31, 2023
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
155 changes: 155 additions & 0 deletions crm/dash_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import click

def get_attr_full_name(ctx, threshold):
attr = 'dash_'

if ctx.obj["crm"].addr_family:
attr += ctx.obj["crm"].addr_family + '_'

if ctx.obj["crm"].direction:
attr += ctx.obj["crm"].direction + '_'

attr += ctx.obj["crm"].res_type + '_' + threshold
return attr

@click.command('type')
@click.argument('value', type=click.Choice(['percentage', 'used', 'free']))
@click.pass_context
def config_dash_type(ctx, value):
"""CRM threshold type configuration"""
ctx.obj["crm"].config(get_attr_full_name(ctx, 'threshold_type'), value)

@click.command('low')
@click.argument('value', type=click.INT)
@click.pass_context
def config_dash_low(ctx, value):
"""CRM low threshold configuration"""
ctx.obj["crm"].config(get_attr_full_name(ctx, 'low_threshold'), value)

@click.command('high')
@click.argument('value', type=click.INT)
@click.pass_context
def config_dash_high(ctx, value):
"""CRM high threshold configuration"""
ctx.obj["crm"].config(get_attr_full_name(ctx, 'high_threshold'), value)

def group_add_thresholds(group):
group.add_command(config_dash_type)
group.add_command(config_dash_low)
group.add_command(config_dash_high)

@click.group('dash')
@click.pass_context
def config_dash(ctx):
"""CRM configuration for DASH resource"""
pass

@config_dash.group('ipv4')
@click.pass_context
def config_dash_ipv4(ctx):
"""DASH CRM resource IPv4 address family"""
ctx.obj["crm"].addr_family = 'ipv4'

@config_dash.group('ipv6')
@click.pass_context
def config_dash_ipv6(ctx):
"""DASH CRM resource IPv6 address family"""
ctx.obj["crm"].addr_family = 'ipv6'

@click.group('inbound')
@click.pass_context
def config_dash_inbound(ctx):
"""DASH CRM inbound direction resource"""
ctx.obj["crm"].direction = 'inbound'

config_dash_ipv4.add_command(config_dash_inbound)
config_dash_ipv6.add_command(config_dash_inbound)

@click.group('outbound')
@click.pass_context
def config_dash_outbound(ctx):
"""DASH CRM outbound direction resource"""
ctx.obj["crm"].direction = 'outbound'

config_dash_ipv4.add_command(config_dash_outbound)
config_dash_ipv6.add_command(config_dash_outbound)

@config_dash.group('eni')
@click.pass_context
def config_dash_eni(ctx):
"""CRM configuration for DASH ENI resource"""
ctx.obj["crm"].res_type = 'eni'

group_add_thresholds(config_dash_eni)

@config_dash.group('eni-ether-address')
@click.pass_context
def config_dash_eni_ether_address_map(ctx):
"""CRM configuration for DASH ENI ETHER address map entry"""
ctx.obj["crm"].res_type = 'eni_ether_address_map'

group_add_thresholds(config_dash_eni_ether_address_map)

@config_dash.group('vnet')
@click.pass_context
def config_dash_vnet(ctx):
"""CRM configuration for DASH VNET resource"""
ctx.obj["crm"].res_type = 'vnet'

group_add_thresholds(config_dash_vnet)

@click.group('routing')
@click.pass_context
def config_dash_routing(ctx):
"""CRM configuration for DASH inbound routes"""
ctx.obj["crm"].res_type = 'routing'

group_add_thresholds(config_dash_routing)
config_dash_inbound.add_command(config_dash_routing)
config_dash_outbound.add_command(config_dash_routing)

@click.group('pa-validation')
@click.pass_context
def config_dash_pa_validation(ctx):
"""CRM configuration for DASH PA validation entries"""
ctx.obj["crm"].res_type = 'pa_validation'

group_add_thresholds(config_dash_pa_validation)
config_dash_ipv4.add_command(config_dash_pa_validation)
config_dash_ipv6.add_command(config_dash_pa_validation)

@click.group('ca-to-pa')
@click.pass_context
def config_dash_ca_to_pa(ctx):
"""CRM configuration for DASH CA to PA entries"""
ctx.obj["crm"].res_type = 'ca_to_pa'

group_add_thresholds(config_dash_ca_to_pa)
config_dash_outbound.add_command(config_dash_ca_to_pa)

@click.group('acl')
@click.pass_context
def config_dash_acl(ctx):
"""DASH CRM ACL resource"""

config_dash_ipv4.add_command(config_dash_acl)
config_dash_ipv6.add_command(config_dash_acl)

@click.group('group')
@click.pass_context
def config_dash_acl_group(ctx):
"""CRM configuration for DASH ACL group entries"""
ctx.obj["crm"].res_type = 'acl_group'

group_add_thresholds(config_dash_acl_group)
config_dash_acl.add_command(config_dash_acl_group)

@click.group('rule')
@click.pass_context
def config_dash_acl_rule(ctx):
"""CRM configuration for DASH ACL rule entries"""
ctx.obj["crm"].res_type = 'acl_rule'

group_add_thresholds(config_dash_acl_rule)
config_dash_acl.add_command(config_dash_acl_rule)

119 changes: 119 additions & 0 deletions crm/dash_show.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import click

def show_resource(ctx, resource):
if ctx.obj["crm"].cli_mode == 'thresholds':
ctx.obj["crm"].show_thresholds(resource)
elif ctx.obj["crm"].cli_mode == 'resources':
ctx.obj["crm"].show_resources(resource)

@click.group('dash')
@click.pass_context
def show_dash(ctx):
"""Show CRM information for DASH"""
pass

@show_dash.group('ipv4')
@click.pass_context
def show_dash_ipv4(ctx):
"""Show CRM information for IPv4 address family"""
ctx.obj["crm"].addr_family = 'ipv4'

@show_dash.group('ipv6')
@click.pass_context
def show_dash_ipv6(ctx):
"""Show CRM information for IPv6 address family"""
ctx.obj["crm"].addr_family = 'ipv6'

@click.group('inbound')
@click.pass_context
def show_dash_inbound(ctx):
"""Show CRM information for inbound direction"""
ctx.obj["crm"].direction = 'inbound'

show_dash_ipv4.add_command(show_dash_inbound)
show_dash_ipv6.add_command(show_dash_inbound)

@click.group('outbound')
@click.pass_context
def show_dash_outbound(ctx):
"""Show CRM information for outbound direction"""
ctx.obj["crm"].direction = 'outbound'

show_dash_ipv4.add_command(show_dash_outbound)
show_dash_ipv6.add_command(show_dash_outbound)

@show_dash.command('vnet')
@click.pass_context
def show_dash_vnet(ctx):
"""Show CRM information for VNETs"""
show_resource(ctx, 'dash_vnet')

@show_dash.command('eni')
@click.pass_context
def show_dash_eni(ctx):
"""Show CRM information for ENIs"""
show_resource(ctx, 'dash_eni')

@show_dash.command('eni-ether-address')
@click.pass_context
def show_dash_eni_ether_address_map(ctx):
"""Show CRM information for ENI ETHER address map entries"""
show_resource(ctx, 'dash_eni_ether_address_map')

@click.command('routing')
@click.pass_context
def show_dash_routing(ctx):
"""Show CRM information for inbound routes"""
resource = f'dash_{ctx.obj["crm"].addr_family}_{ctx.obj["crm"].direction}_routing'
show_resource(ctx, resource)

show_dash_inbound.add_command(show_dash_routing)
show_dash_outbound.add_command(show_dash_routing)

@click.command('pa-validation')
@click.pass_context
def show_dash_pa_validation(ctx):
"""Show CRM information for PA validation entries"""
resource = f'dash_{ctx.obj["crm"].addr_family}_pa_validation'
show_resource(ctx, resource)

show_dash_ipv4.add_command(show_dash_pa_validation)
show_dash_ipv6.add_command(show_dash_pa_validation)

@click.command('ca-to-pa')
@click.pass_context
def show_dash_ca_to_pa(ctx):
"""Show CRM information for CA to PA entries"""
resource = f'dash_{ctx.obj["crm"].addr_family}_{ctx.obj["crm"].direction}_ca_to_pa'
show_resource(ctx, resource)

show_dash_outbound.add_command(show_dash_ca_to_pa)

@click.group('acl')
@click.pass_context
def show_dash_acl(ctx):
"""Show CRM information for ACL resources"""

show_dash_ipv4.add_command(show_dash_acl)
show_dash_ipv6.add_command(show_dash_acl)

@click.command('group')
@click.pass_context
def show_dash_acl_group(ctx):
"""Show CRM information for ACL group entries"""
resource = f'dash_{ctx.obj["crm"].addr_family}_acl_group'
show_resource(ctx, resource)

show_dash_acl.add_command(show_dash_acl_group)

@click.command('rule')
@click.pass_context
def show_dash_acl_rule(ctx):
"""Show CRM information for ACL rule entries"""
resource = f'dash_{ctx.obj["crm"].addr_family}_acl_rule'
if ctx.obj["crm"].cli_mode == 'thresholds':
ctx.obj["crm"].show_thresholds(resource)
elif ctx.obj["crm"].cli_mode == 'resources':
ctx.obj["crm"].show_acl_group_resources(resource)

show_dash_acl.add_command(show_dash_acl_rule)
Loading