Use username and password from "os" in 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 #User Provider Network configuration
26 PROVIDER_NETWORK_GATEWAY=${PROVIDER_NETWORK_GATEWAY:-}
27 PROVIDER_NETWORK_DNS=${PROVIDER_NETWORK_DNS:-}
28
29 #Ironic variables
30 IRONIC_IMAGE=${IRONIC_IMAGE:-"integratedcloudnative/ironic:v1.0-icn"}
31 IRONIC_INSPECTOR_IMAGE=${IRONIC_INSPECTOR_IMAGE:-"integratedcloudnative/ironic-inspector:v1.0-icn"}
32 IRONIC_BAREMETAL_IMAGE=${IRONIC_BAREMETAL_IMAGE:-"integratedcloudnative/baremetal-operator:v1.0-icn"}
33 IPA_DOWNLOADER_IMAGE=${IPA_DOWNLOADER_IMAGE:-"integratedcloudnative/ironic-ipa-downloader:v1.0-icn"}
34 IRONIC_BAREMETAL_SOCAT_IMAGE=${IRONIC_BAREMETAL_SOCAT_IMAGE:-"alpine/socat:latest"}
35
36 IRONIC_DATA_DIR=${IRONIC_DATA_DIR:-"/opt/ironic"}
37 #IRONIC_PROVISIONING_INTERFACE is required to be provisioning, don't change it
38 IRONIC_INTERFACE=${IRONIC_INTERFACE:-}
39 IRONIC_PROVISIONING_INTERFACE=${IRONIC_PROVISIONING_INTERFACE:-"provisioning"}
40 IRONIC_IPMI_INTERFACE=${IRONIC_IPMI_INTERFACE:-}
41 IRONIC_PROVISIONING_INTERFACE_IP=${IRONIC_PROVISIONING_INTERFACE_IP:-"172.22.0.1"}
42 IRONIC_IPMI_INTERFACE_IP=${IRONIC_IPMI_INTERFACE_IP:-}
43 BM_IMAGE_URL=${BM_IMAGE_URL:-"https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img"}
44 BM_IMAGE=${BM_IMAGE:-"bionic-server-cloudimg-amd64.img"}
45
46 #refered from onap
47 function call_api {
48     #Runs curl with passed flags and provides
49     #additional error handling and debug information
50
51     #Function outputs server response body
52     #and performs validation of http_code
53
54     local status
55     local curl_response_file="$(mktemp -p /tmp)"
56     local curl_common_flags=(-s -w "%{http_code}" -o "${curl_response_file}")
57     local command=(curl "${curl_common_flags[@]}" "$@")
58
59     echo "[INFO] Running '${command[@]}'" >&2
60     if ! status="$("${command[@]}")"; then
61         echo "[ERROR] Internal curl error! '$status'" >&2
62         cat "${curl_response_file}"
63         rm "${curl_response_file}"
64         return 2
65     else
66         echo "[INFO] Server replied with status: ${status}" >&2
67         cat "${curl_response_file}"
68         rm "${curl_response_file}"
69         if [[ "${status:0:1}" =~ [45] ]]; then
70             return 1
71         else
72             return 0
73         fi
74     fi
75 }
76
77 function list_nodes {
78     NODES_FILE="${IRONIC_DATA_DIR}/nodes.json"
79
80     if [ ! -f "$NODES_FILE" ]; then
81         exit 1
82     fi
83
84     cat "$NODES_FILE" | \
85         jq -r '.nodes[] | [
86            .name,
87            .ipmi_driver_info.username,
88            .ipmi_driver_info.password,
89            .ipmi_driver_info.address,
90            .os.username,
91            .os.password,
92            .os.image_name
93            ] | @csv' | \
94         sed 's/"//g'
95 }
96