Skip to content

Commit b8c5478

Browse files
committed
Add fence_heuristics_resource agent
Signed-off-by: Kumabuchi Kenji <[email protected]>
1 parent 9a641b7 commit b8c5478

File tree

3 files changed

+245
-0
lines changed

3 files changed

+245
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/usr/libexec/platform-python -tt
2+
3+
import io
4+
import re
5+
import subprocess
6+
import shlex
7+
import sys, stat
8+
import logging
9+
import os
10+
import atexit
11+
import time
12+
sys.path.append("/usr/share/fence")
13+
from fencing import fail_usage, run_command, fence_action, all_opt
14+
from fencing import atexit_handler, check_input, process_input, show_docs
15+
from fencing import run_delay
16+
17+
def heuristics_resource(con, options):
18+
19+
if options["--action"] == "on":
20+
return True
21+
22+
if not "--resource" in options or options["--resource"] == "":
23+
logging.error("resource parameter required")
24+
return False
25+
26+
crm_resource_path = options["--crm-resource-path"]
27+
resource = options["--resource"]
28+
standby_wait = int(options["--standby-wait"])
29+
p = None
30+
cmd = "%s -r %s -W" % (crm_resource_path, resource)
31+
search_str = re.compile(r"\s%s$" % os.uname()[1])
32+
33+
logging.info("Running command: %s", cmd)
34+
try:
35+
p = subprocess.Popen(shlex.split(cmd),
36+
stdout=subprocess.PIPE);
37+
except OSError:
38+
logging.error("Command failed on OS level");
39+
return False
40+
41+
if p != None:
42+
p.wait()
43+
if p.returncode == 0:
44+
for line in p.stdout:
45+
searchres = search_str.search(line.decode().strip())
46+
if searchres:
47+
# This node is ACT! Continue fencing.
48+
return True
49+
logging.info("Resource %s NOT found on this node" % resource);
50+
else:
51+
logging.error("Command failed. rc=%s" % p.returncode);
52+
53+
if standby_wait > 0:
54+
# The SBY node waits for fencing from the ACT node, and
55+
# tries to fencing to the ACT node when waking up from sleep.
56+
logging.info("Standby wait %s sec" % standby_wait);
57+
time.sleep(standby_wait)
58+
return True
59+
60+
return False
61+
62+
63+
def define_new_opts():
64+
all_opt["resource"] = {
65+
"getopt" : ":",
66+
"longopt" : "resource",
67+
"required" : "1",
68+
"help" : "--resource=[resource-id] ID of the resource that should be running in the ACT node",
69+
"shortdesc" : "Resource ID",
70+
"default" : "",
71+
"order" : 1
72+
}
73+
all_opt["standby_wait"] = {
74+
"getopt" : ":",
75+
"longopt" : "standby-wait",
76+
"required" : "0",
77+
"help" : "--standby-wait=[seconds] Wait X seconds on SBY node. If a positive number is specified, fencing action of this agent will always succeed after waits.",
78+
"shortdesc" : "Wait X seconds on SBY node. If a positive number is specified, fencing action of this agent will always succeed after waits.",
79+
"default" : "0",
80+
"order" : 1
81+
}
82+
all_opt["crm_resource_path"] = {
83+
"getopt" : ":",
84+
"longopt" : "crm-resource-path",
85+
"required" : "0",
86+
"help" : "--crm-resource-path=[path] Path to crm_resource",
87+
"shortdesc" : "Path to crm_resource",
88+
"default" : "/usr/sbin/crm_resource",
89+
"order" : 1
90+
}
91+
92+
93+
def main():
94+
device_opt = ["no_status", "no_password", "resource", "standby_wait", "crm_resource_path", "method"]
95+
define_new_opts()
96+
atexit.register(atexit_handler)
97+
98+
all_opt["method"]["default"] = "cycle"
99+
all_opt["method"]["help"] = "-m, --method=[method] Method to fence (cycle|onoff) (Default: cycle)"
100+
101+
options = check_input(device_opt, process_input(device_opt))
102+
103+
docs = {}
104+
docs["shortdesc"] = "Fence agent for resource-heuristic based fencing"
105+
docs["longdesc"] = "fence_heuristics_resource uses resource-heuristics to control execution of another fence agent on the same fencing level.\
106+
\n.P\n\
107+
This is not a fence agent by itself! \
108+
Its only purpose is to enable/disable another fence agent that lives on the same fencing level but after fence_heuristic_resource."
109+
docs["vendorurl"] = ""
110+
show_docs(options, docs)
111+
112+
run_delay(options)
113+
114+
result = fence_action(\
115+
None, \
116+
options, \
117+
None, \
118+
None, \
119+
reboot_cycle_fn = heuristics_resource,
120+
sync_set_power_fn = heuristics_resource)
121+
122+
sys.exit(result)
123+
124+
if __name__ == "__main__":
125+
main()

