This is the mail archive of the cluster-cvs@sourceware.org mailing list for the cluster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cluster: STABLE2 - fence: Add libvirt (virsh) based agent


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=8650d4a9642ab15210df0fa204e3708a4fc145ab
Commit:        8650d4a9642ab15210df0fa204e3708a4fc145ab
Parent:        b680b0d005b898e04de7f12800b571e215e11260
Author:        Jan Friesse <jfriesse@redhat.com>
AuthorDate:    Tue Nov 25 18:11:12 2008 +0100
Committer:     Jan Friesse <jfriesse@redhat.com>
CommitterDate: Tue Nov 25 18:11:12 2008 +0100

fence: Add libvirt (virsh) based agent

Following agent is very different in way how it works from
our xvm fence agent. This agent connects via ssh to dom0
and there run virsh, which performs required action.

rhbz#472785
---
 fence/agents/virsh/Makefile       |    5 ++
 fence/agents/virsh/fence_virsh.py |   86 ++++++++++++++++++++++++++++++
 fence/man/Makefile                |    1 +
 fence/man/fence_virsh.8           |  104 +++++++++++++++++++++++++++++++++++++
 4 files changed, 196 insertions(+), 0 deletions(-)

diff --git a/fence/agents/virsh/Makefile b/fence/agents/virsh/Makefile
new file mode 100644
index 0000000..bbea7b6
--- /dev/null
+++ b/fence/agents/virsh/Makefile
@@ -0,0 +1,5 @@
+include ../../../make/defines.mk
+
+TARGET= fence_virsh
+
+include $(OBJDIR)/make/fencebuild.mk
diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py
new file mode 100644
index 0000000..3058087
--- /dev/null
+++ b/fence/agents/virsh/fence_virsh.py
@@ -0,0 +1,86 @@
+#!/usr/bin/python
+
+# The Following Agent Has Been Tested On:
+#
+# Virsh 0.3.3 on RHEL 5.2 with xen-3.0.3-51
+#
+
+import sys, re, pexpect
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION="Virsh fence agent"
+REDHAT_COPYRIGHT=""
+BUILD_DATE=""
+#END_VERSION_GENERATION
+
+def get_outlets_status(conn, options):
+	try:
+		conn.sendline("virsh list --all")
+		conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		fail(EC_TIMED_OUT)
+
+	result={}
+
+        #This is status of mini finite automata. 0 = we didn't found Id and Name, 1 = we did
+        fa_status=0
+
+        for line in conn.before.splitlines():
+	        domain=re.search("^\s*(\S+)\s+(\S+)\s+(\S+).*$",line)
+
+                if (domain!=None):
+			if ((fa_status==0) and (domain.group(1).lower()=="id") and (domain.group(2).lower()=="name")):
+				fa_status=1
+			elif (fa_status==1):
+				result[domain.group(2)]=("",(domain.group(3).lower() in ["running","blocked"] and "on" or "off"))
+	return result
+
+def get_power_status(conn, options):
+	outlets=get_outlets_status(conn,options)
+
+        if (not (options["-n"] in outlets)):
+                fail_usage("Failed: You have to enter existing name of virtual machine!")
+        else:
+                return outlets[options["-n"]][1]
+
+def set_power_status(conn, options):
+	try:
+		conn.sendline("virsh %s "%(options["-o"] == "on" and "start" or "destroy")+options["-n"])
+
+		conn.log_expect(options, options["-c"], POWER_TIMEOUT)
+                time.sleep(1)
+
+	except pexpect.EOF:
+		fail(EC_CONNECTION_LOST)
+	except pexpect.TIMEOUT:
+		fail(EC_TIMED_OUT)
+
+def main():
+	device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug",
+			"action", "ipaddr", "login", "passwd", "passwd_script",
+			"secure", "identity_file", "test", "port" ]
+
+	options = check_input(device_opt, process_input(device_opt))
+
+	## Defaults for fence agent
+	if 0 == options.has_key("-c"):
+		options["-c"] = "\[EXPECT\]#\ "
+
+	options["-x"]=1
+
+	options["ssh_options"]="-t '/bin/bash -c \"PS1=\[EXPECT\]#\  /bin/bash\"'"
+
+	## Operate the fencing device
+	conn = fence_login(options)
+	fence_action(conn, options, set_power_status, get_power_status)
+
+	## Logout from system
+	conn.sendline("quit")
+	conn.close()
+
+if __name__ == "__main__":
+	main()
diff --git a/fence/man/Makefile b/fence/man/Makefile
index a80182d..701b02a 100644
--- a/fence/man/Makefile
+++ b/fence/man/Makefile
@@ -18,6 +18,7 @@ TARGET= fence.8 \
 	fence_rib.8 \
 	fence_sanbox2.8 \
 	fence_tool.8 \
