mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #29440 from rallytime/bp-28925
Back-port #28925 to 2015.8
This commit is contained in:
commit
6cc6f776bc
2 changed files with 167 additions and 0 deletions
|
@ -9,9 +9,11 @@ Manage Dell DRAC.
|
|||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
||||
# Import Salt libs
|
||||
from salt.exceptions import CommandExecutionError
|
||||
import salt.utils
|
||||
|
||||
# Import 3rd-party libs
|
||||
|
@ -1320,3 +1322,98 @@ def bare_rac_cmd(cmd, host=None,
|
|||
return ret['stdout']
|
||||
else:
|
||||
return ret
|
||||
|
||||
|
||||
def _update_firmware(cmd,
|
||||
host=None,
|
||||
admin_username=None,
|
||||
admin_password=None):
|
||||
|
||||
if not admin_username:
|
||||
admin_username = __pillar__['proxy']['admin_username']
|
||||
if not admin_username:
|
||||
admin_password = __pillar__['proxy']['admin_password']
|
||||
|
||||
ret = __execute_ret(cmd,
|
||||
host=host,
|
||||
admin_username=admin_username,
|
||||
admin_password=admin_password)
|
||||
|
||||
if ret['retcode'] == 0:
|
||||
return ret['stdout']
|
||||
else:
|
||||
return ret
|
||||
|
||||
|
||||
def update_firmware(filename,
|
||||
host=None,
|
||||
admin_username=None,
|
||||
admin_password=None):
|
||||
'''
|
||||
Updates firmware using local firmware file
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt dell dracr.update_firmware firmware.exe
|
||||
|
||||
This executes the following command on your FX2
|
||||
(using username and password stored in the pillar data)
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
racadm update –f firmware.exe -u user –p pass
|
||||
|
||||
'''
|
||||
if os.path.exists(filename):
|
||||
return _update_firmware('update -f {0}'.format(filename),
|
||||
host=None,
|
||||
admin_username=None,
|
||||
admin_password=None)
|
||||
else:
|
||||
raise CommandExecutionError('Unable to find firmware file {0}'
|
||||
.format(filename))
|
||||
|
||||
|
||||
def update_firmware_nfs_or_cifs(filename, share,
|
||||
host=None,
|
||||
admin_username=None,
|
||||
admin_password=None):
|
||||
'''
|
||||
Executes the following for CIFS
|
||||
(using username and password stored in the pillar data)
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
racadm update -f <updatefile> -u user –p pass -l //IP-Address/share
|
||||
|
||||
Or for NFS
|
||||
(using username and password stored in the pillar data)
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
racadm update -f <updatefile> -u user –p pass -l IP-address:/share
|
||||
|
||||
|
||||
Salt command for CIFS:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt dell dracr.update_firmware_nfs_or_cifs \
|
||||
firmware.exe //IP-Address/share
|
||||
|
||||
|
||||
Salt command for NFS:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt dell dracr.update_firmware_nfs_or_cifs \
|
||||
firmware.exe IP-address:/share
|
||||
'''
|
||||
if os.path.exists(filename):
|
||||
return _update_firmware('update -f {0} -l {1}'.format(filename, share),
|
||||
host=None,
|
||||
admin_username=None,
|
||||
admin_password=None)
|
||||
else:
|
||||
raise CommandExecutionError('Unable to find firmware file {0}'
|
||||
.format(filename))
|
||||
|
|
|
@ -140,9 +140,12 @@ pillar stated above:
|
|||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
import os
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
|
||||
def __virtual__():
|
||||
return 'chassis.cmd' in __salt__
|
||||
|
@ -545,3 +548,70 @@ def switch(name, ip=None, netmask=None, gateway=None, dhcp=None,
|
|||
|
||||
ret['comment'] = 'Dell chassis switch {0} was updated.'.format(name)
|
||||
return ret
|
||||
|
||||
|
||||
def _firmware_update(firmwarefile='', host='',
|
||||
directory=''):
|
||||
'''
|
||||
Update firmware for a single host
|
||||
'''
|
||||
dest = os.path.join(directory, firmwarefile[7:])
|
||||
|
||||
__salt__['cp.get_file'](firmwarefile, dest)
|
||||
|
||||
username = __pillar__['proxy']['admin_user']
|
||||
password = __pillar__['proxy']['admin_password']
|
||||
__salt__['dracr.update_firmware'](dest,
|
||||
host=host,
|
||||
admin_username=username,
|
||||
admin_password=password)
|
||||
|
||||
|
||||
def firmware_update(hosts=None, directory=''):
|
||||
'''
|
||||
State to update the firmware on host
|
||||
using the ``racadm`` command
|
||||
|
||||
firmwarefile
|
||||
filename (string) starting with ``salt://``
|
||||
host
|
||||
string representing the hostname
|
||||
supplied to the ``racadm`` command
|
||||
directory
|
||||
Directory name where firmwarefile
|
||||
will be downloaded
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
dell-chassis-firmware-update:
|
||||
dellchassis.firmware_update:
|
||||
hosts:
|
||||
cmc:
|
||||
salt://firmware_cmc.exe
|
||||
server-1:
|
||||
salt://firmware.exe
|
||||
directory: /opt/firmwares
|
||||
'''
|
||||
ret = {}
|
||||
ret.changes = {}
|
||||
success = True
|
||||
for host, firmwarefile in hosts:
|
||||
try:
|
||||
_firmware_update(firmwarefile, host, directory)
|
||||
ret['changes'].update({
|
||||
'host': {
|
||||
'comment': 'Firmware update submitted for {0}'.format(host),
|
||||
'success': True,
|
||||
}
|
||||
})
|
||||
except CommandExecutionError as err:
|
||||
success = False
|
||||
ret['changes'].update({
|
||||
'host': {
|
||||
'comment': 'FAILED to update firmware for {0}'.format(host),
|
||||
'success': False,
|
||||
'reason': str(err),
|
||||
}
|
||||
})
|
||||
ret['result'] = success
|
||||
return ret
|
||||
|
|
Loading…
Add table
Reference in a new issue