Skip to content

Commit

Permalink
Add hpilo_cli download_rib_firmware all all to download all firmware …
Browse files Browse the repository at this point in the history
…versions

We already supported:

* download_rib_firmware ilotype version, for downloading a specific version
* download_rib_firmware ilotype all, for downloading all firmware
  versions for a specific ilo type
* download-rib_firmware all, for downloading the latest firmware for all
  ilo types

'all all' complements this and allows you to create your own mirror.
  • Loading branch information
seveas committed Oct 5, 2015
1 parent 19216f6 commit 2efbeea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/firmware.rst
Expand Up @@ -26,6 +26,7 @@ that too::
hpilo_cli download_rib_firmware ilo4 # Download latest iLO 4 firmware
hpilo_cli download_rib_firmware ilo4 1.50 # Download a specific firmware version
hpilo_cli download_rib_firmware ilo4 all # Download all firmware versions for iLO 4
hpilo_cli download_rib_firmware all all # Download all firmware versions for all iLO types

.. _`firmware.conf`: https://raw.githubusercontent.com/seveas/python-hpilo/master/firmware.conf

Expand Down Expand Up @@ -89,8 +90,7 @@ auto-update via cron) such a mirror with a simple shellscript::

cd /var/www/html/ilo-firmware
wget -q https://raw.githubusercontent.com/seveas/python-hpilo/master/firmware.conf
hpilo_cli -c /dev/null download_rib_firmware ilo3
hpilo_cli -c /dev/null download_rib_firmware ilo4
hpilo_cli -c /dev/null download_rib_firmware all all

This will download and extract the necessary files to
:file:`/var/www/html/ilo-firmware`.
15 changes: 10 additions & 5 deletions hpilo_cli
Expand Up @@ -22,6 +22,7 @@ import optparse
import os
from pprint import pprint
import sys
import urllib2

ilo_methods = sorted([x for x in dir(hpilo.Ilo) if not x.startswith('_') and x.islower()])

Expand Down Expand Up @@ -304,7 +305,7 @@ def download(ilotype, versions):
config = hpilo_fw.config()
if ilotype == 'all':
for ilotype in sorted(config.keys()):
if ' ' not in ilotype:
if (versions == ['all']) == (' ' in ilotype):
_download(config, ilotype)
else:
if not versions:
Expand All @@ -321,10 +322,14 @@ def _download(config, key):
if key not in config:
sys.stderr.write("Unkown ilo/firmware version: %s\n" % key)
sys.exit(1)
if hpilo_fw.download(key, progress=print_progress):
print("")
else:
print("%s firmware version %s was already downloaded" % (key.split()[0], config[key]['version']))
try:
if hpilo_fw.download(key, progress=print_progress):
print("")
else:
print("%s firmware version %s was already downloaded" % (key.split()[0], config[key]['version']))
except urllib2.HTTPError:
e = sys.exc_info()[1]
print("\n%s" % str(e))

if __name__ == '__main__':
main()
11 changes: 8 additions & 3 deletions hpilo_fw.py
Expand Up @@ -97,11 +97,16 @@ def _parse(scexe, path, filename=None):
raise ValueError("scexe file seems corrupt")

tf = tarfile.open(name="bogus_name_for_old_python_versions", fileobj=BytesIO(tarball), mode='r:gz')
if not filename:
filenames = [x for x in tf.getnames() if x.endswith('.bin')]
filenames = [x for x in tf.getnames() if x.endswith('.bin')]
orig_filename = filename
if not filename or filename not in filenames:
if len(filenames) != 1:
raise ValueError("scexe file seems corrupt")
if filename and filename.lower() != filenames[0].lower():
raise ValueError("scexe file seems corrupt")
filename = filenames[0]

tf.extract(filename, path)
return filename
if filename != filename.lower():
os.rename(filename, filename.lower())
return filename.lower()

0 comments on commit 2efbeea

Please sign in to comment.