scripts: add kvm scripts folder
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Thu, 21 Apr 2011 19:49:25 +0000 (22:49 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Thu, 21 Apr 2011 20:32:38 +0000 (23:32 +0300)
Scripts for interacting with KVM virtual machines in NCIT cluster.

scripts/kvm/create-ssh-tunnel [new file with mode: 0755]
scripts/kvm/destinations.default.conf [new file with mode: 0644]
scripts/kvm/mcreate-ssh-tunnel [new file with mode: 0755]

diff --git a/scripts/kvm/create-ssh-tunnel b/scripts/kvm/create-ssh-tunnel
new file mode 100755 (executable)
index 0000000..a2a52a8
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+#
+# Create an SSH tunnel to a remote host (destination) through another host
+# (gateway). This is useful, for example, when destionation in not accesible
+# directly, but may be accessed through the gateway.
+#
+# dest_... refers the destionation, gw_... refers the gateway.
+#
+# 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
+#
+
+# Use _DRY_RUN_ for testing purposes in case you don't want any action to
+# be undertaken.
+
+#_DRY_RUN_=1
+
+gw_username=razvan.deaconescu
+gw_ip=fep.grid.pub.ro
+gw_port=22
+
+if test $# -ne 2; then
+    echo "Usage: $0 localport dest-ip-address" 1>&2
+    exit 1
+fi
+
+localport=$1
+dest_ip=$2
+dest_port=22    # hard code SSH port
+
+# run SSH tunnel in background
+if test "x${_DRY_RUN_}" != "x1"; then
+    ssh -N -n -f -L ${localport}:${dest_ip}:${dest_port} \
+        -l ${gw_username} -p ${gw_port} ${gw_ip}
+fi
diff --git a/scripts/kvm/destinations.default.conf b/scripts/kvm/destinations.default.conf
new file mode 100644 (file)
index 0000000..f89f62c
--- /dev/null
@@ -0,0 +1,26 @@
+# Sample configuration file for SSH tunnel creation scripts.
+# Use a single TAB as separator between localport an destination IP or
+# hostname.
+#
+# localport    destination
+
+60122  10.42.5.136
+60222  10.42.5.225
+60322  10.42.5.223
+60422  10.42.5.226
+60522  10.42.5.224
+60622  10.42.5.227
+60722  10.42.5.228
+60822  10.42.5.229
+60922  10.42.5.230
+61022  10.42.5.231
+61122  10.42.5.240
+61222  10.42.5.243
+61322  10.42.5.232
+61422  10.42.5.233
+61522  10.42.5.234
+61622  10.42.5.239
+61722  10.42.5.235
+61822  10.42.5.236
+61922  10.42.5.237
+62022  10.42.5.244
diff --git a/scripts/kvm/mcreate-ssh-tunnel b/scripts/kvm/mcreate-ssh-tunnel
new file mode 100755 (executable)
index 0000000..c80f277
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+#
+# Create multiple SSH tunnels. Read configuration file and call
+# create-ssh-tunnel script.
+#
+# Configuration file consists of a set of destination hostnames or IP
+# addresses accesible from the gateway.
+#
+# 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
+#
+
+default_config=destinations.default.conf
+
+if test $# -ge 2; then
+    echo "Usage: $0 [config]" 1>&2
+    exit 1
+elif test $# -eq 1; then
+    config="$1"
+else
+    config=${default_config}
+fi
+
+# 1 - debug enabled
+# 0 or none - debug disabled
+_DEBUG_=1
+
+DEBUG()
+{
+    if test "x${_DEBUG_}" == "x1"; then
+        echo $@ 1>&2
+    fi
+}
+
+while read local_port destination; do
+    DEBUG "Adding tunnel to ${destination} through local port ${local_port} ..."
+    ./create-ssh-tunnel ${local_port} ${destination}
+done < <(grep -v '^[ \t]*#' ${config} | grep -v '^[ \t]*$')