blob: d4d8a57eb488bee88c7894305398f8209ce4acab [file] [log] [blame]
Vasyl Saienko775c1da2023-07-13 11:34:25 +00001EXAMPLES_DIR=$(cd $(dirname "$0")/.. && pwd)
2WORKDIR=$(cd $(dirname "$0") && pwd)
3source ${EXAMPLES_DIR}/lib.sh
4
5command=$1
6
7function run {
8 echo "Creating PVC with CDI"
9 echo "Downloading cirros"
10 if [[ ! -f ${TMP_DIR}/cirros-0.6.2-x86_64-disk.img ]]; then
11 wget https://download.cirros-cloud.net/0.6.2/cirros-0.6.2-x86_64-disk.img -O ${TMP_DIR}/cirros-0.6.2-x86_64-disk.img
12 cp ${TMP_DIR}/cirros-0.6.2-x86_64-disk.img ${TMP_DIR}/disk.img
13 fi
14
15 echo "Uploading cirros to PVC."
16 UPLOADPROXY_URL=https://$(kubectl get nodes -o wide| tail -1 | awk '{print $6}'):31119
17 virtctl image-upload pvc cirros-add-volume --size 5G --image-path=${TMP_DIR}/disk.img --insecure --uploadproxy-url ${UPLOADPROXY_URL}
18
19 kubectl get pvc
20 kubectl get pods
21
22 echo "Creating VM"
23 kubectl apply -f cirros-add-volume.yaml
24
25 echo "Waiting VM is Running."
26 wait_vm_state cirros-add-volume Running
27
28 read -p "Press any key to add volume" -n 1 -r
29 echo "Adding volume"
30 virtctl addvolume cirros-add-volume --volume-name=cirros-add-volume
31
32 read -p "Press any key to remove volume" -n 1 -r
33 echo "Removing volume"
34 virtctl removevolume cirros-add-volume --volume-name=cirros-add-volume
35}
36
37function cleanup {
38 kubectl delete -f cirros-add-volume.yaml
39 kubectl delete datavolume cirros-add-volume
40 kubectl delete pvc cirros-add-volume
41}
42
43pushd $WORKDIR
44$command
45popd