Blame SOURCES/fence_aliyun-1.patch

658b6c
From 418df5845d1781e18e300cf17b2de714e4ff09d1 Mon Sep 17 00:00:00 2001
658b6c
From: "feng.changf1" <feng.changf1@alibaba-inc.com>
658b6c
Date: Tue, 24 Jul 2018 15:56:50 +0800
658b6c
Subject: [PATCH 1/3] Add Aliyun fence agent.
658b6c
658b6c
---
658b6c
 agents/aliyun/fence_aliyun.py | 146 ++++++++++++++++++++++++++++++++++++++++++
658b6c
 1 file changed, 146 insertions(+)
658b6c
 create mode 100644 agents/aliyun/fence_aliyun.py
658b6c
658b6c
diff --git a/agents/aliyun/fence_aliyun.py b/agents/aliyun/fence_aliyun.py
658b6c
new file mode 100644
658b6c
index 00000000..ec7d2316
658b6c
--- /dev/null
658b6c
+++ b/agents/aliyun/fence_aliyun.py
658b6c
@@ -0,0 +1,146 @@
658b6c
+#!/usr/bin/python -tt
658b6c
+
658b6c
+import sys, re
658b6c
+import logging
658b6c
+import atexit
658b6c
+import json
658b6c
+sys.path.append("@FENCEAGENTSLIBDIR@")
658b6c
+from fencing import *
658b6c
+from fencing import fail, fail_usage, EC_TIMED_OUT, run_delay
658b6c
+
658b6c
+from aliyunsdkcore import client
658b6c
+
658b6c
+from aliyunsdkecs.request.v20140526.DescribeInstancesRequest import DescribeInstancesRequest
658b6c
+from aliyunsdkecs.request.v20140526.StartInstanceRequest import StartInstanceRequest
658b6c
+from aliyunsdkecs.request.v20140526.StopInstanceRequest import StopInstanceRequest
658b6c
+from aliyunsdkecs.request.v20140526.RebootInstanceRequest import RebootInstanceRequest
658b6c
+
658b6c
+def _send_request(conn, request):
658b6c
+	request.set_accept_format('json')
658b6c
+	try:
658b6c
+		response_str = conn.do_action_with_exception(request)
658b6c
+		response_detail = json.loads(response_str)
658b6c
+		return response_detail
658b6c
+	except Exception as e:
658b6c
+		fail_usage("Failed: _send_request failed")
658b6c
+
658b6c
+def start_instance(conn, instance_id):
658b6c
+	request = StartInstanceRequest()
658b6c
+	request.set_InstanceId(instance_id)
658b6c
+	_send_request(conn, request)
658b6c
+
658b6c
+def stop_instance(conn, instance_id):
658b6c
+	request = StopInstanceRequest()
658b6c
+	request.set_InstanceId(instance_id)
658b6c
+	request.set_ForceStop('true')
658b6c
+	_send_request(conn, request)
658b6c
+
658b6c
+def reboot_instance(conn, instance_id):
658b6c
+	request = RebootInstanceRequest()
658b6c
+	request.set_InstanceId(instance_id)
658b6c
+	request.set_ForceStop('true')
658b6c
+	_send_request(conn, request)
658b6c
+
658b6c
+def get_status(conn, instance_id):
658b6c
+	request = DescribeInstancesRequest()
658b6c
+	request.set_InstanceIds(json.dumps([instance_id]))
658b6c
+	response = _send_request(conn, request)
658b6c
+	instance_status = None
658b6c
+	if response is not None:
658b6c
+		instance_list = response.get('Instances').get('Instance')
658b6c
+		for item in instance_list:
658b6c
+			instance_status = item.get('Status')
658b6c
+	return instance_status
658b6c
+
658b6c
+def get_nodes_list(conn, options):
658b6c
+	result = {}
658b6c
+	request = DescribeInstancesRequest()
658b6c
+	response = _send_request(conn, request)
658b6c
+	instance_status = None
658b6c
+	if response is not None:
658b6c
+		instance_list = response.get('Instances').get('Instance')
658b6c
+		for item in instance_list:
658b6c
+			instance_id = item.get('InstanceId')
658b6c
+			result[instance_id] = ("", None)
658b6c
+	return result
658b6c
+
658b6c
+def get_power_status(conn, options):
658b6c
+	state = get_status(conn, options["--plug"])
658b6c
+	if state == "Running":
658b6c
+		return "on"
658b6c
+	elif state == "Stopped":
658b6c
+		return "off"
658b6c
+	else:
658b6c
+		return "unknown"
658b6c
+
658b6c
+
658b6c
+def set_power_status(conn, options):
658b6c
+	if (options["--action"]=="off"):
658b6c
+		stop_instance(conn, options["--plug"])
658b6c
+	elif (options["--action"]=="on"):
658b6c
+		start_instance(conn, options["--plug"])
658b6c
+	elif (options["--action"]=="reboot"):
658b6c
+		reboot_instance(conn, options["--plug"])
658b6c
+
658b6c
+
658b6c
+def define_new_opts():
658b6c
+	all_opt["region"] = {
658b6c
+		"getopt" : "r:",
658b6c
+		"longopt" : "region",
658b6c
+		"help" : "-r, --region=[name]            Region, e.g. cn-hangzhou",
658b6c
+		"shortdesc" : "Region.",
658b6c
+		"required" : "0",
658b6c
+		"order" : 2
658b6c
+	}
658b6c
+	all_opt["access_key"] = {
658b6c
+		"getopt" : "a:",
658b6c
+		"longopt" : "access-key",
658b6c
+		"help" : "-a, --access-key=[name]         Access Key",
658b6c
+		"shortdesc" : "Access Key.",
658b6c
+		"required" : "0",
658b6c
+		"order" : 3
658b6c
+	}
658b6c
+	all_opt["secret_key"] = {
658b6c
+		"getopt" : "s:",
658b6c
+		"longopt" : "secret-key",
658b6c
+		"help" : "-s, --secret-key=[name]         Secret Key",
658b6c
+		"shortdesc" : "Secret Key.",
658b6c
+		"required" : "0",
658b6c
+		"order" : 4
658b6c
+	}
658b6c
+
658b6c
+# Main agent method
658b6c
+def main():
658b6c
+	conn = None
658b6c
+
658b6c
+	device_opt = ["port", "no_password", "region", "access_key", "secret_key"]
658b6c
+
658b6c
+	atexit.register(atexit_handler)
658b6c
+
658b6c
+	define_new_opts()
658b6c
+
658b6c
+	all_opt["power_timeout"]["default"] = "60"
658b6c
+
658b6c
+	options = check_input(device_opt, process_input(device_opt))
658b6c
+
658b6c
+	docs = {}
658b6c
+	docs["shortdesc"] = "Fence agent for Aliyun (Aliyun Web Services)"
658b6c
+	docs["longdesc"] = "fence_aliyun is an I/O Fencing agent for Aliyun"
658b6c
+	docs["vendorurl"] = "http://www.aliyun.com"
658b6c
+	show_docs(options, docs)
658b6c
+
658b6c
+	run_delay(options)
658b6c
+
658b6c
+	if "--region" in options and "--access-key" in options and "--secret-key" in options:  
658b6c
+		region = options["--region"]
658b6c
+		access_key = options["--access-key"]
658b6c
+		secret_key = options["--secret-key"]
658b6c
+		conn = client.AcsClient(access_key, secret_key, region)
658b6c
+
658b6c
+
658b6c
+	# Operate the fencing device
658b6c
+	result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list)
658b6c
+	sys.exit(result)
658b6c
+
658b6c
+if __name__ == "__main__":
658b6c
+	main()
658b6c
658b6c
From 28b55555abda9b6c278a7f082bb22c4f6f1e2474 Mon Sep 17 00:00:00 2001
658b6c
From: "feng.changf1" <feng.changf1@alibaba-inc.com>
658b6c
Date: Tue, 24 Jul 2018 17:18:53 +0800
658b6c
Subject: [PATCH 2/3] Add Aliyun fence agent.
658b6c
658b6c
---
658b6c
 tests/data/metadata/fence_aliyun.xml | 113 +++++++++++++++++++++++++++++++++++
