90c66bab31988f591ae908e0cd1ac526a2409718
[kvmfornfv.git] / ci / envs / utils.sh
1 #!/bin/bash
2 ###############################################################################
3 #      This script is to fetch kernel version and host ip at run time.
4 ###############################################################################
5
6 #To get the Kernel version from RPM generated(example:kernel-4.4.6_rt14_1607061504nfv-3.x86_64.rpm)
7 function getKernelVersion {
8    rpm_dir="/root/workspace/rpm/"
9    if [ -d "$WORKSPACE" ];then
10       cd $WORKSPACE/build_output 2>/dev/null; kernelRPM=`ls kernel-[[:digit:]]* 2>/dev/null`
11       RPMVERSION=`echo ${kernelRPM}|awk -F '_' '{print $1}' | awk -F '-' '{print $NF}'`
12    elif [ -d "$rpm_dir" ];then
13       cd $rpm_dir 2>/dev/null; kernelRPM=`ls kernel-[[:digit:]]* 2>/dev/null`
14       RPMVERSION=`echo ${kernelRPM}|awk -F '_' '{print $1}' | awk -F '-' '{print $NF}'`
15    fi
16    echo ${RPMVERSION}
17 }
18
19 #Get the IP address from pod.yaml file (example ip : 10.10.100.22)
20 function getHostIP {
21    host_dir="/root/workspace/scripts/"
22    container_dir="/opt/scripts/"
23    if [ -d "$container_dir" ];then
24       HOST_IP=`grep 'ip' $container_dir/pod.yaml | awk -F ': ' '{print $NF}' | tail -1`
25    elif [ -d "$host_dir" ];then
26       HOST_IP=`grep 'ip' $host_dir/pod.yaml | awk -F ': ' '{print $NF}' | tail -1`
27    fi
28    echo $HOST_IP
29 }