Remove bootstrap network
[icn.git] / env / lib / common.sh
1 #!/usr/bin/env bash
2 set -eu -o pipefail
3
4 #supported OS version
5 UBUNTU_BIONIC=${UBUNTU_BIONIC:-Ubuntu 18.04.2 LTS}
6
7 #offline mode variable
8 DOWNLOAD_PATH=${DOWNLOAD_PATH:-/opt/icn}
9 LOCAL_APT_REPO=${LOCAL_APT_REPO:-$DOWNLOAD_PATH/apt}
10 PIP_CACHE_DIR=${PIP_CACHE_DIR:-$DOWNLOAD_PATH/pip-cache-dir}
11 BUILD_DIR=${BUILD_DIR:-$DOWNLOAD_PATH/build-dir}
12 CONTAINER_IMAGES_DIR=${CONTAINER_IMAGES_DIR:-$DOWNLOAD_PATH/docker-dir}
13
14 #set variables
15 #Todo include over all variables here
16 KUBE_VERSION=${KUBE_VERSION:-"v1.15.0"}
17 POD_NETWORK_CIDR=${POD_NETWORK_CIDR:-"10.244.0.0/16"}
18 PODMAN_CNI_CONFLIST=${PODMAN_CNI_CONFLIST:-"https://raw.githubusercontent.com/containers/libpod/v1.4.4/cni/87-podman-bridge.conflist"}
19
20 #Ironic variables
21 IRONIC_IMAGE=${IRONIC_IMAGE:-"integratedcloudnative/ironic:v1.0-icn"}
22 IRONIC_INSPECTOR_IMAGE=${IRONIC_INSPECTOR_IMAGE:-"integratedcloudnative/ironic-inspector:v1.0-icn"}
23 IRONIC_BAREMETAL_IMAGE=${IRONIC_BAREMETAL_IMAGE:-"integratedcloudnative/baremetal-operator:v2.0-icn"}
24 IPA_DOWNLOADER_IMAGE=${IPA_DOWNLOADER_IMAGE:-"integratedcloudnative/ironic-ipa-downloader:v1.0-icn"}
25 IRONIC_BAREMETAL_SOCAT_IMAGE=${IRONIC_BAREMETAL_SOCAT_IMAGE:-"alpine/socat:latest"}
26
27 IRONIC_DATA_DIR=${IRONIC_DATA_DIR:-"/opt/ironic"}
28 #IRONIC_PROVISIONING_INTERFACE is required to be provisioning, don't change it
29 IRONIC_INTERFACE=${IRONIC_INTERFACE:-}
30 IRONIC_PROVISIONING_INTERFACE=${IRONIC_PROVISIONING_INTERFACE:-"provisioning"}
31 IRONIC_IPMI_INTERFACE=${IRONIC_IPMI_INTERFACE:-}
32 IRONIC_PROVISIONING_INTERFACE_IP=${IRONIC_PROVISIONING_INTERFACE_IP:-"172.22.0.1"}
33 IRONIC_IPMI_INTERFACE_IP=${IRONIC_IPMI_INTERFACE_IP:-}
34 BM_IMAGE_URL=${BM_IMAGE_URL:-"https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img"}
35 BM_IMAGE=${BM_IMAGE:-"bionic-server-cloudimg-amd64.img"}
36
37 #Path to clone the metal3 dev env repo
38 M3PATH="$(go env GOPATH)/src/github.com/metal3-io"
39 #Path to clone the baremetal operator repo
40 BMOPATH="${M3PATH}/baremetal-operator"
41 #Baremetal operator repository URL
42 BMOREPO="${BMOREPO:-https://github.com/metal3-io/baremetal-operator.git}"
43 #Baremetal operator repository branch to checkout
44 BMOBRANCH="${BMOBRANCH:-10eb5aa3e614d0fdc6315026ebab061cbae6b929}"
45 #Discard existing baremetal operator repo directory
46 FORCE_REPO_UPDATE="${FORCE_REPO_UPDATE:-true}"
47
48 #refered from onap
49 function call_api {
50     #Runs curl with passed flags and provides
51     #additional error handling and debug information
52
53     #Function outputs server response body
54     #and performs validation of http_code
55
56     local status
57     local curl_response_file="$(mktemp -p /tmp)"
58     local curl_common_flags=(-s -w "%{http_code}" -o "${curl_response_file}")
59     local command=(curl "${curl_common_flags[@]}" "$@")
60
61     echo "[INFO] Running '${command[@]}'" >&2
62     if ! status="$("${command[@]}")"; then
63         echo "[ERROR] Internal curl error! '$status'" >&2
64         cat "${curl_response_file}"
65         rm "${curl_response_file}"
66         return 2
67     else
68         echo "[INFO] Server replied with status: ${status}" >&2
69         cat "${curl_response_file}"
70         rm "${curl_response_file}"
71         if [[ "${status:0:1}" =~ [45] ]]; then
72             return 1
73         else
74             return 0
75         fi
76     fi
77 }
78
79 function list_nodes {
80     NODES_FILE="${IRONIC_DATA_DIR}/nodes.json"
81
82     if [ ! -f "$NODES_FILE" ]; then
83         exit 1
84     fi
85
86     cat "$NODES_FILE" | \
87         jq -r '.nodes[] | [
88            .name,
89            .ipmi_driver_info.username,
90            .ipmi_driver_info.password,
91            .ipmi_driver_info.address,
92            .os.username,
93            .os.password,
94            .os.image_name
95            ] | @csv' | \
96         sed 's/"//g'
97 }
98
99 function node_networkdata {
100     name=$1
101
102     NODES_FILE="${IRONIC_DATA_DIR}/nodes.json"
103
104     if [ ! -f "$NODES_FILE" ]; then
105         exit 1
106     fi
107
108     cat $NODES_FILE  | jq -r --arg name "$name" '.nodes[] | select(.name==$name) | .net'
109 }