658b6c
 1 file changed, 113 insertions(+)
658b6c
 create mode 100644 tests/data/metadata/fence_aliyun.xml
658b6c
658b6c
diff --git a/tests/data/metadata/fence_aliyun.xml b/tests/data/metadata/fence_aliyun.xml
658b6c
new file mode 100644
658b6c
index 00000000..1db692ee
658b6c
--- /dev/null
658b6c
+++ b/tests/data/metadata/fence_aliyun.xml
658b6c
@@ -0,0 +1,113 @@
658b6c
+
658b6c
+<resource-agent name="fence_aliyun" shortdesc="Fence agent for Aliyun (Aliyun Web Services)" >
658b6c
+<longdesc>fence_aliyun is an I/O Fencing agent for Aliyun</longdesc>
658b6c
+<vendor-url>http://www.aliyun.com</vendor-url>
658b6c
+<parameters>
658b6c
+	<parameter name="action" unique="0" required="1">
658b6c
+		<getopt mixed="-o, --action=[action]" />
658b6c
+		<content type="string" default="reboot"  />
658b6c
+		<shortdesc lang="en">Fencing action</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="plug" unique="0" required="1" obsoletes="port">
658b6c
+		<getopt mixed="-n, --plug=[id]" />
658b6c
+		<content type="string"  />
658b6c
+		<shortdesc lang="en">Physical plug number on device, UUID or identification of machine</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="port" unique="0" required="1" deprecated="1">
658b6c
+		<getopt mixed="-n, --plug=[id]" />
658b6c
+		<content type="string"  />
658b6c
+		<shortdesc lang="en">Physical plug number on device, UUID or identification of machine</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="region" unique="0" required="0">
658b6c
+		<getopt mixed="-r, --region=[name]" />
658b6c
+		<content type="string"  />
658b6c
+		<shortdesc lang="en">Region.</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="access_key" unique="0" required="0">
658b6c
+		<getopt mixed="-a, --access-key=[name]" />
658b6c
+		<content type="string"  />
658b6c
+		<shortdesc lang="en">Access Key.</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="secret_key" unique="0" required="0">
658b6c
+		<getopt mixed="-s, --secret-key=[name]" />
658b6c
+		<content type="string"  />
658b6c
+		<shortdesc lang="en">Secret Key.</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="quiet" unique="0" required="0">
658b6c
+		<getopt mixed="-q, --quiet" />
658b6c
+		<content type="boolean"  />
658b6c
+		<shortdesc lang="en">Disable logging to stderr. Does not affect --verbose or --debug-file or logging to syslog.</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="verbose" unique="0" required="0">
658b6c
+		<getopt mixed="-v, --verbose" />
658b6c
+		<content type="boolean"  />
658b6c
+		<shortdesc lang="en">Verbose mode</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="debug" unique="0" required="0" deprecated="1">
658b6c
+		<getopt mixed="-D, --debug-file=[debugfile]" />
658b6c
+		<content type="string"  />
658b6c
+		<shortdesc lang="en">Write debug information to given file</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="debug_file" unique="0" required="0" obsoletes="debug">
658b6c
+		<getopt mixed="-D, --debug-file=[debugfile]" />
658b6c
+		<content type="string"  />
658b6c
+		<shortdesc lang="en">Write debug information to given file</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="version" unique="0" required="0">
658b6c
+		<getopt mixed="-V, --version" />
658b6c
+		<content type="boolean"  />
658b6c
+		<shortdesc lang="en">Display version information and exit</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="help" unique="0" required="0">
658b6c
+		<getopt mixed="-h, --help" />
658b6c
+		<content type="boolean"  />
658b6c
+		<shortdesc lang="en">Display help and exit</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="separator" unique="0" required="0">
658b6c
+		<getopt mixed="-C, --separator=[char]" />
658b6c
+		<content type="string" default=","  />
658b6c
+		<shortdesc lang="en">Separator for CSV created by 'list' operation</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="delay" unique="0" required="0">
658b6c
+		<getopt mixed="--delay=[seconds]" />
658b6c
+		<content type="second" default="0"  />
658b6c
+		<shortdesc lang="en">Wait X seconds before fencing is started</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="login_timeout" unique="0" required="0">
658b6c
+		<getopt mixed="--login-timeout=[seconds]" />
658b6c
+		<content type="second" default="5"  />
658b6c
+		<shortdesc lang="en">Wait X seconds for cmd prompt after login</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="power_timeout" unique="0" required="0">
658b6c
+		<getopt mixed="--power-timeout=[seconds]" />
658b6c
+		<content type="second" default="60"  />
658b6c
+		<shortdesc lang="en">Test X seconds for status change after ON/OFF</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="power_wait" unique="0" required="0">
658b6c
+		<getopt mixed="--power-wait=[seconds]" />
658b6c
+		<content type="second" default="0"  />
658b6c
+		<shortdesc lang="en">Wait X seconds after issuing ON/OFF</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="shell_timeout" unique="0" required="0">
658b6c
+		<getopt mixed="--shell-timeout=[seconds]" />
658b6c
+		<content type="second" default="3"  />
658b6c
+		<shortdesc lang="en">Wait X seconds for cmd prompt after issuing command</shortdesc>
658b6c
+	</parameter>
658b6c
+	<parameter name="retry_on" unique="0" required="0">
658b6c
+		<getopt mixed="--retry-on=[attempts]" />
658b6c
+		<content type="integer" default="1"  />
658b6c
+		<shortdesc lang="en">Count of attempts to retry power on</shortdesc>
658b6c
+	</parameter>
658b6c
+</parameters>
658b6c
+<actions>
658b6c
+	<action name="on" automatic="0"/>
658b6c
+	<action name="off" />
658b6c
+	<action name="reboot" />
658b6c
+	<action name="status" />
658b6c
+	<action name="list" />
658b6c
+	<action name="list-status" />
658b6c
+	<action name="monitor" />
658b6c
+	<action name="metadata" />
658b6c
+	<action name="validate-all" />
658b6c
+</actions>
658b6c
+</resource-agent>
658b6c
658b6c
From 53bbd91e91c231c89ae8981238bb15d85d02207b Mon Sep 17 00:00:00 2001
658b6c
From: "feng.changf1" <feng.changf1@alibaba-inc.com>
658b6c
Date: Tue, 24 Jul 2018 17:26:45 +0800
658b6c
Subject: [PATCH 3/3] Fix CI error.
658b6c
658b6c
---
658b6c
 agents/aliyun/fence_aliyun.py | 32 +++++++++++++++++---------------
