diff options
author | Steve McIntyre <steve.mcintyre@linaro.org> | 2014-12-05 16:51:41 +0000 |
---|---|---|
committer | Steve McIntyre <steve.mcintyre@linaro.org> | 2014-12-05 16:51:41 +0000 |
commit | ae95fd65a43c16737e2e2cc2e5b53cd8ab6c1da7 (patch) | |
tree | d58e3afdece74b187d2cb0bb3be179427716f27d /admin.py | |
parent | 028b3cc174b74188aab4ed815c13d49f409a79f7 (diff) |
Factor out parsing of True/False values
Change-Id: Icbceeaeb0f6b6a7005f3960979d0d775750404ff
Diffstat (limited to 'admin.py')
-rw-r--r-- | admin.py | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -35,6 +35,14 @@ from db.db import VlanDB version = "0.0.0-DEV" banner = "Linaro VLANd admin interface, version %s" % version +def is_positive(text): + if text in ('1', 'y', 'Y', 't', 'T', 'True'): + return True + elif text in ('0', 'n', 'N', 'f', 'F', 'False'): + return False + else: + raise InputError("Cannot parse \"%s\" as True or False" % text) + def dump_switch(switch): print switch @@ -280,13 +288,10 @@ elif opts.create_port is not None: except InputError as inst: print 'Failed: %s' % inst elif opts.create_vlan is not None: - is_base = False - if opts.create_vlan[2] in ('1', 'y', 'Y'): - is_base = True try: vlan_id = db.create_vlan(opts.create_vlan[0], opts.create_vlan[1], - is_base) + is_positive(opts.create_vlan[2])) print 'Created vlan_id %d' % vlan_id except InputError as inst: print 'Failed: %s' % inst |