Add explicit network configuration to nodes.json
[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 #Bootstrap K8s cluster
21 BS_DHCP_INTERFACE=${BS_DHCP_INTERFACE:-}
22 BS_DHCP_INTERFACE_IP=${BS_DHCP_INTERFACE_IP:-}
23 BS_DHCP_DIR=${BS_DHCP_DIR:-$DOWNLOAD_PATH/dhcp}
24
25 #Ironic variables
26 IRONIC_IMAGE=${IRONIC_IMAGE:-"integratedcloudnative/ironic:v1.0-icn"}
27 IRONIC_INSPECTOR_IMAGE=${IRONIC_INSPECTOR_IMAGE:-"integratedcloudnative/ironic-inspector:v1.0-icn"}
28 IRONIC_BAREMETAL_IMAGE=${IRONIC_BAREMETAL_IMAGE:-"integratedcloudnative/baremetal-operator:v2.0-icn"}
29 IPA_DOWNLOADER_IMAGE=${IPA_DOWNLOADER_IMAGE:-"integratedcloudnative/ironic-ipa-downloader:v1.0-icn"}
30 IRONIC_BAREMETAL_SOCAT_IMAGE=${IRONIC_BAREMETAL_SOCAT_IMAGE:-"alpine/socat:latest"}
31
32 IRONIC_DATA_DIR=${IRONIC_DATA_DIR:-"/opt/ironic"}
33 #IRONIC_PROVISIONING_INTERFACE is required to be provisioning, don't change it
34 IRONIC_INTERFACE=${IRONIC_INTERFACE:-}
35 IRONIC_PROVISIONING_INTERFACE=${IRONIC_PROVISIONING_INTERFACE:-"provisioning"}
36 IRONIC_IPMI_INTERFACE=${IRONIC_IPMI_INTERFACE:-}
37 IRONIC_PROVISIONING_INTERFACE_IP=${IRONIC_PROVISIONING_INTERFACE_IP:-"172.22.0.1"}
38 IRONIC_IPMI_INTERFACE_IP=${IRONIC_IPMI_INTERFACE_IP:-}
39 BM_IMAGE_URL=${BM_IMAGE_URL:-"https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img"}
40 BM_IMAGE=${BM_IMAGE:-"bionic-server-cloudimg-amd64.img"}
41
42 #Path to clone the metal3 dev env repo
43 M3PATH="$(go env GOPATH)/src/github.com/metal3-io"
44 #Path to clone the baremetal operator repo
45 BMOPATH="${M3PATH}/baremetal-operator"
46 #Baremetal operator repository URL
47 BMOREPO="${BMOREPO:-https://github.com/metal3-io/baremetal-operator.git}"
48 #Baremetal operator repository branch to checkout
49 BMOBRANCH="${BMOBRANCH:-10eb5aa3e614d0fdc6315026ebab061cbae6b929}"
50 #Discard existing baremetal operator repo directory
51 FORCE_REPO_UPDATE="${FORCE_REPO_UPDATE:-true}"
52
53 #refered from onap
54 function call_api {
55     #Runs curl with passed flags and provides
56     #additional error handling and debug information
57
58     #Function outputs server response body
59     #and performs validation of http_code
60
61     local status
62     local curl_response_file="$(mktemp -p /tmp)"
63     local curl_common_flags=(-s -w "%{http_code}" -o "${curl_response_file}")
64     local command=(curl "${curl_common_flags[@]}" "$@")
65
66     echo "[INFO] Running '${command[@]}'" >&2
67     if ! status="$("${command[@]}")"; then
68         echo "[ERROR] Internal curl error! '$status'" >&2
69         cat "${curl_response_file}"
70         rm "${curl_response_file}"
71         return 2
72     else
73         echo "[INFO] Server replied with status: ${status}" >&2
74         cat "${curl_response_file}"
75         rm "${curl_response_file}"
76         if [[ "${status:0:1}" =~ [45] ]]; then
77             return 1
78         else
79             return 0
80         fi
81     fi
82 }
83
84 function list_nodes {
85     NODES_FILE="${IRONIC_DATA_DIR}/nodes.json"
86
87     if [ ! -f "$NODES_FILE" ]; then
88         exit 1
89     fi
90
91     cat "$NODES_FILE" | \
92         jq -r '.nodes[] | [
93            .name,
94            .ipmi_driver_info.username,
95            .ipmi_driver_info.password,
96            .ipmi_driver_info.address,
97            .os.username,
98            .os.password,
99            .os.image_name
100            ] | @csv' | \
101         sed 's/"//g'
102 }
103
104 function node_networkdata {
105     name=$1
106
107     NODES_FILE="${IRONIC_DATA_DIR}/nodes.json"
108
109     if [ ! -f "$NODES_FILE" ]; then
110         exit 1
111     fi
112
113     cat $NODES_FILE  | jq -r --arg name "$name" '.nodes[] | select(.name==$name) | .net'
114 }