Blob Blame History Raw
--- a/fence/agents/lib/fencing.py.py.orig	2017-10-16 13:51:44.994248524 +0200
+++ b/fence/agents/lib/fencing.py.py	2017-10-16 14:09:05.576468918 +0200
@@ -938,7 +938,7 @@
 
 	return status
 
-def set_multi_power_fn(tn, options, set_power_fn, get_power_fn, retry_attempts = 1):
+def async_set_multi_power_fn(tn, options, set_power_fn, get_power_fn, retry_attempts):
 	plugs = options["--plugs"] if options.has_key("--plugs") else [""]
 
 	for _ in range(retry_attempts):
@@ -961,6 +961,39 @@
 				return True
 	return False
 
+def sync_set_multi_power_fn(tn, options, sync_set_power_fn, retry_attempts):
+	success = True
+	plugs = options["--plugs"] if options.has_key("--plugs") else [""]
+
+	for plug in plugs:
+		try:
+			options["--uuid"] = str(uuid.UUID(plug))
+		except ValueError:
+			pass
+		except KeyError:
+			pass
+
+		options["--plug"] = plug
+		for retry in range(retry_attempts):
+			if sync_set_power_fn(tn, options):
+				break
+			if retry == retry_attempts-1:
+				success = False
+		time.sleep(int(options["--power-wait"]))
+
+	return success
+
+def set_multi_power_fn(tn, options, set_power_fn, get_power_fn, sync_set_power_fn, retry_attempts=1):
+
+	if set_power_fn != None:
+		if get_power_fn != None:
+			return async_set_multi_power_fn(tn, options, set_power_fn, get_power_fn, retry_attempts)
+	elif sync_set_power_fn != None:
+		return sync_set_multi_power_fn(tn, options, sync_set_power_fn, retry_attempts)
+
+	return False
+
+
 def show_docs(options, docs=None):
 	device_opt = options["device_opt"]
 
@@ -986,7 +1019,7 @@
 		print __main__.REDHAT_COPYRIGHT
 		sys.exit(0)
 
-def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list=None, reboot_cycle_fn=None):
+def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list=None, reboot_cycle_fn=None, sync_set_power_fn=None):
 	result = 0
 
 	try:
@@ -1042,12 +1075,12 @@
 				return 0
 
 		if options["--action"] == "on":
-			if set_multi_power_fn(tn, options, set_power_fn, get_power_fn, 1 + int(options["--retry-on"])):
+			if set_multi_power_fn(tn, options, set_power_fn, get_power_fn, sync_set_power_fn, 1 + int(options["--retry-on"])):
 				print "Success: Powered ON"
 			else:
 				fail(EC_WAITING_ON)
 		elif options["--action"] == "off":
-			if set_multi_power_fn(tn, options, set_power_fn, get_power_fn):
+			if set_multi_power_fn(tn, options, set_power_fn, get_power_fn, sync_set_power_fn):
 				print "Success: Powered OFF"
 			else:
 				fail(EC_WAITING_OFF)
@@ -1065,13 +1098,13 @@
 			else:
 				if status != "off":
 					options["--action"] = "off"
-					if not set_multi_power_fn(tn, options, set_power_fn, get_power_fn):
+					if not set_multi_power_fn(tn, options, set_power_fn, get_power_fn, sync_set_power_fn):
 						fail(EC_WAITING_OFF)
 
 				options["--action"] = "on"
 
 				try:
-					power_on = set_multi_power_fn(tn, options, set_power_fn, get_power_fn, int(options["--retry-on"]))
+					power_on = set_multi_power_fn(tn, options, set_power_fn, get_power_fn, sync_set_power_fn, int(options["--retry-on"]))
 				except Exception, ex:
 					# an error occured during power ON phase in reboot
 					# fence action was completed succesfully even in that case