fence-agents: RHEL6 - fence_vmware_soap: Support for alias names as ports

Marek GrĂ¡c marx at fedoraproject.org
Tue Feb 21 13:20:47 UTC 2012


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=cebc142bc880de0b012fcd69e70a6f9ccfe8a168
Commit:        cebc142bc880de0b012fcd69e70a6f9ccfe8a168
Parent:        4aa16fe367f3637f694d1792f40aad6eac3fe447
Author:        Marek 'marx' Grac <mgrac at redhat.com>
AuthorDate:    Fri Dec 9 09:30:12 2011 +0100
Committer:     Marek 'marx' Grac <mgrac at redhat.com>
CommitterDate: Sat Feb 18 14:53:42 2012 +0100

fence_vmware_soap: Support for alias names as ports

Extending fence agent to support (-n / port) can use alias names of VM.
They can be obtained using 'list' action. This feature won't work correctly
if you have several VM with same name, in that case you should use either
full path or UUID.

Resolves: rhbz#771211
---
 fence/agents/vmware_soap/fence_vmware_soap.py |   35 ++++++++++++++++--------
 1 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/fence/agents/vmware_soap/fence_vmware_soap.py b/fence/agents/vmware_soap/fence_vmware_soap.py
index 2718560..f9344ff 100644
--- a/fence/agents/vmware_soap/fence_vmware_soap.py
+++ b/fence/agents/vmware_soap/fence_vmware_soap.py
@@ -94,18 +94,28 @@ def get_power_status(conn, options):
 		return machines
 	else:
 		if options.has_key("-U") == False:
-			## Transform InventoryPath to UUID
-			mo_SearchIndex = Property(options["ServiceContent"].searchIndex.value)
-			mo_SearchIndex._type = "SearchIndex"
+			if options["-n"].startswith('/'):
+				## Transform InventoryPath to UUID
+				mo_SearchIndex = Property(options["ServiceContent"].searchIndex.value)
+				mo_SearchIndex._type = "SearchIndex"
 			
-			vm = conn.service.FindByInventoryPath(mo_SearchIndex, options["-n"])
+				vm = conn.service.FindByInventoryPath(mo_SearchIndex, options["-n"])
 			
-			try:
-				options["-U"] = mappingToUUID[vm.value]
-			except KeyError, ex:
-				fail(EC_STATUS)
-			except AttributeError, ex:
-				fail(EC_STATUS)
+				try:
+					options["-U"] = mappingToUUID[vm.value]
+				except KeyError, ex:
+					fail(EC_STATUS)
+				except AttributeError, ex:
+					fail(EC_STATUS)
+			else:
+				## Name of virtual machine instead of path
+				## warning: if you have same names of machines this won't work correctly
+				try:
+					(options["-U"], _) = machines[options["-n"]]
+				except KeyError, ex:
+					fail(EC_STATUS)
+				except AttributeError, ex:
+					fail(EC_STATUS)
 
 		try:
 			if uuid[options["-U"]] == "poweredOn":
@@ -149,8 +159,9 @@ which can be used with the virtual machines managed by VMWare products \
 that have SOAP API v4.1+. \
 \n.P\n\
 Name of virtual machine (-n / port) has to be used in inventory path \
-format (e.g. /datacenter/vm/Discovered virtual machine/myMachine). Alternatively \
-you can use UUID (-U / uuid) to access virtual machine."
+format (e.g. /datacenter/vm/Discovered virtual machine/myMachine). \
+In the cases when name of yours VM is unique you can use it instead. \
+Alternatively you can always use UUID (-U / uuid) to access virtual machine."
 	docs["vendorurl"] = "http://www.vmware.com"
 	show_docs(options, docs)
 


More information about the cluster-commits mailing list