source: drbl-virt/sbin/drbl_xen_cmd.sh @ 203

Last change on this file since 203 was 203, checked in by rock, 14 years ago

Add Function Code: intergated xen command (drbl_xen_cmd.sh)

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#!/bin/bash
2# Program:
3#   Deploy PXE PV VM to DRBL client
4# Author:
5#   Jazz, Rock {jazz, rock}@nchc.org.tw
6# Version:
7#    1.0
8# History:                                                                                         
9#   2010/08/27  Rock    First release (1.0)
10
11# [Source]
12source /opt/drbl-virt/conf/drbl-virt.conf
13source $Work_Path/functions_drbl_virt
14#source ./functions_drbl_PXE_PV-VM_create
15
16
17# [Declation]
18# = 1. Varibales declation =
19#vm_dir="/home/domains"
20
21
22# = 2. Functions declation =
23Usage(){
24echo "Usage: drbl_xen_cmd.sh options"
25echo "Options:"
26echo "-h|--host           which host"
27echo "-v|--vm             vm name"
28echo "-x|--xen_command    xen command"
29echo "Example:"
30echo "drbl_xen_cmd.sh -h drbl101 -v drbl131 -x 'shutdown'"
31}
32
33
34# [Main]
35check_root
36# = 1. Parse parameters =
37if [ $# -eq 0 ]; then
38Usage && exit
39fi
40
41while [ $# -gt 0 ]; do
42    case "$1" in
43        -h|--host)
44            shift 
45            if [ -z "$(echo $1 |grep ^-.)" ]; then
46                if [ -n "$(echo $1)" ]; then
47                    client_name=$1
48                else
49                    echo "-h host_value is null"
50                    Usage && exit 2
51                fi
52            shift 
53            fi 
54            ;; 
55        -v|--vm)
56            shift
57            if [ -z "$(echo $1 |grep ^-.)" ]; then
58                if [ -n "$(echo $1)" ]; then
59                    vm_name=$1
60                else
61                    echo "-v vm_name is null"
62                    Usage && exit 2
63                fi
64            shift
65            fi
66            ;;
67        -x|--xen_command)
68            shift 
69            if [ -z "$(echo $1 |grep ^-.)" ]; then
70                if [ -n "$(echo $1)" ]; then
71                xen_command="$1"
72                else
73                    echo "-x xen command is null"
74                    Usage && exit 2
75                fi 
76            shift 
77            fi 
78            ;;
79        -*)
80            echo "$0 $1 invalid option" >&2
81            echo ""
82            Usage >&2
83            exit 2
84            ;;
85        *)  Usage >&2
86            exit 2
87            ;;
88    esac
89done
90
91
92# = 2. Check null value =
93[ -z $client_name ] && echo "[Error] no host" && Usage && exit 2
94[ -z $vm_name ] && echo "[Error] no VM value" && Usage && exit 2
95[ -z "$xen_command" ] && echo "[Error] no xen command" && Usage && exit 2
96
97
98# = 3. Check exist
99# VM name
100IP_VM_files=$(ls $Work_Home/etc/IP_VM_eth[0-9]*)
101
102for IP_VM_file in $IP_VM_files
103do                                                                                                                                 
104    IP_VM_ip=$(cat $IP_VM_file | grep "$vm_name" | awk '{print $1}') 
105    if [ -n $IP_VM_name ]; then
106        IP_VM_right_file=$IP_VM_file
107        IP_VM_right_ip=$IP_VM_ip
108    fi
109done
110
111if [ -z $IP_VM_right_ip ]; then
112    echo ""
113    echo "[Error] this vm name is wrong!"
114    echo "Please check $Wokr_Home/etc/"
115    exit 2
116fi
117
118cat $Work_Home/etc/IP_HOST_TABLE | grep $client_name
119if [ $? -ne 0 ]; then
120    echo "[Error] This host is not DRBL client"
121    exit 2
122fi
123
124
125# = 4. ssh host to deploy VM  =
126# local varibales
127host_IP=$(cat $Work_Home/etc/IP_HOST_TABLE | grep $client_name | awk '{print $1}')
128
129# start ssh
130ssh -o StrictHostKeyChecking=no $host_IP "$xen_command"
131
Note: See TracBrowser for help on using the repository browser.