Utilize salt.utils.validate.net.* and _raise_error_iface

This commit is contained in:
Sean Jenkins 2017-10-25 11:16:27 -06:00
parent 6818f3631d
commit b97e8046ca
No known key found for this signature in database
GPG Key ID: 42A215FB270D94BD

View File

@ -692,11 +692,27 @@ def _parse_settings_eth(opts, iface_type, enabled, iface):
if 'ipaddrs' in opts:
result['ipaddrs'] = []
for opt in opts['ipaddrs']:
ip, prefix = [i.strip() for i in opt.split('/')]
result['ipaddrs'].append({'ipaddr': ip, 'prefix': prefix})
try:
if salt.utils.validate.net.ipv4_addr(opt):
ip, prefix = [i.strip() for i in opt.split('/')]
result['ipaddrs'].append({'ipaddr': ip, 'prefix': prefix})
else:
msg = 'ipv4 address is invalid'
log.error(msg)
raise AttributeError(msg)
except Exception:
_raise_error_iface(iface, 'ipaddrs', ['127.0.0.1/8'])
if 'ipv6addrs' in opts:
result['ipv6addrs'] = opts['ipv6addrs']
for opt in opts['ipv6addrs']:
try:
if not salt.utils.validate.net.ipv6_addr(opt):
msg = 'ipv6 address is invalid'
log.error(msg)
raise AttributeError(msg)
result['ipv6addrs'] = opts['ipv6addrs']
except Exception:
_raise_error_iface(iface, 'ipv6addrs', ['fc00::1/128'])
if 'enable_ipv6' in opts:
result['enable_ipv6'] = opts['enable_ipv6']