Mate Lakat | 57e3da9 | 2013-03-22 16:34:05 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | function xapi_plugin_location { |
Mate Lakat | fe586b1 | 2013-03-28 15:02:27 +0000 | [diff] [blame] | 4 | for PLUGIN_DIR in "/etc/xapi.d/plugins/" "/usr/lib/xcp/plugins/"; do |
| 5 | if [ -d $PLUGIN_DIR ]; then |
Mate Lakat | 57e3da9 | 2013-03-22 16:34:05 +0000 | [diff] [blame] | 6 | echo $PLUGIN_DIR |
| 7 | return 0 |
| 8 | fi |
| 9 | done |
| 10 | return 1 |
| 11 | } |
| 12 | |
| 13 | function zip_snapshot_location { |
| 14 | echo $1 | sed "s:\.git$::;s:$:/zipball/$2:g" |
| 15 | } |
| 16 | |
| 17 | function create_directory_for_kernels { |
Mate Lakat | fe586b1 | 2013-03-28 15:02:27 +0000 | [diff] [blame] | 18 | if [ -d "/boot/guest" ]; then |
| 19 | echo "INFO: /boot/guest directory already exists, using that" >&2 |
| 20 | else |
| 21 | local LOCALPATH="$(get_local_sr_path)/os-guest-kernels" |
| 22 | mkdir -p $LOCALPATH |
| 23 | ln -s $LOCALPATH /boot/guest |
| 24 | fi |
Mate Lakat | 57e3da9 | 2013-03-22 16:34:05 +0000 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | function extract_remote_zipball { |
| 28 | local ZIPBALL_URL=$1 |
| 29 | |
| 30 | local LOCAL_ZIPBALL=$(mktemp) |
| 31 | local EXTRACTED_FILES=$(mktemp -d) |
| 32 | |
| 33 | ( |
| 34 | wget -nv $ZIPBALL_URL -O $LOCAL_ZIPBALL --no-check-certificate |
| 35 | unzip -q -o $LOCAL_ZIPBALL -d $EXTRACTED_FILES |
| 36 | rm -f $LOCAL_ZIPBALL |
| 37 | ) >&2 |
| 38 | |
| 39 | echo "$EXTRACTED_FILES" |
| 40 | } |
| 41 | |
| 42 | function find_xapi_plugins_dir { |
| 43 | find $1 -path '*/xapi.d/plugins' -type d -print |
| 44 | } |
| 45 | |
| 46 | function install_xapi_plugins_from_zipball { |
| 47 | local XAPI_PLUGIN_DIR |
| 48 | local EXTRACTED_FILES |
| 49 | local EXTRACTED_PLUGINS_DIR |
| 50 | |
| 51 | XAPI_PLUGIN_DIR=$(xapi_plugin_location) |
| 52 | |
| 53 | EXTRACTED_FILES=$(extract_remote_zipball $1) |
| 54 | EXTRACTED_PLUGINS_DIR=$(find_xapi_plugins_dir $EXTRACTED_FILES) |
| 55 | |
| 56 | cp -pr $EXTRACTED_PLUGINS_DIR/* $XAPI_PLUGIN_DIR |
| 57 | rm -rf $EXTRACTED_FILES |
| 58 | chmod a+x ${XAPI_PLUGIN_DIR}* |
| 59 | } |
Mate Lakat | fe586b1 | 2013-03-28 15:02:27 +0000 | [diff] [blame] | 60 | |
| 61 | function get_local_sr { |
| 62 | xe sr-list name-label="Local storage" --minimal |
| 63 | } |
| 64 | |
| 65 | function get_local_sr_path { |
| 66 | echo "/var/run/sr-mount/$(get_local_sr)" |
| 67 | } |
Mate Lakat | 8644676 | 2013-05-12 18:34:29 +0100 | [diff] [blame^] | 68 | |
| 69 | function find_ip_by_name() { |
| 70 | local guest_name="$1" |
| 71 | local interface="$2" |
| 72 | |
| 73 | local period=10 |
| 74 | local max_tries=10 |
| 75 | local i=0 |
| 76 | |
| 77 | while true; do |
| 78 | if [ $i -ge $max_tries ]; then |
| 79 | echo "Timeout: ip address for interface $interface of $guest_name" |
| 80 | exit 11 |
| 81 | fi |
| 82 | |
| 83 | ipaddress=$(xe vm-list --minimal \ |
| 84 | name-label=$guest_name \ |
| 85 | params=networks | sed -ne "s,^.*${interface}/ip: \([0-9.]*\).*\$,\1,p") |
| 86 | |
| 87 | if [ -z "$ipaddress" ]; then |
| 88 | sleep $period |
| 89 | ((i++)) |
| 90 | else |
| 91 | echo $ipaddress |
| 92 | break |
| 93 | fi |
| 94 | done |
| 95 | } |