+	fence_virsh.8 \
 	fence_vixel.8 \
 	fence_wti.8 \
 	fence_bullpap.8 \
diff --git a/fence/man/fence_virsh.8 b/fence/man/fence_virsh.8
new file mode 100644
index 0000000..36077a0
--- /dev/null
+++ b/fence/man/fence_virsh.8
@@ -0,0 +1,104 @@
+.TH fence_virsh 8
+
+.SH NAME
+fence_virsh - I/O Fencing agent for libvirt virtual machines using
+
+.SH SYNOPSIS
+.B
+fence_virsh
+[\fIOPTION\fR]...
+
+.SH DESCRIPTION
+fence_virsh is an I/O Fencing agent which can be used with the virtual machines
+managed by libvirt. It logs via ssh to a dom0 and there run virsh command,
+which does all work.
+
+By default, virsh needs root account to do properly work. So you must allow
+ssh login in your sshd_config.
+
+fence_virsh accepts options on the command line as well as from stdin.
+Fenced sends parameters through stdin when it execs the agent.  fence_virsh
+can be run by itself with command line options.  This is useful for testing 
+and for turning outlets on or off from scripts.
+
+.SH OPTIONS
+.TP
+\fB-a\fP \fIIPaddress\fR
+IP address or hostname of dom0.
+.TP
+\fB-h\fP
+Print out a help message describing available options, then exit.
+.TP
+\fB-l\fP \fIlogin\fR
+Login name of user root in dom0.
+.TP
+\fB-o\fP \fIaction\fR
+The action required.  This can be reboot (default), status, off or on.
+.TP
+\fB-p\fP \fIpassword\fR
+Password for login or for passphrase for dom0 machine.
+.TP
+\fB-B\fP \fIscript\fR
+Script to run to retrieve password for dom0 machine.
+.TP
+\fB-n\fP \fIname\fR
+Name of virtual machine to fence
+.TP
+\fB-x\fP
+Use secure connection over ssh (this is default, and can't be disabled)
+.TP
+\fB-k\fP \fIfilename\fR
+Identity file (private key) for ssh
+.TP
+\fB-T\fP
+Test only. Answer NO to the confirmation prompt instead of YES.
+.TP
+\fB-v\fP
+Verbose. Record session to stdout, or debug file if specified (see -D).
+.TP
+\fB-D\fP
+Specifies file, where will be written debug messages from session.
+.TP
+\fB-V\fP
+Print out a version message, then exit.
+
+.SH STDIN PARAMETERS
+.TP
+\fIagent = < param >\fR
+This option is used by fence_node(8) and is ignored by fence_virsh.
+.TP
+\fIipaddr = < hostname | ip >\fR
+IP address or hostname of dom0.
+.TP
+\fIlogin = < param >\fR
+Login name of user root in dom0.
+.TP
+\fIoption = < param >\fR
+The action required.  This can be reboot (default), status, off or on.
+.TP
+\fIpasswd = < param >\fR
+Password for login or for passphrase for dom0 machine.
+.TP
+\fIpasswd_script = < param >\fR
+Script to run to retrieve password for dom0 machine.
+.TP
+\fIport = < param >\fR
+Name of virtual machine to fence.
+.TP
+\fIsecure = < param >\fR
+Use secure connection over ssh (this is default, and can't be disabled)
+.TP
+\fIidentity_file = < param >\fR
+Identity file (private key) for ssh
+.TP
+\fItest = < param >\fR
+Test only.  Answer NO to the confirmation prompt instead of YES.
+.TP
+\fIverbose = < param >\fR
+Verbose.  Record session to stdout, or debug file if specified (see debug).
+.TP
+\fIdebug = < param >\fR
+Specifies file, where will be written debug messages from session.
+
+.SH SEE ALSO
+fence(8), fence_node(8)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]