summaryrefslogtreecommitdiff
path: root/others/vm3/compute
diff options
context:
space:
mode:
Diffstat (limited to 'others/vm3/compute')
-rwxr-xr-xothers/vm3/compute/create.sh43
1 files changed, 26 insertions, 17 deletions
diff --git a/others/vm3/compute/create.sh b/others/vm3/compute/create.sh
index 0bb2e63..84646d7 100755
--- a/others/vm3/compute/create.sh
+++ b/others/vm3/compute/create.sh
@@ -7,7 +7,8 @@
7vcpu=8 7vcpu=8
8ram_gb=4 8ram_gb=4
9disk_gb=32 9disk_gb=32
10os="fedora40.qcow2" 10os="fedora40"
11ostype="linux"
11 12
12# parse arguments 13# parse arguments
13while [[ $# -gt 0 ]]; do 14while [[ $# -gt 0 ]]; do
@@ -41,35 +42,39 @@ while [[ $# -gt 0 ]]; do
41 esac 42 esac
42done 43done
43 44
45scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #&& echo $scriptdir
46workingdir="/var/lib/libvirt/images/.temp"
47seed_iso="${workingdir}/seed.iso"
48xml="${workingdir}/xml"
49
50image_dir_path="/var/lib/libvirt/images/.image_store"
51src_file="${image_dir_path}/${os}.qcow2"
52new_vm_dir="/var/lib/libvirt/images/${vmname}"
53new_vm="${new_vm_dir}/${vmname}.qcow2"
54
44# Check mandatory arguments, basicaly checking for initial 1 argument. if it dont exist, vmname will be null 55# Check mandatory arguments, basicaly checking for initial 1 argument. if it dont exist, vmname will be null
45# image is os!! 56# image is os!!
46if [ -z "$vmname" ] ; then 57if [ -z "$vmname" ] ; then
47 echo "Usage: $0 <vm-name> [--image <os>.qcow2] [--vcpu N] [--ram N] [--disk-size N]" 58 echo ""
59 echo "Usage: $0 <vm-name> [--image <os>] [--vcpu N] [--ram N] [--disk-size N]"
48 echo "seed.iso and image file have to be present! Default os is fedora" 60 echo "seed.iso and image file have to be present! Default os is fedora"
49 echo "" 61 echo ""
50 echo "Available images:" 62 echo "Available images:"
51 sudo ls /var/lib/libvirt/images/.image_store 63 sudo ls -1 /var/lib/libvirt/images/.image_store | sed 's/\.qcow2$//'
64 echo ""
65 echo "Available images to download:"
66 sudo ls -1 "${scriptdir}/../.config/cloud-init-generator/" | sed 's/\.sh$//'
52 exit 1 67 exit 1
53fi 68fi
54 69
55scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #&& echo $scriptdir 70# run the script to make the cloud init files
56workingdir="/var/lib/libvirt/images/.temp" 71sudo bash "${scriptdir}/../.config/cloud-init-generator/${os}.sh" "${vmname}"
57seed_iso="${workingdir}/seed.iso"
58xml="${workingdir}/xml"
59
60image_dir_path="/var/lib/libvirt/images/.image_store"
61src_file="${image_dir_path}/${os}"
62new_vm_dir="/var/lib/libvirt/images/${vmname}"
63new_vm="${new_vm_dir}/${vmname}.qcow2"
64 72
65if [ ! -f "${src_file}" ]; then 73if [ ! -f "${src_file}" ]; then
66 echo -e "${os} image file is cannot be found. please make it available in ${image_dir_path}" 74 echo -e "${os} image file is cannot be found. please make it available in ${image_dir_path}"
67 exit 1 75 exit 1
68fi 76fi
69 77
70# run the script to make the cloud init files
71sudo bash "${scriptdir}/../.config/cloud-init-files/$(basename "$os" .qcow2).sh" "${vmname}"
72
73sudo mkdir -p $new_vm_dir 78sudo mkdir -p $new_vm_dir
74 79
75sudo cp "$src_file" "$new_vm" &> /dev/null || { echo "Failed to create a new image."; exit 1; } 80sudo cp "$src_file" "$new_vm" &> /dev/null || { echo "Failed to create a new image."; exit 1; }
@@ -79,13 +84,17 @@ if sudo virsh list --all | awk "\$2==\"$vmname\"" | grep -q .; then
79 exit 1 84 exit 1
80fi 85fi
81 86
87if [[ ${os,,} == *"freebsd"* ]]; then
88 ostype="generic"
89fi
90
82sudo virt-install --name $vmname \ 91sudo virt-install --name $vmname \
83 --vcpus $vcpu \ 92 --vcpus $vcpu \
84 --memory "$((ram_gb * 1024))"\ 93 --memory "$((ram_gb * 1024))"\
85 --disk path=$new_vm,format=qcow2 \ 94 --disk path=$new_vm,format=qcow2 \
86 --disk path=$seed_iso,device=cdrom \ 95 --disk path=$seed_iso,device=cdrom \
87 --os-type linux \ 96 --os-type $ostype \
88 --os-variant $(basename "$os" .qcow2) \ 97 --os-variant $os \
89 --virt-type kvm \ 98 --virt-type kvm \
90 --graphics none \ 99 --graphics none \
91 --network bridge=virbr0,model=virtio \ 100 --network bridge=virbr0,model=virtio \