File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 2
2
import os
3
3
import yaml
4
4
import subprocess
5
+ import re
5
6
6
7
DOCUMENTATION = '''
7
8
---
@@ -44,10 +45,26 @@ def get_sonic_version_info():
44
45
data = yaml .load (stream )
45
46
return data
46
47
48
+ def valid_mac_address (mac ):
49
+ return bool (re .match ("^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$" , mac ))
50
+
47
51
def get_system_mac ():
48
52
version_info = get_sonic_version_info ()
49
53
50
54
if (version_info ['asic_type' ] == 'mellanox' ):
55
+ # With Mellanox ONIE release(2019.05-5.2.0012) and above
56
+ # "onie_base_mac" was added to /host/machine.conf:
57
+ # onie_base_mac=e4:1d:2d:44:5e:80
58
+ # So we have another way to get the mac address besides decode syseeprom
59
+ # By this can mitigate the dependency on the hw-management service
60
+ base_mac_key = "onie_base_mac"
61
+ machine_vars = get_machine_info ()
62
+ if machine_vars is not None and base_mac_key in machine_vars :
63
+ mac = machine_vars [base_mac_key ]
64
+ mac = mac .strip ()
65
+ if valid_mac_address (mac ):
66
+ return mac
67
+
51
68
get_mac_cmd = "sudo decode-syseeprom -m"
52
69
else :
53
70
get_mac_cmd = "ip link show eth0 | grep ether | awk '{print $2}'"
@@ -59,6 +76,9 @@ def get_system_mac():
59
76
60
77
mac = mac .strip ()
61
78
79
+ if not valid_mac_address (mac ):
80
+ return None
81
+
62
82
# Align last byte of MAC if necessary
63
83
if version_info and version_info ['asic_type' ] == 'centec' :
64
84
last_byte = mac [- 2 :]
You can’t perform that action at this time.
0 commit comments