diff --git a/fence/agents/zvm/fence_zvm_man_page b/fence/agents/zvm/fence_zvm_man_page index 359436ea..057cc6db 100644 --- a/fence/agents/zvm/fence_zvm_man_page +++ b/fence/agents/zvm/fence_zvm_man_page @@ -1,87 +1,88 @@ .TH fence_zvm 8 .SH NAME fence_zvm - Power Fencing agent for GFS on System z z/VM Clusters .SH SYNOPSIS .B fence_zvm [\fIOPTION\fR]... .SH DESCRIPTION fence_zvm is a Power Fencing agent used on a GFS virtual machine in a System z z/VM cluster. It uses the SMAPI interface to recycle an active image. fence_zvm accepts options on the command line as well as from stdin. fence_node sends the options through stdin when it execs the agent. fence_zvm can be run by itself with command line options which is useful for testing. Vendor URL: http://www.sinenomine.net .SH OPTIONS .TP \fB-o --action\fP Fencing action: "off" - deactivate virtual machine; "on" - activate virtual machine; "metadata" - display device metadata" - describe fence agent parameters; "status" - state of virtual machine .TP \fB--delay\fP \fIseconds\fP Time to delay fencing action in seconds .TP \fB-n --plug\fP \fItarget\fP Name of virtual machine to recycle. .TP \fB-h --help\fP Print out a help message describing available options, then exit. .TP \fB-a --ip\fP \fIsmapi Server\fP \fBName\fP of SMAPI server virtual machine. To be consistent with other fence agents this name is a little misleading: it is the name of the virtual machine not its IP address or hostname. .TP \fB--zvmsys\fP \fIz/VM System\fP \fBName\fP of z/VM on which the SMAPI server virtual machine resides. Optional - defaults to system on which the node is running. .TP \fB-h --help\fP Display usage information .TP \fI-t --timeout = < shutdown timeout >\fP Amount of \fIgrace\fP time to give the virtual machine to shutdown cleanly before being forcibly terminated. Currently, this option is ignored. .SH STDIN PARAMETERS .TP \fIagent = < param >\fP This option is used by fence_node(8) and is ignored by fence_zvm. .TP \fIaction = < action >\fP Fencing action: "off" - fence off device; "metadata" - display device metadata; "status" - state of device .TP \fIport = < target >\fP Name of virtual machine to recycle. .TP \fIipaddr= < server name >\fP \fBName\fP of SMAPI server virtual machine. To be consistent with other fence agents thisname is a little misleading: it is the name of the virtual machine not its IP address or hostname. .TP \fItimeout = < shutdown timeout >\fP Amount of \fIgrace\fP time to give the virtual machine to shutdown cleanly before being forcibly terminated. Currently, this option is ignored. .SH SEE ALSO fence(8), fenced(8), fence_node(8) .SH NOTES To use this agent the z/VM SMAPI service needs to be configured to allow the virtual machine running this agent to connect to it and issue the image_recycle operation. This involves updating the VSMWORK1 AUTHLIST VMSYS:VSMWORK1. file. The entry should look something similar to this: .nf Column 1 Column 66 Column 131 | | | V V V -XXXXXXXX ALL IMAGE_OPERATIONS +XXXXXXXX ALL IMAGE_CHARACTERISTICS .fi -Where XXXXXXX is the name of the virtual machine where the agent resides. +Where XXXXXXX is the name of the virtual machine used in the authuser field of the request. This virtual machine also has to be authorized +to access the system's directory manager. In addition, the VM directory entry that defines this virtual machine requires the IUCV ANY statement (or IUCV ). This authorizes use of IUCV to connect to the SMAPI server. diff --git a/fence/agents/zvm/fence_zvmip.py b/fence/agents/zvm/fence_zvmip.py index 34b8a8f9..5fbe53e4 100644 --- a/fence/agents/zvm/fence_zvmip.py +++ b/fence/agents/zvm/fence_zvmip.py @@ -1,189 +1,190 @@ #!@PYTHON@ -tt import sys import atexit import socket import struct import logging sys.path.append("@FENCEAGENTSLIBDIR@") from fencing import * from fencing import fail, fail_usage, run_delay, EC_LOGIN_DENIED, EC_TIMED_OUT INT4 = 4 def open_socket(options): try: if "--inet6-only" in options: protocol = socket.AF_INET6 elif "--inet4-only" in options: protocol = socket.AF_INET else: protocol = 0 (_, _, _, _, addr) = socket.getaddrinfo( \ options["--ip"], options["--ipport"], protocol, 0, socket.IPPROTO_TCP, socket.AI_PASSIVE )[0] except socket.gaierror: fail(EC_LOGIN_DENIED) conn = socket.socket() conn.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) conn.settimeout(float(options["--shell-timeout"])) try: conn.connect(addr) except socket.error: fail(EC_LOGIN_DENIED) return conn def smapi_pack_string(string): return struct.pack("!i%ds" % (len(string)), len(string), string) def prepare_smapi_command(options, smapi_function, additional_args): packet_size = 3*INT4 + len(smapi_function) + len(options["--username"]) + len(options["--password"]) for arg in additional_args: packet_size += INT4 + len(arg) command = struct.pack("!i", packet_size) command += smapi_pack_string(smapi_function) command += smapi_pack_string(options["--username"]) command += smapi_pack_string(options["--password"]) for arg in additional_args: command += smapi_pack_string(arg) return command def get_power_status(conn, options): del conn if options.get("--original-action", None) == "monitor": (return_code, reason_code, images_active) = \ get_list_of_images(options, "Check_Authentication", None) logging.debug("Check_Authenticate (%d,%d)", return_code, reason_code) if return_code == 0: return {} else: fail(EC_LOGIN_DENIED) if options["--action"] == "list": # '*' = list all active images options["--plug"] = "*" (return_code, reason_code, images_active) = \ get_list_of_images(options, "Image_Status_Query", options["--plug"]) logging.debug("Image_Status_Query results are (%d,%d)", return_code, reason_code) if not options["--action"] == "list": if (return_code == 0) and (reason_code == 0): return "on" elif (return_code == 0) and (reason_code == 12): # We are running always with --missing-as-off because we can not check if image # is defined or not (look at rhbz#1188750) return "off" else: return "unknown" else: (return_code, reason_code, images_defined) = \ get_list_of_images(options, "Image_Name_Query_DM", options["--username"]) logging.debug("Image_Name_Query_DM results are (%d,%d)", return_code, reason_code) return dict([(i, ("", "on" if i in images_active else "off")) for i in images_defined]) def set_power_status(conn, options): conn = open_socket(options) packet = None if options["--action"] == "on": packet = prepare_smapi_command(options, "Image_Activate", [options["--plug"]]) elif options["--action"] == "off": packet = prepare_smapi_command(options, "Image_Deactivate", [options["--plug"], "IMMED"]) conn.send(packet) request_id = struct.unpack("!i", conn.recv(INT4))[0] (output_len, request_id, return_code, reason_code) = struct.unpack("!iiii", conn.recv(INT4 * 4)) logging.debug("Image_(De)Activate results are (%d,%d)", return_code, reason_code) conn.close() return def get_list_of_images(options, command, data_as_plug): conn = open_socket(options) if data_as_plug is None: packet = prepare_smapi_command(options, command, []) else: packet = prepare_smapi_command(options, command, [data_as_plug]) conn.send(packet) request_id = struct.unpack("!i", conn.recv(INT4))[0] (output_len, request_id, return_code, reason_code) = struct.unpack("!iiii", conn.recv(INT4 * 4)) images = set() if output_len > 3*INT4: array_len = struct.unpack("!i", conn.recv(INT4))[0] data = "" while True: read_data = conn.recv(1024, socket.MSG_WAITALL) data += read_data if array_len == len(data): break elif not read_data: logging.error("Failed: Not enough data read from socket") fail(EC_TIMED_OUT) parsed_len = 0 while parsed_len < array_len: string_len = struct.unpack("!i", data[parsed_len:parsed_len+INT4])[0] parsed_len += INT4 image_name = struct.unpack("!%ds" % (string_len), data[parsed_len:parsed_len+string_len])[0] parsed_len += string_len images.add(image_name) conn.close() return (return_code, reason_code, images) def main(): device_opt = ["ipaddr", "login", "passwd", "port", "method", "missing_as_off"] atexit.register(atexit_handler) all_opt["ipport"]["default"] = "44444" all_opt["shell_timeout"]["default"] = "5" all_opt["missing_as_off"]["default"] = "1" options = check_input(device_opt, process_input(device_opt), other_conditions=True) if len(options.get("--plug", "")) > 8: fail_usage("Failed: Name of image can not be longer than 8 characters") if options["--action"] == "validate-all": sys.exit(0) docs = {} docs["shortdesc"] = "Fence agent for use with z/VM Virtual Machines" docs["longdesc"] = """The fence_zvm agent is intended to be used with with z/VM SMAPI service via TCP/IP To use this agent the z/VM SMAPI service needs to be configured to allow the virtual machine running this agent to connect to it and issue the image_recycle operation. This involves updating the VSMWORK1 AUTHLIST VMSYS:VSMWORK1. file. The entry should look something similar to this: Column 1 Column 66 Column 131 | | | V V V -XXXXXXXX ALL IMAGE_OPERATIONS +XXXXXXXX ALL IMAGE_CHARACTERISTICS -Where XXXXXXX is the name of the virtual machine used in the authuser field of the request. +Where XXXXXXX is the name of the virtual machine used in the authuser field of the request. This virtual machine also has to be authorized +to access the system's directory manager. """ docs["vendorurl"] = "http://www.ibm.com" show_docs(options, docs) run_delay(options) result = fence_action(None, options, set_power_status, get_power_status, get_power_status) sys.exit(result) if __name__ == "__main__": main() diff --git a/tests/data/metadata/fence_zvmip.xml b/tests/data/metadata/fence_zvmip.xml index 8dad35d4..71ba84cf 100644 --- a/tests/data/metadata/fence_zvmip.xml +++ b/tests/data/metadata/fence_zvmip.xml @@ -1,180 +1,181 @@ The fence_zvm agent is intended to be used with with z/VM SMAPI service via TCP/IP To use this agent the z/VM SMAPI service needs to be configured to allow the virtual machine running this agent to connect to it and issue the image_recycle operation. This involves updating the VSMWORK1 AUTHLIST VMSYS:VSMWORK1. file. The entry should look something similar to this: Column 1 Column 66 Column 131 | | | V V V -XXXXXXXX ALL IMAGE_OPERATIONS +XXXXXXXX ALL IMAGE_CHARACTERISTICS -Where XXXXXXX is the name of the virtual machine used in the authuser field of the request. +Where XXXXXXX is the name of the virtual machine used in the authuser field of the request. This virtual machine also has to be authorized +to access the system's directory manager. http://www.ibm.com Fencing action Forces agent to use IPv4 addresses only Forces agent to use IPv6 addresses only IP address or hostname of fencing device IP address or hostname of fencing device TCP/UDP port to use for connection with device Login name Method to fence Login password or passphrase Script to run to retrieve password Login password or passphrase Script to run to retrieve password Physical plug number on device, UUID or identification of machine Physical plug number on device, UUID or identification of machine Login name Disable logging to stderr. Does not affect --verbose or --debug-file or logging to syslog. Verbose mode Write debug information to given file Write debug information to given file Display version information and exit Display help and exit Separator for CSV created by 'list' operation Wait X seconds before fencing is started Wait X seconds for cmd prompt after login Missing port returns OFF instead of failure Test X seconds for status change after ON/OFF Wait X seconds after issuing ON/OFF Wait X seconds for cmd prompt after issuing command Count of attempts to retry power on