From 66bb4bb381fe382b521cf1c6a70574b0ca99ba96 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Thu, 21 Apr 2011 22:49:25 +0300 Subject: [PATCH] scripts: add kvm scripts folder Scripts for interacting with KVM virtual machines in NCIT cluster. --- scripts/kvm/create-ssh-tunnel | 35 ++++++++++++++++++++++++ scripts/kvm/destinations.default.conf | 26 ++++++++++++++++++ scripts/kvm/mcreate-ssh-tunnel | 38 +++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100755 scripts/kvm/create-ssh-tunnel create mode 100644 scripts/kvm/destinations.default.conf create mode 100755 scripts/kvm/mcreate-ssh-tunnel diff --git a/scripts/kvm/create-ssh-tunnel b/scripts/kvm/create-ssh-tunnel new file mode 100755 index 0000000..a2a52a8 --- /dev/null +++ b/scripts/kvm/create-ssh-tunnel @@ -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 index 0000000..f89f62c --- /dev/null +++ b/scripts/kvm/destinations.default.conf @@ -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 index 0000000..c80f277 --- /dev/null +++ b/scripts/kvm/mcreate-ssh-tunnel @@ -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]*$') -- 2.20.1