Docker container for managing HP servers via ILO

You might be wondering — why use Docker here? What's the problem with accessing the ILO web interface and configuring your server properly?
That's what I thought when I received a couple of old unused servers that I needed to reinstall (what's called reprovisioning). The servers are located across the ocean, and the only thing available is the web interface. Naturally, I had to access the Virtual Console to execute some commands. This is where it all began.
As is known, various virtual consoles usually use Java, both in HP and Dell. At least that's how it used to be (and the systems are very old). But Firefox and Chrome have long stopped supporting these applets, and the new IcedTea doesn't work with these systems either. Therefore, a few options emerged:

1. Start constructing a menagerie of browsers and Java versions on my machine; this option was discarded immediately. I had no desire to torture my system for a couple of commands.
2. Run something sufficiently old on a virtual machine (it turned out through experience that Java 6 is needed) and configure everything that’s required through it.
3. The same as point 2, but in a container, since several colleagues faced the same problem and it's much easier to share a link to the container on Docker Hub than to the virtual machine image, with all the passwords etc.
(In fact, I only arrived at point 3 after completing point 2)
Today, we will implement point 3.

I was mainly inspired by two projects:
1. docker-baseimage-gui
2. docker-firefox-java
The first project, in principle, already includes tools and configurations for running desktop applications in Docker. Usually, you need to define standard variables, and your application will be accessible through a browser (websocket) or VNC. In our case, we will be launching through Firefox and VNC; we couldn't get it to work via websocket. docker-baseimage-gui First, let's install the necessary packages — Java 6 and IcedTea:
Now we just need to go to the ILO interface page and enter our username and password. We start Firefox in auto-start:

RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list &&
apt-get update &&
apt-get -y upgrade &&
apt-get -y install firefox
nano curl
icedtea-6-plugin
icedtea-netx
openjdk-6-jre
openjdk-6-jre-headless
tzdata-java

The environment variable HILO_HOST contains the web address of our ILO interface, for example

RUN bash -c 'echo "exec openbox-session &" >> ~/\.xinitrc' &&
bash -c 'echo "firefox ${HILO_HOST}" >> ~/\.xinitrc' &&
bash -c 'chmod 755 ~/\.xinitrc'

myhp.example.com To automate the login, let's add authorization. Logging into ILO occurs through a standard POST request, resulting in a JSON session_key, which you then pass on in a GET request:
To automate login, let's implement authorization. The login to ILO is done through a standard POST request, which results in receiving a JSON session_key that is then passed in a GET request:
Let's calculate the session_key using curl if the environment variables HILO_USER and HILO_PASS are defined:

export HOME=/config
export HILO_HOST=${HILO_HOST%%/}
SESSION_KEY=""
data="{"method":"login","user_login":"${HILO_USER}","password":"${HILO_PASS}"}"
if [[ -n "${HILO_USER}" && -n "${HILO_PASS}" ]]; then
    SESSION_KEY=$(curl -k -X POST "${HILO_HOST}/json/login_session" -d "$data" 2>/dev/null | grep -Eo '"session_key":"[^"]+' | sed 's/"session_key":"//')
fi
echo "SESSION_KEY=$SESSION_KEY"
echo $SESSION_KEY > /session_key

After we have written the session_key in Docker, we can start VNC:

exec x11vnc -forever -create

Now we just connect via VNC to port 5900 (or any other of your choice) on localhost and access the virtual console.
The entire code is available in the repository docker-ilo-client.
The full command to connect to ILO:

docker run -d --rm --name ilo-client -p 5900:5900 -e HILO_HOST=https://ADDRESS_OF_YOUR_HOST -e HILO_USER=SOME_USERNAME -e HILO_PASS=SOME_PASSWORD sshnaidm/docker-ilo-client

where ADDRESS_OF_YOUR_HOST is the ILO hostname, SOME_USERNAME is the login, and SOME_PASSWORD is the password for ILO.
After this, simply run any VNC client at the address: vnc://localhost:5900
Contributions and pull requests are of course welcome.

A similar project exists for connecting to IDRAC interfaces of DELL machines: docker-idrac6.

Source: habr.com

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster