Skip to main content

Command line tool to inspect and manipulate LSI MegaRAID adapters, such as used in IBM ServeRAID systems and Dell PowerEdge RAID Controller (PERC).

Latest release 20260912.1: Fix project spec.

Many IBM xSeries servers come with LSI Logic MegaRAID RAID controllers, under the name IBM ServerRAID. These controllers are also used by Dell as Dell PowerEdge RAID Controller (PERC).

These can be accessed during the machine boot process via the BIOS screens using a conventional BIOS-like text interface or a ghastly and painful to use GUI interface. However, either of these requires the machine OS to be down.

The RAID adapters can also be accessed while the machine OS is up. For Linux, IBM offer a set of command line tools named MegaCLI_, which are installed in /opt/MegaRAID. Unfortunately, their MegaCLI executable is both fiddly to invoke and, in its reporting mode, produces a barely human readable report which is quite hostlie to machine parsing. I would surmise that someone was told to dump the adapter data in text form, and did so with an ad hoc report; it is pages long and arduous to inspect by eye.

The situation was sufficiently painful that I wrote this module which runs a couple of the report modes and parses their output.

Report Mode

The "report" mode then dumps a short summary report of relevant information which can be eyeballed immediately; RAID configuration and issues are immediately apparent. Here is an example output (the "+" tracing lines are on stderr and recite the underlying MegaCLI commands used):

# mcli report
+ exec py26+ -m cs.app.megacli report
+ exec /opt/MegaRAID/MegaCli/MegaCli64 -CfgDsply -aAll
+ exec /opt/MegaRAID/MegaCli/MegaCli64 -PDlist -aAll
Adapter 0 IBM ServeRAID-MR10i SAS/SATA Controller serial# Pnnnnnnnnn
  Virtual Drive 0
    2 drives, size = 278.464GB, raid = Primary-1, Secondary-0, RAID Level Qualifier-0
      physical drive enc252.devid8 [252:0]
      physical drive enc252.devid7 [252:1]
  4 drives:
    enc252.devid7 [252:1]: VD 0, DG None: 42D0628 279.396 GB, Online, Spun Up
    enc252.devid8 [252:0]: VD 0, DG None: 81Y9671 279.396 GB, Online, Spun Up
    enc252.devid2 [252:2]: VD None, DG None: 42D0628 279.396 GB, Unconfigured(good), Spun Up
    enc252.devid3 [252:3]: VD None, DG None: 42D0628 279.396 GB, Unconfigured(good), Spun Up

Status Mode

The "status" mode recites the RAID status in a series of terse one line summaries; we use its output in our nagios monitoring. Here is an example output (the "+" tracing lines are on stderr, and recite the underlying MegaCLI commands used):

# mcli status
+ exec py26+ -m cs.app.megacli status
+ exec /opt/MegaRAID/MegaCli/MegaCli64 -CfgDsply -aAll
+ exec /opt/MegaRAID/MegaCli/MegaCli64 -PDlist -aAll
OK A0

Locate Mode

The "locate" mode prints a MegaCLI command line which can be used to activate or deactivate the location LED on a specific drive. Here is an example output:

# mcli locate 252:4
/opt/MegaRAID/MegaCli/MegaCli64 -PdLocate -start -physdrv[252:4] -a0

# mcli locate 252:4 stop
/opt/MegaRAID/MegaCli/MegaCli64 -PdLocate -stop -physdrv[252:4] -a0

New_RAID Mode

The "new_raid" mode prints a MegaCLI command line which can be used to instruct the adapter to assemble a new RAID set.

MegaCLI class

The module provides a MegaCLI class which embodies the parsed information from the MegaCLI reporting modes. This can be imported and used for special needs.

.. _MegaCLI: http://www-947.ibm.com/support/entry/portal/docdisplay?lndocid=migr-5082327

Short summary:

Functions

cmd_append(msg, *a)

cmd_pop()

main(argv=None)

merge_attrs(o, **kw)

Classes

class Adapter(types.SimpleNamespace)

Adapter.DRV_by_enc_slot(self, enc_slot)

Find first matching drive by enclosure id and slot number. Report errors on multiple matches - serious misconfiguration. Returns None if no match.

Adapter.__firstlineno__

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.

int('0b100', base=0) 4

Adapter.__static_attributes__

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

class Disk_Group(types.SimpleNamespace)

