summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--op-mode-definitions/show-system-info.xml7
-rw-r--r--op-mode-definitions/show-systemintegrity.xml14
-rw-r--r--python/vyos/ifconfig/interface.py35
3 files changed, 39 insertions, 17 deletions
diff --git a/op-mode-definitions/show-system-info.xml b/op-mode-definitions/show-system-info.xml
index ade3829f2..61c947bbe 100644
--- a/op-mode-definitions/show-system-info.xml
+++ b/op-mode-definitions/show-system-info.xml
@@ -51,6 +51,13 @@
</children>
</node>
+ <leafNode name= "integrity">
+ <properties>
+ <help>Checks overall system integrity</help>
+ </properties>
+ <command>sudo ${vyos_op_scripts_dir}/system_integrity.py</command>
+ </leafNode>
+
<leafNode name="kernel-messages">
<properties>
<help>Show messages in kernel ring buffer</help>
diff --git a/op-mode-definitions/show-systemintegrity.xml b/op-mode-definitions/show-systemintegrity.xml
deleted file mode 100644
index 44b5faf68..000000000
--- a/op-mode-definitions/show-systemintegrity.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0"?>
-
-<interfaceDefinition>
- <node name="show">
- <children>
- <leafNode name= "system-integrity">
- <properties>
- <help>checks the integrity of the system</help>
- </properties>
- <command>sudo ${vyos_op_scripts_dir}/system_integrity.py</command>
- </leafNode>
- </children>
- </node>
-</interfaceDefinition>
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index 718fe93db..18256cf99 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -93,6 +93,9 @@ class Interface(Control):
}
_sysfs_get = {
+ 'mac': {
+ 'location': '/sys/class/net/{ifname}/address',
+ },
'mtu': {
'location': '/sys/class/net/{ifname}/mtu',
},
@@ -287,6 +290,17 @@ class Interface(Control):
"""
return self.set_interface('mtu', mtu)
+ def get_mac(self):
+ """
+ Get current interface MAC (Media Access Contrl) address used.
+
+ Example:
+ >>> from vyos.ifconfig import Interface
+ >>> Interface('eth0').get_mac()
+ '00:50:ab:cd:ef:00'
+ """
+ self.get_interface('mac')
+
def set_mac(self, mac):
"""
Set interface MAC (Media Access Contrl) address to given value.
@@ -295,6 +309,16 @@ class Interface(Control):
>>> from vyos.ifconfig import Interface
>>> Interface('eth0').set_mac('00:50:ab:cd:ef:01')
"""
+
+ # If MAC is unchanged, bail out early
+ if mac == self.get_mac():
+ return None
+
+ # MAC address can only be changed if interface is in 'down' state
+ prev_state = self.get_state()
+ if prev_state == 'up':
+ self.set_state('down')
+
self.set_interface('mac', mac)
def set_vrf(self, vrf=''):
@@ -426,7 +450,7 @@ class Interface(Control):
def get_state(self):
"""
- Enable (up) / Disable (down) an interface
+ Get interface administrative state. Function will return 'up' or 'down'
Example:
>>> from vyos.ifconfig import Interface
@@ -436,11 +460,16 @@ class Interface(Control):
cmd = 'ip -json link show dev {}'.format(self.config['ifname'])
tmp = self._cmd(cmd)
out = json.loads(tmp)
- return out[0]['operstate'].lower()
+
+ state = 'down'
+ if 'UP' in out[0]['flags']:
+ state = 'up'
+
+ return state
def set_state(self, state):
"""
- Enable (up) / Disable (down) an interface
+ Set interface administrative state to be 'up' or 'down'
Example:
>>> from vyos.ifconfig import Interface