Closed kevydotvinu closed 1 year ago
#!/bin/bash
# The script needs userdata, networkdata, network and directory as an args
set -eou pipefail
BRIDGE=${1}
NETWORK=$(echo ${BRIDGE} | tr "," "\n" | while read bridge; do echo --network bridge=${bridge}; done)
DIRECTORY=${2}
CLOUDINIT_USER_DATA=${3}
CLOUDINIT_NETWORK_CONFIG=${4}
IMAGE=${5}
HOST_IP=$(ip r s default | awk '{print $9}')
ONP_DIR=/home/onp/openshift-network-playground
VM_NAME=$(basename -- ${DIRECTORY})
VM_NAME=${VM_NAME%.*}
IMAGE_NAME=$(basename -- ${IMAGE})
EXTENSION=${IMAGE_NAME##*.}
DISK=${DIRECTORY}/${VM_NAME}.${EXTENSION}
sudo rm -rf ${DIRECTORY}
sudo mkdir -p ${DIRECTORY}
sudo cloud-localds -m local --network-config=${CLOUDINIT_NETWORK_CONFIG} ${DIRECTORY}/seed.iso ${CLOUDINIT_USER_DATA}
echo "Downloading ${VM_NAME} image ..."
sudo curl -#Lo ${DISK} ${IMAGE}
sudo virsh -q destroy ${VM_NAME} > /dev/null || true
sudo virsh -q undefine ${VM_NAME} > /dev/null || true
sudo virt-install --name ${VM_NAME} \
--vcpus 1 \
--ram 2048 \
--os-variant fedora-unknown \
--import \
${NETWORK} \
--disk ${DISK} \
--disk ${DIRECTORY}/seed.iso \
--graphics spice,listen=${HOST_IP} \
--video virtio \
--channel spicevmc \
--console pty,target.type=virtio \
--serial pty \
--noautoconsole
sudo virsh console ${VM_NAME}
cat openshift-network-playground/fedora-user-data.yaml
#cloud-config
preserve_hostname: False
hostname: fedora
fqdn: fedora.onp2.example.local
packages:
- cloud-initramfs-growroot
output:
all: ">> /var/log/cloud-init.log"
users:
- name: onp
plain_text_passwd: 'Onp@123'
lock-passwd: False
sudo: ['ALL=(ALL) NOPASSWD:ALL']
groups: sudo
shell: /bin/bash
ssh_pwauth: True
$ cat openshift-network-playground/fedora-dhcp-network-v1.yaml
network:
version: 1
config:
- type: physical
name: eth0
subnets:
- type: dhcp
cat .Makefile | head -n 20
SHELL = /bin/bash
RELEASE ?= stable
LOGLEVEL ?= info
SCRIPT_DIR = $(shell cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )
CONTAINERS = $(shell sudo podman ps --format {{.Names}} | sort | grep -oE '^dhcp|^proxy|^vbmc|^webserver' | xargs)
VMS = $(shell sudo virsh list --all --name | grep -oE 'master0|master1|master2|worker0|worker1' | xargs)
TFF = $(shell ls /tmp/openshift-install-bootstrap-*/terraform.platform.auto.tfvars.json 2>/dev/null | wc -l)
VIRBR0=$(shell sudo virsh net-info default | awk '/Bridge:/{print $$2}')
VIRBR0MAC=$(shell ip a s ${VIRBR0} | awk '/ether /{print $$2}' | cut -f1-4 -d':')
NETWORK ?= baremetal
BUTANE?=${HOME}/openshift-network-playground/core-passwd.bu
FEDORA_DIR=/opt/openshift-network-playground/libvirt/fedora
FEDORA_CLOUDINIT_USER ?= ${HOME}/openshift-network-playground/fedora-user-data.yaml
FEDORA_CLOUDINIT_NETWORK ?= ${HOME}/openshift-network-playground/fedora-network-config-v1.yaml
FEDORA_IMAGE=https://download.fedoraproject.org/pub/fedora/linux/releases/38/Cloud/x86_64/images/Fedora-Cloud-Base-38-1.6.x86_64.qcow2
VYOS_DIR=/opt/openshift-network-playground/libvirt/vyos
VYOS_CLOUDINIT_USER=${HOME}/openshift-network-playground/vyos-user-data.yaml
VYOS_CLOUDINIT_NETWORK=${HOME}/openshift-network-playground/vyos-network-config-v2.yaml
VYOS_IMAGE=https://s3-us.vyos.io/1.2.9-S1/vyos-1.2.9-S1-10G-qemu.qcow2
$ grep -A7 fedora: .Makefile
fedora:
@${HOME}/openshift-network-playground/vm.sh ${NETWORK} ${FEDORA_DIR} ${FEDORA_CLOUDINIT_USER} ${FEDORA_CLOUDINIT_NETWORK} ${FEDORA_IMAGE}
.PHONY: vyos
vyos:
@${HOME}/openshift-network-playground/vm.sh ${NETWORK} ${VYOS_DIR} ${VYOS_CLOUDINIT_USER} ${VYOS_CLOUDINIT_NETWORK} ${VYOS_IMAGE}
$ cat openshift-network-playground/fedora-static-network-v1.yaml
network:
version: 1
config:
- type: physical
name: eth0
subnets:
- type: static
address: 192.168.124.11
gateway: 192.168.124.2
dns_nameservers:
- 192.168.124.2
dns_search:
- onp1.example.local
ubuntu:
@${HOME}/openshift-network-playground/vm.sh ${NETWORK} ${UBUNTU_DIR} ${UBUNTU_CLOUDINIT_USER} ${UBUNTU_CLOUDINIT_NETWORK} ${UBUNTU_IMAGE}
UBUNTU_DIR=/opt/openshift-network-playground/libvirt/ubuntu
UBUNTU_CLOUDINIT_USER ?= ${HOME}/openshift-network-playground/ubuntu-user-data.yaml
UBUNTU_CLOUDINIT_NETWORK ?= ${HOME}/openshift-network-playground/ubuntu-network-dhcp-v1.yaml
UBUNTU_IMAGE=https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
#cloud-config
preserve_hostname: False
hostname: ubuntu
fqdn: ubuntu.onp.example.local
packages:
- cloud-initramfs-growroot
output:
all: ">> /var/log/cloud-init.log"
users:
- name: onp
plain_text_passwd: 'Onp@123'
lock-passwd: False
sudo: ['ALL=(ALL) NOPASSWD:ALL']
groups: sudo
shell: /bin/bash
ssh_pwauth: True
#cloud-config
preserve_hostname: False
hostname: fedora-metallb
fqdn: fedora-metallb.onp.example.local
packages:
- zsh
- git
- pip
- podman
- make
- lua
runcmd:
- [ modprobe, ip_tables ]
- [ modprobe, ip6_tables ]
- [ su, onp, -c, "git clone https://github.com/kevydotvinu/dotfiles /home/onp/dotfiles" ]
- [ su, onp, -c, "make -C /home/onp/dotfiles nvim" ]
- [ su, onp, -c, "make -C /home/onp/dotfiles ohmyzsh" ]
- [ su, onp, -c, "make -C /home/onp/dotfiles go-download GO_VERSION=go" ]
- [ su, onp, -c, "make -C /home/onp/dotfiles kind-download" ]
- [ su, onp, -c, "git clone https://github.com/kevydotvinu/metallb-metallb /home/onp/metallb-metallb" ]
- [ su, onp, -c, "pip3 install invoke semver" ]
- [ ln, -sfv, /usr/bin/podman, /usr/bin/docker ]
output:
all: ">> /var/log/cloud-init.log"
users:
- name: onp
plain_text_passwd: 'Onp@123'
lock-passwd: False
sudo: ALL=(ALL) NOPASSWD:ALL
groups: sudo
shell: /bin/bash
ssh_pwauth: True
Add
cloud-utils
package in https://github.com/kevydotvinu/openshift-network-playground/blob/main/manifest.yaml https://blog.josefsson.org/2022/08/22/static-network-config-with-debian-cloud-images/