blob: 14d290bdac3c9c10e75561780938d8c6c2ac1d3e (
plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
OCF_RESKEY_user_domain_name_default="Default"
OCF_RESKEY_project_domain_name_default="Default"
OCF_RESKEY_openstackcli_default="/usr/bin/openstack"
OCF_RESKEY_insecure_default="false"
: ${OCF_RESKEY_user_domain_name=${OCF_RESKEY_user_domain_name_default}}
: ${OCF_RESKEY_project_domain_name=${OCF_RESKEY_project_domain_name_default}}
: ${OCF_RESKEY_openstackcli=${OCF_RESKEY_openstackcli_default}}
: ${OCF_RESKEY_insecure=${OCF_RESKEY_insecure_default}}
if ocf_is_true "${OCF_RESKEY_insecure}"; then
OCF_RESKEY_openstackcli="${OCF_RESKEY_openstackcli} --insecure"
fi
common_meta_data() {
cat <<END
<parameter name="cloud" required="0">
<longdesc lang="en">
Openstack cloud (from ~/.config/openstack/clouds.yaml or /etc/openstack/clouds.yaml).
</longdesc>
<shortdesc lang="en">Cloud from clouds.yaml</shortdesc>
<content type="string" />
</parameter>
<parameter name="openrc" required="0">
<longdesc lang="en">
Openstack credentials as openrc file from api_access/openrc.
</longdesc>
<shortdesc lang="en">openrc file</shortdesc>
<content type="string" />
</parameter>
<parameter name="auth_url" required="0">
<longdesc lang="en">
Keystone Auth URL
</longdesc>
<shortdesc lang="en">Keystone Auth URL</shortdesc>
<content type="string" />
</parameter>
<parameter name="username" required="0">
<longdesc lang="en">
Username.
</longdesc>
<shortdesc lang="en">Username</shortdesc>
<content type="string" />
</parameter>
<parameter name="password" required="0">
<longdesc lang="en">
Password.
</longdesc>
<shortdesc lang="en">Password</shortdesc>
<content type="string" />
</parameter>
<parameter name="project_name" required="0">
<longdesc lang="en">
Keystone Project.
</longdesc>
<shortdesc lang="en">Keystone Project</shortdesc>
<content type="string" />
</parameter>
<parameter name="user_domain_name" required="0">
<longdesc lang="en">
Keystone User Domain Name.
</longdesc>
<shortdesc lang="en">Keystone User Domain Name</shortdesc>
<content type="string" default="${OCF_RESKEY_user_domain_name_default}" />
</parameter>
<parameter name="project_domain_name" required="0">
<longdesc lang="en">
Keystone Project Domain Name.
</longdesc>
<shortdesc lang="en">Keystone Project Domain Name</shortdesc>
<content type="string" default="${OCF_RESKEY_project_domain_name_default}" />
</parameter>
<parameter name="openstackcli">
<longdesc lang="en">
Path to command line tools for openstack.
</longdesc>
<shortdesc lang="en">Path to Openstack CLI tool</shortdesc>
<content type="string" default="${OCF_RESKEY_openstackcli_default}" />
</parameter>
<parameter name="insecure">
<longdesc lang="en">
Allow insecure connections
</longdesc>
<shortdesc lang="en">Allow insecure connections</shortdesc>
<content type="boolean" default="${OCF_RESKEY_insecure_default}" />
</parameter>
END
}
get_config() {
if [ -n "$OCF_RESKEY_cloud" ]; then
TILDE=$(echo ~)
clouds_yaml="$TILDE/.config/openstack/clouds.yaml"
if [ ! -f "$clouds_yaml" ]; then
clouds_yaml="/etc/openstack/clouds.yaml"
fi
if [ ! -f "$clouds_yaml" ]; then
ocf_exit_reason "~/.config/openstack/clouds.yaml and /etc/openstack/clouds.yaml does not exist"
exit $OCF_ERR_CONFIGURED
fi
OCF_RESKEY_openstackcli="${OCF_RESKEY_openstackcli} --os-cloud $OCF_RESKEY_cloud"
elif [ -n "$OCF_RESKEY_openrc" ]; then
if [ ! -f "$OCF_RESKEY_openrc" ]; then
ocf_exit_reason "$OCF_RESKEY_openrc does not exist"
exit $OCF_ERR_CONFIGURED
fi
. $OCF_RESKEY_openrc
else
if [ -z "$OCF_RESKEY_auth_url" ]; then
ocf_exit_reason "auth_url not set"
exit $OCF_ERR_CONFIGURED
fi
if [ -z "$OCF_RESKEY_username" ]; then
ocf_exit_reason "username not set"
exit $OCF_ERR_CONFIGURED
fi
if [ -z "$OCF_RESKEY_password" ]; then
ocf_exit_reason "password not set"
exit $OCF_ERR_CONFIGURED
fi
if [ -z "$OCF_RESKEY_project_name" ]; then
ocf_exit_reason "project_name not set"
exit $OCF_ERR_CONFIGURED
fi
if [ -z "$OCF_RESKEY_user_domain_name" ]; then
ocf_exit_reason "user_domain_name not set"
exit $OCF_ERR_CONFIGURED
fi
if [ -z "$OCF_RESKEY_project_domain_name" ]; then
ocf_exit_reason "project_domain_name not set"
exit $OCF_ERR_CONFIGURED
fi
OCF_RESKEY_openstackcli="${OCF_RESKEY_openstackcli} --os-auth-url $OCF_RESKEY_auth_url"
OCF_RESKEY_openstackcli="${OCF_RESKEY_openstackcli} --os-username $OCF_RESKEY_username"
OCF_RESKEY_openstackcli="${OCF_RESKEY_openstackcli} --os-password $OCF_RESKEY_password"
OCF_RESKEY_openstackcli="${OCF_RESKEY_openstackcli} --os-project-name $OCF_RESKEY_project_name"
OCF_RESKEY_openstackcli="${OCF_RESKEY_openstackcli} --os-user-domain-name $OCF_RESKEY_user_domain_name"
OCF_RESKEY_openstackcli="${OCF_RESKEY_openstackcli} --os-project-domain-name $OCF_RESKEY_project_domain_name"
fi
}
run_openstackcli() {
local cmd="${OCF_RESKEY_openstackcli} $1"
local result
local rc
local start_time=$(date +%s)
local end_time
local elapsed_time
result=$($cmd)
rc=$?
end_time=$(date +%s)
elapsed_time=$(expr $end_time - $start_time)
if [ $elapsed_time -gt 20 ]; then
ocf_log warn "$cmd took ${elapsed_time}s to complete"
fi
echo "$result"
return $rc
}
|