summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-09-24 18:10:39 +0200
committerChristian Poessinger <christian@poessinger.com>2019-09-24 18:11:49 +0200
commitd80398b6542b24042961ff6eae657c58c98d93c3 (patch)
tree66fb3964a744694391b99d0b7d46378ec5be8819
parentd77f68ef3198cff019e1e2d74dfe2290800a1ea6 (diff)
downloadvyos-1x-d80398b6542b24042961ff6eae657c58c98d93c3.tar.gz
vyos-1x-d80398b6542b24042961ff6eae657c58c98d93c3.zip
Python/ifconfig: T1557: refactor 'mac' property to set_mac()
-rw-r--r--python/vyos/ifconfig.py22
-rwxr-xr-xsrc/conf_mode/interface-bonding.py4
-rwxr-xr-xsrc/conf_mode/interface-bridge.py2
-rwxr-xr-xsrc/conf_mode/interface-ethernet.py6
4 files changed, 9 insertions, 25 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py
index a128c3d54..afc7bbbf8 100644
--- a/python/vyos/ifconfig.py
+++ b/python/vyos/ifconfig.py
@@ -173,29 +173,13 @@ class Interface:
return self._write_sysfs('/sys/class/net/{}/mtu'
.format(self._ifname), mtu)
- @property
- def mac(self):
- """
- Get/set interface mac address
-
- Example:
- >>> from vyos.ifconfig import Interface
- >>> Interface('eth0').mac
- '00:0c:29:11:aa:cc'
- """
- return self._read_sysfs('/sys/class/net/{}/address'
- .format(self._ifname))
-
- @mac.setter
- def mac(self, mac):
+ def set_mac(self, mac):
"""
- Get/set interface mac address
+ Set interface MAC (Media Access Contrl) address to given value.
Example:
>>> from vyos.ifconfig import Interface
- >>> Interface('eth0').mac = '00:90:43:fe:fe:1b'
- >>> Interface('eth0').mac
- '00:90:43:fe:fe:1b'
+ >>> Interface('eth0').set_mac('00:50:ab:cd:ef:01')
"""
# on interface removal (ethernet) an empty string is passed - ignore it
if not mac:
diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py
index 4a91619f1..fddc73b0f 100755
--- a/src/conf_mode/interface-bonding.py
+++ b/src/conf_mode/interface-bonding.py
@@ -91,7 +91,7 @@ def apply_vlan_config(vlan, config):
vlan.set_mtu(config['mtu'])
# Change VLAN interface MAC address
if config['mac']:
- vlan.mac = config['mac']
+ vlan.set_mac(config['mac'])
# enable/disable VLAN interface
if config['disable']:
@@ -388,7 +388,7 @@ def apply(bond):
# Change interface MAC address
if bond['mac']:
- b.mac = bond['mac']
+ b.set_mac(bond['mac'])
# Bonding policy
b.mode = bond['mode']
diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py
index cb768e082..6be7d6714 100755
--- a/src/conf_mode/interface-bridge.py
+++ b/src/conf_mode/interface-bridge.py
@@ -205,7 +205,7 @@ def apply(bridge):
# Change interface MAC address
if bridge['mac']:
- br.mac = bridge['mac']
+ br.set_mac(bridge['mac'])
# remove interface from bridge
for intf in bridge['member_remove']:
diff --git a/src/conf_mode/interface-ethernet.py b/src/conf_mode/interface-ethernet.py
index 43e598618..7708c0086 100755
--- a/src/conf_mode/interface-ethernet.py
+++ b/src/conf_mode/interface-ethernet.py
@@ -74,7 +74,7 @@ def apply_vlan_config(vlan, config):
vlan.set_mtu(config['mtu'])
# Change VLAN interface MAC address
if config['mac']:
- vlan.mac = config['mac']
+ vlan.set_mac(config['mac'])
# enable/disable VLAN interface
if config['disable']:
@@ -291,9 +291,9 @@ def apply(eth):
# Change interface MAC address - re-set to real hardware address (hw-id)
# if custom mac is removed
if eth['mac']:
- e.mac = eth['mac']
+ e.set_mac(eth['mac'])
else:
- e.mac = eth['hw_id']
+ e.set_mac(eth['hw_id'])
# Maximum Transmission Unit (MTU)
e.set_mtu(eth['mtu'])