-
Notifications
You must be signed in to change notification settings - Fork 10
/
openstack-cli
executable file
·72 lines (61 loc) · 2.11 KB
/
openstack-cli
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
#!/bin/bash
################################################################################
## Platform9 OpenStack CLI Utility
## Copyright(c) 2018 Platform9 Systems, Inc.
################################################################################
# initialize variables
basedir=$(dirname $0)
os_cli=/home/centos/.virtenvs/os_cli/bin/openstack
oscli_rc_file=${basedir}/pf9-openstack.rc
os_cmd=""
rc_file=${basedir}/pf9-openstack.rc
pf9_config=${basedir}/pf9-express.conf
pf9_custom_configFile=""
usage() {
echo "Usage: `basename $0` [Args] [<command>]"
echo -e "\nArgs (Optional):\n"
echo "-c|--config <configFile> : use custom configuration file"
echo -e "-h|--help : display this message\n"
exit 1
}
# include libraries
source ${basedir}/lib/config_util.sh
# process arguments
while [ $# -gt 0 ]; do
case ${1} in
-h|--help)
usage ;;
-c|--config)
if [ $# -lt 2 ]; then usage; fi
pf9_custom_configFile=${2}
shift 2
;;
*)
if [ -z "${os_cmd}" ]; then
os_cmd=${1}
else
os_cmd="${os_cmd} ${1}"
fi
shift
;;
esac
done
## use custom config (if specified on commandline)
if [ -n "${pf9_custom_configFile}" ]; then pf9_config=${pf9_custom_configFile}; fi
# validate config file
if [ ! -r ${pf9_config} ]; then assert "could not find pf9-express config file (looked in ${pf9_config})"; fi
## lookup configuration values from config file
ctrl_hostname=$(grep ^du_url ${pf9_config} | cut -d \| -f2 | cut -d \/ -f3)
du_region=$(grep ^os_region ${pf9_config} | cut -d \| -f2)
du_tenant=$(grep ^os_tenant ${pf9_config} | cut -d \| -f2)
du_username=$(grep ^os_username ${pf9_config} | cut -d \| -f2)
du_password=$(grep ^os_password ${pf9_config} | cut -d \| -f2)
# build rc file
update_openstack_rc ${ctrl_hostname} ${du_region} ${du_tenant} ${du_username} ${du_password}
# source rc file
if [ ! -r ${rc_file} ]; then assert "could not find openstack rc file (looked in ${rc_file})"; fi
source ${rc_file}
# validate openstack cli is installed
if [ ! -r ${os_cli} ]; then assert "could not find openstack cli (looked in ${os_cli})"; fi
eval ${os_cli} ${os_cmd}
exit $?