mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-02-24 05:20:02 +08:00
fix: Local variables (#447)
* fix: Local variables * fix: Keep location
This commit is contained in:
parent
ba7fd2fe4a
commit
03d2665725
@ -39,7 +39,6 @@ fi
|
|||||||
location=$(cat "$file")
|
location=$(cat "$file")
|
||||||
|
|
||||||
if ! curl -m 20 -ILfSs "http://$location/" > /dev/null; then
|
if ! curl -m 20 -ILfSs "http://$location/" > /dev/null; then
|
||||||
rm -f $file
|
|
||||||
echo "Failed to reach http://$location"
|
echo "Failed to reach http://$location"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
29
src/disk.sh
29
src/disk.sh
@ -57,8 +57,7 @@ ext2fmt() {
|
|||||||
|
|
||||||
getSize() {
|
getSize() {
|
||||||
local DISK_FILE=$1
|
local DISK_FILE=$1
|
||||||
local DISK_EXT
|
local DISK_EXT DISK_FMT
|
||||||
local DISK_FMT
|
|
||||||
|
|
||||||
DISK_EXT="$(echo "${DISK_FILE//*./}" | sed 's/^.*\.//')"
|
DISK_EXT="$(echo "${DISK_FILE//*./}" | sed 's/^.*\.//')"
|
||||||
DISK_FMT="$(ext2fmt "$DISK_EXT")"
|
DISK_FMT="$(ext2fmt "$DISK_EXT")"
|
||||||
@ -77,18 +76,13 @@ getSize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resizeDisk() {
|
resizeDisk() {
|
||||||
|
|
||||||
local GB
|
|
||||||
local REQ
|
|
||||||
local FAIL
|
|
||||||
local SPACE
|
|
||||||
local SPACE_GB
|
|
||||||
local DISK_FILE=$1
|
local DISK_FILE=$1
|
||||||
local CUR_SIZE=$2
|
local CUR_SIZE=$2
|
||||||
local DATA_SIZE=$3
|
local DATA_SIZE=$3
|
||||||
local DISK_SPACE=$4
|
local DISK_SPACE=$4
|
||||||
local DISK_DESC=$5
|
local DISK_DESC=$5
|
||||||
local DISK_FMT=$6
|
local DISK_FMT=$6
|
||||||
|
local GB REQ FAIL SPACE SPACE_GB
|
||||||
|
|
||||||
GB=$(( (CUR_SIZE + 1073741823)/1073741824 ))
|
GB=$(( (CUR_SIZE + 1073741823)/1073741824 ))
|
||||||
info "Resizing $DISK_DESC from ${GB}G to $DISK_SPACE .."
|
info "Resizing $DISK_DESC from ${GB}G to $DISK_SPACE .."
|
||||||
@ -135,7 +129,6 @@ resizeDisk() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
convertDisk() {
|
convertDisk() {
|
||||||
|
|
||||||
local CONV_FLAGS="-p"
|
local CONV_FLAGS="-p"
|
||||||
local SOURCE_FILE=$1
|
local SOURCE_FILE=$1
|
||||||
local SOURCE_FMT=$2
|
local SOURCE_FMT=$2
|
||||||
@ -153,15 +146,11 @@ convertDisk() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createDisk() {
|
createDisk() {
|
||||||
|
|
||||||
local GB
|
|
||||||
local FAIL
|
|
||||||
local SPACE
|
|
||||||
local SPACE_GB
|
|
||||||
local DISK_FILE=$1
|
local DISK_FILE=$1
|
||||||
local DISK_SPACE=$2
|
local DISK_SPACE=$2
|
||||||
local DISK_DESC=$3
|
local DISK_DESC=$3
|
||||||
local DISK_FMT=$4
|
local DISK_FMT=$4
|
||||||
|
local GB FAIL SPACE SPACE_GB
|
||||||
|
|
||||||
FAIL="Could not create a $DISK_SPACE $DISK_FMT file for $DISK_DESC ($DISK_FILE)"
|
FAIL="Could not create a $DISK_SPACE $DISK_FMT file for $DISK_DESC ($DISK_FILE)"
|
||||||
|
|
||||||
@ -206,12 +195,6 @@ createDisk() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addDisk () {
|
addDisk () {
|
||||||
|
|
||||||
local FS
|
|
||||||
local DIR
|
|
||||||
local CUR_SIZE
|
|
||||||
local DATA_SIZE
|
|
||||||
local DISK_FILE
|
|
||||||
local DISK_ID=$1
|
local DISK_ID=$1
|
||||||
local DISK_BASE=$2
|
local DISK_BASE=$2
|
||||||
local DISK_EXT=$3
|
local DISK_EXT=$3
|
||||||
@ -220,6 +203,7 @@ addDisk () {
|
|||||||
local DISK_INDEX=$6
|
local DISK_INDEX=$6
|
||||||
local DISK_ADDRESS=$7
|
local DISK_ADDRESS=$7
|
||||||
local DISK_FMT=$8
|
local DISK_FMT=$8
|
||||||
|
local FS DIR CUR_SIZE DATA_SIZE DISK_FILE
|
||||||
|
|
||||||
DISK_FILE="$DISK_BASE.$DISK_EXT"
|
DISK_FILE="$DISK_BASE.$DISK_EXT"
|
||||||
DIR=$(dirname "$DISK_FILE")
|
DIR=$(dirname "$DISK_FILE")
|
||||||
@ -239,9 +223,7 @@ addDisk () {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -f "$DISK_FILE" ] ; then
|
if ! [ -f "$DISK_FILE" ] ; then
|
||||||
local PREV_EXT
|
local PREV_EXT PREV_FMT PREV_FILE TMP_FILE
|
||||||
local PREV_FMT
|
|
||||||
local PREV_FILE
|
|
||||||
|
|
||||||
if [[ "${DISK_FMT,,}" != "raw" ]]; then
|
if [[ "${DISK_FMT,,}" != "raw" ]]; then
|
||||||
PREV_FMT="raw"
|
PREV_FMT="raw"
|
||||||
@ -256,7 +238,6 @@ addDisk () {
|
|||||||
info "Detected that ${DISK_DESC^^}_FMT changed from \"$PREV_FMT\" to \"$DISK_FMT\"."
|
info "Detected that ${DISK_DESC^^}_FMT changed from \"$PREV_FMT\" to \"$DISK_FMT\"."
|
||||||
info "Starting conversion of $DISK_DESC to this new format, please wait until completed..."
|
info "Starting conversion of $DISK_DESC to this new format, please wait until completed..."
|
||||||
|
|
||||||
local TMP_FILE
|
|
||||||
TMP_FILE="$DISK_BASE.tmp"
|
TMP_FILE="$DISK_BASE.tmp"
|
||||||
rm -f "$TMP_FILE"
|
rm -f "$TMP_FILE"
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ configureDHCP() {
|
|||||||
sleep 2
|
sleep 2
|
||||||
done
|
done
|
||||||
|
|
||||||
|
local TAP_NR TAP_PATH MAJOR MINOR
|
||||||
TAP_NR=$(</sys/class/net/"$VM_NET_TAP"/ifindex)
|
TAP_NR=$(</sys/class/net/"$VM_NET_TAP"/ifindex)
|
||||||
TAP_PATH="/dev/tap${TAP_NR}"
|
TAP_PATH="/dev/tap${TAP_NR}"
|
||||||
|
|
||||||
|
13
src/power.sh
13
src/power.sh
@ -21,6 +21,7 @@ _trap(){
|
|||||||
_graceful_shutdown() {
|
_graceful_shutdown() {
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
local cnt response
|
||||||
|
|
||||||
[ ! -f "$QEMU_PID" ] && exit 130
|
[ ! -f "$QEMU_PID" ] && exit 130
|
||||||
[ -f "$QEMU_COUNT" ] && return
|
[ -f "$QEMU_COUNT" ] && return
|
||||||
@ -32,11 +33,11 @@ _graceful_shutdown() {
|
|||||||
# echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null
|
# echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_PORT}" > /dev/null
|
||||||
|
|
||||||
# Send shutdown command to guest agent via serial port
|
# Send shutdown command to guest agent via serial port
|
||||||
RESPONSE=$(curl -sk -m 30 -S http://127.0.0.1:2210/read?command=6 2>&1)
|
response=$(curl -sk -m 30 -S http://127.0.0.1:2210/read?command=6 2>&1)
|
||||||
|
|
||||||
if [[ ! "$RESPONSE" =~ "\"success\"" ]]; then
|
if [[ ! "$response" =~ "\"success\"" ]]; then
|
||||||
|
|
||||||
echo && error "Failed to send shutdown command ( ${RESPONSE} )."
|
echo && error "Failed to send shutdown command ( $response )."
|
||||||
|
|
||||||
kill -15 "$(cat "$QEMU_PID")"
|
kill -15 "$(cat "$QEMU_PID")"
|
||||||
pkill -f qemu-system-x86_64 || true
|
pkill -f qemu-system-x86_64 || true
|
||||||
@ -46,15 +47,15 @@ _graceful_shutdown() {
|
|||||||
while [ "$(cat $QEMU_COUNT)" -lt "$QEMU_TIMEOUT" ]; do
|
while [ "$(cat $QEMU_COUNT)" -lt "$QEMU_TIMEOUT" ]; do
|
||||||
|
|
||||||
# Increase the counter
|
# Increase the counter
|
||||||
echo $(($(cat $QEMU_COUNT)+1)) > $QEMU_COUNT
|
echo $(($(cat $QEMU_COUNT)+1)) > "$QEMU_COUNT"
|
||||||
|
|
||||||
# Try to connect to qemu
|
# Try to connect to qemu
|
||||||
if echo 'info version'| nc -q 1 -w 1 localhost "$QEMU_PORT" >/dev/null 2>&1 ; then
|
if echo 'info version'| nc -q 1 -w 1 localhost "$QEMU_PORT" >/dev/null 2>&1 ; then
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
CNT="$(cat $QEMU_COUNT)/$QEMU_TIMEOUT"
|
cnt="$(cat $QEMU_COUNT)/$QEMU_TIMEOUT"
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && info "Shutting down, waiting... ($CNT)"
|
[[ "$DEBUG" == [Yy1]* ]] && info "Shutting down, waiting... ($cnt)"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -48,11 +48,9 @@ rm -rf "$STORAGE/tmp"
|
|||||||
|
|
||||||
getCountry () {
|
getCountry () {
|
||||||
|
|
||||||
local rc
|
|
||||||
local json
|
|
||||||
local result
|
|
||||||
local url=$1
|
local url=$1
|
||||||
local query=$2
|
local query=$2
|
||||||
|
local rc json result
|
||||||
|
|
||||||
{ json=$(curl -m 5 -H "Accept: application/json" -sfk "$url"); rc=$?; } || :
|
{ json=$(curl -m 5 -H "Accept: application/json" -sfk "$url"); rc=$?; } || :
|
||||||
(( rc != 0 )) && return 0
|
(( rc != 0 )) && return 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user