cmd_mappings.py revision 9047c7fb
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', 'one', 'one_enable_disable')
54SimpleMapping('lisp_map_resolver', 'one map-resolver', 'one_add_del_map_resolver')
55SimpleMapping('lisp_map_server', 'one map-server', 'one_add_del_map_server')
56SimpleMapping('lisp_local_eid', 'one eid-table', 'one_add_del_local_eid')
57SimpleMapping('lisp_remote_mapping', 'one remote-mapping', 'one_add_del_remote_mapping')
58SimpleMapping('lisp_pitr', 'one pitr ls', 'one_pitr_set_locator_set locator-set')
59SimpleMapping('lisp_adjacency', 'one adjacency', 'one_add_del_adjacency')
60SimpleMapping('lisp_map_request_mode', 'one map-request mode', 'one_map_request_mode')
61SimpleMapping('set_if_ip', 'set int ip address', 'sw_interface_add_del_address')
62SimpleMapping('lisp_rloc_probe_state', 'one rloc-probe', 'one_rloc_probe_enable_disable')
63SimpleMapping('lisp_map_register_state', 'one map-register', 'one_map_register_enable_disable')
64SimpleMapping('lisp_stats', 'one statistics', 'one_stats_enable_disable')
65
66SimpleMapping('ipsec_sad_add_del_entry', 'TODO', 'ipsec_sad_add_del_entry')
67SimpleMapping('ipsec_spd_add_del', 'todo', 'ipsec_spd_add_del')
68SimpleMapping('ipsec_interface_add_del_spd' , 'todo', 'ipsec_interface_add_del_spd')
69SimpleMapping('ipsec_spd_add_del_entry', 'todo', 'ipsec_spd_add_del_entry')
70
71CustomMapping('lisp_eid_map_bd',
72              'one eid-table map vni {0} bd {1}',
73              'one_eid_table_add_del_map vni {0} bd_index {1}')
74CustomMapping('lisp_eid_map_vrf',
75              'one eid-table map vni {0} vrf {1}',
76              'one_eid_table_add_del_map vni {0} vrf {1}')
77CustomMapping('set_if_l2_bridge', 'set interface l2 bridge {0} {1}',
78              'sw_interface_set_l2_bridge {0} bd_id {1}')
79CustomMapping('set_if_ip_table', 'set interface ip table {0} {1}',
80              'sw_interface_set_table {0} vrf {1}')
81CustomMapping('lisp_locator_set_with_locator',
82              'one locator-set add {0} iface {1} p {2} w {3}',
83              'one_add_del_locator_set locator-set {0} iface {1} p {2} w {3}')
84CustomMapping('create_host_iface',
85    'create host-interface name {0}\n'
86    'set int state host-{0} up\n'
87    'set int ip address host-{0} {1}',
88
89    'af_packet_create name {0}\n'
90    'sw_interface_set_flags host-{0} admin-up link-up\n'
91    'sw_interface_add_del_address host-{0} {1}')
92
93CustomMapping('create_host_iface_vrf',
94    'create host-interface name {0}\n'
95    'set int state host-{0} up\n'
96    'set interface ip table host-{0} {2}\n'
97    'set int ip address host-{0} {1}',
98
99    'af_packet_create name {0}\n'
100    'sw_interface_set_flags host-{0} admin-up link-up\n'
101    'sw_interface_set_table host-{0} vrf {2}\n'
102    'sw_interface_add_del_address host-{0} {1}')
103
104CustomMapping('create_host_iface_vrf_v6',
105    'create host-interface name {0}\n'
106    'set int state host-{0} up\n'
107    'set interface ip6 table host-{0} {2}\n'
108    'set int ip address host-{0} {1}',
109
110    'af_packet_create name {0}\n'
111    'sw_interface_set_flags host-{0} admin-up link-up\n'
112    'sw_interface_set_table host-{0} vrf {2} ipv6\n'
113    'sw_interface_add_del_address host-{0} {1}')
114
115RepeatableLocators('lisp_ls_multiple_locs',
116                   'one locator-set add',
117                   'one_add_del_locator_set locator-set')
118
119