[208] | 1 | #!/bin/bash |
---|
| 2 | # Program: |
---|
| 3 | # Create PXE PV VM |
---|
| 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_name="" |
---|
| 20 | vm_cpu="1" |
---|
| 21 | vm_ram="128" |
---|
| 22 | #vm_host="" |
---|
| 23 | vm_mac="" |
---|
| 24 | |
---|
| 25 | vm_dir="/home/domains" |
---|
| 26 | # = 2. Functions declation = |
---|
| 27 | Usage(){ |
---|
| 28 | echo "Usage: drbl_PXE_PV-VM_create_all [options]" |
---|
| 29 | echo "Options: " |
---|
| 30 | echo "-c|--cpu cpu number (default: 1)" |
---|
| 31 | echo "-r|--ram ram size(M) (default: 128)" |
---|
| 32 | echo "Examples: " |
---|
| 33 | echo "drbl_PXE_PV-VM_create_all -c 2 -r 512" |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | # [Main] |
---|
| 38 | check_root |
---|
| 39 | # = 1. Parse parameters = |
---|
| 40 | if [ $# -eq 0 ]; then |
---|
| 41 | Usage && exit |
---|
| 42 | fi |
---|
| 43 | |
---|
| 44 | while [ $# -gt 0 ]; do |
---|
| 45 | case "$1" in |
---|
| 46 | -c|--cpu) |
---|
| 47 | shift |
---|
| 48 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
---|
| 49 | if [ -n "$(echo $1)" ]; then |
---|
| 50 | vm_cpu=$1 |
---|
| 51 | fi |
---|
| 52 | shift |
---|
| 53 | fi |
---|
| 54 | ;; |
---|
| 55 | -r|--ram) |
---|
| 56 | shift |
---|
| 57 | if [ -z "$(echo $1 |grep ^-.)" ]; then |
---|
| 58 | if [ -n "$(echo $1)" ]; then |
---|
| 59 | vm_ram=$1 |
---|
| 60 | fi |
---|
| 61 | shift |
---|
| 62 | fi |
---|
| 63 | ;; |
---|
| 64 | # -h|--host) |
---|
| 65 | # shift |
---|
| 66 | # if [ -z "$(echo $1 |grep ^-.)" ]; then |
---|
| 67 | # if [ -n "$(echo $1)" ]; then |
---|
| 68 | # vm_host=$1 |
---|
| 69 | # else |
---|
| 70 | # echo "-h host_value is null" |
---|
| 71 | # Usage && exit 2 |
---|
| 72 | # fi |
---|
| 73 | # shift |
---|
| 74 | # fi |
---|
| 75 | # ;; |
---|
| 76 | -*) |
---|
| 77 | echo "$0 $1 invalid option" >&2 |
---|
| 78 | echo "" |
---|
| 79 | Usage >&2 |
---|
| 80 | exit 2 |
---|
| 81 | ;; |
---|
| 82 | *) Usage >&2 |
---|
| 83 | exit 2 |
---|
| 84 | ;; |
---|
| 85 | esac |
---|
| 86 | done |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | # = 2. Create all VM configuration = |
---|
| 90 | IP_VM_files=$(ls $Work_Home/etc/IP_VM_eth[0-9]) |
---|
| 91 | |
---|
| 92 | # create directory to store vm config file |
---|
| 93 | if [ ! -e $vm_dir ]; then |
---|
| 94 | mkdir $vm_dir |
---|
| 95 | fi |
---|
| 96 | |
---|
| 97 | for IP_VM_file in $IP_VM_files |
---|
| 98 | do |
---|
| 99 | VM_nu=$(wc -l $IP_VM_file |awk '{print $1}') |
---|
| 100 | |
---|
| 101 | for (( i=1 ; i<=$VM_nu ; i++ )) |
---|
| 102 | do |
---|
| 103 | VM_name=$(sed -n "${i}p" $IP_VM_file | awk '{print $2}') |
---|
| 104 | $Work_Path/drbl_PXE_PV-VM_create -v $VM_name -c $vm_cpu -r $vm_ram |
---|
| 105 | done |
---|
| 106 | |
---|
| 107 | done |
---|
| 108 | |
---|