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