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

Marek GrĂ¡c marx at fedoraproject.org
Fri Dec 9 09:03:41 UTC 2011


Gitweb:        http://git.fedorahosted.org/git/fence-agents.git?p=fence-agents.git;a=commitdiff;h=db314d3957b2c17b6e3bcc035f2738b771631bdd
Commit:        db314d3957b2c17b6e3bcc035f2738b771631bdd
Parent:        6f27315c0737a98395b7d905dc289ef3c344630b
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: Fri Dec 9 09:44:47 2011 +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#715107
---
 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