Skip to content

Commit

Permalink
Merge pull request #43 from jbrawdy/master
Browse files Browse the repository at this point in the history
Added write function to inventory script and redfish utilities
  • Loading branch information
mraineri authored Jul 9, 2020
2 parents 30d39bf + 728d8bd commit ad5b260
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__pycache__/
dist/
*.egg-info/

*.xlsx
launch.json
1 change: 1 addition & 0 deletions redfish_utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .accounts import modify_user
from .inventory import get_system_inventory
from .inventory import print_system_inventory
from .inventory import write_system_inventory
from .logs import log_container
from .logs import get_log_entries
from .logs import print_log_entries
Expand Down
48 changes: 48 additions & 0 deletions redfish_utilities/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Redfish service for an inventory of components
"""

import xlsxwriter

def get_system_inventory( context ):
"""
Walks a Redfish service for system component information, such as drives,
Expand Down Expand Up @@ -284,3 +286,49 @@ def print_system_inventory( inventory_list, details = False, skip_absent = False
if item[detail] is not None:
print( inventory_line_format_detail.format( "", detail, item[detail] ) )
print( "" )


def write_system_inventory( inventory_list, file_name):
"""
Write the system inventory list into a spreadsheet
Args:
inventory_list: The inventory list to write to an Excel spreadsheet
"""

# Excel workbook to save data extracted and parsed
workbook = xlsxwriter.Workbook(f"./{file_name}.xlsx")

worksheet = workbook.add_worksheet("Device Inventory")
cell_header_format = workbook.add_format({'bold': True, 'bg_color': 'yellow'})
cell_name_format = workbook.add_format({'bold': True})

column = 0
row = 0

# Adds header to Excel file
header = ["NAME", "DESCRIPTION", "MANUFACTURER", "MODEL", "SKU", "PART NUMBER", "SERIAL NUMBER", "ASSET TAG" ]
for column_title in header:
worksheet.write(row, column, column_title, cell_header_format)
column += 1
row = 1




for chassis in inventory_list:
# Go through each component type in the chassis
type_list = [ "Chassis", "Processors", "Memory", "Drives", "PCIeDevices", "StorageControllers", "NetworkAdapters" ]
for inv_type in type_list:
# Go through each component and prints its info
for item in chassis[inv_type]:
column = 0
worksheet.write(row, column, inv_type, cell_name_format)
column += 1
detail_list = [ "Description", "Manufacturer", "Model", "SKU", "PartNumber", "SerialNumber", "AssetTag" ]
for detail in detail_list:
worksheet.write(row, column, item[detail] )
column += 1
row += 1

workbook.close()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
redfish>=2.1.0
XlsxWriter>=1.2.7
5 changes: 5 additions & 0 deletions scripts/rf_sys_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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 if the full details of each component should be shown" )
argget.add_argument( "--noabsent", "-noabsent", action = "store_true", help = "Indicates if absent devices should be skipped" )
argget.add_argument( "--write", "-w", nargs = "?", const = "Device_Inventory", type = str, help = "Indicates if the inventory should be written to a spreadsheet and what the file name should be if given" )
args = argget.parse_args()

# Set up the Redfish object
Expand All @@ -35,6 +36,10 @@
# Get and print the system inventory
inventory = redfish_utilities.get_system_inventory( redfish_obj )
redfish_utilities.print_system_inventory( inventory, details = args.details, skip_absent = args.noabsent )

if(args.write):
redfish_utilities.write_system_inventory( inventory, args.write )

finally:
# Log out
redfish_obj.logout()

0 comments on commit ad5b260

Please sign in to comment.