-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from DMTF/Fix172-Firmware-Inventory
Added 'rf_firmware_inventory.py' script to collect and display firmware versions
- Loading branch information
Showing
6 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Firmware Inventory (rf_firmware_inventory.py) | ||
|
||
Copyright 2019-2025 DMTF. All rights reserved. | ||
|
||
## About | ||
|
||
A tool to collect firmware inventory from a Redfish service. | ||
|
||
## Usage | ||
|
||
``` | ||
usage: rf_firmware_inventory.py [-h] --user USER --password PASSWORD --rhost | ||
RHOST [--details] [--id] [--debug] | ||
A tool to collect firmware inventory from a Redfish service | ||
required arguments: | ||
--user USER, -u USER The user name for authentication | ||
--password PASSWORD, -p PASSWORD | ||
The password for authentication | ||
--rhost RHOST, -r RHOST | ||
The address of the Redfish service (with scheme) | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
--details, -details Indicates details to be shown for each firmware entry | ||
--id, -i Construct inventory names using 'Id' values | ||
--debug Creates debug file showing HTTP traces and exceptions | ||
``` | ||
|
||
The tool will log into the service specified by the *rhost* argument using the credentials provided by the *user* and *password* arguments. | ||
It then retrieves the firmware inventory collection under the update service and prints its contents. | ||
|
||
Example: | ||
|
||
``` | ||
$ rf_firmware_inventory.py -u root -p root -r https://192.168.1.100 -details | ||
Contoso BMC Firmware | Version: 1.45.455b66-rev4 | ||
| Manufacturer: Contoso | ||
| SoftwareId: 1624A9DF-5E13-47FC-874A-DF3AFF143089 | ||
| ReleaseDate: 2017-08-22T12:00:00Z | ||
Contoso Simple Storage Firmware | Version: 2.50 | ||
| Manufacturer: Contoso | ||
| ReleaseDate: 2021-10-18T12:00:00Z | ||
Contoso BIOS Firmware | Version: P79 v1.45 | ||
| Manufacturer: Contoso | ||
| SoftwareId: FEE82A67-6CE2-4625-9F44-237AD2402C28 | ||
| ReleaseDate: 2017-12-06T12:00:00Z | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#! /usr/bin/python | ||
# Copyright Notice: | ||
# Copyright 2019-2025 DMTF. All rights reserved. | ||
# License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/Redfish-Tacklebox/blob/main/LICENSE.md | ||
|
||
""" | ||
Redfish Firmware Inventory | ||
File : rf_firmware_inventory.py | ||
Brief : This script uses the redfish_utilities module to manage firmware inventory | ||
""" | ||
|
||
import argparse | ||
import datetime | ||
import logging | ||
import redfish | ||
import redfish_utilities | ||
import traceback | ||
import sys | ||
from redfish.messages import RedfishPasswordChangeRequiredError | ||
|
||
# Get the input arguments | ||
argget = argparse.ArgumentParser(description="A tool to collect firmware inventory from a Redfish service") | ||
argget.add_argument("--user", "-u", type=str, required=True, help="The user name for authentication") | ||
argget.add_argument("--password", "-p", type=str, required=True, help="The password for authentication") | ||
argget.add_argument("--rhost", "-r", type=str, required=True, help="The address of the Redfish service (with scheme)") | ||
argget.add_argument( | ||
"--details", "-details", action="store_true", help="Indicates details to be shown for each firmware entry" | ||
) | ||
argget.add_argument("--id", "-i", action="store_true", help="Construct inventory names using 'Id' values") | ||
argget.add_argument("--debug", action="store_true", help="Creates debug file showing HTTP traces and exceptions") | ||
args = argget.parse_args() | ||
|
||
if args.debug: | ||
log_file = "rf_firmware_inventory-{}.log".format(datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")) | ||
log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" | ||
logger = redfish.redfish_logger(log_file, log_format, logging.DEBUG) | ||
logger.info("rf_firmware_inventory Trace") | ||
|
||
# Set up the Redfish object | ||
redfish_obj = None | ||
try: | ||
redfish_obj = redfish.redfish_client( | ||
base_url=args.rhost, username=args.user, password=args.password, timeout=15, max_retry=3 | ||
) | ||
redfish_obj.login(auth="session") | ||
except RedfishPasswordChangeRequiredError: | ||
redfish_utilities.print_password_change_required_and_logout(redfish_obj, args) | ||
sys.exit(1) | ||
except Exception: | ||
raise | ||
|
||
exit_code = 0 | ||
try: | ||
firmware_inventory = redfish_utilities.get_firmware_inventory(redfish_obj) | ||
redfish_utilities.print_software_inventory(firmware_inventory, details=args.details, use_id=args.id) | ||
except Exception as e: | ||
if args.debug: | ||
logger.error("Caught exception:\n\n{}\n".format(traceback.format_exc())) | ||
exit_code = 1 | ||
print(e) | ||
finally: | ||
# Log out | ||
redfish_utilities.logout(redfish_obj) | ||
sys.exit(exit_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters