fix creating a nic tag on a link with double 0 in the MAC

otherwise we get a message like '12:34:00:56:78:90 is not present on this system.'
as dladm prints the '00' as '0' and we fail to correctly identify
the existing interface.

Fix a linting issue while here
This commit is contained in:
Jasper Lievisse Adriaanse 2018-03-03 16:31:27 +01:00 committed by Jasper.LievisseAdriaanse
parent a3cb0e576e
commit 47a66975ff

View File

@ -118,7 +118,7 @@ def exists(*nictag, **kwargs):
salt '*' nictagadm.exists admin salt '*' nictagadm.exists admin
''' '''
ret = {} ret = {}
if len(nictag) == 0: if not nictag:
return {'Error': 'Please provide at least one nictag to check.'} return {'Error': 'Please provide at least one nictag to check.'}
cmd = 'nictagadm exists -l {0}'.format(' '.join(nictag)) cmd = 'nictagadm exists -l {0}'.format(' '.join(nictag))
@ -159,7 +159,8 @@ def add(name, mac, mtu=1500):
if mac != 'etherstub': if mac != 'etherstub':
cmd = 'dladm show-phys -m -p -o address' cmd = 'dladm show-phys -m -p -o address'
res = __salt__['cmd.run_all'](cmd) res = __salt__['cmd.run_all'](cmd)
if mac not in res['stdout'].splitlines(): # dladm prints '00' as '0', so account for that.
if mac.replace('00', '0') not in res['stdout'].splitlines():
return {'Error': '{0} is not present on this system.'.format(mac)} return {'Error': '{0} is not present on this system.'.format(mac)}
if mac == 'etherstub': if mac == 'etherstub':
@ -207,7 +208,8 @@ def update(name, mac=None, mtu=None):
else: else:
cmd = 'dladm show-phys -m -p -o address' cmd = 'dladm show-phys -m -p -o address'
res = __salt__['cmd.run_all'](cmd) res = __salt__['cmd.run_all'](cmd)
if mac not in res['stdout'].splitlines(): # dladm prints '00' as '0', so account for that.
if mac.replace('00', '0') not in res['stdout'].splitlines():
return {'Error': '{0} is not present on this system.'.format(mac)} return {'Error': '{0} is not present on this system.'.format(mac)}
if mac and mtu: if mac and mtu: