cmd_mappings.py revision 5089c812
1
2mappings = {}
3
4class SimpleMapping(object):
5
6  def __init__(self, cmd, cli, vat):
7    if cmd in mappings:
8      raise Exception('{} already in cmd db!'.format(cmd))
9
10    self.cmd = cmd
11    self.cli = cli
12    self.vat = vat
13    mappings[cmd] = self
14
15  def generate(self, mode, args):
16    s = ''
17    # simply append arguments string to right command
18    if mode == 'vat':
19      s = self.vat + ' ' + args
20    else:
21      s = self.cli + ' ' + args
22    return s
23
24
25class CustomMapping(SimpleMapping):
26
27  def generate(self, mode, args):
28    s = ''
29    if mode == 'vat':
30      s = self.vat
31    else:
32      s = self.cli
33
34    args = args.split(' ')
35    return s.format(*args)
36
37
38class RepeatableLocators(SimpleMapping):
39
40  def generate(self, mode, args):
41    name = args[:args.index(' ')]  # first word is ls name
42    locs = args[args.index(' '):]
43
44    if mode == 'vat':
45      s = self.vat
46    else:
47      s = self.cli
48
49    s = s + ' ' + name + locs
50    return s
51
52
53SimpleMapping('lisp_state', 'lisp', 'lisp_enable_disable')
54SimpleMapping('lisp_map_resolver', 'lisp map-resolver', 'lisp_add_del_map_resolver')
55SimpleMapping('lisp_local_eid', 'lisp eid-table', 'lisp_add_del_local_eid')
56SimpleMapping('lisp_remote_mapping', 'lisp remote-mapping', 'lisp_add_del_remote_mapping')
57SimpleMapping('lisp_pitr', 'lisp pitr ls', 'lisp_pitr_set_locator_set locator-set')
58SimpleMapping('lisp_adjacency', 'lisp adjacency', 'lisp_add_del_adjacency')
59SimpleMapping('lisp_map_request_mode', 'lisp map-request mode', 'lisp_map_request_mode')
60SimpleMapping('set_if_ip', 'set int ip address', 'sw_interface_add_del_address')
61
62CustomMapping('lisp_eid_map_bd',
63              'lisp eid-table map vni {0} bd {1}',
64              'lisp_eid_table_add_del_map vni {0} bd_index {1}')
65CustomMapping('lisp_eid_map_vrf',
66              'lisp eid-table map vni {0} vrf {1}',
67              'lisp_eid_table_add_del_map vni {0} vrf {1}')
68CustomMapping('set_if_l2_bridge', 'set interface l2 bridge {0} {1}',
69              'sw_interface_set_l2_bridge {0} bd_id {1}')
70CustomMapping('set_if_ip_table', 'set interface ip table {0} {1}',
71              'sw_interface_set_table {0} vrf {1}')
72CustomMapping('lisp_locator_set_with_locator',
73              'lisp locator-set add {0} iface {1} p {2} w {3}',
74              'lisp_add_del_locator_set locator-set {0} iface {1} p {2} w {3}')
75CustomMapping('create_host_iface',
76    'create host-interface name {0}\n'
77    'set int state host-{0} up\n'
78    'set int ip address host-{0} {1}',
79
80    'af_packet_create name {0}\n'
81    'sw_interface_set_flags host-{0} admin-up link-up\n'
82    'sw_interface_add_del_address host-{0} {1}')
83
84CustomMapping('create_host_iface_vrf',
85    'create host-interface name {0}\n'
86    'set int state host-{0} up\n'
87    'set interface ip table host-{0} {2}\n'
88    'set int ip address host-{0} {1}',
89
90    'af_packet_create name {0}\n'
91    'sw_interface_set_flags host-{0} admin-up link-up\n'
92    'sw_interface_set_table host-{0} vrf {2}\n'
93    'sw_interface_add_del_address host-{0} {1}')
94
95CustomMapping('create_host_iface_vrf_v6',
96    'create host-interface name {0}\n'
97    'set int state host-{0} up\n'
98    'set interface ip6 table host-{0} {2}\n'
99    'set int ip address host-{0} {1}',
100
101    'af_packet_create name {0}\n'
102    'sw_interface_set_flags host-{0} admin-up link-up\n'
103    'sw_interface_set_table host-{0} vrf {2} ipv6\n'
104    'sw_interface_add_del_address host-{0} {1}')
105
106RepeatableLocators('lisp_ls_multiple_locs',
107                   'lisp locator-set add',
108                   'lisp_add_del_locator_set locator-set')
109
110