Skip to content

Commit

Permalink
Add fake_ipa config
Browse files Browse the repository at this point in the history
  • Loading branch information
mboukhalfa committed Mar 22, 2023
1 parent 0c341b4 commit 2a75fc3
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 74 deletions.
12 changes: 7 additions & 5 deletions Support/Multitenancy/ironic-env/01-vm-setup.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
set -e
#install kvm for minikube
dnf -y install qemu-kvm libvirt virt-install net-tools
dnf -y install qemu-kvm libvirt virt-install net-tools podman firewalld
systemctl enable --now libvirtd
systemctl start firewalld
systemctl enable firewalld
# create provisioning network
cat <<EOF > provisioning.xml
cat <<EOF >provisioning.xml
<network
xmlns:dnsmasq='http://libvirt.org/schemas/network/dnsmasq/1.0'>
<dnsmasq:options>
Expand All @@ -16,7 +18,7 @@ cat <<EOF > provisioning.xml
</network>
EOF

cat <<EOF > baremetal.xml
cat <<EOF >baremetal.xml
<network xmlns:dnsmasq='http://libvirt.org/schemas/network/dnsmasq/1.0'>
<name>baremetal</name>
<forward mode='nat'>
Expand Down Expand Up @@ -46,11 +48,11 @@ cat <<EOF > baremetal.xml
</network>
EOF
# define networks
virsh net-define baremetal.xml
virsh net-define baremetal.xml
virsh net-start baremetal
virsh net-autostart baremetal