Disk_Group.__firstlineno__

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.

int('0b100', base=0) 4

Disk_Group.__static_attributes__

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

class Disk_Port(types.SimpleNamespace)

Disk_Port.__firstlineno__

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.

int('0b100', base=0) 4

Disk_Port.__static_attributes__

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

class MegaRAID(types.SimpleNamespace)

MegaRAID.FW_STATES_AVAILABLE

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

MegaRAID.__firstlineno__

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.

int('0b100', base=0) 4

MegaRAID.__static_attributes__

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

MegaRAID.adapters

Mapping of adapter numbers to Adapters.

MegaRAID.docmd(self, *args)

Pretend to execute a megacli command as specified. This currently just echoes commands to stderr; I fear running the "new raid" stuff etc automatically. Return True if the exit code is 0, False otherwise.

MegaRAID.info

Read various megacli query command outputs and construct a data structure with the adpater information.

MegaRAID.locate(self, adapter, enc_slot, do_start=True)

Start or stop to location light on the specified drive.

MegaRAID.new_raid(self, level, enc_slots, adapter=0)

Construct a new RAID device with specified RAID level on adapter using the devices specified by enc_slots.

MegaRAID.offline(self, adapter, enc_slot)

Take a drive offline (==> failed).

MegaRAID.readcmd(self, *args)

Open a pipe from the megacli command and yield lines from its output.

class Physical_Disk(types.SimpleNamespace)

Physical_Disk.__firstlineno__

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.

int('0b100', base=0) 4

Physical_Disk.__static_attributes__

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

Physical_Disk.enc_slot

Identifier used by megacli, regretably not unique if enclosure misconfigure/misinstalled.

Physical_Disk.id

Unique identifier for drive, regrettably not what the megacli wants to use.

class Span(types.SimpleNamespace)

Span.__firstlineno__

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.

int('0b100', base=0) 4

Span.__static_attributes__

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

class Virtual_Drive(types.SimpleNamespace)

Virtual_Drive.__firstlineno__

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.

int('0b100', base=0) 4

Virtual_Drive.__static_attributes__

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

Release Log

Release 20260912.1: Fix project spec.

Release 20260912: Internal change for a renamed function.

Release 20211031:

  • Update to Python 3, old Python 2 code recorded in cs.app.megacli2.
  • Various interna updates while parsing Dell PERC output.

Release 20190729: A little more report line parsing flexibility.

Release 20160310: remove more external dependencies, mention operation with Dell PowerEdge RAID Controller (PERC)

Release 20160226: cs.app.megacli: honour $MEGACLI for MegaCLI executable path, remove some external script dependencies, note Dell PowerEdge RAID Controller (PERC) is also a MegaRAID or compatible

Release 20160225: changes to remove dependencies on pythons newer than 2.4 and also other modules; issue reported by desius@gmail.com

Release 20150801.1: Update README-megacli.rst documentation.

Release 20150801:

  • New commands "locate" and "offline".
  • Report drive error counts.

Release 20150118.5: README: scrub adapter serial number from example, fix typo.

Release 20150118.4: example outputs in README

Release 20150118.3: mention MegaCLI class in README

Release 20150118.2: README fix

Release 20150118: Initial PyPI release.

Release files for cs-app-megacli 20260912.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs-app-megacli 20260912.1
File Size Uploaded
cs_app_megacli-20260912.1.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cs-app-megacli 20260912.1
File Interpreter ABI Platform
cs_app_megacli-20260912.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 21.1 kB

Release files / cs_app_megacli-20260912.1.tar.gz

Download URL cs_app_megacli-20260912.1.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ee2b73558b67a950f70e39a7af984cbfb95f4844b182a6a206226f213bd424b3
BLAKE2b-256 checksum
How to use checksums
0c4966218e6b410fde93635afc7cf4311b9e1b51806a2f1f1ab91b1a95e40bdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / cs_app_megacli-20260912.1-py2.py3-none-any.whl

Download URL cs_app_megacli-20260912.1-py2.py3-none-any.whl
Size 11.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d7dba1eabdf5dbcb8a59be3e7adcd84120ed223df158f59b8b23f44c9d7365a5
BLAKE2b-256 checksum
How to use checksums
d4599da6ea1b3992c2dd87cd2fbbad0fdc50b63e5a8563f822dfdf6f6d829cf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

20260912.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page