@@ -20,90 +20,100 @@ runs:
20
20
scp $SSH_OPTS /opt/ubuntu-cloud-init-ds.iso "$USER@$IP_HV2:/var/lib/libvirt/images/ubuntu-cloud-init-ds.iso"
21
21
22
22
- name : Start VM on HyperVisor 1
23
- uses : appleboy/ssh-action@v1
24
- with :
25
- host : 192.168.122.2
26
- username : root
27
- key_path : /opt/ssh_host_ed25519_key
28
- script : |
23
+ shell : bash
24
+ run : |
25
+ KEY=/opt/ssh_host_ed25519_key
26
+ SSH_OPTS="-i $KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
27
+ USER="root"
28
+ IP_HV1="192.168.122.2"
29
+
30
+ ssh $SSH_OPTS "$USER@$IP_HV1" << EOF
29
31
virsh define /opt/vm.xml
30
32
virsh start VM
33
+ EOF
31
34
32
35
- name : Wait for VM to be ready
33
- uses : appleboy/ssh-action@v1
34
- with :
35
- host : 192.168.122.2
36
- username : root
37
- key_path : /opt/ssh_host_ed25519_key
38
- script : |
36
+ shell : bash
37
+ run : |
38
+ KEY=/opt/ssh_host_ed25519_key
39
+ SSH_OPTS="-i $KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
40
+ USER="root"
41
+ IP_HV1="192.168.122.2"
42
+
43
+ ssh $SSH_OPTS "$USER@$IP_HV1" << EOF
39
44
KEY=/opt/ssh_host_ed25519_key
40
- SSH_OPTS="-i $KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
45
+ SSH_OPTS="-i \ $KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
41
46
USER="root"
42
47
43
48
MAX_ITER=40
44
49
for ((i=1; i<=MAX_ITER; i++)); do
45
- IP=$(virsh domifaddr VM | awk '/ipv4/ {print $4}' | cut -d'/' -f1)
46
- if [ -z "$IP" ]; then
50
+ IP=\ $(virsh domifaddr VM | awk '/ipv4/ {print \ $4}' | cut -d'/' -f1)
51
+ if [ -z "\ $IP" ]; then
47
52
echo "No IP address found for VM. Retrying..."
48
- elif ssh $SSH_OPTS "$USER@$IP" 'exit' 2>/dev/null; then
49
- echo "VM is up at IP: $IP"
53
+ elif ssh \ $SSH_OPTS "\ $USER@\ $IP" 'exit' 2>/dev/null; then
54
+ echo "VM is up at IP: \ $IP"
50
55
# create a dummy file for verification later
51
- ssh $SSH_OPTS "$USER@$IP" 'echo "Hello, World!" > /opt/hello.txt'
56
+ ssh \ $SSH_OPTS "\ $USER@\ $IP" 'echo "Hello, World!" > /opt/hello.txt'
52
57
break
53
58
fi
54
59
if (( i == MAX_ITER )); then
55
60
echo "Timeout waiting for VM to respond to SSH."
56
61
cat /var/log/VM.log
57
62
exit 1
58
63
fi
59
- echo "Waiting for VM to respond to SSH... ($i/$MAX_ITER)"
64
+ echo "Waiting for VM to respond to SSH... (\ $i/\ $MAX_ITER)"
60
65
sleep 10
61
66
done
67
+ EOF
62
68
63
69
- name : Mirgrate the VM to HyperVisor 2
64
- uses : appleboy/ssh-action@v1
65
- with :
66
- host : 192.168.122.2
67
- username : root
68
- key_path : /opt/ssh_host_ed25519_key
69
- script : |
70
+ shell : bash
71
+ run : |
72
+ KEY=/opt/ssh_host_ed25519_key
73
+ SSH_OPTS="-i $KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
74
+ USER="root"
75
+ IP_HV1="192.168.122.2"
76
+
77
+ ssh $SSH_OPTS "$USER@$IP_HV1" << EOF
70
78
USER="root"
71
- HV2_IP ="192.168.122.3"
79
+ IP_HV2 ="192.168.122.3"
72
80
73
- virsh migrate --persistent --undefinesource --copy-storage-all --live VM qemu+ssh://$USER@$HV2_IP /system
81
+ virsh migrate --persistent --undefinesource --copy-storage-all --live VM qemu+ssh://\ $USER@\$IP_HV2 /system
74
82
if virsh dominfo VM &>/dev/null; then
75
83
echo "VM is still present on HV1 after migration!"
76
84
exit 1
77
85
fi
86
+ EOF
78
87
79
88
- name : Verify VM status on HyperVisor 2
80
- uses : appleboy/ssh-action@v1
81
- with :
82
- host : 192.168.122.3
83
- username : root
84
- key_path : /opt/ssh_host_ed25519_key
85
- command_timeout : 30m
86
- script : |
87
- if virsh dominfo VM | awk '/State:/ {print $2}' | grep -q "running"; then
89
+ shell : bash
90
+ run : |
91
+ KEY=/opt/ssh_host_ed25519_key
92
+ SSH_OPTS="-i $KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
93
+ USER="root"
94
+ IP_HV2="192.168.122.3"
95
+
96
+ ssh $SSH_OPTS "$USER@$IP_HV2" << EOF
97
+ if virsh dominfo VM | awk '/State:/ {print \$2}' | grep -q "running"; then
88
98
echo "VM is running on HV2."
89
99
else
90
100
echo "VM is not running on HV2."
91
101
exit 1
92
102
fi
93
103
94
104
KEY=/opt/ssh_host_ed25519_key
95
- SSH_OPTS="-i $KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
105
+ SSH_OPTS="-i \ $KEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
96
106
USER="root"
97
107
# waiting for the IP to be visible to the new HyperVisor via DHCP takes WAYYYYYYY too long
98
108
# the IP is static, so we can just use it directly
99
109
IP="192.168.222.2"
100
110
101
111
MAX_ITER=40
102
112
for ((i=1; i<=MAX_ITER; i++)); do
103
- if ssh $SSH_OPTS "$USER@$IP" 'exit' 2>/dev/null; then
104
- echo "VM is up at IP: $IP"
113
+ if ssh \ $SSH_OPTS "\ $USER@\ $IP" 'exit' 2>/dev/null; then
114
+ echo "VM is up at IP: \ $IP"
105
115
# verify the migration by checking the dummy file
106
- if ssh $SSH_OPTS "$USER@$IP" 'test -f /opt/hello.txt'; then
116
+ if ssh \ $SSH_OPTS "\ $USER@\ $IP" 'test -f /opt/hello.txt'; then
107
117
echo "Dummy file exists on VM, migration successful."
108
118
break
109
119
else
@@ -116,6 +126,7 @@ runs:
116
126
cat /var/log/VM.log
117
127
exit 1
118
128
fi
119
- echo "Waiting for VM to respond to SSH... ($i/$MAX_ITER)"
129
+ echo "Waiting for VM to respond to SSH... (\ $i/\ $MAX_ITER)"
120
130
sleep 10
121
131
done
132
+ EOF
0 commit comments