Docker container for HP servers management with ILO
Published: 2019-05-21 14:35:29

![HP ILO](http://dev-random.net/wp-content/uploads/2015/06/ilo.png)

Well, you can wonder — why would I use docker container for such a purpose? What’s the problem to enter web-interface of ILO and manage server as usual?
The same thought I had when I’ve got a few old servers that required a reprovision. The servers are located in different continent and the only interface I had it was just a web interface of ILO. And when I had to enter a few manual commands via Virtual Console I discovered that it’s hardly possible.

For various sorts of Virtual Console of servers (both HP and Dells) usually Java web applets are used. But Firefox and Chrome don’t support them anymore and the newest IcedTea doesn’t work with those old system anyway. So I had a few options:

1. To install in parallel old versions of browsers and Java, trying to find a required combination, on my system. This option was filtered out, since I don’t want to pollute my system just because of few console commands.
2. Create a virtual machine with old systems, install there Java 6 and use Virtual Console as before.
3. The same as in point 2, but with container, not a virtual machine. Since a few my colleagues hit the same problem, I’d prefer to pass them one bash command to run Virtual Console instead of sharing Virtual Machine disk, passwords for it, etc etc.
(To be honest, point 3 I made only after point 2).
Point 3 is what we are going to implement today.

I’ve been inspired mostly by these two projects:
* [docker-baseimage-gui](https://github.com/jlesage/docker-baseimage-gui)
* [docker-firefox-java](https://github.com/ktelep/docker-firefox-java)

Actually, the first project docker-baseimage-gui contains already all needed configs and tools to start desktop apps in browser within a container. Usually you define specific environment variables and your app will become accessible via browser (websocket) or VNC. In our case we start with Firefox and VNC, websocket didn’t work well.

Firstly, let’s install required packages: Java 6 and IcedTea:

```Docker
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 let’s open the web page of ILO interface in Firefox and enter credentials there. Start Firefox:

```Docker
RUN bash -c ‘echo “exec openbox-session &” >> ~/.xinitrc’ && \
    bash -c ‘echo “firefox \${HILO_HOST}”>> ~/.xinitrc’ && \
    bash -c ‘chmod 755 ~/.xinitrc’
```
Variable `HILO_HOST` is URL of our ILO interface, for example `https://myhp.example.com`.

For automation let’s add authentication. ILO login is executed via simple POST request, in response you get session_key value and then pass this value in GET request. Let’s discover session_key with curl if environment variables `HILO_USER` and `HILO_PASS` are defined:
```bash
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 wrote session_key in containers we can start VNC server:

```bash
exec x11vnc -forever -create
```
Now just connect with VNC client to port 5900 (or what you defined in your choice) to localhost and enter the Virtual Console of HP server.
The code is located in git repository docker-ilo-client.

Full one line command to connect to ILO Virtual Console:

```
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 hostname of ILO, `SOME_USERNAME` is login and `SOME_PASSWORD` is password for ILO.

Next just go with any VNC client to address `vnc://localhost:5900`.
Pull requests and comments are more than welcome.

The similar project for connection to Dell IDRAC servers is here: [docker-idrac6](https://github.com/DomiStyle/docker-idrac6).