歡迎您光臨本站 註冊首頁

一個XENSERVER實用的bash

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

迅速清除VM的C盤.以模板系統的C盤代替..
 其它盤不用動..
 其效果..可想而知...
 #!/bin/sh
 #reset driver C
 #write by bendy 67052  qq.com
 
 if [ -z "${XE}" ]; then
   XE=xe
 fi
 
 # Check there's a vm uuid parameter to the command
 if [ $# -ne 1 ]; then
         echo "usage: $0

"
         exit 1
 fi
 vmuuid=$1
 
 # Check if there's a VM by the uuid specified
 ${XE} vm-list params=uuid | grep -q " ${vmuuid}$"
 if [ $? -ne 0 ]; then
         echo "error: no vm uuid \"${vmuuid}\" found"
         exit 2
 fi
 
 # Check the power state of the vm
 name=$(${XE} vm-list uuid=${vmuuid} params=name-label --minimal)
 state=$(${XE} vm-list uuid=${vmuuid} params=power-state --minimal)
 wasrunning=0
 
 # If the VM state is running, we shutdown the vm first
 if [ "${state}" = "running" ]; then
         ${XE} vm-shutdown uuid=${vmuuid}
         ${XE} event-wait class=vm power-state=halted uuid=${vmuuid}
         wasrunning=1
 fi
 
 # destroy OLD C
 ${XE} vbd-destroy uuid=`${XE} vbd-list vm-uuid=${vmuuid} device=hda | /usr/bin/perl -e 'while () { if (/^uuid.* ([^ ]*)$/) { $uuid = $1; } } print "$uuid";'`
 #echo "destroy ok"
 
 # get drivce c uuid
 viduuid=$(${XE} vbd-list device=hda  | /usr/bin/perl -e 'while () { if (/vdi-uuid.* ([^ ]*)$/) { $uuid = $1; } if ( $find ) { last;} if (/vm-name-label \( RO\): win/) { $find="yes" } } print "$uuid";')
 #echo ${viduuid}
 
 # clone driver C
 newviduuid=$(${XE} vdi-clone new-name-label=clone uuid=${viduuid})
 #echo "${newviduuid}"
 
 # inst new vbd
 ${XE} vbd-create vm-uuid=${vmuuid} device=hda vdi-uuid=${newviduuid} bootable=true type=Disk mode=RW
 
 (tips...模板系統的LABEL需要是win開頭)

[火星人 ] 一個XENSERVER實用的bash已經有539次圍觀

http://coctec.com/docs/service/show-post-5888.html