Add support for IPv6 to machine and cluster chart
[icn.git] / tools / vagrant / start_sushy.sh
1 #!/bin/bash
2 # To validate emulator is up and running:
3 #   curl --insecure -u admin:password https://192.168.121.1:8000/redfish/v1/Systems/
4 set -eu -o pipefail
5
6 listen_ip=$1
7
8 if [[ -f ${HOME}/.sushy/emulator.pid ]]; then
9     if ps -p $(cat ${HOME}/.sushy/emulator.pid); then
10         echo sushy-emulator is already started
11         exit 0
12     fi
13 fi
14
15 # Install prerequisites
16 if [[ $(which apt-get 2>/dev/null) ]]; then
17     DEBIAN_FRONTEND=noninteractive sudo apt-get install -y make apache2-utils libvirt-dev ovmf python3-pip
18 elif [[ $(which yum) ]]; then
19     # TODO OVMF doesn't include OVMF_CODE.fd
20     sudo yum install -y make httpd-tools libvirt-devel OVMF python3-pip
21 fi
22 sudo python3 -m pip install libvirt-python sushy-tools
23 # Add route to provisioning network - sushy-emulator needs to
24 # fetch ISOs over this during virtual media boot
25 dev=$(ip -o addr show to ${listen_ip} | awk '{print $2}')
26 sudo ip route add 172.22.0.0/24 dev ${dev}
27 # Configure sushy-emulator
28 mkdir -p ${HOME}/.sushy
29 openssl req -x509 -newkey rsa:4096 -keyout ${HOME}/.sushy/key.pem -out ${HOME}/.sushy/cert.pem -sha256 -days 365 -nodes -subj "/CN=${listen_ip}"
30 htpasswd -c -b -B ${HOME}/.sushy/htpasswd admin password
31 cat <<EOF >${HOME}/.sushy/emulator.conf
32 SUSHY_EMULATOR_LISTEN_IP = u'${listen_ip}'
33 SUSHY_EMULATOR_SSL_CERT = u'${HOME}/.sushy/cert.pem'
34 SUSHY_EMULATOR_SSL_KEY = u'${HOME}/.sushy/key.pem'
35 SUSHY_EMULATOR_AUTH_FILE = u'${HOME}/.sushy/htpasswd'
36 SUSHY_EMULATOR_VMEDIA_VERIFY_SSL = False
37 EOF
38 sushy-emulator --config ${HOME}/.sushy/emulator.conf 1>${HOME}/.sushy/emulator-stdout.log 2>${HOME}/.sushy/emulator-stderr.log &
39 echo $! >${HOME}/.sushy/emulator.pid