summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-01-12 18:43:40 +0100
committerChristian Poessinger <christian@poessinger.com>2021-01-12 21:23:04 +0100
commit92f3673538e0328488c14c90c8acf7ea6b2141ba (patch)
treeba74310b2e2e248db02a1d14f177cd887f55cc78 /python
parent7e9f934194551ac895bfd5321bfdc146c9eca6a4 (diff)
downloadvyos-1x-92f3673538e0328488c14c90c8acf7ea6b2141ba.tar.gz
vyos-1x-92f3673538e0328488c14c90c8acf7ea6b2141ba.zip
ifconfig: T2653: use iproute2 commands for alias, mac and mtu set()/get()
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ifconfig/interface.py47
1 files changed, 24 insertions, 23 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index 4c05ac613..ba0a8adc0 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -79,6 +79,14 @@ class Interface(Control):
'shellcmd': 'ip -json link show dev {ifname}',
'format': lambda j: 'up' if 'UP' in jmespath.search('[*].flags | [0]', json.loads(j)) else 'down',
},
+ 'alias': {
+ 'shellcmd': 'ip -json -detail link list dev {ifname}',
+ 'format': lambda j: jmespath.search('[*].ifalias | [0]', json.loads(j)),
+ },
+ 'mac': {
+ 'shellcmd': 'ip -json -detail link list dev {ifname}',
+ 'format': lambda j: jmespath.search('[*].address | [0]', json.loads(j)),
+ },
'min_mtu': {
'shellcmd': 'ip -json -detail link list dev {ifname}',
'format': lambda j: jmespath.search('[*].min_mtu | [0]', json.loads(j)),
@@ -87,6 +95,14 @@ class Interface(Control):
'shellcmd': 'ip -json -detail link list dev {ifname}',
'format': lambda j: jmespath.search('[*].max_mtu | [0]', json.loads(j)),
},
+ 'mtu': {
+ 'shellcmd': 'ip -json -detail link list dev {ifname}',
+ 'format': lambda j: jmespath.search('[*].mtu | [0]', json.loads(j)),
+ },
+ 'oper_state': {
+ 'shellcmd': 'ip -json -detail link list dev {ifname}',
+ 'format': lambda j: jmespath.search('[*].operstate | [0]', json.loads(j)),
+ },
}
_command_set = {
@@ -94,40 +110,25 @@ class Interface(Control):
'validate': lambda v: assert_list(v, ['up', 'down']),
'shellcmd': 'ip link set dev {ifname} {value}',
},
+ 'alias': {
+ 'convert': lambda name: name if name else '',
+ 'shellcmd': 'ip link set dev {ifname} alias "{value}"',
+ },
'mac': {
'validate': assert_mac,
'shellcmd': 'ip link set dev {ifname} address {value}',
},
+ 'mtu': {
+ 'validate': assert_mtu,
+ 'shellcmd': 'ip link set dev {ifname} mtu {value}',
+ },
'vrf': {
'convert': lambda v: f'master {v}' if v else 'nomaster',
'shellcmd': 'ip link set dev {ifname} {value}',
},
}
- _sysfs_get = {
- 'alias': {
- 'location': '/sys/class/net/{ifname}/ifalias',
- },
- 'mac': {
- 'location': '/sys/class/net/{ifname}/address',
- },
- 'mtu': {
- 'location': '/sys/class/net/{ifname}/mtu',
- },
- 'oper_state':{
- 'location': '/sys/class/net/{ifname}/operstate',
- },
- }
-
_sysfs_set = {
- 'alias': {
- 'convert': lambda name: name if name else '\0',
- 'location': '/sys/class/net/{ifname}/ifalias',
- },
- 'mtu': {
- 'validate': assert_mtu,
- 'location': '/sys/class/net/{ifname}/mtu',
- },
'arp_cache_tmo': {
'convert': lambda tmo: (int(tmo) * 1000),
'location': '/proc/sys/net/ipv4/neigh/{ifname}/base_reachable_time_ms',