fence-agents.spec.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ fence-agents-emerson \\
5050
fence-agents-eps \\
5151
fence-agents-hds-cb \\
5252
fence-agents-heuristics-ping \\
53+
fence-agents-heuristics-resource \\
5354
fence-agents-hpblade \\
5455
fence-agents-ibmblade \\
5556
fence-agents-ifmib \\
@@ -536,6 +537,20 @@ ping-heuristics.
536537
%{_sbindir}/fence_heuristics_ping
537538
%{_mandir}/man8/fence_heuristics_ping.8*
538539

540+
%package heuristics-resource
541+
License: GPLv2+ and LGPLv2+
542+
Summary: Pseudo fence agent to affect other agents based on resource-heuristics
543+
Requires: pacemaker-cli
544+
Requires: fence-agents-common = %{version}-%{release}
545+
BuildArch: noarch
546+
Obsoletes: fence-agents
547+
%description heuristics-resource
548+
Fence pseudo agent used to affect other agents based on
549+
resource-heuristics.
550+
%files heuristics-resource
551+
%{_sbindir}/fence_heuristics_resource
552+
%{_mandir}/man8/fence_heuristics_resource.8*
553+
539554
%package hpblade
540555
License: GPLv2+ and LGPLv2+
541556
Summary: Fence agent for HP BladeSystem devices
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" ?>
2+
<resource-agent name="fence_heuristics_resource" shortdesc="Fence agent for resource-heuristic based fencing" >
3+
<longdesc>fence_heuristics_resource uses resource-heuristics to control execution of another fence agent on the same fencing level.
4+
5+
This is not a fence agent by itself! Its only purpose is to enable/disable another fence agent that lives on the same fencing level but after fence_heuristic_resource.</longdesc>
6+
<vendor-url></vendor-url>
7+
<parameters>
8+
<parameter name="action" unique="0" required="1">
9+
<getopt mixed="-o, --action=[action]" />
10+
<content type="string" default="reboot" />
11+
<shortdesc lang="en">Fencing action</shortdesc>
12+
</parameter>
13+
<parameter name="crm_resource_path" unique="0" required="0">
14+
<getopt mixed="--crm-resource-path=[path]" />
15+
<shortdesc lang="en">Path to crm_resource</shortdesc>
16+
</parameter>
17+
<parameter name="method" unique="0" required="0">
18+
<getopt mixed="-m, --method=[method]" />
19+
<content type="select" default="cycle" >
20+
<option value="onoff" />
21+
<option value="cycle" />
22+
</content>
23+
<shortdesc lang="en">Method to fence</shortdesc>
24+
</parameter>
25+
<parameter name="resource" unique="0" required="1">
26+
<getopt mixed="--resource=[resource-id]" />
27+
<content type="string" default="" />
28+
<shortdesc lang="en">Resource ID</shortdesc>
29+
</parameter>
30+
<parameter name="standby_wait" unique="0" required="0">
31+
<getopt mixed="--standby-wait=[seconds]" />
32+
<content type="string" default="0" />
33+
<shortdesc lang="en">Wait X seconds on SBY node. If a positive number is specified, fencing action of this agent will always succeed after waits.</shortdesc>
34+
</parameter>
35+
<parameter name="quiet" unique="0" required="0">
36+
<getopt mixed="-q, --quiet" />
37+
<content type="boolean" />
38+
<shortdesc lang="en">Disable logging to stderr. Does not affect --verbose or --debug-file or logging to syslog.</shortdesc>
39+
</parameter>
40+
<parameter name="verbose" unique="0" required="0">
41+
<getopt mixed="-v, --verbose" />
42+
<content type="boolean" />
43+
<shortdesc lang="en">Verbose mode</shortdesc>
44+
</parameter>
45+
<parameter name="debug" unique="0" required="0" deprecated="1">
46+
<getopt mixed="-D, --debug-file=[debugfile]" />
47+
<content type="string" />
48+
<shortdesc lang="en">Write debug information to given file</shortdesc>
49+
</parameter>
50+
<parameter name="debug_file" unique="0" required="0" obsoletes="debug">
51+
<getopt mixed="-D, --debug-file=[debugfile]" />
52+
<content type="string" />
53+
<shortdesc lang="en">Write debug information to given file</shortdesc>
54+
</parameter>
55+
<parameter name="version" unique="0" required="0">
56+
<getopt mixed="-V, --version" />
57+
<content type="boolean" />
58+
<shortdesc lang="en">Display version information and exit</shortdesc>
59+
</parameter>
60+
<parameter name="help" unique="0" required="0">
61+
<getopt mixed="-h, --help" />
62+
<content type="boolean" />
63+
<shortdesc lang="en">Display help and exit</shortdesc>
64+
</parameter>
65+
<parameter name="delay" unique="0" required="0">
66+
<getopt mixed="--delay=[seconds]" />
67+
<content type="second" default="0" />
68+
<shortdesc lang="en">Wait X seconds before fencing is started</shortdesc>
69+
</parameter>
70+
<parameter name="login_timeout" unique="0" required="0">
71+
<getopt mixed="--login-timeout=[seconds]" />
72+
<content type="second" default="5" />
73+
<shortdesc lang="en">Wait X seconds for cmd prompt after login</shortdesc>
74+
</parameter>
75+
<parameter name="power_timeout" unique="0" required="0">
76+
<getopt mixed="--power-timeout=[seconds]" />
77+
<content type="second" default="20" />
78+
<shortdesc lang="en">Test X seconds for status change after ON/OFF</shortdesc>
79+
</parameter>
80+
<parameter name="power_wait" unique="0" required="0">
81+
<getopt mixed="--power-wait=[seconds]" />
82+
<content type="second" default="0" />
83+
<shortdesc lang="en">Wait X seconds after issuing ON/OFF</shortdesc>
84+
</parameter>
85+
<parameter name="shell_timeout" unique="0" required="0">
86+
<getopt mixed="--shell-timeout=[seconds]" />
87+
<content type="second" default="3" />
88+
<shortdesc lang="en">Wait X seconds for cmd prompt after issuing command</shortdesc>
89+
</parameter>
90+
<parameter name="retry_on" unique="0" required="0">
91+
<getopt mixed="--retry-on=[attempts]" />
92+
<content type="integer" default="1" />
93+
<shortdesc lang="en">Count of attempts to retry power on</shortdesc>
94+
</parameter>
95+
</parameters>
96+
<actions>
97+
<action name="on" automatic="0"/>
98+
<action name="off" />
99+
<action name="reboot" />
100+
<action name="monitor" />
101+
<action name="metadata" />
102+
<action name="manpage" />
103+
<action name="validate-all" />
104+
</actions>
105+
</resource-agent>

0 commit comments

Comments
 (0)