1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

Support value-in-range with <number> keyword

This allows syntax checking to pass for fields like vxlan-ttl/vxlan-tos
which can be a number in a range OR a string value representing a special
meaning (0-255 or "auto", for instance).  Without this, you can only pass
a --syntax-check for such fields if your value is one of those literally
specified because, for instance, "64" is not "auto", "0", or "255":

invalid value "64": valid attribute values: ['0', '255']
info: exit status 1

Note that _applying_ such configuration still works, because netlink's
acceptance criteria are independent of ifupdown2's.
This commit is contained in:
Sam Osterkil
2021-06-01 13:45:34 -06:00
parent a8dd54b0fa
commit b20f983630
2 changed files with 7 additions and 3 deletions

View File

@ -97,12 +97,14 @@ class vxlan(Addon, moduleBase):
"help": "specifies the TTL value to use in outgoing packets "
"(range 0..255), 0=auto",
"default": "0",
"validvals": ["0", "255"],
"validrange": ["0", "255"],
"validvals": ["<number>", "auto"],
"example": ['vxlan-ttl 42'],
},
"vxlan-tos": {
"help": "specifies the ToS value (range 0..255), 1=inherit",
"validvals": ["inherit", "0", "255"],
"validrange": ["0", "255"],
"validvals": ["<number>", "inherit"],
"example": ['vxlan-tos 42'],
},
"vxlan-mcastgrp": {

View File

@ -1224,7 +1224,9 @@ class ifupdownMain:
def _keyword_number(self, value, validrange=None):
try:
int(value)
int_value = int(value)
if validrange is not None:
return int(validrange[0]) <= int_value <= int(validrange[1])
return True
except Exception as e:
self.logger.debug('keyword: number: %s' % str(e))