From 31cfa79073dfc70eedb93ff85a2ee9825c3e5ef0 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Wed, 15 Apr 2026 23:08:19 +0200 Subject: [PATCH] feat: Use vagrant for managing vm --- .gitignore | 1 + Vagrantfile | 28 +++++++ mise.toml | 2 + talos/clusters/testing.yaml | 2 +- tools/vm | 153 ------------------------------------ 5 files changed, 32 insertions(+), 154 deletions(-) create mode 100644 Vagrantfile create mode 100644 mise.toml delete mode 100755 tools/vm diff --git a/.gitignore b/.gitignore index b676401..8a5fca4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .ipxe/ rendered/ configs/ +.vagrant/ diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..a8bb2f3 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,28 @@ +Vagrant.configure("2") do |config| + config.vm.define "talos-vm" do |vm| + vm.vm.network :private_network, + :type => "dhcp", + :libvirt__network_address => "192.168.1.0", + :libvirt__netmask => "255.255.255.0", + # :libvirt__dhcp_bootp_file => "ipxe.pxe" + :libvirt__dhcp_bootp_file => "http://192.168.1.1:8000/ipxe.pxe" + + vm.vm.hostname = "talos" + + vm.vm.provider :libvirt do |domain| + domain.cpus = 6 + domain.memory = 16 * 1024 + domain.storage :file, :size => '100G', :type => 'raw' + domain.mgmt_attach = false + + domain.boot "hd" + domain.boot "network" + + domain.sysinfo = { + "system": { + "serial": "talos-vm" + } + } + end + end +end diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..dae9f7e --- /dev/null +++ b/mise.toml @@ -0,0 +1,2 @@ +[env] +VAGRANT_DEFAULT_PROVIDER = "libvirt" diff --git a/talos/clusters/testing.yaml b/talos/clusters/testing.yaml index 193b8fd..a67ab30 100644 --- a/talos/clusters/testing.yaml +++ b/talos/clusters/testing.yaml @@ -7,7 +7,7 @@ nodes: default: network: - interface: enp1s0 + interface: ens5 netmask: 255.255.255.0 gateway: 192.168.1.1 sops: diff --git a/tools/vm b/tools/vm deleted file mode 100755 index bb3b514..0000000 --- a/tools/vm +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -ROOT=$(git rev-parse --show-toplevel) - -VM_NAME="talos-vm" -VCPUS="6" -RAM_MB="16384" -DISK_GB="100" -NETWORK=talos -CONNECTION="qemu:///system" - -function define_network() { - config_file=$(mktemp) - cat > ${config_file} << EOF - - ${NETWORK} - - - - - - - - - - - -EOF - - function cleanup() { - rm ${config_file} - } - trap cleanup EXIT - - if [[ $(virsh --connect="${CONNECTION}" net-list --all | grep -c "${NETWORK}") == "0" ]]; then - virsh --connect="${CONNECTION}" net-define "${config_file}" - virsh --connect="${CONNECTION}" net-start "${NETWORK}" - virsh --connect="${CONNECTION}" net-autostart "${NETWORK}" - fi - - trap - EXIT - cleanup -} - - -function create() { - define_network - - if [[ $(virsh --connect="${CONNECTION}" list --all | grep -c "${VM_NAME}") == "0" ]]; then - virt-install --connect="${CONNECTION}" --name="${VM_NAME}" --vcpus="${VCPUS}" --memory="${RAM_MB}" \ - --os-variant="linux2022" \ - --disk="size=${DISK_GB}" \ - --pxe \ - --sysinfo system.serial=${VM_NAME} \ - --network network="${NETWORK}" - else - echo -n "VM already exists, start it with: - ${0} start -" - exit -1 - fi -} - -function start() { - if [[ $(virsh --connect="${CONNECTION}" list --all | grep -c "${VM_NAME}") > "0" ]]; then - virsh --connect="${CONNECTION}" start ${VM_NAME} - virt-viewer --connect="${CONNECTION}" ${VM_NAME} - else - echo -n "VM doest not exists yet, create it with: - ${0} create -" - exit -1 - fi -} - -function connect() { - if [[ $(virsh --connect="${CONNECTION}" list | grep -c "${VM_NAME}") > "0" ]]; then - virt-viewer --connect="${CONNECTION}" ${VM_NAME} - else - echo "VM is not running" - exit -1 - fi -} - -function stop() { - if [[ $(virsh --connect="${CONNECTION}" list | grep -c "${VM_NAME}") > "0" ]]; then - virsh --connect="${CONNECTION}" shutdown ${VM_NAME} - WAIT=240 - for i in $(seq 0 1 ${WAIT}); do - echo -en "\rWaiting for VM to shutdown... (${i}/${WAIT})" - - if [[ $(virsh --connect="${CONNECTION}" list | grep -c "${VM_NAME}") == "0" ]]; then - echo -e "\nVM successfully shutdown" - exit - fi - - sleep 1 - done - - echo -e "\nDestroying VM" - virsh --connect="${CONNECTION}" destroy ${VM_NAME} - else - echo "VM is not running" - exit -1 - fi -} - -function delete() { - if [[ $(virsh --connect="${CONNECTION}" list --all | grep -c "${VM_NAME}") > "0" ]]; then - if [[ $(virsh --connect="${CONNECTION}" list | grep -c "${VM_NAME}") > "0" ]]; then - virsh --connect="${CONNECTION}" destroy "${VM_NAME}" - fi - virsh --connect="${CONNECTION}" undefine "${VM_NAME}" --remove-all-storage - fi - - if [[ $(virsh --connect="${CONNECTION}" net-list --all | grep -c "${NETWORK}") > "0" ]]; then - if [[ $(virsh --connect="${CONNECTION}" list | grep -c "${VM_NAME}") > "0" ]]; then - virsh --connect="${CONNECTION}" net-destroy "${NETWORK}" - fi - virsh --connect="${CONNECTION}" net-undefine "${NETWORK}" - fi -} - -function help() { - echo -n "Available commands: - start - stop - remove - connect -" -} - -COMMAND=${1:-} -case ${COMMAND} in - create) - create Create the vm and perform first install - ;; - start) - start Start the vm - ;; - stop) - stop Stop the vm - ;; - delete) - delete Delete the vm - ;; - connect) - connect Connect to an already running vm - ;; - *) - help - ;; -esac