virsh net-define provisioning.xml
virsh net-define provisioning.xml
virsh net-start provisioning
virsh net-autostart provisioning
tee -a /etc/NetworkManager/system-connections/provisioning.nmconnection <<EOF
Expand Down
118 changes: 79 additions & 39 deletions Support/Multitenancy/ironic-env/03-images-and-run-local-services.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,87 @@
set -e
virsh attach-interface --domain minikube --model virtio --source provisioning --type network --config
# Set variables
REGISTRY_NAME="registry"
REGISTRY_PORT="5000"
IMAGE_NAMES=(
"quay.io/metal3-io/sushy-tools"
"quay.io/metal3-io/ironic-ipa-downloader"
"quay.io/metal3-io/ironic:latest"
"quay.io/metal3-io/ironic-client"
"quay.io/metal3-io/keepalived"
)
${quay.io/metal3-io/sushy-tools##*/}
# Attach provisioning and baremetal network interfaces to minikube domain
virsh attach-interface --domain minikube --model virtio --source provisioning --type network --config
virsh attach-interface --domain minikube --model virtio --source baremetal --type network --config
# Download images
podman run -d -p 5000:5000 --name registry docker.io/library/registry:2.7.1
# Create pods
podman pod create -n infra-pod || true
podman pod create -n ironic-pod || true
# Pull images
mkdir -p /opt/metal3-dev-env/ironic/html/images
podman pull quay.io/metal3-io/sushy-tools
podman pull quay.io/metal3-io/ironic-ipa-downloader
podman pull quay.io/metal3-io/ironic:latest
podman pull quay.io/metal3-io/ironic-client
podman pull quay.io/metal3-io/keepalived
podman tag quay.io/metal3-io/sushy-tools 127.0.0.1:5000/localimages/sushy-tools
podman tag quay.io/metal3-io/ironic-ipa-downloader 127.0.0.1:5000/localimages/ironic-ipa-downloader
podman tag quay.io/metal3-io/ironic-client 127.0.0.1:5000/localimages/ironic-client
podman tag quay.io/metal3-io/keepalived 127.0.0.1:5000/localimages/keepalived
podman tag quay.io/metal3-io/ironic:latest 127.0.0.1:5000/localimages/ironic:latest
podman push --tls-verify=false 127.0.0.1:5000/localimages/keepalived
podman push --tls-verify=false 127.0.0.1:5000/localimages/ironic-client
podman push --tls-verify=false 127.0.0.1:5000/localimages/ironic:latest
podman push --tls-verify=false 127.0.0.1:5000/localimages/ironic-ipa-downloader
podman push --tls-verify=false 127.0.0.1:5000/localimages/sushy-tools
# Run host services
# Run httpd
podman run -d --net host --name httpd-infra --pod infra-pod -v /opt/metal3-dev-env/ironic:/shared -e PROVISIONING_INTERFACE=provisioning -e LISTEN_ALL_INTERFACES=false --entrypoint /bin/runhttpd 127.0.0.1:5000/localimages/ironic:latest
# Run sushy-tools
mkdir /opt/metal3-dev-env/ironic/virtualbmc
mkdir /opt/metal3-dev-env/ironic/virtualbmc/sushy-tools
chmod -R 755 /opt/metal3-dev-env/ironic/virtualbmc

cat <<EOF > /opt/metal3-dev-env/ironic/virtualbmc/sushy-tools/conf.py
SUSHY_EMULATOR_LIBVIRT_URI = "qemu+ssh://root@192.168.111.1/system?&keyfile=/root/ssh/id_rsa_virt_power&no_verify=1&no_tty=1"

# Start podman registry if it's not already running
if ! podman ps | grep -q "$REGISTRY_NAME"; then
podman run -d -p "$REGISTRY_PORT":"$REGISTRY_PORT" --name "$REGISTRY_NAME" docker.io/library/registry:2.7.1
fi

# Pull images, tag to local registry, and push to registry
for NAME in "${IMAGE_NAMES[@]}"; do
# Pull and tag the image
podman pull "$NAME"
podman tag "$NAME" 127.0.0.1:"$REGISTRY_PORT"/localimages/"${NAME##*/}"
# Push the image to the local registry
podman push --tls-verify=false 127.0.0.1:5000/localimages/"${NAME##*/}"
done

# Define variables for repeated values
IRONIC_IMAGE="127.0.0.1:5000/localimages/ironic:latest"
SUSHY_TOOLS_IMAGE="127.0.0.1:5000/localimages/sushy-tools"
LIBVIRT_URI="qemu+ssh://root@192.168.111.1/system?&keyfile=/root/ssh/id_rsa_virt_power&no_verify=1&no_tty=1"
API_URL="http://172.22.0.2:6385"
CALLBACK_URL="http://172.22.0.2:5050/v1/continue"
ADVERTISE_HOST="192.168.111.1"
ADVERTISE_PORT="9999"

# Create directories
DIRECTORIES=(
"/opt/metal3-dev-env/ironic/virtualbmc"
"/opt/metal3-dev-env/ironic/virtualbmc/sushy-tools"
)
for DIR in "${DIRECTORIES[@]}"; do
mkdir -p "$DIR"
chmod -R 755 "$DIR"
done

# Run httpd container
podman run -d --net host --name httpd-infra \
--pod infra-pod \
-v /opt/metal3-dev-env/ironic:/shared \
-e PROVISIONING_INTERFACE=provisioning \
-e LISTEN_ALL_INTERFACES=false \
--entrypoint /bin/runhttpd \
"$IRONIC_IMAGE"
# Set configuration options
cat <<EOF >/opt/metal3-dev-env/ironic/virtualbmc/sushy-tools/conf.py
import collections
Host = collections.namedtuple('Host', ['hostname', 'port'])
SUSHY_EMULATOR_LIBVIRT_URI = "${LIBVIRT_URI}"
SUSHY_EMULATOR_IGNORE_BOOT_DEVICE = False
SUSHY_EMULATOR_VMEDIA_VERIFY_SSL = False
SUSHY_EMULATOR_AUTH_FILE = "/root/sushy/htpasswd"
SUSHY_EMULATOR_FAKE_DRIVER = True
FAKE_IPA_API_URL = "${API_URL}"
FAKE_IPA_INSPECTION_CALLBACK_URL = "${CALLBACK_URL}"
FAKE_IPA_ADVERTISE_ADDRESS = Host(hostname="${ADVERTISE_HOST}", port="${ADVERTISE_PORT}")
EOF
cat <<'EOF' > /opt/metal3-dev-env/ironic/virtualbmc/sushy-tools/htpasswd
admin:$2b$12$/dVOBNatORwKpF.ss99KB.vESjfyONOxyH.UgRwNyZi1Xs/W2pGVS

# Create an htpasswd file
cat <<EOF >/opt/metal3-dev-env/ironic/virtualbmc/sushy-tools/htpasswd
admin:$2b${12}$/dVOBNatORwKpF.ss99KB.vESjfyONOxyH.UgRwNyZi1Xs/W2pGVS
EOF
ssh-keygen -f /root/.ssh/id_rsa_virt_power -P ""
/root/.ssh/id_rsa_virt_power.pub | tee -a /root/.ssh/authorized_keys
podman run -d --net host --name sushy-tools --pod infra-pod -v /opt/metal3-dev-env/ironic/virtualbmc/sushy-tools:/root/sushy -v "/root/.ssh":/root/ssh 127.0.0.1:5000/localimages/sushy-tools

# Generate ssh keys to use for virtual power and add them to authorized_keys
sudo ssh-keygen -f /root/.ssh/id_rsa_virt_power -P "" -q -y
sudo cat /root/.ssh/id_rsa_virt_power.pub | sudo tee -a /root/.ssh/authorized_keys

# Create and start a container for sushy-tools
podman run -d --net host --name sushy-tools --pod infra-pod \
-v /opt/metal3-dev-env/ironic/virtualbmc/sushy-tools:/root/sushy \
-v /root/.ssh:/root/ssh \
"${SUSHY_TOOLS_IMAGE}"
10 changes: 7 additions & 3 deletions Support/Multitenancy/ironic-env/04-start-minikube.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
set -e

# Start Minikube with insecure registry flag
minikube start --insecure-registry 172.22.0.1:5000

# SSH into the Minikube VM and execute the following commands
sudo su -l -c "minikube ssh sudo brctl addbr ironicendpoint" "${USER}"
sudo su -l -c "minikube ssh sudo ip link set ironicendpoint up" "${USER}"
sudo su -l -c "minikube ssh sudo brctl addif ironicendpoint eth2" "${USER}"
sudo su -l -c "minikube ssh sudo ip addr add 172.22.0.2/24 dev ironicendpoint" "${USER}"

# Firewall
for i in 8000 80 9999 6385 5050 6180 53 5000; do sudo firewall-cmd --zone=public --add-port=${i}/tcp; done
for i in 69 547 546 68 67 5353 6230 6231 6232 6233 6234 6235; do sudo firewall-cmd --zone=libvirt --add-port=${i}/udp; done
# Firewall rules
for i in 8000 80 9999 6385 5050 6180 53 5000; do sudo firewall-cmd --zone=public --add-port=${i}/tcp; done
for i in 69 547 546 68 67 5353 6230 6231 6232 6233 6234 6235; do sudo firewall-cmd --zone=libvirt --add-port=${i}/udp; done
sudo firewall-cmd --zone=libvirt --add-port=8000/tcp
17 changes: 8 additions & 9 deletions Support/Multitenancy/ironic-env/05-apply-manifests.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set -e
# Apply ironic
kubectl apply -f manifests/ironic.yaml -n baremetal-operator-system

cat <<'EOF' > ironicclient.sh
kubectl -n baremetal-operator-system wait --for=condition=available deployment/baremetal-operator-ironic --timeout=300s
cat <<'EOF' >ironicclient.sh
#!/bin/bash
DIR="$(dirname "$(readlink -f "$0")")"
Expand All @@ -26,7 +26,7 @@ EOF

mkdir _clouds_yaml

cat <<'EOF' > _clouds_yaml/clouds.yaml
cat <<'EOF' >_clouds_yaml/clouds.yaml
clouds:
metal3:
auth_type: none
Expand All @@ -36,15 +36,14 @@ EOF
sudo chmod a+x ironicclient.sh
sudo ln -sf "$PWD/ironicclient.sh" "/usr/local/bin/baremetal"


# Create ironic node

baremetal node create --driver redfish --driver-info \
redfish_address=http://192.168.111.1:8000 --driver-info \
redfish_system_id=/redfish/v1/Systems/27946b59-9e44-4fa7-8e91-f3527a1ef094 --driver-info \
redfish_username=admin --driver-info redfish_password=password \
--name default-node
redfish_address=http://192.168.111.1:8000 --driver-info \
redfish_system_id=/redfish/v1/Systems/27946b59-9e44-4fa7-8e91-f3527a1ef094 --driver-info \
redfish_username=admin --driver-info redfish_password=password \
--name default-node

# baremetal node manage $NODE_UUID
# get mac : virsh domiflist vmname
# baremetal port create 00:5c:52:31:3a:9c --node $NODE_UUID
# baremetal port create 00:5c:52:31:3a:9c --node $NODE_UUID
47 changes: 29 additions & 18 deletions Support/Multitenancy/ironic-env/clean.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
#!/bin/bash

# Delete network connections
sudo nmcli con delete baremetal provisioning

sudo nmcli con delete baremetal
sudo nmcli con delete provisioning
sudo nmcli con delete provisioning
# Disable and delete bridge interfaces
for iface in baremetal provisioning; do
if ip link show $iface &>/dev/null; then
sudo ip link set $iface down
sudo brctl delbr $iface
fi
done

sudo virsh net-undefine provisioning
sudo virsh net-undefine baremetal
# Delete libvirt networks
for net in provisioning baremetal; do
if sudo virsh net-info $net &>/dev/null; then
sudo virsh net-destroy $net
sudo virsh net-undefine $net
fi
done

sudo virsh net-destroy baremetal
sudo virsh net-destroy provisioning

sudo ip link set provisioning down
sudo ip link set provisioning down
sudo ip link set baremetal down
sudo brctl delbr baremetal
sudo brctl delbr provisioning
sudo brctl delbr provisioning
#sudo rm -rf /opt/metal3-dev-env
sudo rm -rf /opt/metal3-dev-env/ironic/virtualbmc/
sudo podman stop -a
sudo podman rmi "$(sudo podman images -qa)" -f
# Delete directories
sudo rm -rf /opt/metal3-dev-env
sudo rm -rf "$(dirname "$0")/_clouds_yaml"

# Stop and delete minikube cluster
minikube stop
minikube delete --all --purge

# Stop and delete containers
containers=("sushy-tools" "ironic-ipa-downloader" "ironic" "keepalived" "registry" "ironic-client")
for container in "${containers[@]}"; do
echo "Deleting the container: $container"
sudo podman stop "$container" &>/dev/null
sudo podman rm "$container" &>/dev/null
done

0 comments on commit 2a75fc3

Please sign in to comment.