Commit b00dc70a authored by Mark Schouten's avatar Mark Schouten
Browse files

* Fix Regexp for ipv4

* Fix vlanid, we forgot that
parent 1cbc54bd
......@@ -21,7 +21,7 @@ def Get(cfg):
def Validate(document):
def ipv4(teststring):
regex = re.compile('^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/([1-9]|1[0-9]|2[0-4])$')
regex = re.compile('^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/([1-9]|[12][0-9]|3[0-2])$')
if regex.match(teststring):
return teststring
......@@ -47,10 +47,13 @@ def Validate(document):
return ipv4(ip)
def Adminstate(state):
if state.upper() in ['UP', 'DOWN']:
if type(int()) == type(state):
state = list(['DOWN', 'UP'])[state]
if state.upper() in ['UP', 'DOWN', 'UNKNOWN']:
return state.upper()
else:
raise ValueError("Adminstate must be UP or DOWN")
raise ValueError("Adminstate must be UP or DOWN, not %s" % (state))
def Mtu(mtu):
if 65536 >= mtu > 1280:
......@@ -58,6 +61,12 @@ def Validate(document):
else:
raise ValueError("Invalid value for MTU")
def VlanId(vlanid):
if 4096 >= vlanid > 0:
return vlanid
else:
raise ValueError("Invalid value for vlanid")
def Interface(iface, iname):
ret = {}
ret['name'] = iname
......@@ -95,6 +104,13 @@ def Validate(document):
else:
ret['mtu'] = '1500'
try:
ret['vlanid'] = VlanId(iface['vlanid'])
except ValueError as e:
raise e
except KeyError:
pass
try:
if iface['vlans']:
vlans = []
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment