Factor out parsing of True/False values
Change-Id: Icbceeaeb0f6b6a7005f3960979d0d775750404ff
diff --git a/admin.py b/admin.py
index d4b3a92..a77d79f 100644
--- a/admin.py
+++ b/admin.py
@@ -35,6 +35,14 @@
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 @@
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