Gitweb:
http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=b2afa6...
Commit: b2afa6263795d06bbfc027444c812a7c20d500c7
Parent: 3cd42f9de648ae2d7f2bbd49530f7adf18cf80a9
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Thu Aug 9 15:02:23 2012 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Thu Aug 9 15:02:23 2012 +0200
fence_virsh: Support for using sudo for running virsh
Based on patch from Niels de Vos (in bugzilla)
Resolves: rhbz#632851
---
fence/agents/lib/fencing.py.py | 14 +++++++++++---
fence/agents/virsh/fence_virsh.py | 17 ++++++++++++++---
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index cb8ec26..2cc6e7b 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -30,6 +30,7 @@ EC_PASSWORD_MISSING = 10
TELNET_PATH = "/usr/bin/telnet"
SSH_PATH = "/usr/bin/ssh"
SSL_PATH = "@SBINDIR@/fence_nss_wrapper"
+SUDO_PATH = "/usr/bin/sudo"
all_opt = {
"help" : {
@@ -386,17 +387,24 @@ all_opt = {
"session_url" : {
"getopt" : "s:",
"longopt" : "session-url",
- "help" : "-s, --session-url URL to connect to XenServer
on.",
+ "help" : "-s, --session-url URL to connect to XenServer
on",
"required" : "1",
"shortdesc" : "The URL of the XenServer host.",
"order" : 1},
"uuid" : {
"getopt" : "U:",
"longopt" : "uuid",
- "help" : "-U, --uuid UUID of the VM to
fence.",
+ "help" : "-U, --uuid UUID of the VM to fence",
"required" : "0",
"shortdesc" : "The UUID of the virtual machine to fence.",
- "order" : 1}
+ "order" : 1},
+ "sudo" : {
+ "getopt" : "d",
+ "longopt" : "use-sudo",
+ "help" : "--use-sudo Use sudo (without password)
when calling 3rd party software",
+ "required" : "0",
+ "shortdesc" : "Use sudo (without password) when calling 3rd party
sotfware.",
+ "order" : 205}
}
common_opt = [ "retry_on", "delay" ]
diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py
index 13099da..4859d7d 100644
--- a/fence/agents/virsh/fence_virsh.py
+++ b/fence/agents/virsh/fence_virsh.py
@@ -16,8 +16,14 @@ BUILD_DATE=""
#END_VERSION_GENERATION
def get_outlets_status(conn, options):
+ if options.has_key("-d"):
+ prefix = SUDO_PATH + " "
+ else:
+ prefix = ""
+
try:
- conn.sendline("virsh list --all")
+ conn.sendline(prefix + "virsh list --all")
+ conn.interact()
conn.log_expect(options, options["-c"], int(options["-Y"]))
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
@@ -48,8 +54,13 @@ def get_power_status(conn, options):
return outlets[options["-n"]][1]
def set_power_status(conn, options):
+ if options.has_key("-d"):
+ prefix = SUDO_PATH + " "
+ else:
+ prefix = ""
+
try:
- conn.sendline("virsh %s "%(options["-o"] == "on" and
"start" or "destroy")+options["-n"])
+ conn.sendline(prefix + "virsh %s "%(options["-o"] == "on"
and "start" or "destroy")+options["-n"])
conn.log_expect(options, options["-c"], int(options["-g"]))
time.sleep(1)
@@ -63,7 +74,7 @@ def main():
device_opt = [ "help", "version", "agent",
"quiet", "verbose", "debug",
"action", "ipaddr", "login", "passwd",
"passwd_script",
"secure", "identity_file", "test", "port",
"separator",
- "inet4_only", "inet6_only", "ipport",
+ "inet4_only", "inet6_only", "ipport", "sudo",
"power_timeout", "shell_timeout", "login_timeout",
"power_wait" ]
atexit.register(atexit_handler)