Remove IRONIC_IPMI_INTERFACE_IP
[icn.git] / env / metal3 / 02_configure.sh
1 #!/usr/bin/env bash
2 set -eux -o pipefail
3
4 LIBDIR="$(dirname "$PWD")"
5
6 source $LIBDIR/lib/logging.sh
7 source $LIBDIR/lib/common.sh
8
9 if [[ $EUID -ne 0 ]]; then
10     echo "confgiure script must be run as root"
11     exit 1
12 fi
13
14 function check_interface_ip {
15     local interface=$1
16     local ipaddr=$2
17
18     ip addr show dev $interface
19     if [ $? -ne 0 ]; then
20         exit 1
21     fi
22
23     local ipv4address=$(ip addr show dev $interface | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }')
24     if [ "$ipv4address" != "$ipaddr" ]; then
25         exit 1
26     fi
27 }
28
29 function configure_ironic_bridge {
30     ip link add dev provisioning type bridge
31     ip link set provisioning up
32     ip link set dev $IRONIC_INTERFACE master provisioning
33     ip addr add dev provisioning 172.22.0.1/24
34 }
35
36 function configure_ironic_interfaces {
37     # Add firewall rules to ensure the IPA ramdisk can reach httpd, Ironic and the Inspector API on the host
38     if [ "$IRONIC_PROVISIONING_INTERFACE" ]; then
39         check_interface_ip $IRONIC_PROVISIONING_INTERFACE $IRONIC_PROVISIONING_INTERFACE_IP
40     else
41         exit 1
42     fi
43
44     for port in 80 5050 6385 ; do
45         if ! sudo iptables -C INPUT -i $IRONIC_PROVISIONING_INTERFACE -p tcp -m tcp --dport $port -j ACCEPT > /dev/null 2>&1; then
46             sudo iptables -I INPUT -i $IRONIC_PROVISIONING_INTERFACE -p tcp -m tcp --dport $port -j ACCEPT
47         fi
48     done
49
50     # Allow ipmi to the bmc processes
51     if ! sudo iptables -C INPUT -i $IRONIC_IPMI_INTERFACE -p udp -m udp --dport 6230:6235 -j ACCEPT 2>/dev/null ; then
52         sudo iptables -I INPUT -i $IRONIC_IPMI_INTERFACE -p udp -m udp --dport 6230:6235 -j ACCEPT
53     fi
54
55     #Allow access to dhcp and tftp server for pxeboot
56     for port in 67 69 ; do
57         if ! sudo iptables -C INPUT -i $IRONIC_PROVISIONING_INTERFACE -p udp --dport $port -j ACCEPT 2>/dev/null ; then
58             sudo iptables -I INPUT -i $IRONIC_PROVISIONING_INTERFACE -p udp --dport $port -j ACCEPT
59         fi
60     done
61 }
62
63 function configure_ironic {
64     for name in ironic ironic-inspector dnsmasq httpd mariadb ipa-downloader; do
65         sudo docker ps | \
66             grep -w "$name$" && sudo docker kill "$name"
67         sudo docker ps --all | \
68             grep -w "$name$" && sudo docker rm "$name" -f
69     done
70     rm -rf "$IRONIC_DATA_DIR"
71
72     docker pull $IRONIC_IMAGE
73     docker pull $IRONIC_INSPECTOR_IMAGE
74     docker pull $IPA_DOWNLOADER_IMAGE
75
76     mkdir -p "$IRONIC_DATA_DIR/html/images"
77     pushd $IRONIC_DATA_DIR/html/images
78
79     if [[ "$BM_IMAGE_URL" && "$BM_IMAGE" ]]; then
80         curl -o ${BM_IMAGE} --insecure --compressed -O -L ${BM_IMAGE_URL}
81         md5sum ${BM_IMAGE} | awk '{print $1}' > ${BM_IMAGE}.md5sum
82     fi
83     popd
84 }
85
86 function configure {
87     configure_ironic
88     configure_ironic_bridge
89     configure_ironic_interfaces
90 }
91
92 configure