Note to self: Parsec and ‘nova list’

https://gist.github.com/carlohamalainen/4982764.js

Example input:

+--------------------------------------+------------------------+--------+----------------------------+
| ID                                   | Name                   | Status | Networks                   |
+--------------------------------------+------------------------+--------+----------------------------+
| 10000000-0000-0000-0000-000000000001 | vm 1                   | ACTIVE | cell1=192.168.1.1          |
| 10000000-0000-0000-0000-000000000002 | vm 2                   | ACTIVE | cell2=192.168.1.2          |
| 10000000-0000-0000-0000-000000000003 | vm 3                   | ACTIVE | cell2=192.168.1.3          |
| 10000000-0000-0000-0000-000000000004 | vm 4                   | ACTIVE | cell1=192.168.1.4          |
| 10000000-0000-0000-0000-000000000005 | vm 5                   | ACTIVE | cell1=192.168.1.5          |
| 10000000-0000-0000-0000-000000000006 | vm 6                   | BUILD  | cell1=192.168.1.6          |
| 10000000-0000-0000-0000-000000000007 | vm 7                   | BUILD  | cell1=192.168.1.7          |
| 10000000-0000-0000-0000-000000000008 | vm 8                   | ACTIVE | cell2=192.168.1.8          |
| 10000000-0000-0000-0000-000000000009 | vm 9                   | ACTIVE | cell1=192.168.1.9          |
| 10000000-0000-0000-0000-000000000010 | vm 10                  | ACTIVE | cell1=192.168.1.10         |
| 10000000-0000-0000-0000-000000000011 | vm 11                  | ACTIVE | cell2=192.168.1.11         |
| 10000000-0000-0000-0000-000000000012 | vm 12                  | ACTIVE | cell2=192.168.1.12         |
| 10000000-0000-0000-0000-000000000013 | vm 13                  | ACTIVE | cell1=192.168.1.13         |
| 10000000-0000-0000-0000-000000000014 | vm 14                  | ACTIVE | cell1=192.168.1.14         |
| 10000000-0000-0000-0000-000000000015 | vm 15                  | ACTIVE | cell1=192.168.1.15         |
| 10000000-0000-0000-0000-000000000016 | vm 16                  | ACTIVE | cell2=192.168.1.16         |
| 10000000-0000-0000-0000-000000000017 | vm 17                  | ACTIVE | cell1=192.168.1.17         |
| 10000000-0000-0000-0000-000000000018 | vm 18                  | ACTIVE | cell2=192.168.1.18         |
| 10000000-0000-0000-0000-000000000019 | vm 19                  | ACTIVE | cell2=192.168.1.19         |
| 10000000-0000-0000-0000-000000000020 | vm 20                  | ACTIVE | cell1=192.168.1.20         |
| 10000000-0000-0000-0000-000000000021 | vm 21                  | ACTIVE | cell2=192.168.1.21         |
| 10000000-0000-0000-0000-000000000022 | vm 22                  | BUILD  |                            |
| 10000000-0000-0000-0000-000000000023 | vm 23                  | ACTIVE | cell1=192.168.1.22         |
| 10000000-0000-0000-0000-000000000024 | vm 24                  | DERP   | cell1=192.168.1.23         |
+--------------------------------------+------------------------+--------+----------------------------+

Example run:

$ ghc --make ReadNovaList.hs && cat nova_list_output.txt  | ./ReadNovaList
("10000000-0000-0000-0000-000000000001","vm 1",Active,Just (Network {networkCell = "cell1", networkIP = "192.168.1.1"}))
("10000000-0000-0000-0000-000000000002","vm 2",Active,Just (Network {networkCell = "cell2", networkIP = "192.168.1.2"}))
("10000000-0000-0000-0000-000000000003","vm 3",Active,Just (Network {networkCell = "cell2", networkIP = "192.168.1.3"}))
("10000000-0000-0000-0000-000000000004","vm 4",Active,Just (Network {networkCell = "cell1", networkIP = "192.168.1.4"}))
("10000000-0000-0000-0000-000000000005","vm 5",Active,Just (Network {networkCell = "cell1", networkIP = "192.168.1.5"}))
("10000000-0000-0000-0000-000000000006","vm 6",Building,Just (Network {networkCell = "cell1", networkIP = "192.168.1.6"}))
("10000000-0000-0000-0000-000000000007","vm 7",Building,Just (Network {networkCell = "cell1", networkIP = "192.168.1.7"}))
("10000000-0000-0000-0000-000000000008","vm 8",Active,Just (Network {networkCell = "cell2", networkIP = "192.168.1.8"}))
("10000000-0000-0000-0000-000000000009","vm 9",Active,Just (Network {networkCell = "cell1", networkIP = "192.168.1.9"}))
("10000000-0000-0000-0000-000000000010","vm 10",Active,Just (Network {networkCell = "cell1", networkIP = "192.168.1.10"}))
("10000000-0000-0000-0000-000000000011","vm 11",Active,Just (Network {networkCell = "cell2", networkIP = "192.168.1.11"}))
("10000000-0000-0000-0000-000000000012","vm 12",Active,Just (Network {networkCell = "cell2", networkIP = "192.168.1.12"}))
("10000000-0000-0000-0000-000000000013","vm 13",Active,Just (Network {networkCell = "cell1", networkIP = "192.168.1.13"}))
("10000000-0000-0000-0000-000000000014","vm 14",Active,Just (Network {networkCell = "cell1", networkIP = "192.168.1.14"}))
("10000000-0000-0000-0000-000000000015","vm 15",Active,Just (Network {networkCell = "cell1", networkIP = "192.168.1.15"}))
("10000000-0000-0000-0000-000000000016","vm 16",Active,Just (Network {networkCell = "cell2", networkIP = "192.168.1.16"}))
("10000000-0000-0000-0000-000000000017","vm 17",Active,Just (Network {networkCell = "cell1", networkIP = "192.168.1.17"}))
("10000000-0000-0000-0000-000000000018","vm 18",Active,Just (Network {networkCell = "cell2", networkIP = "192.168.1.18"}))
("10000000-0000-0000-0000-000000000019","vm 19",Active,Just (Network {networkCell = "cell2", networkIP = "192.168.1.19"}))
("10000000-0000-0000-0000-000000000020","vm 20",Active,Just (Network {networkCell = "cell1", networkIP = "192.168.1.20"}))
("10000000-0000-0000-0000-000000000021","vm 21",Active,Just (Network {networkCell = "cell2", networkIP = "192.168.1.21"}))
("10000000-0000-0000-0000-000000000022","vm 22",Building,Nothing)
("10000000-0000-0000-0000-000000000023","vm 23",Active,Just (Network {networkCell = "cell1", networkIP = "192.168.1.22"}))
("10000000-0000-0000-0000-000000000024","vm 24",StatusError "DERP",Just (Network {networkCell = "cell1", networkIP = "192.168.1.23"}))

