Skip to content

Commit 434f61e

Browse files
committed
.WIP
1 parent b96ff43 commit 434f61e

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

src/cron-callback.sh

+16-16
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ ssh_pwauth: True
3636

3737
function download_cloud_img_if_not_exist () {
3838
local cloudimg="$1"
39-
[[ "$1" != "focal-server-cloudimg-amd64.img" ]] && echo "ERROR: cloudimg not supported"
40-
[[ -f "base/$cloudimg" ]] || aria2c -o "base/$cloudimg" https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img || ! echo "Failed to download ubuntu cloudimg" || return $?
39+
[[ "$1" != "focal-server-cloudimg-amd64.img" ]] && echo2 "ERROR: cloudimg not supported"
40+
[[ -f "base/$cloudimg" ]] || aria2c -o "base/$cloudimg" https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img || ! echo2 "Failed to download ubuntu cloudimg" || return $?
4141
}
4242

4343
function create_vm_if_not_exist () {
@@ -65,7 +65,8 @@ function create_vm_if_not_exist () {
6565

6666
function start_vm_if_not_running () {
6767
local name=$1
68-
local options="$2"
68+
local options_txt="$2"
69+
read -a options <<< "$options_txt"
6970

7071
# For tracking started instance
7172
local uuid=`uuidgen --namespace @oid --name "qemu.$name" --sha1`
@@ -74,15 +75,18 @@ function start_vm_if_not_running () {
7475
ps aux | grep -F "--uuid $uuid" | grep qemu && return 0
7576

7677
# start it
78+
[[ ! -f "vm/$name/disk.img" ]] && echo2 "In start_vm, disk image vm/$name/disk.img doesn't exist. Did init_vm fail?" && return 1
7779
nohup qemu-system-x86_64 --uuid "$uuid" -drive file="vm/$name/disk.img",if=virtio -cdrom "vm/$name/initimg.iso" -cpu host --enable-kvm -bios /usr/share/edk2-ovmf/x64/OVMF.fd -net nic,model=rtl8139 "${options[@]}" & disown
7880
}
7981

80-
# [[ $2 = "" ]] && echo "Temp script to create VM. Usage: $0 MY_GOOD_VM11 :11" && exit 1
81-
# create_vm_from "$1" 2 4G 50G __hardcoded__ r 1 "$2" __hardcoded__ || exit $?
82-
# echo "DEBUG: sshpass -p 1 ssh -p 30472 r@localhost"
83-
8482
function do_init () {
8583
while IFS= read -r line; do
84+
# Ignore lines starting with #
85+
if [[ "$line" =~ ^\# ]]; then
86+
continue
87+
fi
88+
# Trim leading and trailing whitespaces
89+
line=$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
8690
# Check if the line is non-empty
8791
if [ -n "$line" ]; then
8892
# Parse the line as "name;cloudimg;disk;username;password", trim space
@@ -104,27 +108,23 @@ function do_start () {
104108
if [[ "$line" =~ ^\# ]]; then
105109
continue
106110
fi
107-
108111
# Trim leading and trailing whitespaces
109112
line=$(echo "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
110-
111113
# Check if the line is non-empty
112114
if [ -n "$line" ]; then
113115
# Parse the line as "name;options", only trim space in name, options can contain ;
114116
name=$(echo "$line" | sed -e 's/[[:space:]]*;.*$//' -e 's/^[[:space:]]*//')
115-
options=$(echo "$line" | sed 's/^[^:]*://')
117+
options=$(echo "$line" | sed 's/^[^;]*;//')
116118

117119
# Check if the name is empty
118120
if [ -n "$name" ]; then
119-
# Print the parsed values
120-
echo "Name: $name|"
121-
echo "Options: $options|"
122-
echo "---------------------"
121+
start_vm_if_not_running "$name" "$options" || echo2 "Failed to start_vm_if_not_running. $?"
123122
else
124-
# Print an error message for empty name
125-
echo "Error: Name is empty. Skipping the line."
123+
echo2 "Error: Bad configuration line: $line"
126124
fi
127125
fi
128126
done < ../runtime.settings
129127
}
130128

129+
do_init
130+
do_start

src/init.settings

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# name;cloudimg;disk;username;password (space will be trimmed)
22
instance1;focal-server-cloudimg-amd64.img;60G;r;1
3-
gitlab-ci;focal-server-cloudimg-amd64.img;60G;r;1
4-
httptest ;focal-server-cloudimg-amd64.img;60G;r;1
3+
#gitlab-ci;focal-server-cloudimg-amd64.img;60G;r;1
4+
#httptest ;focal-server-cloudimg-amd64.img;60G;r;1

src/runtime.settings

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# name;options (space in name will be trimmed)
1+
# name;options (name will be trimmed, options will be passed as-is)
22
instance1;-m 2G -smp 2 -vnc :11 -net user,hostfwd=tcp::30472-:22
3-
gitlab-ci;-m 4G -smp 4 -vnc :12 -net user,hostfwd=tcp::30473-:22
4-
httptest ;-m 1G -smp 1 -vnc :13 -net user,hostfwd=tcp::30474-:22
3+
#gitlab-ci;-m 4G -smp 4 -vnc :12 -net user,hostfwd=tcp::30473-:22
4+
#httptest ;-m 1G -smp 1 -vnc :13 -net user,hostfwd=tcp::30474-:22

0 commit comments

Comments
 (0)