mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Utilize salt.utils.validate.net.* and _raise_error_iface
This commit is contained in:
parent
6818f3631d
commit
b97e8046ca
@ -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']
|
||||
|
Loading…
Reference in New Issue
Block a user