Docker container for managing HP servers via ILO

You may probably wonder - why is Docker here? What's the problem with accessing the ILO web interface and setting up your server properly?
So I thought when they gave me a couple of old unnecessary servers that I had to reinstall (what is called reprovision). The servers themselves are overseas, the only thing available is the web interface. Well, accordingly, I had to go to the Virtual Console to execute some commands. This is where it started.
As you know, for various kinds of virtual consoles, Java is usually used, both in HP and Dell. In any case, it used to be so for sure (and the systems are very old). But Firefox and Chrome have long ceased to support these applets, and the new IcedTea does not work with these systems. Therefore, there were several options:

1. Start constructing a zoo from browsers and Java versions on your machine, this option disappeared immediately. There is no desire to mock the system for the sake of a couple of commands.
2. Run something quite old on the virtual machine (experimentally it turned out that Java 6 is needed) and configure everything you need through it.
3. The same as point 2, only in the container, since several colleagues faced the same problem and it is much easier to send them a link to the container on dockerhub than an image of a virtual machine with all passwords, etc.
(In fact, I only got to point 3 after I did point 2)
Point 3 we will do today.

I was inspired mainly by two projects:
1. docker-baseimage-gui
2. docker-firefox-java
Basically the first project docker-baseimage-gui already contains utilities and configurations for running desktop applications in docker. Usually you need to define standard variables and your application will be accessible via browser (websocket) or VNC. In our case, we will run through Firefox and VNC, it did not work through websocket.
First, install the necessary packages - Java 6 and IcedTea:

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

Now it remains to go to the ILO interface page and enter your username and password. Launch Firefox in autostart:

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

The HILO_HOST environment variable contains the web address of our ILO interface, for example myhp.example.com
To automate the login, let's fasten the authorization. Login in ILO occurs with a regular POST request, as a result of which you get a JSON session_key, which you then pass in a GET request:
Calculate the session_key via curl if the HILO_USER and HILO_PASS environment variables 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 recorded the session_key in the 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 go to the virtual console.
All code is in the repository docker-ilo-client.
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, accordingly, SOME_PASSWORD is the ILO password.
After that, just launch any VNC client to the address: vnc://localhost:5900
Additions and pull requests are of course welcome.

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

Source: habr.com

Add a comment