aboutgitcodelistschat:MatrixIRC
diff options
context:
space:
mode:
authorAlice Frosi <afrosi@redhat.com>2023-06-28 14:17:41 +0200
committerAlice Frosi <afrosi@redhat.com>2023-06-28 14:21:26 +0200
commit7c783a3b82b27033b86f75c018f991ffa59fa548 (patch)
treee89aac0ab7388adde4580b395c6a0845e8cd968f
parentc6286510d5f8c1b7f82f9cdb9153f402a921a49e (diff)
downloadseitan-7c783a3b82b27033b86f75c018f991ffa59fa548.tar
seitan-7c783a3b82b27033b86f75c018f991ffa59fa548.tar.gz
seitan-7c783a3b82b27033b86f75c018f991ffa59fa548.tar.bz2
seitan-7c783a3b82b27033b86f75c018f991ffa59fa548.tar.lz
seitan-7c783a3b82b27033b86f75c018f991ffa59fa548.tar.xz
seitan-7c783a3b82b27033b86f75c018f991ffa59fa548.tar.zst
seitan-7c783a3b82b27033b86f75c018f991ffa59fa548.zip
vm-images: create script to setut fcos test VM
-rwxr-xr-xvm-images/create_coreos_vm.sh55
-rw-r--r--vm-images/fcos_test.bu20
2 files changed, 75 insertions, 0 deletions
diff --git a/vm-images/create_coreos_vm.sh b/vm-images/create_coreos_vm.sh
new file mode 100755
index 0000000..03ac937
--- /dev/null
+++ b/vm-images/create_coreos_vm.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# create_coreos_vm.sh: Create a Fedora CoreOS VM for testing with libvirt.
+# The VM can be accessed using user: coreos password: test
+#
+# Copyright (c) 2023 Red Hat GmbH
+# Author: Alice Frosi <afrosi@redhat.com>
+
+BUTANE_CONFIG="fcos_test.bu"
+IGNITION_CONFIG=$(pwd)/"fcos_test.ign"
+VM_NAME="fcos-test"
+VCPUS="2"
+RAM_MB="2048"
+STREAM="stable"
+DISK_GB="10"
+IMAGE_PREFIX="fedora-coreos-"
+
+IGNITION_DEVICE_ARG=(--qemu-commandline="-fw_cfg name=opt/com.coreos/config,file=${IGNITION_CONFIG}")
+URL=https://builds.coreos.fedoraproject.org/streams/stable.json
+URL_IMAGES=https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/38.20230609.3.0/x86_64
+LAST_RELEASE=$(curl -s $URL| jq '.architectures.x86_64[].qemu.release| select( . != null )' |tr -d "\"")
+IMAGE_NAME=${IMAGE_PREFIX}${LAST_RELEASE}-qemu.x86_64.qcow2
+LIBVIRT_IMAGES=$HOME/.local/share/libvirt/images
+IMAGE=${LIBVIRT_IMAGES}/${IMAGE_NAME}
+
+set -e
+
+# Don't execute the script if VM is still exists in libvirt
+if virsh list --all | grep ${VM_NAME} ; then
+ echo "VM ${VM_NAME} still exists"
+ exit 0
+fi
+
+# Avoid to download the image if it is already present locally
+if [ ! -f "${IMAGE}" ] ; then
+ podman run --pull=always --rm -v ${LIBVIRT_IMAGES}:/data -w /data \
+ quay.io/coreos/coreos-installer:release \
+ download -s "${STREAM}" -p qemu -f qcow2.xz --decompress
+fi
+
+# Create ignition file from butane config
+podman run --interactive --rm --security-opt label=disable \
+ --volume $(pwd):/pwd --workdir /pwd quay.io/coreos/butane:release \
+ --pretty --strict ${BUTANE_CONFIG=} > ${IGNITION_CONFIG}
+
+# Setup the correct SELinux label to allow access to the config
+chcon --verbose --type svirt_home_t ${IGNITION_CONFIG}
+
+# Install the VM
+virt-install --name="${VM_NAME}" --vcpus="${VCPUS}" --memory="${RAM_MB}" \
+ --os-variant="fedora-coreos-$STREAM" --import --graphics=none \
+ --disk="size=${DISK_GB},backing_store=${IMAGE}" \
+ --network bridge=virbr0 "${IGNITION_DEVICE_ARG[@]}"
diff --git a/vm-images/fcos_test.bu b/vm-images/fcos_test.bu
new file mode 100644
index 0000000..70edd1e
--- /dev/null
+++ b/vm-images/fcos_test.bu
@@ -0,0 +1,20 @@
+variant: fcos
+version: 1.4.0
+passwd:
+ users:
+ - name: core
+ # password: test
+ password_hash: "$y$j9T$MvL4tZ2JgfWZEaO4SFuMF0$tHtlfyp.LoPRrMrGAaNV8pvC5u62R8dicPnT0Z9LW65"
+ groups:
+ - wheel
+ - sudo
+storage:
+ files:
+ - path: /etc/ssh/sshd_config.d/20-enable-passwords.conf
+ mode: 0644
+ contents:
+ inline: |
+ # Fedora CoreOS disables SSH password login by default.
+ # Enable it.
+ # This file must sort before 40-disable-passwords.conf.
+ PasswordAuthentication yes