658b6c
 1 file changed, 17 insertions(+), 15 deletions(-)
658b6c
658b6c
diff --git a/agents/aliyun/fence_aliyun.py b/agents/aliyun/fence_aliyun.py
658b6c
index ec7d2316..0f24b83e 100644
658b6c
--- a/agents/aliyun/fence_aliyun.py
658b6c
+++ b/agents/aliyun/fence_aliyun.py
658b6c
@@ -1,20 +1,22 @@
658b6c
 #!/usr/bin/python -tt
658b6c
 
658b6c
-import sys, re
658b6c
-import logging
658b6c
-import atexit
658b6c
-import json
658b6c
-sys.path.append("@FENCEAGENTSLIBDIR@")
658b6c
-from fencing import *
658b6c
-from fencing import fail, fail_usage, EC_TIMED_OUT, run_delay
658b6c
-
658b6c
-from aliyunsdkcore import client
658b6c
-
658b6c
-from aliyunsdkecs.request.v20140526.DescribeInstancesRequest import DescribeInstancesRequest
658b6c
-from aliyunsdkecs.request.v20140526.StartInstanceRequest import StartInstanceRequest
658b6c
-from aliyunsdkecs.request.v20140526.StopInstanceRequest import StopInstanceRequest
658b6c
-from aliyunsdkecs.request.v20140526.RebootInstanceRequest import RebootInstanceRequest
658b6c
-
658b6c
+try:
658b6c
+	import sys, re
658b6c
+	import logging
658b6c
+	import atexit
658b6c
+	import json
658b6c
+	sys.path.append("@FENCEAGENTSLIBDIR@")
658b6c
+	from fencing import *
658b6c
+	from fencing import fail, fail_usage, EC_TIMED_OUT, run_delay
658b6c
+
658b6c
+	from aliyunsdkcore import client
658b6c
+
658b6c
+	from aliyunsdkecs.request.v20140526.DescribeInstancesRequest import DescribeInstancesRequest
658b6c
+	from aliyunsdkecs.request.v20140526.StartInstanceRequest import StartInstanceRequest
658b6c
+	from aliyunsdkecs.request.v20140526.StopInstanceRequest import StopInstanceRequest
658b6c
+	from aliyunsdkecs.request.v20140526.RebootInstanceRequest import RebootInstanceRequest
658b6c
+except ImportError:
658b6c
+	pass
658b6c
 def _send_request(conn, request):
658b6c
 	request.set_accept_format('json')
658b6c
 	try: