diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/ifconfig.py | 33 | ||||
-rw-r--r-- | python/vyos/validate.py | 2 |
2 files changed, 15 insertions, 20 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index 430b3c4e4..7f03befeb 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -143,7 +143,7 @@ class Control: """ Using the defined names, get data write from sysfs. """ - filename = self._sysfs_get[name]['location'].format(config) + filename = self._sysfs_get[name]['location'].format(**config) if not filename: return None return self._read_sysfs(filename) @@ -283,10 +283,9 @@ class Interface(Control): self.config = deepcopy(self.default) self.config['ifname'] = ifname - for k in kargs: - if k not in self.options: - raise ConfigError('invalid option {} for {}'.format(k,self.__class__)) - self.config[k] = kargs[k] + for k in self.options: + if k in kargs: + self.config[k] = kargs[k] for k in self.required: if k not in kargs: @@ -1062,32 +1061,31 @@ class BridgeIf(Interface): _sysfs_set = {**Interface._sysfs_set, **{ 'ageing_time': { 'validate': assert_positive, - 'convert': lambda time: int(time) * 100, + 'convert': lambda t: int(t) * 100, 'location': '/sys/class/net/{ifname}/bridge/ageing_time', }, 'forward_delay': { 'validate': assert_positive, - 'convert': lambda time: int(time) * 100, + 'convert': lambda t: int(t) * 100, 'location': '/sys/class/net/{ifname}/bridge/forward_delay', }, 'hello_time': { 'validate': assert_positive, - 'convert': lambda time: int(time) * 100, + 'convert': lambda t: int(t) * 100, 'location': '/sys/class/net/{ifname}/bridge/hello_time', }, 'max_age': { 'validate': assert_positive, - 'convert': lambda time: int(time) * 100, + 'convert': lambda t: int(t) * 100, 'location': '/sys/class/net/{ifname}/bridge/max_age', }, 'priority': { 'validate': assert_positive, - 'convert': lambda time: int(time) * 100, 'location': '/sys/class/net/{ifname}/bridge/priority', }, 'stp': { 'validate': assert_boolean, - 'location': '/sys/class/net/{ifconfig}/bridge/stp_state', + 'location': '/sys/class/net/{ifname}/bridge/stp_state', }, 'multicast_querier': { 'validate': assert_boolean, @@ -1097,11 +1095,9 @@ class BridgeIf(Interface): _command_set = {**Interface._command_set, **{ 'add_port': { - 'validate': assert_boolean, 'shellcmd': 'ip link set dev {value} master {ifname}', }, 'del_port': { - 'validate': assert_boolean, 'shellcmd': 'ip link set dev {value} nomaster', }, }} @@ -1166,7 +1162,7 @@ class BridgeIf(Interface): >>> from vyos.ifconfig import BridgeIf >>> BridgeIf('br0').set_priority(8192) """ - self.set_interface('priority', time) + self.set_interface('priority', priority) def set_stp(self, state): """ @@ -1307,8 +1303,8 @@ class VLANIf(Interface): opt_e = 'egress-qos-map ' + egress_qos # create interface in the system - cmd = 'ip link add link {intf} name {intf}.{vlan} type vlan {proto} id {vlan} {opt_e} {opt_i}' \ - .format(intf=self.config['ifname'], vlan=self._vlan_id, proto=ethertype, opt_e=opt_e, opt_i=opt_i) + cmd = 'ip link add link {ifname} name {ifname}.{vlan} type vlan {proto} id {vlan} {opt_e} {opt_i}' \ + .format(ifname=self.config['ifname'], vlan=self._vlan_id, proto=ethertype, opt_e=opt_e, opt_i=opt_i) self._cmd(cmd) # return new object mapping to the newly created interface @@ -1563,7 +1559,7 @@ class MACVLANIf(VLANIf): super().__init__(ifname, **kargs) def _create(self): - cmd = 'ip link add {intf} link {link} type macvlan mode {mode}'.format(**self.config) + cmd = 'ip link add {ifname} link {link} type macvlan mode {mode}'.format(**self.config) self._cmd(cmd) @staticmethod @@ -2032,8 +2028,7 @@ class VXLANIf(Interface): if self.config['dev']: dev = 'dev {}'.format(self.config['dev']) - cmd = 'ip link add {intf} type vxlan id {vni} {grp_rem} {dev} dstport {port}' \ - .format(intf=self.config['ifname'], vni=self.config['vni'], grp_rem=group, dev=dev, port=self.config['port']) + cmd = 'ip link add {ifname} type vxlan id {vni} {group} {dev} dstport {port}'.format(**config) self._cmd(cmd) @staticmethod diff --git a/python/vyos/validate.py b/python/vyos/validate.py index 4dca82dd8..48a18642b 100644 --- a/python/vyos/validate.py +++ b/python/vyos/validate.py @@ -187,7 +187,7 @@ def assert_list(s, l): def assert_number(n): - if not n.isnumeric(): + if not str(n).isnumeric(): raise ValueError(f'{n} must be a number') |