Blame SOURCES/fence_aliyun-1.patch

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