Skip to content

Commit

Permalink
Refine the command parsing
Browse files Browse the repository at this point in the history
yeasy committed Jul 20, 2015
1 parent 9ee6532 commit b6d9aa6
Showing 2 changed files with 16 additions and 23 deletions.
32 changes: 12 additions & 20 deletions bin/easyovs
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ from easyovs import VERSION, config
from easyovs.bridge_ctrl import br_addbr, br_delbr, br_addflow, br_delflow, \
br_dump, br_list, br_show
from easyovs.cli import CLI
from easyovs.common import CMDS_ONE, CMDS_TWO, CMDS_OTHER
from easyovs.common import CMDS_ONE, CMDS_BR, CMDS_OTHER
from easyovs.iptables import show_iptables_rules
from easyovs.log import info, debug, error, output, LEVELS, lg
from easyovs.neutron import show_port_info
@@ -61,31 +61,23 @@ class Platform(object):
start = time.time()
cmd = cfg.CONF.cmd
info("cmd = %s\n" % cmd)
if len(cmd.split()) == 1 and cmd in CMDS_ONE:
cmd_split = cmd.split()
if len(cmd_split) == 1 and cmd in CMDS_ONE:
if cmd == 'cli':
CLI()
elif cmd == 'list':
self.list()
elif len(cmd.split()) == 2:
if cmd.split()[1] in CMDS_TWO: # e.g., br0 show
arg, func = cmd.split()[0], cmd.split()[1]
getattr(self, func)(arg)
elif cmd.split()[0] in CMDS_TWO: # e.g., show br0
func, arg = cmd.split()[0], cmd.split()[1]
getattr(self, func)(arg)
else:
output('Wrong command format is given\n')
elif len(cmd.split()) >= 3:
if cmd.split()[1] in CMDS_OTHER: # e.g., br0 delflow 9
br, func, arg = cmd.split()[0], cmd.split()[1], ' '.join(
cmd.split()[2:])
elif len(cmd_split) >= 2:
if cmd_split[1] in CMDS_BR: # e.g., br0 delflow 9
br, func, arg = cmd_split[0], cmd_split[1], ' '.join(
cmd_split[2:])
getattr(self, func)(br, arg.replace(',', ' '))
elif cmd.split()[0] in CMDS_OTHER: # e.g., delflow br0 9
br, func, arg = cmd.split()[1], cmd.split()[0], ' '.join(
cmd.split()[2:])
elif cmd_split[0] in CMDS_BR: # e.g., delflow br0 9
br, func, arg = cmd_split[1], cmd_split[0], ' '.join(
cmd_split[2:])
getattr(self, func)(br, arg.replace(',', ' '))
elif cmd.split()[0] == 'ipt': # e.g., ipt 10.0.0.1, 10.0.0.2
func, arg = cmd.split()[0], ' '.join(cmd.split()[1:])
elif cmd_split[0] in CMDS_OTHER: # e.g., ipt 10.0.0.1, 10.0.0.2
func, arg = cmd_split[0], ' '.join(cmd_split[1:])
getattr(self, func)(arg)
else:
output('Wrong command format is given\n')
7 changes: 4 additions & 3 deletions easyovs/common.py
Original file line number Diff line number Diff line change
@@ -4,8 +4,9 @@

# optional tests to run
CMDS_ONE = ['cli', 'list']
CMDS_TWO = ['addbr', 'delbr', 'dump', 'ipt', 'query', 'show']
CMDS_OTHER = ['addflow', 'delflow']

CMDS_BR = \
['addbr', 'delbr', 'addflow', 'delflow', 'dump', 'show']
CMDS_OTHER = \
['ipt', 'query']
if __name__ == '__main__':
pass

0 comments on commit b6d9aa6

Please sign in to comment.