mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Validate MAC using salt.utils.validate.net.mac()
That was introduced in 01eb5f5
.
This commit is contained in:
parent
154b7ee38b
commit
9d75c7230d
@ -17,6 +17,7 @@ import jinja2.exceptions
|
|||||||
# Import salt libs
|
# Import salt libs
|
||||||
import salt.utils
|
import salt.utils
|
||||||
import salt.utils.templates
|
import salt.utils.templates
|
||||||
|
import salt.utils.validate.net
|
||||||
|
|
||||||
# Set up logging
|
# Set up logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -60,7 +61,6 @@ _RH_CONFIG_BONDING_OPTS = [
|
|||||||
_RH_NETWORK_SCRIPT_DIR = '/etc/sysconfig/network-scripts'
|
_RH_NETWORK_SCRIPT_DIR = '/etc/sysconfig/network-scripts'
|
||||||
_RH_NETWORK_FILE = '/etc/sysconfig/network'
|
_RH_NETWORK_FILE = '/etc/sysconfig/network'
|
||||||
_RH_NETWORK_CONF_FILES = '/etc/modprobe.d'
|
_RH_NETWORK_CONF_FILES = '/etc/modprobe.d'
|
||||||
_MAC_REGEX = re.compile('([0-9A-F]{1,2}:){5}[0-9A-F]{1,2}')
|
|
||||||
_CONFIG_TRUE = ['yes', 'on', 'true', '1', True]
|
_CONFIG_TRUE = ['yes', 'on', 'true', '1', True]
|
||||||
_CONFIG_FALSE = ['no', 'off', 'false', '0', False]
|
_CONFIG_FALSE = ['no', 'off', 'false', '0', False]
|
||||||
_IFACE_TYPES = [
|
_IFACE_TYPES = [
|
||||||
@ -575,7 +575,7 @@ def _parse_settings_eth(opts, iface_type, enabled, iface):
|
|||||||
|
|
||||||
if iface_type not in ['bond', 'vlan', 'bridge']:
|
if iface_type not in ['bond', 'vlan', 'bridge']:
|
||||||
if 'addr' in opts:
|
if 'addr' in opts:
|
||||||
if _MAC_REGEX.match(opts['addr']):
|
if salt.utils.validate.net.mac(opts['addr']):
|
||||||
result['addr'] = opts['addr']
|
result['addr'] = opts['addr']
|
||||||
else:
|
else:
|
||||||
_raise_error_iface(iface, opts['addr'], ['AA:BB:CC:DD:EE:FF'])
|
_raise_error_iface(iface, opts['addr'], ['AA:BB:CC:DD:EE:FF'])
|
||||||
|
@ -10,8 +10,8 @@ def mac(mac):
|
|||||||
Validates a mac address
|
Validates a mac address
|
||||||
'''
|
'''
|
||||||
valid = re.compile(r'''
|
valid = re.compile(r'''
|
||||||
(^([0-9A-F]{2}[-]){5}([0-9A-F]{2})$
|
(^([0-9A-F]{1,2}[-]){5}([0-9A-F]{1,2})$
|
||||||
|^([0-9A-F]{2}[:]){5}([0-9A-F]{2})$)
|
|^([0-9A-F]{1,2}[:]){5}([0-9A-F]{1,2})$)
|
||||||
''',
|
''',
|
||||||
re.VERBOSE|re.IGNORECASE)
|
re.VERBOSE|re.IGNORECASE)
|
||||||
if valid.match(mac) is None:
|
if valid.match(mac) is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user