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] |
---|
12 | source /opt/drbl-virt/conf/drbl-virt.conf |
---|
13 | source $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 = |
---|
23 | Usage(){ |
---|
24 | echo "Usage: drbl_PXE_PV-VM_deploy [options]" |
---|
25 | echo "Options:" |
---|
26 | echo "-h|--host deploy vm to which host" |
---|
27 | echo "-v|--vm vm name" |
---|
28 | echo "Example:" |
---|
29 | echo "drbl_PXE_PV-VM_deploy -h drbl101 -v drbl131" |
---|
30 | } |
---|
31 | |
---|
32 | |
---|
33 | # [Main] |
---|
34 | check_root |
---|
35 | # = 1. Parse parameters = |
---|
36 | if [ $# -eq 0 ]; then |
---|
37 | Usage && exit |
---|
38 | fi |
---|
39 | |
---|
40 | while [ $# -gt 0 ]; do |
---|
41 | case "$1" in |
---|
42 | -h|--host) |
---|
43 | shift |
---|
44 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
---|
45 | if [ -n "$(echo $1)" ]; then |
---|
46 | client_name=$1 |
---|
47 | else |
---|
48 | echo "-h host_value is null" |
---|
49 | Usage && exit 2 |
---|
50 | fi |
---|
51 | shift |
---|
52 | fi |
---|
53 | ;; |
---|
54 | -v|--vm) |
---|
55 | shift |
---|
56 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
---|
57 | if [ -n "$(echo $1)" ]; then |
---|
58 | vm_conf_file=${vm_dir}/${1}_PXE_PV-VM.cfg |
---|
59 | else |
---|
60 | echo "-v vm_name is null" |
---|
61 | Usage && exit 2 |
---|
62 | fi |
---|
63 | shift |
---|
64 | fi |
---|
65 | ;; |
---|
66 | |
---|
67 | -*) |
---|
68 | echo "$0 $1 invalid option" >&2 |
---|
69 | echo "" |
---|
70 | Usage >&2 |
---|
71 | exit 2 |
---|
72 | ;; |
---|
73 | *) Usage >&2 |
---|
74 | exit 2 |
---|
75 | ;; |
---|
76 | esac |
---|
77 | done |
---|
78 | |
---|
79 | |
---|
80 | # = 2. Check null value = |
---|
81 | [ -z $client_name ] && echo "[Error] no host" && Usage && exit 2 |
---|
82 | [ -z $vm_conf_file ] && echo "[Error] no VM configuration file" && Usage && exit 2 |
---|
83 | |
---|
84 | |
---|
85 | # = 3. Check exist |
---|
86 | # VM configuration |
---|
87 | [ ! -e "$vm_conf_file" ] && echo "[Error] Don't find $vm_conf_file" && exit 2 |
---|
88 | cat $Work_Home/etc/IP_HOST_TABLE | grep $client_name |
---|
89 | if [ $? -ne 0 ]; then |
---|
90 | echo "[Error] This host is not DRBL client" |
---|
91 | exit 2 |
---|
92 | fi |
---|
93 | |
---|
94 | |
---|
95 | # = 4. ssh host to deploy VM = |
---|
96 | # local varibales |
---|
97 | host_IP=$(cat $Work_Home/etc/IP_HOST_TABLE | grep $client_name | awk '{print $1}') |
---|
98 | |
---|
99 | # start ssh |
---|
100 | ssh -o StrictHostKeyChecking=no $host_IP "xm create $vm_conf_file" |
---|
101 | |
---|