Xfce4-xfapplet-plugin for Centos 6.3

For some reason xfce4-xfapplet-plugin has been dropped from recent Centos/Fedora releases, as the spec file for xfce4-panel proclaims:

# xfce4-xfapplet-plugin isn't in F15
Provides:       xfce4-xfapplet-plugin%{?_isa} = 0.1.0-11
Obsoletes:      xfce4-xfapplet-plugin <= 0.1.0-10.fc15

This makes it basically impossible for anyone to use a Gnome2 applet on Xfce4. As a temporary work-around I have built an RPM of xfapplet-plugin on Centos 6.3 with the release number of 0.1.0-15, which gets around the Provides/Obsoletes lines:

xfce4-xfapplet-plugin-0.1.0-15.el6.x86_64.rpm

The git repo is here: https://github.com/carlohamalainen/xfce4-xfapplet-centos6.

Note to self: “cabal install libssh2” on Debian testing

Debian Squeeze doesn’t have a new enough libssh2 for the LibSSH2 package on hackage. So I tried the libssh library and dev package from Debian testing:

$ dpkg -l | grep -i libssh2
ii  libssh2-1                                       1.4.2-1.1                          SSH2 client-side library
ii  libssh2-1-dev                                   1.4.2-1.1                          SSH2 client-side library (development headers)

However libssh2 failed to install using cabal:

$ cabal install libssh2
Resolving dependencies...
Configuring libssh2-0.2.0.1...
cabal: The pkg-config package libssh2 version >=1.2.8 is required but it could
not be found.
Failed to install libssh2-0.2.0.1
cabal: Error: some packages failed to install:
libssh2-0.2.0.1 failed during the configure step. The exception was:
ExitFailure 1

We can help it along by setting PKG_CONFIG_PATH so that cabal finds libssh2, and also set the extra lib/include directories so that it finds libgcrypt:

$ export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig
$ cabal install libssh2 --extra-include-dirs=/usr/include --extra-lib-dirs=/lib/x86_64-linux-gnu

Finally, compiling ssh-client.hs blew up in a weird way:

$ ghc –make ssh-client.hs
[1 of 1] Compiling Main ( ssh-client.hs, ssh-client.o )

ssh-client.hs:22:18:
    Couldn't match expected type `BSL.ByteString'
                with actual type `bytestring-0.9.2.1:Data.ByteString.Lazy.Internal.ByteString'
    In the first argument of `BSL.putStr', namely `result'
    In a stmt of a 'do' block: BSL.putStr result
    In the expression:
      do { channelExecute ch command;
           result <- readAllChannel ch;
           BSL.putStr result }

Thanks to this stackoverflow question I found out that I had two versions of the bytestring library installed on my system:

$ ghc-pkg list bytestring
/opt/sw/64bit/debian/ghc-7.4.2/lib/ghc-7.4.2/package.conf.d
   bytestring-0.9.2.1
/home/carlo/.ghc/x86_64-linux-7.4.2/package.conf.d
   bytestring-0.10.0.1

and the answer was to hide the 0.10.x version:

$ ghc --make -hide-package bytestring-0.10.0.1 ssh-client.hs

Example usage:

$ ./ssh-client command carlo 192.168.1.70 22 uptime
 20:04:43 up 35 days, 22:14,  0 users,  load average: 0.00, 0.00, 0.00