This repository has been archived by the owner on Jun 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ocp_usage.sh
executable file
·112 lines (94 loc) · 2.75 KB
/
ocp_usage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
#===============================================================================
#
# FILE: ocp_usage.sh
#
# USAGE: ./ocp_usage.sh
#
# DESCRIPTION: Setup and collect OCP usage data.
#
# OPTIONS: -h | --help Obtain command USAGE
# -e | --extra-vars set additional variables as key=value
#===============================================================================
export PATH=$PATH:$ANSIBLE_HOME/bin
BASEDIR=$(dirname "$0")
PLAYBOOKFILE="ocp_usage_playbook.yml"
SETUP_TAG="--tags=setup"
COLLECT_TAG="--tags=collect"
tag=""
declare -a args
args=("$*")
set -- ${args[@]}
usage() {
cat <<EOM
Setup and collect OCP usage data.
Usage:
$(basename $0)
Options:
-h | --help Obtain command USAGE
(--setup | --collect) Run either the setup phase or collect phase
-e | --extra-vars Set additional variables as key=value
Extra Variables:
* Provide OpenShift Container Platform API Endpoint:
-e OCP_API=https://api.openshift-prod.mycompany.com
* Provide OpenShift Container Platform User Token File:
-e OCP_TOKEN_PATH=/path/to/file/with/ocp/token
* Provide OpenShift Metering Namespace:
-e OCP_METERING_NAMESPACE=metering
* Provide OpenShift Container Platform CLI (defaults to /usr/bin/oc):
-e OCP_CLI=/usr/local/bin/oc
* Validate OpenShift SSL Certificates (defaults to false):
-e OCP_SSL_CERT_VALIDATION=false
* Provide OpenShift Cluster Identifier:
-e OCP_CLUSTER_ID=bbb0b82b-e40d-41eb-8354-e07bc6a26a38
EOM
exit 0
}
if [[ ($1 == "--help") || ($1 == "-h") ]]
then
usage;
elif [[ ($1 == "--setup") ]]
then
tag=$SETUP_TAG
elif [[ ($1 == "--collect") ]]
then
tag=$COLLECT_TAG
else
echo "Unexpected argument $1. Should be either --setup or --collect."
exit 1
fi
# if [ ! -f /etc/redhat-release ]; then
# echo '/etc/redhat-release not found. You need to run this on a Red Hat based OS.'
# exit 1
# fi
if dnf --version > /dev/null 2>&1; then
PKG_MGR=dnf
else
PKG_MGR=yum
fi
echo 'Checking if ansible is installed...'
command -v ansible > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo 'Ansible prerequisite could not be found. Trying to install ansible...'
ansible_not_installed=1
fi
if [ $ansible_not_installed ]; then
sudo "${PKG_MGR}" install -y ansible
fi
command -v ansible > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Installation failed. Ansible prerequisite could not be installed."
echo "Follow installation documentation for installing Ansible."
exit 1
fi
echo ansible-playbook $BASEDIR/$PLAYBOOKFILE -v $tag ${@:2}
ansible-playbook $BASEDIR/$PLAYBOOKFILE -v $tag ${@:2}
if [ $? -eq 0 ]
then
echo "Execution complete."
else
echo "Execution failed. Review the install logs."
exit $?
fi