Validate MAC using salt.utils.validate.net.mac()

That was introduced in 01eb5f5.
This commit is contained in:
Henrik Holmboe 2013-10-14 19:06:13 +02:00
parent 154b7ee38b
commit 9d75c7230d
2 changed files with 4 additions and 4 deletions

View File

@ -17,6 +17,7 @@ import jinja2.exceptions
# Import salt libs
import salt.utils
import salt.utils.templates
import salt.utils.validate.net
# Set up logging
log = logging.getLogger(__name__)
@ -60,7 +61,6 @@ _RH_CONFIG_BONDING_OPTS = [
_RH_NETWORK_SCRIPT_DIR = '/etc/sysconfig/network-scripts'
_RH_NETWORK_FILE = '/etc/sysconfig/network'
_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_FALSE = ['no', 'off', 'false', '0', False]
_IFACE_TYPES = [
@ -575,7 +575,7 @@ def _parse_settings_eth(opts, iface_type, enabled, iface):
if iface_type not in ['bond', 'vlan', 'bridge']:
if 'addr' in opts:
if _MAC_REGEX.match(opts['addr']):
if salt.utils.validate.net.mac(opts['addr']):
result['addr'] = opts['addr']
else:
_raise_error_iface(iface, opts['addr'], ['AA:BB:CC:DD:EE:FF'])

View File

@ -10,8 +10,8 @@ def mac(mac):
Validates a mac address
'''
valid = re.compile(r'''
(^([0-9A-F]{2}[-]){5}([0-9A-F]{2})$
|^([0-9A-F]{2}[:]){5}([0-9A-F]{2})$)
(^([0-9A-F]{1,2}[-]){5}([0-9A-F]{1,2})$
|^([0-9A-F]{1,2}[:]){5}([0-9A-F]{1,2})$)
''',
re.VERBOSE|re.IGNORECASE)
if valid.match(mac) is None: