Gitweb:
http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=be464e...
Commit: be464e49a941f727812615107cbeeda119cf5669
Parent: 44f59b0698a3d82d3362da4c68a0d188f14f97da
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Oct 14 13:54:47 2013 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Mon Oct 14 13:54:47 2013 +0200
fence_vmware_soap: Correct error message when user does not have privileges
Previously, when an user does not have privileges to reboot a virtual machine, the
fence agent fails with python traceback. After applying this patch (by Shane Bradley),
the fence_vmware_soap fails with human readable error message.
Resolves: rhbz#1918263
---
fence/agents/lib/fencing.py.py | 4 +++-
fence/agents/vmware_soap/fence_vmware_soap.py | 17 +++++++++++++----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index d6b02d3..b2ab4be 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -24,6 +24,7 @@ EC_WAITING_OFF = 7
EC_STATUS = 8
EC_STATUS_HMC = 9
EC_PASSWORD_MISSING = 10
+EC_INVALID_PRIVILEGES = 11
TELNET_PATH = "/usr/bin/telnet"
SSH_PATH = "/usr/bin/ssh"
@@ -413,7 +414,8 @@ def fail(error_code):
EC_STATUS : "Failed: Unable to obtain correct plug status or plug is not
available",
EC_STATUS_HMC :
"Failed: Either unable to obtain correct plug status, partition is not available
or incorrect HMC version used",
- EC_PASSWORD_MISSING : "Failed: You have to set login password"
+ EC_PASSWORD_MISSING : "Failed: You have to set login password",
+ EC_INVALID_PRIVILEGES : "Failed: The user does not have the correct privileges to
do the requested action."
}[error_code] + "\n"
sys.stderr.write(message)
syslog.syslog(syslog.LOG_ERR, message)
diff --git a/fence/agents/vmware_soap/fence_vmware_soap.py
b/fence/agents/vmware_soap/fence_vmware_soap.py
index ac7f0d9..98ac011 100644
--- a/fence/agents/vmware_soap/fence_vmware_soap.py
+++ b/fence/agents/vmware_soap/fence_vmware_soap.py
@@ -156,10 +156,19 @@ def set_power_status(conn, options):
mo_machine = Property(vm.value)
mo_machine._type = "VirtualMachine"
- if options["--action"] == "on":
- conn.service.PowerOnVM_Task(mo_machine)
- else:
- conn.service.PowerOffVM_Task(mo_machine)
+ try:
+ if options["--action"] == "on":
+ conn.service.PowerOnVM_Task(mo_machine)
+ else:
+ conn.service.PowerOffVM_Task(mo_machine)
+ except WebFault, ex:
+ if ((str(ex).find("Permission to perform this operation was denied")) >=
0):
+ fail(EC_INVALID_PRIVILEGES)
+ else:
+ if options["--action"] == "on":
+ fail(EC_WAITING_ON)
+ else:
+ fail(EC_WAITING_OFF)
def remove_tmp_dir(tmp_dir):
shutil.rmtree(tmp_dir)