|
| 1 | +import click |
| 2 | + |
| 3 | +def get_attr_full_name(ctx, threshold): |
| 4 | + attr = 'dash_' |
| 5 | + |
| 6 | + if ctx.obj["crm"].addr_family: |
| 7 | + attr += ctx.obj["crm"].addr_family + '_' |
| 8 | + |
| 9 | + if ctx.obj["crm"].direction: |
| 10 | + attr += ctx.obj["crm"].direction + '_' |
| 11 | + |
| 12 | + attr += ctx.obj["crm"].res_type + '_' + threshold |
| 13 | + return attr |
| 14 | + |
| 15 | +@click.command('type') |
| 16 | +@click.argument('value', type=click.Choice(['percentage', 'used', 'free'])) |
| 17 | +@click.pass_context |
| 18 | +def config_dash_type(ctx, value): |
| 19 | + """CRM threshold type configuration""" |
| 20 | + ctx.obj["crm"].config(get_attr_full_name(ctx, 'threshold_type'), value) |
| 21 | + |
| 22 | +@click.command('low') |
| 23 | +@click.argument('value', type=click.INT) |
| 24 | +@click.pass_context |
| 25 | +def config_dash_low(ctx, value): |
| 26 | + """CRM low threshold configuration""" |
| 27 | + ctx.obj["crm"].config(get_attr_full_name(ctx, 'low_threshold'), value) |
| 28 | + |
| 29 | +@click.command('high') |
| 30 | +@click.argument('value', type=click.INT) |
| 31 | +@click.pass_context |
| 32 | +def config_dash_high(ctx, value): |
| 33 | + """CRM high threshold configuration""" |
| 34 | + ctx.obj["crm"].config(get_attr_full_name(ctx, 'high_threshold'), value) |
| 35 | + |
| 36 | +def group_add_thresholds(group): |
| 37 | + group.add_command(config_dash_type) |
| 38 | + group.add_command(config_dash_low) |
| 39 | + group.add_command(config_dash_high) |
| 40 | + |
| 41 | +@click.group('dash') |
| 42 | +@click.pass_context |
| 43 | +def config_dash(ctx): |
| 44 | + """CRM configuration for DASH resource""" |
| 45 | + pass |
| 46 | + |
| 47 | +@config_dash.group('ipv4') |
| 48 | +@click.pass_context |
| 49 | +def config_dash_ipv4(ctx): |
| 50 | + """DASH CRM resource IPv4 address family""" |
| 51 | + ctx.obj["crm"].addr_family = 'ipv4' |
| 52 | + |
| 53 | +@config_dash.group('ipv6') |
| 54 | +@click.pass_context |
| 55 | +def config_dash_ipv6(ctx): |
| 56 | + """DASH CRM resource IPv6 address family""" |
| 57 | + ctx.obj["crm"].addr_family = 'ipv6' |
| 58 | + |
| 59 | +@click.group('inbound') |
| 60 | +@click.pass_context |
| 61 | +def config_dash_inbound(ctx): |
| 62 | + """DASH CRM inbound direction resource""" |
| 63 | + ctx.obj["crm"].direction = 'inbound' |
| 64 | + |
| 65 | +config_dash_ipv4.add_command(config_dash_inbound) |
| 66 | +config_dash_ipv6.add_command(config_dash_inbound) |
| 67 | + |
| 68 | +@click.group('outbound') |
| 69 | +@click.pass_context |
| 70 | +def config_dash_outbound(ctx): |
| 71 | + """DASH CRM outbound direction resource""" |
| 72 | + ctx.obj["crm"].direction = 'outbound' |
| 73 | + |
| 74 | +config_dash_ipv4.add_command(config_dash_outbound) |
| 75 | +config_dash_ipv6.add_command(config_dash_outbound) |
| 76 | + |
| 77 | +@config_dash.group('eni') |
| 78 | +@click.pass_context |
| 79 | +def config_dash_eni(ctx): |
| 80 | + """CRM configuration for DASH ENI resource""" |
| 81 | + ctx.obj["crm"].res_type = 'eni' |
| 82 | + |
| 83 | +group_add_thresholds(config_dash_eni) |
| 84 | + |
| 85 | +@config_dash.group('eni-ether-address') |
| 86 | +@click.pass_context |
| 87 | +def config_dash_eni_ether_address_map(ctx): |
| 88 | + """CRM configuration for DASH ENI ETHER address map entry""" |
| 89 | + ctx.obj["crm"].res_type = 'eni_ether_address_map' |
| 90 | + |
| 91 | +group_add_thresholds(config_dash_eni_ether_address_map) |
| 92 | + |
| 93 | +@config_dash.group('vnet') |
| 94 | +@click.pass_context |
| 95 | +def config_dash_vnet(ctx): |
| 96 | + """CRM configuration for DASH VNET resource""" |
| 97 | + ctx.obj["crm"].res_type = 'vnet' |
| 98 | + |
| 99 | +group_add_thresholds(config_dash_vnet) |
| 100 | + |
| 101 | +@click.group('routing') |
| 102 | +@click.pass_context |
| 103 | +def config_dash_routing(ctx): |
| 104 | + """CRM configuration for DASH inbound routes""" |
| 105 | + ctx.obj["crm"].res_type = 'routing' |
| 106 | + |
| 107 | +group_add_thresholds(config_dash_routing) |
| 108 | +config_dash_inbound.add_command(config_dash_routing) |
| 109 | +config_dash_outbound.add_command(config_dash_routing) |
| 110 | + |
| 111 | +@click.group('pa-validation') |
| 112 | +@click.pass_context |
| 113 | +def config_dash_pa_validation(ctx): |
| 114 | + """CRM configuration for DASH PA validation entries""" |
| 115 | + ctx.obj["crm"].res_type = 'pa_validation' |
| 116 | + |
| 117 | +group_add_thresholds(config_dash_pa_validation) |
| 118 | +config_dash_ipv4.add_command(config_dash_pa_validation) |
| 119 | +config_dash_ipv6.add_command(config_dash_pa_validation) |
| 120 | + |
| 121 | +@click.group('ca-to-pa') |
| 122 | +@click.pass_context |
| 123 | +def config_dash_ca_to_pa(ctx): |
| 124 | + """CRM configuration for DASH CA to PA entries""" |
| 125 | + ctx.obj["crm"].res_type = 'ca_to_pa' |
| 126 | + |
| 127 | +group_add_thresholds(config_dash_ca_to_pa) |
| 128 | +config_dash_outbound.add_command(config_dash_ca_to_pa) |
| 129 | + |
| 130 | +@click.group('acl') |
| 131 | +@click.pass_context |
| 132 | +def config_dash_acl(ctx): |
| 133 | + """DASH CRM ACL resource""" |
| 134 | + |
| 135 | +config_dash_ipv4.add_command(config_dash_acl) |
| 136 | +config_dash_ipv6.add_command(config_dash_acl) |
| 137 | + |
| 138 | +@click.group('group') |
| 139 | +@click.pass_context |
| 140 | +def config_dash_acl_group(ctx): |
| 141 | + """CRM configuration for DASH ACL group entries""" |
| 142 | + ctx.obj["crm"].res_type = 'acl_group' |
| 143 | + |
| 144 | +group_add_thresholds(config_dash_acl_group) |
| 145 | +config_dash_acl.add_command(config_dash_acl_group) |
| 146 | + |
| 147 | +@click.group('rule') |
| 148 | +@click.pass_context |
| 149 | +def config_dash_acl_rule(ctx): |
| 150 | + """CRM configuration for DASH ACL rule entries""" |
| 151 | + ctx.obj["crm"].res_type = 'acl_rule' |
| 152 | + |
| 153 | +group_add_thresholds(config_dash_acl_rule) |
| 154 | +config_dash_acl.add_command(config_dash_acl_rule) |
| 155 | + |
0 commit comments