public inbox for cluster-cvs@sourceware.org help / color / mirror / Atom feed
From: "Marek Grác" <marx@fedoraproject.org> To: cluster-cvs-relay@redhat.com Subject: cluster: RHEL5 - fence_virsh: #496629 Add virsh fencing agent Date: Thu, 21 May 2009 12:26:00 -0000 [thread overview] Message-ID: <20090521122609.92F641201FA@lists.fedorahosted.org> (raw) Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=8f7ef65924e8a48178e72ef359dc5a92091bb9e0 Commit: 8f7ef65924e8a48178e72ef359dc5a92091bb9e0 Parent: dc1798cc8ad2216acc8fb08cf6f4b6381c77f447 Author: Marek 'marx' Grac <mgrac@redhat.com> AuthorDate: Thu May 21 14:19:12 2009 +0200 Committer: Marek 'marx' Grac <mgrac@redhat.com> CommitterDate: Thu May 21 14:19:12 2009 +0200 fence_virsh: #496629 Add virsh fencing agent --- fence/agents/Makefile | 4 ++ fence/agents/virsh/Makefile | 39 ++++++++++++++++ fence/agents/virsh/fence_virsh.py | 87 +++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 0 deletions(-) diff --git a/fence/agents/Makefile b/fence/agents/Makefile index 80655fb..c8ef06a 100644 --- a/fence/agents/Makefile +++ b/fence/agents/Makefile @@ -43,6 +43,7 @@ all: # ${MAKE} -C xcat all [ "${enable_xen}" != "1" ] || ${MAKE} -C xvm all # ${MAKE} -C zvm all + ${MAKE} -C virsh all install: all ${MAKE} -C lib install @@ -73,6 +74,7 @@ install: all # ${MAKE} -C xcat install [ "${enable_xen}" != "1" ] || ${MAKE} -C xvm install # ${MAKE} -C zvm install + ${MAKE} -C virsh install clean: ${MAKE} -C lib clean @@ -103,3 +105,5 @@ clean: # ${MAKE} -C xcat clean [ "${enable_xen}" != "1" ] || ${MAKE} -C xvm clean # ${MAKE} -C zvm clean + ${MAKE} -C virsh clean + diff --git a/fence/agents/virsh/Makefile b/fence/agents/virsh/Makefile new file mode 100644 index 0000000..45ca6bf --- /dev/null +++ b/fence/agents/virsh/Makefile @@ -0,0 +1,39 @@ +############################################################################### +############################################################################### +## +## Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +## Copyright (C) 2004 Red Hat, Inc. All rights reserved. +## +## This copyrighted material is made available to anyone wishing to use, +## modify, copy, or redistribute it subject to the terms and conditions +## of the GNU General Public License v.2. +## +############################################################################### +############################################################################### + +SOURCE= fence_virsh.py +TARGET= fence_virsh + +top_srcdir=../.. +include ${top_srcdir}/make/defines.mk + +all: $(TARGET) + +fence_virsh: fence_virsh.py + : > $(TARGET) + awk "{print}(\$$1 ~ /#BEGIN_VERSION_GENERATION/){exit 0}" $(SOURCE) >> $(TARGET) + echo "FENCE_RELEASE_NAME=\"${RELEASE}\";" >> $(TARGET) + ${top_srcdir}/scripts/define2var ${top_srcdir}/config/copyright.cf sh REDHAT_COPYRIGHT >> $(TARGET) + echo "BUILD_DATE=\"(built `date`)\";" >> $(TARGET) + awk -v p=0 "(\$$1 ~ /#END_VERSION_GENERATION/){p = 1} {if(p==1)print}" $(SOURCE) >> $(TARGET) + chmod +x $(TARGET) + +install: all + if [ ! -d ${sbindir} ]; then \ + install -d ${sbindir}; \ + fi + install -m755 ${TARGET} ${sbindir} + +clean: + rm -f $(TARGET) + diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py new file mode 100644 index 0000000..11c3576 --- /dev/null +++ b/fence/agents/virsh/fence_virsh.py @@ -0,0 +1,87 @@ +#!/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("/usr/lib/fence") +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 --noprofile --norc\"'" + + ## 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()
reply other threads:[~2009-05-21 12:26 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20090521122609.92F641201FA@lists.fedorahosted.org \ --to=marx@fedoraproject.org \ --cc=cluster-cvs-relay@redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).