Using sushy-tools in a container to simulate RedFish BMC

ยท 428 words ยท 3 minute read

I wanted to simulate a RedFish BMC to be able to power on/off libvirt virtualmachines and attach ISOs as I do for baremetal hosts.

Entering sushy-tools ๐Ÿ”—

sushy-tools include a RedFish BMC emulator as sushy-emulator (see the code in the official repo).

Basically it can connect to the libvirt socket to perform the required actions exposing a RedFish API.

metal3-io/sushy-tools container image ๐Ÿ”—

To easily consume it, the metal3 folks already have a container image ready for consumption at

sushy-emulator flags and configuration ๐Ÿ”—

There are a bunch of flags already available in the sushy-emualtor app. Some of them can also be specified as environment variables for example:

--config CONFIG       Config file path. Can also be set via environment variable SUSHY_EMULATOR_CONFIG

We will leverage this one later but in the meantime, we can create a custom configuration file for the ones we want as:

mkdir -p ~/sushy-tools/
cat << EOF > ~/sushy-tools/sushy-emulator.conf
SUSHY_EMULATOR_LIBVIRT_URI = u'qemu:///system'
    u'UEFI': {
        u'x86_64': u'/usr/share/OVMF/OVMF_CODE.secboot.fd'
    u'Legacy': {
        u'x86_64': None

Running the container ๐Ÿ”—

A few things to consider:

  • It requires certain privileges to talk with the libvirt socket, so it will be executed with sudo + the privileged flag
  • We need to specify the configuration file we created at podman run level using environment variables
  • We will overwrite the CMD in the container because otherwise the configuration is hardcoded to be placed at /root/sushy/

With that said:

sudo podman run -d --privileged --rm --name sushy-tools \
  -v ${HOME}/sushy-tools/sushy-emulator.conf:/etc/sushy/sushy-emulator.conf:Z \
  -v /var/run/libvirt:/var/run/libvirt:Z \
  -e SUSHY_EMULATOR_CONFIG=/etc/sushy/sushy-emulator.conf \
  -p 8000:8000 \ sushy-emulator

Check it ๐Ÿ”—

Running a simple curl to a RedFish endpoint such as redfish/v1/Systems would be enough:

$ curl -v localhost:8000/redfish/v1/Systems
*   Trying
* Connected to localhost ( port 8000 (#0)
> GET /redfish/v1/Systems HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.79.1
> Accept: */*
* Mark bundle as not supporting multiuse
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: application/json
< Content-Length: 1129
< Server: Werkzeug/2.0.2 Python/3.9.9
< Date: Tue, 22 Feb 2022 16:05:08 GMT
    "@odata.type": "#ComputerSystemCollection.ComputerSystemCollection",
    "Name": "Computer System Collection",
    "Members@odata.count": 5,
    "Members": [
                "": "/redfish/v1/Systems/b5091ded-5dcd-4218-bf69-0e2263bb0a7c"
                "": "/redfish/v1/Systems/3a5d0cd3-69da-455c-b0ce-9bbc8fa1467b"
                "": "/redfish/v1/Systems/dd47aacc-4fcc-4cbd-8ab2-97198007b08e"
                "": "/redfish/v1/Systems/429ac473-b840-4f35-aa2c-bc33e9065a2c"
                "": "/redfish/v1/Systems/7d3e4cb0-042c-44c4-b9c0-a60223c25394"
    "@odata.context": "/redfish/v1/$metadata#ComputerSystemCollection.ComputerSystemCollection",
    "": "/redfish/v1/Systems",
    "@Redfish.Copyright": "Copyright 2014-2016 Distributed Management Task Force, Inc. (DMTF). For the full DMTF copyright policy, see"
* Closing connection 0

References ๐Ÿ”—