Browse Source

Extract the nova wait functionality into its own agent

Change-Id: I635ef96946e376b4182c15575edc3e02705d02be
Andrew Beekhof 3 years ago
parent
commit
9c635bfe34
1 changed files with 236 additions and 0 deletions
  1. 236
    0
      ocf/nova-compute-wait

+ 236
- 0
ocf/nova-compute-wait View File

@@ -0,0 +1,236 @@
1
+#!/bin/sh
2
+#
3
+#
4
+# nova-compute-wait agent manages compute daemons.
5
+#
6
+# Copyright (c) 2015
7
+#
8
+# This program is free software; you can redistribute it and/or modify
9
+# it under the terms of version 2 of the GNU General Public License as
10
+# published by the Free Software Foundation.
11
+#
12
+# This program is distributed in the hope that it would be useful, but
13
+# WITHOUT ANY WARRANTY; without even the implied warranty of
14
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+#
16
+# Further, this software is distributed without any warranty that it is
17
+# free of the rightful claim of any third person regarding infringement
18
+# or the like.  Any license provided herein, whether implied or
19
+# otherwise, applies only to this software file.  Patent licenses, if
20
+# any, provided herein do not apply to combinations of this program with
21
+# other software, or any other product whatsoever.
22
+#
23
+# You should have received a copy of the GNU General Public License
24
+# along with this program; if not, write the Free Software Foundation,
25
+# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
26
+#
27
+
28
+#######################################################################
29
+# Initialization:
30
+
31
+
32
+###
33
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
34
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
35
+###
36
+
37
+: ${__OCF_ACTION=$1}
38
+
39
+#######################################################################
40
+
41
+meta_data() {
42
+	cat <<END
43
+<?xml version="1.0"?>
44
+<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
45
+<resource-agent name="nova-compute-wait" version="1.0">
46
+<version>1.0</version>
47
+
48
+<longdesc lang="en">
49
+OpenStack Nova Compute Server.
50
+</longdesc>
51
+<shortdesc lang="en">OpenStack Nova Compute Server</shortdesc>
52
+
53
+<parameters>
54
+
55
+<parameter name="auth_url" unique="0" required="1">
56
+<longdesc lang="en">
57
+Deprecated option not in use
58
+</longdesc>
59
+<shortdesc lang="en">Deprecated</shortdesc>
60
+<content type="string" default="" />
61
+</parameter>
62
+
63
+<parameter name="username" unique="0" required="1">
64
+<longdesc lang="en">
65
+Deprecated option not in use
66
+</longdesc>
67
+<shortdesc lang="en">Deprecated</shortdesc>
68
+</parameter>
69
+
70
+<parameter name="password" unique="0" required="1">
71
+<longdesc lang="en">
72
+Deprecated option not in use
73
+</longdesc>
74
+<shortdesc lang="en">Deprecated</shortdesc>
75
+<content type="string" default="" />
76
+</parameter>
77
+
78
+<parameter name="tenant_name" unique="0" required="1">
79
+<longdesc lang="en">
80
+Deprecated option not in use
81
+</longdesc>
82
+<shortdesc lang="en">Deprecated</shortdesc>
83
+<content type="string" default="" />
84
+</parameter>
85
+
86
+<parameter name="domain" unique="0" required="0">
87
+<longdesc lang="en">
88
+DNS domain in which hosts live, useful when the cluster uses short names and nova uses FQDN
89
+</longdesc>
90
+<shortdesc lang="en">DNS domain</shortdesc>
91
+<content type="string" default="" />
92
+</parameter>
93
+
94
+<parameter name="endpoint_type" unique="0" required="0">
95
+<longdesc lang="en">
96
+Deprecated option not in use
97
+</longdesc>
98
+<shortdesc lang="en">Deprecated</shortdesc>
99
+<content type="string" default="" />
100
+</parameter>
101
+
102
+<parameter name="no_shared_storage" unique="0" required="0">
103
+<longdesc lang="en">
104
+Deprecated option not in use
105
+</longdesc>
106
+<shortdesc lang="en">Deprecated</shortdesc>
107
+<content type="boolean" default="0" />
108
+</parameter>
109
+
110
+<parameter name="evacuation_delay" unique="0" required="0">
111
+<longdesc lang="en">
112
+How long to wait for nova to finish evacuating instances elsewhere
113
+before starting nova-compute.  Only used when the agent detects
114
+evacuations might be in progress.
115
+
116
+You may need to increase the start timeout when increasing this value.
117
+</longdesc>
118
+<shortdesc lang="en">Delay to allow evacuations time to complete</shortdesc>
119
+<content type="integer" default="120" />
120
+</parameter>
121
+
122
+</parameters>
123
+
124
+<actions>
125
+<action name="start"        timeout="600" />
126
+<action name="stop"         timeout="300" />
127
+<action name="monitor"      timeout="20" interval="10" depth="0"/>
128
+<action name="validate-all" timeout="20" />
129
+<action name="meta-data"    timeout="5" />
130
+</actions>
131
+</resource-agent>
132
+END
133
+}
134
+
135
+#######################################################################
136
+
137
+# don't exit on TERM, to test that lrmd makes sure that we do exit
138
+trap sigterm_handler TERM
139
+sigterm_handler() {
140
+	ocf_log info "They use TERM to bring us down. No such luck."
141
+	return
142
+}
143
+
144
+nova_usage() {
145
+	cat <<END
146
+usage: $0 {start|stop|monitor|validate-all|meta-data}
147
+
148
+Expects to have a fully populated OCF RA-compliant environment set.
149
+END
150
+}
151
+
152
+nova_start() {
153
+    state=$(attrd_updater -p -n evacuate -N ${NOVA_HOST} | sed -e 's/.*value=//' | tr -d '"' )
154
+    if [ "x$state" = x ]; then
155
+	: never been fenced
156
+
157
+    elif [ "x$state" = xno ]; then
158
+	: has been evacuated, however it could have been 1s ago
159
+	ocf_log info "Pausing to give evacuations from ${NOVA_HOST} time to complete"
160
+	sleep ${OCF_RESKEY_evacuation_delay}
161
+
162
+    else
163
+	ocf_log info "Waiting for pending evacuations from ${NOVA_HOST}"
164
+	while [ "x$state" != "xno" ]; do
165
+	    state=$(attrd_updater -p -n evacuate -N ${NOVA_HOST} | sed -e 's/.*value=//' | tr -d '"' )
166
+	    sleep 5
167
+	done
168
+
169
+	ocf_log info "Pausing to give evacuations from ${NOVA_HOST} time to complete"
170
+	sleep ${OCF_RESKEY_evacuation_delay}
171
+    fi
172
+    return $OCF_SUCCESS
173
+}
174
+
175
+nova_stop() {
176
+    return $OCF_SUCCESS
177
+}
178
+
179
+nova_monitor() {
180
+    return $OCF_SUCCESS
181
+}
182
+
183
+nova_notify() {
184
+    return $OCF_SUCCESS
185
+}
186
+
187
+nova_validate() {
188
+    rc=$OCF_SUCCESS
189
+
190
+    check_binary crudini
191
+    check_binary nova-compute
192
+
193
+    if [ ! -f /etc/nova/nova.conf ]; then
194
+	   ocf_exit_reason "/etc/nova/nova.conf not found"
195
+	   exit $OCF_ERR_CONFIGURED
196
+    fi
197
+
198
+    NOVA_HOST=$(crudini --get /etc/nova/nova.conf DEFAULT host 2>/dev/null)
199
+    if [ $? = 1 ]; then
200
+        short_host=$(uname -n | awk -F. '{print $1}')
201
+        if [ "x${OCF_RESKEY_domain}" != x ]; then
202
+            NOVA_HOST=${short_host}.${OCF_RESKEY_domain}
203
+        else
204
+            NOVA_HOST=$(uname -n)
205
+        fi
206
+    fi
207
+
208
+    if [ $rc != $OCF_SUCCESS ]; then
209
+	exit $rc
210
+    fi
211
+    return $rc
212
+}
213
+
214
+: ${OCF_RESKEY_evacuation_delay=120}
215
+case $__OCF_ACTION in
216
+meta-data)	meta_data
217
+		exit $OCF_SUCCESS
218
+		;;
219
+usage|help)	nova_usage
220
+		exit $OCF_SUCCESS
221
+		;;
222
+esac
223
+
224
+case $__OCF_ACTION in
225
+start)		nova_validate; nova_start;;
226
+stop)		nova_stop;;
227
+monitor)	nova_validate; nova_monitor;;
228
+notify)		nova_notify;;
229
+validate-all)	exit $OCF_SUCCESS;;
230
+*)		nova_usage
231
+		exit $OCF_ERR_UNIMPLEMENTED
232
+		;;
233
+esac
234
+rc=$?
235
+ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
236
+exit $rc

Loading…
Cancel
Save