コード例 #1
0
ファイル: fence_eps.py プロジェクト: jhernand/fence-agents
def main():
	device_opt = ["ipaddr", "login", "passwd", "no_login", "no_password", \
			"port", "hidden_page", "web"]

	atexit.register(atexit_handler)

	eps_define_new_opts()

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for ePowerSwitch"
	docs["longdesc"] = "fence_eps  is an I/O Fencing agent \
which can be used with the ePowerSwitch 8M+ power switch to fence \
connected machines. Fence agent works ONLY on 8M+ device, because \
this is only one, which has support for hidden page feature. \
\n.TP\n\
Agent basically works by connecting to hidden page and pass \
appropriate arguments to GET request. This means, that hidden \
page feature must be enabled and properly configured."
	docs["vendorurl"] = "http://www.epowerswitch.com"
	show_docs(options, docs)

	run_delay(options)
	#Run fence action. Conn is None, beacause we always need open new http connection
	result = fence_action(None, options, set_power_status, get_power_status, get_power_status)

	sys.exit(result)
コード例 #2
0
def soap_login(options):
	run_delay(options)

	if options.has_key("--ssl") or options.has_key("--ssl-secure") or options.has_key("--ssl-insecure"):
		if options.has_key("--ssl-insecure"):
			verify = False
		else:
			verify = True
		url = "https://"
	else:
		verify = False
		url = "http://"

	url += options["--ip"] + ":" + str(options["--ipport"]) + "/sdk"

	tmp_dir = tempfile.mkdtemp()
	tempfile.tempdir = tmp_dir
	atexit.register(remove_tmp_dir, tmp_dir)

	try:
		headers = {"Content-Type" : "text/xml;charset=UTF-8", "SOAPAction" : ""}
		conn = Client(url + "/vimService.wsdl", location=url, transport=RequestsTransport(verify=verify), headers=headers)

		mo_ServiceInstance = Property('ServiceInstance')
		mo_ServiceInstance._type = 'ServiceInstance'
		ServiceContent = conn.service.RetrieveServiceContent(mo_ServiceInstance)
		mo_SessionManager = Property(ServiceContent.sessionManager.value)
		mo_SessionManager._type = 'SessionManager'

		conn.service.Login(mo_SessionManager, options["--username"], options["--password"])
	except requests.exceptions.SSLError, ex:
		fail_usage("Server side certificate verification failed")
コード例 #3
0
ファイル: fence_rhevm.py プロジェクト: beekhof/fence-agents
def main():
	device_opt = [
		"ipaddr",
		"api_path",
		"login",
		"passwd",
		"ssl",
		"notls",
		"web",
		"port",
		"use_cookies",
		"disable_http_filter",
	]

	atexit.register(atexit_handler)
	define_new_opts()

	all_opt["power_wait"]["default"] = "1"

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for RHEV-M REST API"
	docs["longdesc"] = "fence_rhevm is an I/O Fencing agent which can be \
used with RHEV-M REST API to fence virtual machines."
	docs["vendorurl"] = "http://www.redhat.com"
	show_docs(options, docs)

	##
	## Fence operations
	####
	run_delay(options)
	result = fence_action(None, options, set_power_status, get_power_status, get_list)

	sys.exit(result)
コード例 #4
0
def soap_login(options):
	run_delay(options)

	if options.has_key("--ssl"):
		url = "https://"
	else:
		url = "http://"

	url += options["--ip"] + ":" + str(options["--ipport"]) + "/sdk"

	tmp_dir = tempfile.mkdtemp()
	tempfile.tempdir = tmp_dir
	atexit.register(remove_tmp_dir, tmp_dir)

	try:
		conn = Client(url + "/vimService.wsdl")
		conn.set_options(location = url)

		mo_ServiceInstance = Property('ServiceInstance')
		mo_ServiceInstance._type = 'ServiceInstance'
		ServiceContent = conn.service.RetrieveServiceContent(mo_ServiceInstance)
		mo_SessionManager = Property(ServiceContent.sessionManager.value)
		mo_SessionManager._type = 'SessionManager'

		conn.service.Login(mo_SessionManager, options["--username"], options["--password"])
	except Exception:
		fail(EC_LOGIN_DENIED)

	options["ServiceContent"] = ServiceContent
	options["mo_SessionManager"] = mo_SessionManager
	return conn
コード例 #5
0
ファイル: fence_gce.py プロジェクト: beekhof/fence-agents
def main():
	conn = None

	device_opt = ["port", "no_password", "zone", "project"]

	atexit.register(atexit_handler)

	define_new_opts()

	all_opt["power_timeout"]["default"] = "60"

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for GCE (Google Cloud Engine)"
	docs["longdesc"] = "fence_gce is an I/O Fencing agent for GCE (Google Cloud " \
			   "Engine). It uses the googleapiclient library to connect to GCE.\n" \
			   "googleapiclient can be configured with Google SDK CLI or by " \
			   "executing 'gcloud auth application-default login'.\n" \
			   "For instructions see: https://cloud.google.com/compute/docs/tutorials/python-guide"
	docs["vendorurl"] = "http://cloud.google.com"
	show_docs(options, docs)

	run_delay(options)

	try:
		credentials = GoogleCredentials.get_application_default()
		conn = discovery.build('compute', 'v1', credentials=credentials)
	except:
		fail_usage("Failed: Unable to connect to GCE. Check your configuration.")

	# Operate the fencing device
	result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list)
	sys.exit(result)
コード例 #6
0
def main():

	device_opt = ["login", "passwd", "port", "no_login", "no_password", "session_url"]

	atexit.register(atexit_handler)

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "XenAPI based fencing for the Citrix XenServer virtual machines."
	docs["longdesc"] = "\
fence_cxs is an I/O Fencing agent used on Citrix XenServer hosts. \
It uses the XenAPI, supplied by Citrix, to establish an XML-RPC sesssion \
to a XenServer host. Once the session is established, further XML-RPC \
commands are issued in order to switch on, switch off, restart and query \
the status of virtual machines running on the host."
	docs["vendorurl"] = "http://www.xenproject.org"
	show_docs(options, docs)

	run_delay(options)

	xen_session = connect_and_login(options)
	result = fence_action(xen_session, options, set_power_fn, get_power_fn, get_outlet_list)

	sys.exit(result)
コード例 #7
0
ファイル: fence_amt.py プロジェクト: andreavb/fence-agents
def main():
	atexit.register(atexit_handler)

	device_opt = [ "ipaddr", "no_login", "passwd", "boot_option", "no_port",
		"sudo", "amttool_path", "method" ]

	define_new_opts()

	options = check_input(device_opt, process_input(device_opt))

	docs = { }
	docs["shortdesc"] = "Fence agent for AMT"
	docs["longdesc"] = "fence_amt is an I/O Fencing agent \
which can be used with Intel AMT. This agent calls support software amttool\
(http://www.kraxel.org/cgit/amtterm/)."
	docs["vendorurl"] = "http://www.intel.com/"
	show_docs(options, docs)

	run_delay(options)

	if not is_executable(options["--amttool-path"]):
		fail_usage("Amttool not found or not accessible")

	result = fence_action(None, options, set_power_status, get_power_status, None, reboot_cycle)

	sys.exit(result)
コード例 #8
0
def main():
    atexit.register(atexit_handler)

    device_opt = ["user", "domain", "password", "tenant", "auth_url",
                  "wf_name", "port", "mistral_url", "on_shared_storage"]
    define_new_opts()
    all_opt["shell_timeout"]["default"] = "180"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for nova compute nodes"
    docs["longdesc"] = "fence_evacuate is a Nova fencing notification agent"
    docs["vendorurl"] = ""

    show_docs(options, docs)
    run_delay(options)

    host = None
    # Potentially we should make this a pacemaker feature
    if options["--domain"] != "" and "--plug" in options:
        options["--plug"] = options["--plug"] + "." + options["--domain"]

    if "--plug" in options:
        host = options["--plug"]

    if options['--action'] in ['reboot', 'off']:
        if host is None:
            logging.error('No host specified')
            sys.exit(1)

        evacuate(host, options)

    sys.exit(0)
コード例 #9
0
def main():
    atexit.register(atexit_handler)

    device_opt = ["ipaddr", "no_login", "passwd", "boot_option", "no_port",
                  "method"]

    define_new_opts()

    all_opt["ipport"]["default"] = "16992"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for AMT (WS)"
    docs["longdesc"] = "fence_amt_ws is an I/O Fencing agent \
which can be used with Intel AMT (WS). This agent requires \
the pywsman Python library which is included in OpenWSMAN. \
(http://openwsman.github.io/)."
    docs["vendorurl"] = "http://www.intel.com/"
    show_docs(options, docs)

    run_delay(options)

    result = fence_action(None, options, set_power_status, get_power_status, \
                          None, reboot_cycle)

    sys.exit(result)
コード例 #10
0
ファイル: fence_dummy.py プロジェクト: beekhof/fence-agents
def main():
	device_opt = ["no_password", "status_file", "random_sleep_range", "type", "no_port"]

	atexit.register(atexit_handler)

	all_opt["status_file"] = {
		"getopt" : ":",
		"longopt" : "status-file",
		"help":"--status-file=[file]           Name of file that holds current status",
		"required" : "0",
		"shortdesc" : "File with status",
		"default" : "/tmp/fence_dummy.status",
		"order": 1
		}

	all_opt["random_sleep_range"] = {
		"getopt" : ":",
		"longopt" : "random_sleep_range",
		"help":"--random_sleep_range=[seconds] Issue a sleep between 1 and [seconds]",
		"required" : "0",
		"shortdesc" : "Issue a sleep between 1 and X seconds. Used for testing.",
		"order": 1
		}

	all_opt["type"] = {
		"getopt" : ":",
		"longopt" : "type",
		"help":"--type=[type]                  Possible types are: file and fail",
		"required" : "0",
		"shortdesc" : "Type of the dummy fence agent",
		"default" : "file",
		"order": 1
		}

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Dummy fence agent"
	docs["longdesc"] = "fence_dummy"
	docs["vendorurl"] = "http://www.example.com"
	show_docs(options, docs)

	run_delay(options)

	# random sleep for testing
	if "--random_sleep_range" in options:
		val = int(options["--random_sleep_range"])
		ran = random.randint(1, val)
		logging.info("Random sleep for %d seconds\n", ran)
		time.sleep(ran)

	if options["--type"] == "fail":
		result = fence_action(None, options, set_power_status_fail, get_power_status_fail, get_outlets_fail)
	else:
		result = fence_action(None, options, set_power_status_file, get_power_status_file, None)

	sys.exit(result)
コード例 #11
0
def main():
	atexit.register(atexit_handler)

	all_opt["tlscert"] = {
		"getopt" : ":",
		"longopt" : "tlscert",
		"help" : "--tlscert                      "
			"Path to client certificate for TLS authentication",
		"required" : "0",
		"shortdesc" : "Path to client certificate (PEM format) \
for TLS authentication. Required if --ssl option is used.",
		"order": 2
	}

	all_opt["tlskey"] = {
		"getopt" : ":",
		"longopt" : "tlskey",
		"help" : "--tlskey                       "
			"Path to client key for TLS authentication",
		"required" : "0",
		"shortdesc" : "Path to client key (PEM format) for TLS \
authentication.  Required if --ssl option is used.",
		"order": 2
	}

	all_opt["tlscacert"] = {
		"getopt" : ":",
		"longopt" : "tlscacert",
		"help" : "--tlscacert                    "
			"Path to CA certificate for TLS authentication",
		"required" : "0",
		"shortdesc" : "Path to CA certificate (PEM format) for \
TLS authentication.  Required if --ssl option is used.",
		"order": 2
	}

	device_opt = ["ipaddr", "no_password", "no_login", "port", "method", "web", "tlscert", "tlskey", "tlscacert", "ssl"]

	options = check_input(device_opt, process_input(device_opt))

	docs = { }
	docs["shortdesc"] = "Fence agent for Docker"
	docs["longdesc"] = "fence_docker is I/O fencing agent which \
can be used with the Docker Engine containers. You can use this \
fence-agent without any authentication, or you can use TLS authentication \
(use --ssl option, more info about TLS authentication in docker: \
http://docs.docker.com/examples/https/)."
	docs["vendorurl"] = "www.docker.io"
	show_docs(options, docs)

	run_delay(options)

	result = fence_action(None, options, set_power_status, get_power_status, get_list, reboot_cycle)

	sys.exit(result)
コード例 #12
0
ファイル: fence_mpath.py プロジェクト: oalbrigt/fence-agents
def main():
    atexit.register(atexit_handler)

    device_opt = [
        "no_login",
        "no_password",
        "devices",
        "key",
        "sudo",
        "fabric_fencing",
        "on_target",
        "store_path",
        "mpathpersist_path",
        "force_on",
    ]

    define_new_opts()

    options = check_input(device_opt, process_input(device_opt), other_conditions=True)

    docs = {}
    docs["shortdesc"] = "Fence agent for multipath persistent reservation"
    docs[
        "longdesc"
    ] = 'fence_mpath is an I/O fencing agent that uses SCSI-3 \
persistent reservations to control access multipath devices. Underlying \
devices must support SCSI-3 persistent reservations (SPC-3 or greater) as \
well as the "preempt-and-abort" subcommand.\nThe fence_mpath agent works by \
having a unique key for each node that has to be set in /etc/multipath.conf. \
Once registered, a single node will become the reservation holder \
by creating a "write exclusive, registrants only" reservation on the \
device(s). The result is that only registered nodes may write to the \
device(s). When a node failure occurs, the fence_mpath agent will remove the \
key belonging to the failed node from the device(s). The failed node will no \
longer be able to write to the device(s). A manual reboot is required.'
    docs["vendorurl"] = "https://www.sourceware.org/dm/"
    show_docs(options, docs)

    run_delay(options)

    # Input control BEGIN
    if not "--key" in options:
        fail_usage("Failed: key is required")

    if options["--action"] == "validate-all":
        sys.exit(0)

    options["devices"] = options["--devices"].split(",")

    if not options["devices"]:
        fail_usage("Failed: No devices found")
        # Input control END

    result = fence_action(None, options, set_status, get_status)
    sys.exit(result)
コード例 #13
0
ファイル: fence_ipmilan.py プロジェクト: beekhof/fence-agents
def main():
	atexit.register(atexit_handler)

	device_opt = ["ipaddr", "login", "no_login", "no_password", "passwd",
		"diag", "lanplus", "auth", "cipher", "privlvl", "sudo",
		"ipmitool_path", "method", "target", "hexadecimal_kg"]
	define_new_opts()

	all_opt["power_wait"]["default"] = 2
	if os.path.basename(sys.argv[0]) == "fence_ilo3":
		all_opt["power_wait"]["default"] = "4"
		all_opt["method"]["default"] = "cycle"
		all_opt["lanplus"]["default"] = "1"
	elif os.path.basename(sys.argv[0]) == "fence_ilo4":
		all_opt["lanplus"]["default"] = "1"

	all_opt["ipport"]["default"] = "623"
	if all_opt["method"]["default"] == "cycle":
		all_opt["method"]["help"] = "-m, --method=[method]          Method to fence (onoff|cycle) (Default: cycle)\n" \
				    "WARNING! This fence agent might report success before the node is powered off. " \
				    "You should use -m/method onoff if your fence device works correctly with that option."

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for IPMI"
	docs["longdesc"] = "fence_ipmilan is an I/O Fencing agent\
which can be used with machines controlled by IPMI.\
This agent calls support software ipmitool (http://ipmitool.sf.net/). \
WARNING! This fence agent might report success before the node is powered off. \
You should use -m/method onoff if your fence device works correctly with that option."
	docs["vendorurl"] = ""
	docs["symlink"] = [("fence_ilo3", "Fence agent for HP iLO3"),
		("fence_ilo4", "Fence agent for HP iLO4"),
		("fence_imm", "Fence agent for IBM Integrated Management Module"),
		("fence_idrac", "Fence agent for Dell iDRAC")]
	show_docs(options, docs)

	run_delay(options)

	if not is_executable(options["--ipmitool-path"]):
		fail_usage("Ipmitool not found or not accessible")

	reboot_fn = reboot_cycle
	if options["--action"] == "diag":
		# Diag is a special action that can't be verified so we will reuse reboot functionality
		# to minimize impact on generic library
		options["--action"] = "reboot"
		options["--method"] = "cycle"
		reboot_fn = reboot_diag

	result = fence_action(None, options, set_power_status, get_power_status, None, reboot_fn)
	sys.exit(result)
コード例 #14
0
ファイル: fence_cisco_ucs.py プロジェクト: vuntz/fence-agents
def main():
    global options_global
    device_opt = ["ipaddr", "login", "passwd", "ssl", "notls", "port", "web", "suborg"]

    atexit.register(atexit_handler)
    atexit.register(logout)

    define_new_opts()

    options_global = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for Cisco UCS"
    docs[
        "longdesc"
    ] = "fence_cisco_ucs is an I/O Fencing agent which can be \
used with Cisco UCS to fence machines."
    docs["vendorurl"] = "http://www.cisco.com"
    show_docs(options_global, docs)

    run_delay(options_global)
    ### Login
    try:
        res = send_command(
            options_global,
            '<aaaLogin inName="'
            + options_global["--username"]
            + '" inPassword="******"--password"]
            + '" />',
            int(options_global["--login-timeout"]),
        )
        result = RE_COOKIE.search(res)
        if result == None:
            ## Cookie is absenting in response
            fail(EC_LOGIN_DENIED)
    except Exception:
        fail(EC_LOGIN_DENIED)

    options_global["cookie"] = result.group(1)

    ##
    ## Modify suborg to format /suborg
    if options_global["--suborg"] != "":
        options_global["--suborg"] = "/" + options_global["--suborg"].lstrip("/").rstrip("/")

        ##
        ## Fence operations
        ####
    result = fence_action(None, options_global, set_power_status, get_power_status, get_list)

    ## Logout is done every time at atexit phase
    sys.exit(result)
コード例 #15
0
def main():
    compute_client = None

    device_opt = ["resourceGroup", "login", "passwd", "tenantId", "subscriptionId","port"]

    atexit.register(atexit_handler)

    define_new_opts()

    all_opt["power_timeout"]["default"] = "150"

    all_opt["login"]["help"] = "-l, --username=[appid]         Application ID"
    all_opt["passwd"]["help"] = "-p, --password=[authkey]       Authentication key"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for Azure Resource Manager"
    docs["longdesc"] = "Used to deallocate virtual machines and to report power state of virtual machines running in Azure. It uses Azure SDK for Python to connect to Azure.\
\n.P\n\
For instructions to setup credentials see: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal\
\n.P\n\
Username and password are application ID and authentication key from \"App registrations\"."
    docs["vendorurl"] = "http://www.microsoft.com"
    show_docs(options, docs)

    run_delay(options)

    try:
        from azure.common.credentials import ServicePrincipalCredentials
        from azure.mgmt.compute import ComputeManagementClient

        tenantid = options["--tenantId"]
        servicePrincipal = options["--username"]
        spPassword = options["--password"]
        subscriptionId = options["--subscriptionId"]
        credentials = ServicePrincipalCredentials(
            client_id = servicePrincipal,
            secret = spPassword,
            tenant = tenantid
        )
        compute_client = ComputeManagementClient(
            credentials,
            subscriptionId
        )
    except ImportError:
        fail_usage("Azure Resource Manager Python SDK not found or not accessible")
    except Exception as e:
        fail_usage("Failed: %s" % re.sub("^, ", "", str(e)))

    # Operate the fencing device
    result = fence_action(compute_client, options, set_power_status, get_power_status, get_nodes_list)
    sys.exit(result)
コード例 #16
0
def main():
    global options_global
    device_opt = [
        "ipaddr", "login", "passwd", "ssl", "notls", "port", "web", "suborg",
        "missing_as_off"
    ]

    atexit.register(atexit_handler)
    atexit.register(logout)

    define_new_opts()

    options_global = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for Cisco UCS"
    docs["longdesc"] = "fence_cisco_ucs is an I/O Fencing agent which can be \
used with Cisco UCS to fence machines."

    docs["vendorurl"] = "http://www.cisco.com"
    show_docs(options_global, docs)

    run_delay(options_global)
    ### Login
    try:
        res = send_command(
            options_global,
            "<aaaLogin inName=\"" + options_global["--username"] +
            "\" inPassword=\"" + options_global["--password"] + "\" />",
            int(options_global["--login-timeout"]))
        result = RE_COOKIE.search(res)
        if result == None:
            ## Cookie is absenting in response
            fail(EC_LOGIN_DENIED)
    except Exception:
        fail(EC_LOGIN_DENIED)

    options_global["cookie"] = result.group(1)

    ##
    ## Modify suborg to format /suborg
    if options_global["--suborg"] != "":
        options_global["--suborg"] = "/" + options_global["--suborg"].lstrip(
            "/").rstrip("/")

    ##
    ## Fence operations
    ####
    result = fence_action(None, options_global, set_power_status,
                          get_power_status, get_list)

    ## Logout is done every time at atexit phase
    sys.exit(result)
コード例 #17
0
def main():
    atexit.register(atexit_handler)

    device_opt = ["no_login", "no_password", "devices", "key", "sudo", \
            "fabric_fencing", "on_target", "store_path", "mpathpersist_path", "force_on"]

    define_new_opts()

    # fence_mpath_check
    if os.path.basename(sys.argv[0]) == "fence_mpath_check":
        sys.exit(mpath_check())
    elif os.path.basename(sys.argv[0]) == "fence_mpath_check_hardreboot":
        sys.exit(mpath_check(hardreboot=True))

    options = check_input(device_opt,
                          process_input(device_opt),
                          other_conditions=True)

    docs = {}
    docs["shortdesc"] = "Fence agent for multipath persistent reservation"
    docs["longdesc"] = "fence_mpath is an I/O fencing agent that uses SCSI-3 \
persistent reservations to control access multipath devices. Underlying \
devices must support SCSI-3 persistent reservations (SPC-3 or greater) as \
well as the \"preempt-and-abort\" subcommand.\nThe fence_mpath agent works by \
having a unique key for each node that has to be set in /etc/multipath.conf. \
Once registered, a single node will become the reservation holder \
by creating a \"write exclusive, registrants only\" reservation on the \
device(s). The result is that only registered nodes may write to the \
device(s). When a node failure occurs, the fence_mpath agent will remove the \
key belonging to the failed node from the device(s). The failed node will no \
longer be able to write to the device(s). A manual reboot is required."

    docs["vendorurl"] = "https://www.sourceware.org/dm/"
    show_docs(options, docs)

    run_delay(options)

    # Input control BEGIN
    if not "--key" in options:
        fail_usage("Failed: key is required")

    if options["--action"] == "validate-all":
        sys.exit(0)

    options["devices"] = options["--devices"].split(",")

    if not options["devices"]:
        fail_usage("Failed: No devices found")
    # Input control END

    result = fence_action(None, options, set_status, get_status)
    sys.exit(result)
コード例 #18
0
def main():
    atexit.register(atexit_handler)

    device_opt = ["rabbit_hosts", "rabbit_port", "user", "domain", "password",
                  "port"]
    define_new_opts()
    all_opt["shell_timeout"]["default"] = "180"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for nova compute nodes"
    docs["longdesc"] = "fence_nova_host is a Nova fencing notification agent"
    docs["vendorurl"] = ""

    show_docs(options, docs)

    run_delay(options)

    host = None
    # Potentially we should make this a pacemaker feature
    if options["--domain"] != "" and "--plug" in options:
        options["--plug"] = options["--plug"] + "." + options["--domain"]

    if "--plug" in options:
        host = options["--plug"]

    rabbit_hosts = options["--rabbit_hosts"].split(",")
    port = int(options["--rabbit_port"])
    user = options["--user"]
    password = options["--password"]
    routing_key = 'auto-evac'
    exchange = 'auto-evac'

    if options['--action'] in ['reboot', 'off']:
        if host is None:
            logging.error('No host specified')
            sys.exit(1)

        for rabbit_host in rabbit_hosts:
            try:
                send(user, password, rabbit_host, port, exchange, routing_key,
                     host)
                sys.exit(0)
            except Exception:
                logging.warning('Cannot connect to rabbitmq on %s',
                                rabbit_host)

        logging.error('Cannot connect to any of rabbitmq brokers')
        sys.exit(1)

    sys.exit(0)
コード例 #19
0
ファイル: fence_ipmilan.py プロジェクト: sbauza/fence-agents
def main():
    atexit.register(atexit_handler)

    device_opt = [
        "ipaddr", "login", "no_login", "no_password", "passwd", "diag",
        "lanplus", "auth", "cipher", "privlvl", "sudo", "ipmitool_path",
        "method"
    ]
    define_new_opts()

    all_opt["power_wait"]["default"] = 2
    if os.path.basename(sys.argv[0]) == "fence_ilo3":
        all_opt["power_wait"]["default"] = "4"
        all_opt["method"]["default"] = "cycle"
        all_opt["lanplus"]["default"] = "1"
    elif os.path.basename(sys.argv[0]) == "fence_ilo4":
        all_opt["lanplus"]["default"] = "1"

    all_opt["ipport"]["default"] = "623"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for IPMI"
    docs["longdesc"] = "fence_ipmilan is an I/O Fencing agent\
which can be used with machines controlled by IPMI.\
This agent calls support software ipmitool (http://ipmitool.sf.net/)."

    docs["vendorurl"] = ""
    docs["symlink"] = [("fence_ilo3", "Fence agent for HP iLO3"),
                       ("fence_ilo4", "Fence agent for HP iLO4"),
                       ("fence_imm",
                        "Fence agent for IBM Integrated Management Module"),
                       ("fence_idrac", "Fence agent for Dell iDRAC")]
    show_docs(options, docs)

    run_delay(options)

    if not is_executable(options["--ipmitool-path"]):
        fail_usage("Ipmitool not found or not accessible")

    reboot_fn = reboot_cycle
    if options["--action"] == "diag":
        # Diag is a special action that can't be verified so we will reuse reboot functionality
        # to minimize impact on generic library
        options["--action"] = "reboot"
        options["--method"] = "cycle"
        reboot_fn = reboot_diag

    result = fence_action(None, options, set_power_status, get_power_status,
                          None, reboot_fn)
    sys.exit(result)
コード例 #20
0
ファイル: fence_vmware.py プロジェクト: beekhof/fence-agents
def main():
	device_opt = ["ipaddr", "login", "passwd", "secure",
		       "exec", "vmware_type", "vmware_datacenter"]

	atexit.register(atexit_handler)

	all_opt["secure"]["default"] = "1"
	all_opt["vmware_type"]["default"] = VMWARE_DEFAULT_TYPE

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for VMWare"
	docs["longdesc"] = "fence_vmware is an I/O Fencing agent \
which can be used with the VMware ESX, VMware ESXi or VMware Server \
to fence virtual machines.\
\n.P\n\
Before you can use this agent, it must be installed VI Perl Toolkit or \
vmrun command on every node you want to make fencing.\
\n.P\n\
VI Perl Toolkit is preferred for VMware ESX/ESXi and Virtual Center. Vmrun \
command is only solution for VMware Server 1/2 (this command will works against \
ESX/ESXi 3.5 up2 and VC up2 too, but not cluster aware!) and is available as part \
of VMware VIX API SDK package. VI Perl and VIX API SDK are both available from \
VMware web pages (not int RHEL repository!). \
\n.P\n\
You can specify type of VMware you are connecting to with \\fB-d\\fP switch \
(or \\fIvmware_type\\fR for stdin). Possible values are esx, server2 and server1.\
Default value is esx, which will use VI Perl. With server1 and server2, vmrun \
command is used.\
\n.P\n\
After you have successfully installed VI Perl Toolkit or VIX API, you should \
be able to run fence_vmware_helper (part of this agent) or vmrun command. \
This agent supports only vmrun from version 2.0.0 (VIX API 1.6.0)."
	docs["vendorurl"] = "http://www.vmware.com"
	show_docs(options, docs)

	run_delay(options)

	# Check vmware type and set path
	vmware_check_vmware_type(options)

	# Test user vmrun command version
	if vmware_internal_type == VMWARE_TYPE_SERVER1 or vmware_internal_type == VMWARE_TYPE_SERVER2:
		if not vmware_is_supported_vmrun_version(options):
			fail_usage("Unsupported version of vmrun command! You must use at least version %d!" %
					(VMRUN_MINIMUM_REQUIRED_VERSION))

	# Operate the fencing device
	result = fence_action(None, options, set_power_status, get_power_status, get_outlets_status)

	sys.exit(result)
コード例 #21
0
def soap_login(options):
    run_delay(options)

    if "--ssl" in options or "--ssl-secure" in options or "--ssl-insecure" in options:
        if "--ssl-insecure" in options:
            import ssl
            from requests.packages.urllib3.exceptions import InsecureRequestWarning
            if hasattr(ssl, '_create_unverified_context'):
                ssl._create_default_https_context = ssl._create_unverified_context
            requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
            verify = False
        else:
            verify = True
        url = "https://"
    else:
        verify = False
        url = "http://"

    url += options["--ip"] + ":" + str(options["--ipport"]) + "/sdk"

    tmp_dir = tempfile.mkdtemp()
    tempfile.tempdir = tmp_dir
    atexit.register(remove_tmp_dir, tmp_dir)

    try:
        headers = {
            "Content-Type": "text/xml;charset=UTF-8",
            "SOAPAction": "vim25"
        }
        conn = Client(url + "/vimService.wsdl",
                      location=url,
                      transport=RequestsTransport(verify=verify),
                      headers=headers)

        mo_ServiceInstance = Property('ServiceInstance')
        mo_ServiceInstance._type = 'ServiceInstance'
        ServiceContent = conn.service.RetrieveServiceContent(
            mo_ServiceInstance)
        mo_SessionManager = Property(ServiceContent.sessionManager.value)
        mo_SessionManager._type = 'SessionManager'

        conn.service.Login(mo_SessionManager, options["--username"],
                           options["--password"])
    except requests.exceptions.SSLError as ex:
        fail_usage("Server side certificate verification failed")
    except Exception:
        fail(EC_LOGIN_DENIED)

    options["ServiceContent"] = ServiceContent
    options["mo_SessionManager"] = mo_SessionManager
    return conn
コード例 #22
0
def main():
    conn = None

    device_opt = [
        "port", "no_password", "region", "access_key", "secret_key", "ram_role"
    ]

    atexit.register(atexit_handler)

    define_new_opts()

    all_opt["power_timeout"]["default"] = "60"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for Aliyun (Aliyun Web Services)"
    docs["longdesc"] = "fence_aliyun is an I/O Fencing agent for Aliyun"
    docs["vendorurl"] = "http://www.aliyun.com"
    show_docs(options, docs)

    run_delay(options)

    if "--region" in options:
        region = options["--region"]
        if "--access-key" in options and "--secret-key" in options:
            access_key = options["--access-key"]
            secret_key = options["--secret-key"]
            conn = client.AcsClient(access_key, secret_key, region)
        elif "--ram-role" in options:
            ram_role = options["--ram-role"]
            role = EcsRamRoleCredential(ram_role)
            conn = client.AcsClient(region_id=region, credential=role)
        else:
            fail_usage(
                "Failed: User credentials are not set. Please set the Access Key and the Secret Key, or configure the RAM role."
            )

        # Use intranet endpoint to access ECS service
        try:
            region_provider.modify_point('Ecs', region,
                                         'ecs.%s.aliyuncs.com' % region)
        except Exception as e:
            logging.warn(
                "Failed: failed to modify endpoint to 'ecs.%s.aliyuncs.com': %s"
                % (region, e))

    # Operate the fencing device
    result = fence_action(conn, options, set_power_status, get_power_status,
                          get_nodes_list)
    sys.exit(result)
コード例 #23
0
ファイル: fence_raritan.py プロジェクト: beekhof/fence-agents
def main():
	device_opt = ["ipaddr", "login", "passwd", "port", "telnet"]

	atexit.register(atexit_handler)

	opt = process_input(device_opt)

	all_opt["ipport"]["default"] = "23"

	opt["eol"] = "\r\n"
	options = check_input(device_opt, opt)

	docs = {}
	docs["shortdesc"] = "I/O Fencing agent for Raritan Dominion PX"
	docs["longdesc"] = "fence_raritan is an I/O Fencing agent which can be \
used with the Raritan DPXS12-20 Power Distribution Unit. It logs into \
device via telnet and reboots a specified outlet. Lengthy telnet connections \
should be avoided while a GFS cluster is running because the connection will \
block any necessary fencing actions."
	docs["vendorurl"] = "http://www.raritan.com/"
	show_docs(options, docs)

	#  add support also for delay before login which is very useful for 2-node clusters
	run_delay(options)

	##
	## Operate the fencing device
	## We can not use fence_login(), username and passwd are sent on one line
	####
	try:
		conn = fspawn(options, options["--telnet-path"])
		conn.send("set binary\n")
		conn.send("open %s -%s\n"%(options["--ip"], options["--ipport"]))
		conn.read_nonblocking(size=100, timeout=int(options["--shell-timeout"]))
		conn.log_expect("Login.*", int(options["--shell-timeout"]))
		conn.send_eol("%s" % (options["--username"]))
		conn.log_expect("Password.*", int(options["--shell-timeout"]))
		conn.send_eol("%s" % (options["--password"]))
		conn.log_expect("clp.*", int(options["--shell-timeout"]))
	except pexpect.EOF:
		fail(EC_LOGIN_DENIED)
	except pexpect.TIMEOUT:
		fail(EC_LOGIN_DENIED)

	result = 0
	if options["--action"] != "monitor":
		result = fence_action(conn, options, set_power_status, get_power_status)

	fence_logout(conn, "exit\n")
	sys.exit(result)
コード例 #24
0
ファイル: fence_evacuate.py プロジェクト: Klaas-/fence-agents
def main():
    atexit.register(atexit_handler)

    device_opt = [
        "login", "passwd", "tenant_name", "auth_url", "no_login",
        "no_password", "port", "domain", "no_shared_storage", "endpoint_type",
        "instance_filtering", "insecure", "region_name"
    ]
    define_new_opts()
    all_opt["shell_timeout"]["default"] = "180"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs[
        "shortdesc"] = "Fence agent for the automatic resurrection of OpenStack compute instances"
    docs["longdesc"] = "Used to reschedule flagged instances"
    docs["vendorurl"] = ""

    show_docs(options, docs)

    run_delay(options)

    connection = create_nova_connection(options)

    # Un-evacuating a server doesn't make sense
    if options["--action"] in ["on"]:
        logging.error("Action %s is not supported by this agent" %
                      (options["--action"]))
        sys.exit(1)

    if options["--action"] in ["off", "reboot"]:
        status = get_power_status(connection, options)
        if status != "off":
            logging.error("Cannot resurrect instances from %s in state '%s'" %
                          (options["--plug"], status))
            sys.exit(1)

        elif not _host_evacuate(connection, options):
            logging.error("Resurrection of instances from %s failed" %
                          (options["--plug"]))
            sys.exit(1)

        logging.info("Resurrection of instances from %s complete" %
                     (options["--plug"]))
        sys.exit(0)

    result = fence_action(connection, options, set_power_status,
                          get_power_status, get_plugs_list, None)
    sys.exit(result)
コード例 #25
0
ファイル: fence_aws.py プロジェクト: johngidt/fence-agents
def main():
    conn = None

    device_opt = ["port", "no_password", "region", "access_key", "secret_key"]

    atexit.register(atexit_handler)

    define_new_opts()

    all_opt["power_timeout"]["default"] = "60"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for AWS (Amazon Web Services)"
    docs["longdesc"] = "fence_aws is an I/O Fencing agent for AWS (Amazon Web\
Services). It uses the boto3 library to connect to AWS.\
\n.P\n\
boto3 can be configured with AWS CLI or by creating ~/.aws/credentials.\n\
For instructions see: https://boto3.readthedocs.io/en/latest/guide/quickstart.html#configuration"

    docs["vendorurl"] = "http://www.amazon.com"
    show_docs(options, docs)

    run_delay(options)

    if "--region" in options and "--access-key" in options and "--secret-key" in options:
        region = options["--region"]
        access_key = options["--access-key"]
        secret_key = options["--secret-key"]
        try:
            conn = boto3.resource('ec2',
                                  region_name=region,
                                  aws_access_key_id=access_key,
                                  aws_secret_access_key=secret_key)
        except Exception as e:
            fail_usage("Failed: Unable to connect to AWS: " + str(e))
    else:
        # If setup with "aws configure" or manually in
        # ~/.aws/credentials
        try:
            conn = boto3.resource('ec2')
        except Exception as e:
            # If any of region/access/secret are missing
            fail_usage("Failed: Unable to connect to AWS: " + str(e))

    # Operate the fencing device
    result = fence_action(conn, options, set_power_status, get_power_status,
                          get_nodes_list)
    sys.exit(result)
コード例 #26
0
ファイル: fence_raritan.py プロジェクト: xtavras/fence-agents
def main():
	device_opt = ["ipaddr", "login", "passwd", "port", "telnet"]

	atexit.register(atexit_handler)

	opt = process_input(device_opt)

	all_opt["ipport"]["default"] = "23"

	opt["eol"] = "\r\n"
	options = check_input(device_opt, opt)

	docs = {}
	docs["shortdesc"] = "I/O Fencing agent for Raritan Dominion PX"
	docs["longdesc"] = "fence_raritan is an I/O Fencing agent which can be \
used with the Raritan DPXS12-20 Power Distribution Unit. It logs into \
device via telnet and reboots a specified outlet. Lengthy telnet connections \
should be avoided while a GFS cluster is running because the connection will \
block any necessary fencing actions."
	docs["vendorurl"] = "http://www.raritan.com/"
	show_docs(options, docs)

	#  add support also for delay before login which is very useful for 2-node clusters
	run_delay(options)

	##
	## Operate the fencing device
	## We can not use fence_login(), username and passwd are sent on one line
	####
	try:
		conn = fspawn(options, options["--telnet-path"])
		conn.send("set binary\n")
		conn.send("open %s -%s\n"%(options["--ip"], options["--ipport"]))
		conn.read_nonblocking(size=100, timeout=int(options["--shell-timeout"]))
		conn.log_expect("Login.*", int(options["--shell-timeout"]))
		conn.send_eol("%s" % (options["--username"]))
		conn.log_expect("Password.*", int(options["--shell-timeout"]))
		conn.send_eol("%s" % (options["--password"]))
		conn.log_expect("clp.*", int(options["--shell-timeout"]))
	except pexpect.EOF:
		fail(EC_LOGIN_DENIED)
	except pexpect.TIMEOUT:
		fail(EC_LOGIN_DENIED)

	result = 0
	if options["--action"] != "monitor":
		result = fence_action(conn, options, set_power_status, get_power_status)

	fence_logout(conn, "exit\n")
	sys.exit(result)
コード例 #27
0
def main():
    atexit.register(atexit_handler)

    all_opt["node_name"] = {
        "getopt": "N:",
        "longopt": "nodename",
        "help": "-N, --nodename                 "
        "Node on which machine is located",
        "required": "0",
        "shortdesc": "Node on which machine is located. "
        "(Optional, will be automatically determined)",
        "order": 2
    }

    device_opt = ["ipaddr", "login", "passwd", "web", "port", "node_name"]

    all_opt["login"]["required"] = "0"
    all_opt["login"]["default"] = "root@pam"
    all_opt["ipport"]["default"] = "8006"
    all_opt["port"]["shortdesc"] = "Id of the virtual machine."
    all_opt["ipaddr"]["shortdesc"] = "IP Address or Hostname of a node " +\
     "within the Proxmox cluster."

    options = check_input(device_opt, process_input(device_opt))
    docs = {}
    docs["shortdesc"] = "Fencing agent for the Proxmox Virtual Environment"
    docs["longdesc"] = "The fence_pve agent can be used to fence virtual \
machines acting as nodes in a virtualized cluster."

    docs["vendorurl"] = "http://www.proxmox.com/"

    show_docs(options, docs)

    run_delay(options)

    if "--nodename" not in options or not options["--nodename"]:
        options["--nodename"] = None

    options["url"] = "https://" + options["--ip"] + ":" + str(
        options["--ipport"]) + "/api2/json/"

    options["auth"] = get_ticket(options)
    if options["auth"] is None:
        fail(EC_LOGIN_DENIED)

    result = fence_action(None, options, set_power_status, get_power_status,
                          get_outlet_list)

    sys.exit(result)
コード例 #28
0
def main():
	global override_status
	atexit.register(atexit_handler)

	device_opt = ["login", "passwd", "tenant-name", "auth-url", "fabric_fencing", "on_target",
		"no_login", "no_password", "port", "domain", "no-shared-storage", "endpoint-type",
		"record-only", "instance-filtering", "insecure", "region-name"]
	define_new_opts()
	all_opt["shell_timeout"]["default"] = "180"

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for the automatic resurrection of OpenStack compute instances"
	docs["longdesc"] = "Used to tell Nova that compute nodes are down and to reschedule flagged instances"
	docs["vendorurl"] = ""

	show_docs(options, docs)

	if options["--record-only"] in [ "2", "Disabled", "disabled" ]:
		sys.exit(0)

	run_delay(options)

	create_nova_connection(options)

	fix_plug_name(options)
	if options["--record-only"] in [ "1", "True", "true", "Yes", "yes"]:
		if options["--action"] == "on":
			set_attrd_status(options["--plug"], "no", options)
			sys.exit(0)

		elif options["--action"] in ["off", "reboot"]:
			set_attrd_status(options["--plug"], "yes", options)
			sys.exit(0)

		elif options["--action"] in ["monitor", "status"]:
			sys.exit(0)

	if options["--action"] in ["off", "reboot"]:
		# Pretend we're 'on' so that the fencing library will always call set_power_status(off)
		override_status = "on"

	if options["--action"] == "on":
		# Pretend we're 'off' so that the fencing library will always call set_power_status(on)
		override_status = "off"

	result = fence_action(None, options, set_power_status, get_power_status, get_plugs_list, None)
	sys.exit(result)
コード例 #29
0
ファイル: fence_redfish.py プロジェクト: s-sys/fence-agents
def main():
    atexit.register(atexit_handler)
    device_opt = [
        "ipaddr", "login", "passwd", "redfish-uri", "systems-uri", "ssl",
        "diag"
    ]
    define_new_opts()

    opt = process_input(device_opt)

    all_opt["ssl"]["default"] = "1"
    options = check_input(device_opt, opt)

    docs = {}
    docs["shortdesc"] = "I/O Fencing agent for Redfish"
    docs[
        "longdesc"] = "fence_redfish is an I/O Fencing agent which can be used with \
Out-of-Band controllers that support Redfish APIs. These controllers provide remote \
access to control power on a server."

    docs["vendorurl"] = "http://www.dmtf.org"
    show_docs(options, docs)
    run_delay(options)

    ##
    ## Operate the fencing device
    ####

    # Disable insecure-certificate-warning message
    if "--ssl-insecure" in opt:
        import urllib3
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    # backwards compatibility for <ip>:<port>
    if options["--ip"].count(":") == 1:
        (options["--ip"], options["--ipport"]) = options["--ip"].split(":")

    if "--systems-uri" not in opt:
        # Systems URI not provided, find it
        sysresult = find_systems_resource(options)
        if sysresult['ret'] is False:
            sys.exit(1)
        else:
            options["--systems-uri"] = sysresult["uri"]

    result = fence_action(None, options, set_power_status, get_power_status,
                          None)
    sys.exit(result)
コード例 #30
0
ファイル: fence_zvmip.py プロジェクト: mmartinv/fence-agents
def main():
    device_opt = [
        "ipaddr", "login", "passwd", "port", "method", "missing_as_off",
        "inet4_only", "inet6_only", "ssl"
    ]

    atexit.register(atexit_handler)

    all_opt["ipport"]["default"] = "44444"
    all_opt["shell_timeout"]["default"] = "5"
    all_opt["missing_as_off"]["default"] = "1"
    all_opt["ssl"]["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_CHARACTERISTICS

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)
コード例 #31
0
ファイル: fence_aws.py プロジェクト: beekhof/fence-agents
def main():
	conn = None

	device_opt = ["port", "no_password", "region", "access_key", "secret_key"]

	atexit.register(atexit_handler)

	define_new_opts()

	all_opt["power_timeout"]["default"] = "60"

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for AWS (Amazon Web Services)"
	docs["longdesc"] = "fence_aws is an I/O Fencing agent for AWS (Amazon Web\
Services). It uses the boto3 library to connect to AWS.\
\n.P\n\
boto3 can be configured with AWS CLI or by creating ~/.aws/credentials.\n\
For instructions see: https://boto3.readthedocs.io/en/latest/guide/quickstart.html#configuration"
	docs["vendorurl"] = "http://www.amazon.com"
	show_docs(options, docs)

	run_delay(options)

	if "--region" in options and "--access-key" in options and "--secret-key" in options:  
		region = options["--region"]
		access_key = options["--access-key"]
		secret_key = options["--secret-key"]
		try:
			conn = boto3.resource('ec2', region_name=region,
					      aws_access_key_id=access_key,
					      aws_secret_access_key=secret_key)
		except:
			fail_usage("Failed: Unable to connect to AWS. Check your configuration.")
	else:
		# If setup with "aws configure" or manually in
		# ~/.aws/credentials
		try:
			conn = boto3.resource('ec2')
		except:
			# If any of region/access/secret are missing
			fail_usage("Failed: Unable to connect to AWS. Check your configuration.")

	# Operate the fencing device
	result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list)
	sys.exit(result)
コード例 #32
0
def main():
    device_opt = [
        "token",
        "crn",
        "instance",
        "region",
        "api-type",
        "proxy",
        "port",
        "no_password",
    ]

    atexit.register(atexit_handler)
    define_new_opts()

    all_opt["shell_timeout"]["default"] = "15"
    all_opt["power_timeout"]["default"] = "30"
    all_opt["power_wait"]["default"] = "1"
    all_opt["stonith_status_sleep"]["default"] = "3"
    all_opt["api-type"]["default"] = "private"
    all_opt["proxy"]["default"] = ""

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for IBM PowerVS"
    docs[
        "longdesc"] = """fence_ibm_powervs is an I/O Fencing agent which can be \
used with IBM PowerVS to fence virtual machines."""
    docs["vendorurl"] = "https://www.ibm.com"
    show_docs(options, docs)

    ####
    ## Fence operations
    ####
    run_delay(options)

    auth_conn = auth_connect(options)
    token = get_token(auth_conn, options)
    disconnect(auth_conn)
    conn = connect(options, token)
    atexit.register(disconnect, conn)

    result = fence_action(conn, options, set_power_status, get_power_status,
                          get_list)

    sys.exit(result)
コード例 #33
0
ファイル: fence_compute.py プロジェクト: Klaas-/fence-agents
def main():
	global override_status
	atexit.register(atexit_handler)

	device_opt = ["login", "passwd", "tenant_name", "auth_url", "fabric_fencing",
		"no_login", "no_password", "port", "domain", "no_shared_storage", "endpoint_type",
		"record_only", "instance_filtering", "insecure", "region_name"]
	define_new_opts()
	all_opt["shell_timeout"]["default"] = "180"

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for the automatic resurrection of OpenStack compute instances"
	docs["longdesc"] = "Used to tell Nova that compute nodes are down and to reschedule flagged instances"
	docs["vendorurl"] = ""

	show_docs(options, docs)

	if options["--record-only"] in [ "2", "Disabled", "disabled" ]:
		sys.exit(0)

	run_delay(options)

	logging.debug("Running "+options["--action"])
	connection = create_nova_connection(options)

	if options["--action"] in ["off", "on", "reboot", "status"]:
		fix_plug_name(connection, options)


	if options["--action"] in ["reboot"]:
		options["--action"]="off"

	if options["--action"] in ["off", "on"]:
		# No status first, call our own version
		result = not set_multi_power_fn(connection, options, set_power_status, get_power_status_simple,
						1 + int(options["--retry-on"]))
	elif options["--action"] in ["monitor"]:
		result = 0
	else:
		result = fence_action(connection, options, set_power_status, get_power_status_simple, get_plugs_list, None)

	logging.debug("Result for "+options["--action"]+": "+repr(result))
	if result == None:
		result = 0
	sys.exit(result)
コード例 #34
0
ファイル: fence_netio.py プロジェクト: xtavras/fence-agents
def main():
    device_opt = ["ipaddr", "login", "passwd", "port", "telnet"]

    atexit.register(atexit_handler)

    all_opt["ipport"]["default"] = "1234"

    opt = process_input(device_opt)
    opt["eol"] = "\r\n"
    options = check_input(device_opt, opt)

    docs = {}
    docs["shortdesc"] = "I/O Fencing agent for Koukaam NETIO-230B"
    docs["longdesc"] = "fence_netio is an I/O Fencing agent which can be \
used with the Koukaam NETIO-230B Power Distribution Unit. It logs into \
device via telnet and reboots a specified outlet. Lengthy telnet connections \
should be avoided while a GFS cluster is running because the connection will \
block any necessary fencing actions."

    docs["vendorurl"] = "http://www.koukaam.se/"
    show_docs(options, docs)

    ##
    ## Operate the fencing device
    ## We can not use fence_login(), username and passwd are sent on one line
    ####
    run_delay(options)
    try:
        conn = fspawn(options, options["--telnet-path"])
        conn.send("set binary\n")
        conn.send("open %s -%s\n" % (options["--ip"], options["--ipport"]))

        conn.read_nonblocking(size=100,
                              timeout=int(options["--shell-timeout"]))
        conn.log_expect("100 HELLO .*", int(options["--shell-timeout"]))
        conn.send_eol("login %s %s" %
                      (options["--username"], options["--password"]))
        conn.log_expect("250 OK", int(options["--shell-timeout"]))
    except pexpect.EOF:
        fail(EC_LOGIN_DENIED)
    except pexpect.TIMEOUT:
        fail(EC_LOGIN_DENIED)

    result = fence_action(conn, options, set_power_status, get_power_status,
                          get_outlet_list)
    fence_logout(conn, "quit\n")
    sys.exit(result)
コード例 #35
0
ファイル: fence_openstack.py プロジェクト: vbp1/fence-agents
def main():
    atexit.register(atexit_handler)

    device_opt = [
        "login", "passwd", "auth-url", "project-name", "user-domain-name",
        "project-domain-name", "port", "no_port", "uuid"
    ]
    define_new_opts()

    all_opt["port"]["required"] = "0"
    all_opt["port"][
        "help"] = "-n, --plug=[UUID]              UUID of the node to be fenced"
    all_opt["port"]["shortdesc"] = "UUID of the node to be fenced."

    options = check_input(device_opt, process_input(device_opt))

    # hack to remove list/list-status actions which are not supported
    options["device_opt"] = [
        o for o in options["device_opt"] if o != "separator"
    ]

    # workaround to avoid regressions
    if "--uuid" in options:
        options["--plug"] = options["--uuid"]
        del options["--uuid"]
    elif "--help" not in options and options["--action"] in ["off", "on", \
         "reboot", "status", "validate-all"] and "--plug" not in options:
        stop_after_error = False if options[
            "--action"] == "validate-all" else True
        fail_usage(
            "Failed: You have to enter plug number or machine identification",
            stop_after_error)

    docs = {}
    docs["shortdesc"] = "Fence agent for OpenStack's Nova service"
    docs["longdesc"] = "fence_openstack is a Fencing agent \
which can be used with machines controlled by the Openstack's Nova service. \
This agent calls the python-novaclient and it is mandatory to be installed "

    docs["vendorurl"] = "https://wiki.openstack.org/wiki/Nova"
    show_docs(options, docs)

    run_delay(options)

    result = fence_action(None, options, set_power_status, get_power_status,
                          None)
    sys.exit(result)
コード例 #36
0
ファイル: fence_compute.py プロジェクト: beekhof/fence-agents
def main():
	global override_status
	atexit.register(atexit_handler)

	device_opt = ["login", "passwd", "tenant_name", "auth_url", "fabric_fencing",
		      "no_login", "no_password", "port", "compute-domain", "project-domain", "user-domain",
		      "no_shared_storage", "endpoint_type", "record_only", "instance_filtering", "insecure", "region_name"]
	define_new_opts()
	all_opt["shell_timeout"]["default"] = "180"

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for the automatic resurrection of OpenStack compute instances"
	docs["longdesc"] = "Used to tell Nova that compute nodes are down and to reschedule flagged instances"
	docs["vendorurl"] = ""

	show_docs(options, docs)

	if options["--record-only"] in [ "2", "Disabled", "disabled" ]:
		sys.exit(0)

	run_delay(options)

	logging.debug("Running "+options["--action"])
	connection = create_nova_connection(options)

	if options["--action"] in ["off", "on", "reboot", "status"]:
		fix_plug_name(connection, options)


	if options["--action"] in ["reboot"]:
		options["--action"]="off"

	if options["--action"] in ["off", "on"]:
		# No status first, call our own version
		result = not set_multi_power_fn(connection, options, set_power_status, get_power_status_simple,
						1 + int(options["--retry-on"]))
	elif options["--action"] in ["monitor"]:
		result = 0
	else:
		result = fence_action(connection, options, set_power_status, get_power_status_simple, get_plugs_list, None)

	logging.debug("Result for "+options["--action"]+": "+repr(result))
	if result == None:
		result = 0
	sys.exit(result)
コード例 #37
0
ファイル: fence_pve.py プロジェクト: johnruemker/fence-agents
def main():
	atexit.register(atexit_handler)

	all_opt["node_name"] = {
		"getopt" : "N:",
		"longopt" : "nodename",
		"help" : "-N, --nodename                 "
			"Node on which machine is located",
		"required" : "0",
		"shortdesc" : "Node on which machine is located. "
			"(Optional, will be automatically determined)",
		"order": 2
	}

	device_opt = ["ipaddr", "login", "passwd", "web", "port", "node_name"]

	all_opt["login"]["required"] = "0"
	all_opt["login"]["default"] = "root@pam"
	all_opt["ipport"]["default"] = "8006"
	all_opt["port"]["shortdesc"] = "Id of the virtual machine."
	all_opt["ipaddr"]["shortdesc"] = "IP Address or Hostname of a node " +\
		"within the Proxmox cluster."

	options = check_input(device_opt, process_input(device_opt))
	docs = {}
	docs["shortdesc"] = "Fencing agent for the Proxmox Virtual Environment"
	docs["longdesc"] = "The fence_pve agent can be used to fence virtual \
machines acting as nodes in a virtualized cluster."
	docs["vendorurl"] = "http://www.proxmox.com/"

	show_docs(options, docs)

	run_delay(options)

	if "--nodename" not in options or not options["--nodename"]:
		options["--nodename"] = None

	options["url"] = "https://" + options["--ip"] + ":" + str(options["--ipport"]) + "/api2/json/"

	options["auth"] = get_ticket(options)
	if options["auth"] is None:
		fail(EC_LOGIN_DENIED)

	result = fence_action(None, options, set_power_status, get_power_status, get_outlet_list)

	sys.exit(result)
コード例 #38
0
def main():
	device_opt = ["ipaddr", "login", "passwd", "port"]

	atexit.register(atexit_handler)

	opt = process_input(device_opt)

	# set default port for telnet only
	if not opt.has_key("--ipport"):
		opt["--ipport"] = "1234"

	opt["eol"] = "\r\n"
	options = check_input(device_opt, opt)

	docs = {}
	docs["shortdesc"] = "I/O Fencing agent for Koukaam NETIO-230B"
	docs["longdesc"] = "fence_netio is an I/O Fencing agent which can be \
used with the Koukaam NETIO-230B Power Distribution Unit. It logs into \
device via telnet and reboots a specified outlet. Lengthy telnet connections \
should be avoided while a GFS cluster is running because the connection will \
block any necessary fencing actions."
	docs["vendorurl"] = "http://www.koukaam.se/"
	show_docs(options, docs)

	##
	## Operate the fencing device
	## We can not use fence_login(), username and passwd are sent on one line
	####
	run_delay(options)
	try:
		conn = fspawn(options, TELNET_PATH)
		conn.send("set binary\n")
		conn.send("open %s -%s\n"%(options["--ip"], options["--ipport"]))

		conn.read_nonblocking(size=100, timeout=int(options["--shell-timeout"]))
		conn.log_expect(options, "100 HELLO .*", int(options["--shell-timeout"]))
		conn.send_eol("login %s %s" % (options["--username"], options["--password"]))
		conn.log_expect(options, "250 OK", int(options["--shell-timeout"]))
	except pexpect.EOF:
		fail(EC_LOGIN_DENIED)
	except pexpect.TIMEOUT:
		fail(EC_LOGIN_DENIED)

	result = fence_action(conn, options, set_power_status, get_power_status, get_outlet_list)
	fence_logout(conn, "quit\n")
	sys.exit(result)
コード例 #39
0
def main():
    device_opt = [
        "ipaddr",
        "api_path",
        "login",
        "passwd",
        "ssl",
        "notls",
        "web",
        "port",
        "filter",
    ]

    atexit.register(atexit_handler)
    define_new_opts()

    all_opt["shell_timeout"]["default"] = "5"
    all_opt["power_wait"]["default"] = "1"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for VMware REST API"
    docs[
        "longdesc"] = """fence_vmware_rest is an I/O Fencing agent which can be \
used with VMware API to fence virtual machines.

NOTE: If there's more than 1000 VMs there is a filter parameter to work around \
the API limit. See https://code.vmware.com/apis/62/vcenter-management#/VM%20/get_vcenter_vm \
for full list of filters."""
    docs["vendorurl"] = "https://www.vmware.com"
    show_docs(options, docs)

    ####
    ## Fence operations
    ####
    run_delay(options)

    conn = connect(options)
    atexit.register(disconnect, conn)

    result = fence_action(conn, options, set_power_status, get_power_status,
                          get_list)

    sys.exit(result)
コード例 #40
0
def main():
    conn = None

    device_opt = [
        "port", "namespace", "kubeconfig", "ssl_insecure", "no_password",
        "apiversion"
    ]

    atexit.register(atexit_handler)
    define_new_opts()

    all_opt["power_timeout"]["default"] = "40"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for KubeVirt"
    docs["longdesc"] = "fence_kubevirt is an I/O Fencing agent for KubeVirt."
    docs["vendorurl"] = "https://kubevirt.io/"
    show_docs(options, docs)

    run_delay(options)

    validate_options(['--namespace'], options)

    # Disable insecure-certificate-warning message
    if "--ssl-insecure" in options:
        import urllib3
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    try:
        from kubernetes import config
        from openshift.dynamic import DynamicClient
        kubeconfig = options.get('--kubeconfig')
        k8s_client = config.new_client_from_config(config_file=kubeconfig)
        conn = DynamicClient(k8s_client)
    except ImportError:
        logging.error(
            "Couldn\'t import kubernetes.config or "
            "openshift.dynamic.DynamicClient - not found or not accessible")

    # Operate the fencing device
    result = fence_action(conn, options, set_power_status, get_power_status,
                          get_nodes_list)
    sys.exit(result)
コード例 #41
0
def main():
    device_opt = [
        "no_status", "no_password", "ping_count", "ping_good_count",
        "ping_interval", "ping_timeout", "ping_maxfail", "ping_targets",
        "method"
    ]
    define_new_opts()
    atexit.register(atexit_handler)

    all_opt["method"]["default"] = "cycle"
    all_opt["method"][
        "help"] = "-m, --method=[method]          Method to fence (cycle|onoff) (Default: cycle)"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for ping-heuristic based fencing"
    docs[
        "longdesc"] = "fence_heuristics_ping uses ping-heuristics to control execution of another fence agent on the same fencing level.\
\n.P\n\
This is not a fence agent by itself! \
Its only purpose is to enable/disable another fence agent that lives on the same fencing level but after fence_heuristics_ping."

    docs["vendorurl"] = ""
    show_docs(options, docs)

    # move ping-test to the end of the time-window set via --delay
    # as to give the network time to settle after the incident that has
    # caused fencing and have the results as current as possible
    max_pingcheck = (int(options["--ping-count"]) - 1) * \
     int(options["--ping-interval"]) + int(options["--ping-timeout"])
    run_delay(options, reserve=max_pingcheck)

    result = fence_action(\
       None, \
       options, \
       None, \
       None, \
       reboot_cycle_fn = ping_test,
       sync_set_power_fn = ping_test)

    # execute the remaining delay
    run_delay(options, result=result)
    sys.exit(result)
コード例 #42
0
def main():
    global cookie, proto, ssl_verify
    define_new_opts()
    device_opt = [
        "ipaddr", "login", "passwd", "port", "web", "ssl", "verbose",
        "graceful", "force"
    ]

    atexit.register(atexit_handler)
    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Skala-R Fence agent"
    docs["longdesc"] = "A fence agent for Skala-R."
    docs["vendorurl"] = "https://www.skala-r.ru/"
    show_docs(options, docs)
    options["eol"] = "\r"

    run_delay(options)

    proto = "https://"
    if "--ssl-secure" in options:
        ssl_verify = True
    elif "--ssl-insecure" in options:
        ssl_verify = False
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    else:
        proto = "http://"
        ssl_verify = False
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    cookie = authorize_and_get_cookie(options["--ip"], options["--username"],
                                      options["--password"], options)
    atexit.register(logout, options["--ip"])

    logging.debug("OPTIONS: " + str(options) + "\n")

    try:
        result = fence_action(None, options, set_power_status,
                              get_power_status, get_list)
        sys.exit(result)
    except Exception:
        logging.exception('Exception occured.')
        fail(EC_STATUS)
コード例 #43
0
def soap_login(options):
	run_delay(options)

	if "--ssl" in options or "--ssl-secure" in options or "--ssl-insecure" in options:
		if "--ssl-insecure" in options:
			import ssl
			from requests.packages.urllib3.exceptions import InsecureRequestWarning
			if hasattr(ssl, '_create_unverified_context'):
				ssl._create_default_https_context = ssl._create_unverified_context
			requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
			verify = False
		else:
			verify = True
		url = "https://"
	else:
		verify = False
		url = "http://"

	url += options["--ip"] + ":" + str(options["--ipport"]) + "/sdk"

	tmp_dir = tempfile.mkdtemp()
	tempfile.tempdir = tmp_dir
	atexit.register(remove_tmp_dir, tmp_dir)

	try:
		headers = {"Content-Type" : "text/xml;charset=UTF-8", "SOAPAction" : ""}
		conn = Client(url + "/vimService.wsdl", location=url, transport=RequestsTransport(verify=verify), headers=headers)

		mo_ServiceInstance = Property('ServiceInstance')
		mo_ServiceInstance._type = 'ServiceInstance'
		ServiceContent = conn.service.RetrieveServiceContent(mo_ServiceInstance)
		mo_SessionManager = Property(ServiceContent.sessionManager.value)
		mo_SessionManager._type = 'SessionManager'

		conn.service.Login(mo_SessionManager, options["--username"], options["--password"])
	except requests.exceptions.SSLError as ex:
		fail_usage("Server side certificate verification failed")
	except Exception:
		fail(EC_LOGIN_DENIED)

	options["ServiceContent"] = ServiceContent
	options["mo_SessionManager"] = mo_SessionManager
	return conn
コード例 #44
0
def main():
	device_opt = [
		'ipaddr',
		'no_password',
		'no_login',
		'powerman_path',
	]

	atexit.register(atexit_handler)

	define_new_opts()

	# redefine default values for the options given by fencing.py
	# these 3 different values are derived from the lssd test cluster and may
	# need to adjusted depending on how other systems fare
	all_opt['ipport']['default'] = '10101'
	all_opt['delay']['default'] = '3'
	all_opt['power_wait']['default'] = '3'

	options = check_input(device_opt, process_input(device_opt))
	docs = {}
	docs["shortdesc"] = "Fence Agent for Powerman"
	docs["longdesc"] = "This is a Pacemaker Fence Agent for the \
Powerman management utility that was designed for LLNL systems."
	docs["vendorurl"] = "https://github.com/chaos/powerman"
	show_docs(options, docs)

	run_delay(options)

	if not is_executable(options["--powerman-path"]):
		fail_usage("Powerman not found or not executable at path " + options["--powerman-path"])

	# call the fencing.fence_action function, passing in my various fence functions
	# def fence_action(connection, options, set_power_fn, get_power_fn, get_outlet_list=None, reboot_cycle_fn=None)
	result = fence_action(
				None,
				options,
				set_power_status,
				get_power_status,
				get_list,
				None
			)
	sys.exit(result)
コード例 #45
0
def main():
	atexit.register(atexit_handler)

	device_opt = ["login", "passwd", "tenant_name", "auth_url",
		      "no_login", "no_password", "port", "compute-domain", "project-domain",
		      "user-domain", "no_shared_storage", "endpoint_type",
		      "instance_filtering", "insecure", "region_name"]
	define_new_opts()
	all_opt["shell_timeout"]["default"] = "180"

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for the automatic resurrection of OpenStack compute instances"
	docs["longdesc"] = "Used to reschedule flagged instances"
	docs["vendorurl"] = ""

	show_docs(options, docs)

	run_delay(options)

	connection = create_nova_connection(options)

	# Un-evacuating a server doesn't make sense
	if options["--action"] in ["on"]:
		logging.error("Action %s is not supported by this agent" % (options["--action"]))
		sys.exit(1)

	if options["--action"] in ["off", "reboot"]:
		status = get_power_status(connection, options)
		if status != "off":
			logging.error("Cannot resurrect instances from %s in state '%s'" % (options["--plug"], status))
			sys.exit(1)

		elif not _host_evacuate(connection, options):
			logging.error("Resurrection of instances from %s failed" % (options["--plug"]))
			sys.exit(1)

		logging.info("Resurrection of instances from %s complete" % (options["--plug"]))
		sys.exit(0)

	result = fence_action(connection, options, set_power_status, get_power_status, get_plugs_list, None)
	sys.exit(result)
コード例 #46
0
def main():
	device_opt = [
		'ipaddr',
		'no_password',
		'no_login',
		'powerman_path',
	]

	atexit.register(atexit_handler)

	define_new_opts()

	# redefine default values for the options given by fencing.py
	# these 3 different values are derived from the lssd test cluster and may
	# need to adjusted depending on how other systems fare
	all_opt['ipport']['default'] = '10101'
	all_opt['delay']['default'] = '3'
	all_opt['power_wait']['default'] = '3'

	options = check_input(device_opt, process_input(device_opt))
	docs = {}
	docs["shortdesc"] = "Fence Agent for Powerman"
	docs["longdesc"] = "This is a Pacemaker Fence Agent for the \
Powerman management utility that was designed for LLNL systems."
	docs["vendorurl"] = "https://github.com/chaos/powerman"
	show_docs(options, docs)

	run_delay(options)

	if not is_executable(options["--powerman-path"]):
		fail_usage("Powerman not found or not executable at path " + options["--powerman-path"])

	# call the fencing.fence_action function, passing in my various fence functions
	result = fence_action(
				None,
				options,
				set_power_status,
				get_power_status,
				get_list,
				None
			)
	sys.exit(result)
コード例 #47
0
ファイル: fence_compute.py プロジェクト: rtheys/fence-agents
def main():
	global override_status
	global nova
	atexit.register(atexit_handler)

	device_opt = ["login", "passwd", "tenant-name", "auth-url",
		"novatool-path", "no_login", "no_password", "port", "domain", "no-shared-storage"]
	define_new_opts()
	all_opt["shell_timeout"]["default"] = "180"

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for nova compute nodes"
	docs["longdesc"] = "fence_nova_host is a Nova fencing notification agent"
	docs["vendorurl"] = ""

	show_docs(options, docs)

	run_delay(options)

	# The first argument is the Nova client version
	nova = nova_client.Client('2',
		options["--username"],
		options["--password"],
		options["--tenant-name"],
		options["--auth-url"])

	if options["--action"] in ["off", "reboot"]:
		# Pretend we're 'on' so that the fencing library will always call set_power_status(off)
		override_status = "on"

	if options["--action"] == "on":
		# Pretend we're 'off' so that the fencing library will always call set_power_status(on)
		override_status = "off"

	# Potentially we should make this a pacemaker feature
	if options["--action"] != "list" and options["--domain"] != "" and options.has_key("--plug"):
		options["--plug"] = options["--plug"]+"."+options["--domain"]

	result = fence_action(None, options, set_power_status, get_power_status, get_plugs_list, None)
	sys.exit(result)
コード例 #48
0
def main():
    compute_client = None

    device_opt = [
        "resourceGroup", "login", "passwd", "tenantId", "subscriptionId",
        "port"
    ]

    atexit.register(atexit_handler)

    define_new_opts()
    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for Azure Resource Manager"
    docs[
        "longdesc"] = "Used to deallocate virtual machines and to report power state of virtual machines running in Azure"
    docs["vendorurl"] = "http://www.microsoft.com"
    show_docs(options, docs)

    run_delay(options)

    try:
        from azure.common.credentials import ServicePrincipalCredentials
        from azure.mgmt.compute import ComputeManagementClient

        tenantid = options["--tenantId"]
        servicePrincipal = options["--username"]
        spPassword = options["--password"]
        subscriptionId = options["--subscriptionId"]
        credentials = ServicePrincipalCredentials(client_id=servicePrincipal,
                                                  secret=spPassword,
                                                  tenant=tenantid)
        compute_client = ComputeManagementClient(credentials, subscriptionId)
    except ImportError:
        fail_usage(
            "Azure Resource Manager Pyhton SDK not found or not accessible")

    # Operate the fencing device
    result = fence_action(compute_client, options, set_power_status,
                          get_power_status, get_nodes_list)
    sys.exit(result)
コード例 #49
0
def main():
    atexit.register(atexit_handler)

    device_opt = ["login", "passwd", "auth-url", "project-name", "user-domain-name", "project-domain-name", "uuid"]
    define_new_opts()

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for OpenStack's Nova service"
    docs["longdesc"] = "fence_openstack is a Fencing agent \
which can be used with machines controlled by the Openstack's Nova service. \
This agent calls the python-novaclient and it is mandatory to be installed "
    docs["vendorurl"] = "https://wiki.openstack.org/wiki/Nova"
    show_docs(options, docs)

    run_delay(options)

    result = fence_action(None, options, set_power_status, get_power_status,None)
    sys.exit(result)
コード例 #50
0
def main():
    conn = None

    device_opt = [
        "port", "no_password", "region", "access_key", "secret_key", "ram_role"
    ]

    atexit.register(atexit_handler)

    define_new_opts()

    all_opt["power_timeout"]["default"] = "60"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for Aliyun (Aliyun Web Services)"
    docs["longdesc"] = "fence_aliyun is an I/O Fencing agent for Aliyun"
    docs["vendorurl"] = "http://www.aliyun.com"
    show_docs(options, docs)

    run_delay(options)

    if "--region" in options:
        region = options["--region"]
        if "--access-key" in options and "--secret-key" in options:
            access_key = options["--access-key"]
            secret_key = options["--secret-key"]
            conn = client.AcsClient(access_key, secret_key, region)
        elif "--ram-role" in options:
            ram_role = options["--ram-role"]
            _check_role(ram_role)
            role = EcsRamRoleCredential(ram_role)
            conn = client.AcsClient(region_id=region, credential=role)
        region_provider.modify_point('Ecs', region,
                                     'ecs.%s.aliyuncs.com' % region)

    # Operate the fencing device
    result = fence_action(conn, options, set_power_status, get_power_status,
                          get_nodes_list)
    sys.exit(result)
コード例 #51
0
def main():
    device_opt = [
        "ipaddr",
        "api_path",
        "login",
        "passwd",
        "ssl",
        "notls",
        "web",
        "port",
    ]

    atexit.register(atexit_handler)
    define_new_opts()

    all_opt["shell_timeout"]["default"] = "5"
    all_opt["power_wait"]["default"] = "1"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for VMware REST API"
    docs[
        "longdesc"] = "fence_vmware_rest is an I/O Fencing agent which can be \
used with VMware API to fence virtual machines."

    docs["vendorurl"] = "https://www.vmware.com"
    show_docs(options, docs)

    ####
    ## Fence operations
    ####
    run_delay(options)

    conn = connect(options)
    atexit.register(disconnect, conn)

    result = fence_action(conn, options, set_power_status, get_power_status,
                          get_list)

    sys.exit(result)
コード例 #52
0
ファイル: fence_zvmip.py プロジェクト: oalbrigt/fence-agents
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

Where XXXXXXX is the name of the virtual machine used in the authuser field of the request.
"""
    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)
コード例 #53
0
ファイル: fence_azure_arm.py プロジェクト: krig/fence-agents
def main():
    compute_client = None

    device_opt = ["resourceGroup", "login", "passwd", "tenantId", "subscriptionId","port"]

    atexit.register(atexit_handler)

    define_new_opts()
    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for Azure Resource Manager"
    docs["longdesc"] = "Used to deallocate virtual machines and to report power state of virtual machines running in Azure"
    docs["vendorurl"] = "http://www.microsoft.com"
    show_docs(options, docs)

    run_delay(options)

    try:
        from azure.common.credentials import ServicePrincipalCredentials
        from azure.mgmt.compute import ComputeManagementClient

        tenantid = options["--tenantId"]
        servicePrincipal = options["--username"]
        spPassword = options["--password"]
        subscriptionId = options["--subscriptionId"]
        credentials = ServicePrincipalCredentials(
            client_id = servicePrincipal,
            secret = spPassword,
            tenant = tenantid
        )
        compute_client = ComputeManagementClient(
            credentials,
            subscriptionId
        )
    except ImportError:
        fail_usage("Azure Resource Manager Pyhton SDK not found or not accessible")

    # Operate the fencing device
    result = fence_action(compute_client, options, set_power_status, get_power_status, get_nodes_list)
    sys.exit(result)
コード例 #54
0
def main():
    device_opt = [
        "ipaddr",
        "login",
        "passwd",
        "ssl",
        "notls",
        "web",
        "port",
        "use_cookies",
        "cookie_file",
        "api_version",
        "api_path",
        "disable_http_filter",
    ]

    atexit.register(atexit_handler)
    define_new_opts()

    all_opt["power_wait"]["default"] = "1"
    all_opt["shell_timeout"]["default"] = "5"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for RHEV-M REST API"
    docs["longdesc"] = "fence_rhevm is an I/O Fencing agent which can be \
used with RHEV-M REST API to fence virtual machines."

    docs["vendorurl"] = "http://www.redhat.com"
    show_docs(options, docs)

    ##
    ## Fence operations
    ####
    run_delay(options)
    result = fence_action(None, options, set_power_status, get_power_status,
                          get_list)

    sys.exit(result)
コード例 #55
0
def main():
    atexit.register(atexit_handler)

    device_opt = ["crosscableip", "timeout", "no_password", "no_login", "port"]
    define_new_opts()

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for cross-link two-node clusters"
    docs["longdesc"] = "This agent helps two-node clusters to tackle the " \
                       "situation where one node lost power, cannot be " \
                       "fenced by telling pacemaker that if the node is not " \
                       "reachable over the crosslink cable, we can assume " \
                       "it is dead"
    docs["vendorurl"] = ""
    show_docs(options, docs)

    run_delay(options)

    result = fence_action(None, options, set_power_status, get_power_status)
    sys.exit(result)
コード例 #56
0
ファイル: fence_ipmilan.py プロジェクト: actatux/fence-agents
def main():
	atexit.register(atexit_handler)

	device_opt = ["ipaddr", "login", "no_login", "no_password", "passwd",
		"lanplus", "auth", "cipher", "privlvl", "sudo", "ipmitool_path", "method"]
	define_new_opts()

	all_opt["power_wait"]["default"] = 2
	if os.path.basename(sys.argv[0]) == "fence_ilo3":
		all_opt["power_wait"]["default"] = "4"
		all_opt["method"]["default"] = "cycle"
		all_opt["lanplus"]["default"] = "1"
	elif os.path.basename(sys.argv[0]) == "fence_ilo4":
		all_opt["lanplus"]["default"] = "1"

	all_opt["ipport"]["default"] = "623"

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for IPMI"
	docs["longdesc"] = "fence_ipmilan is an I/O Fencing agent\
which can be used with machines controlled by IPMI.\
This agent calls support software ipmitool (http://ipmitool.sf.net/)."
	docs["vendorurl"] = ""
	docs["symlink"] = [("fence_ilo3", "Fence agent for HP iLO3"),
		("fence_ilo4", "Fence agent for HP iLO4"),
		("fence_imm", "Fence agent for IBM Integrated Management Module"),
		("fence_idrac", "Fence agent for Dell iDRAC")]
	show_docs(options, docs)

	run_delay(options)

	if not is_executable(options["--ipmitool-path"]):
		fail_usage("Ipmitool not found or not accessible")

	result = fence_action(None, options, set_power_status, get_power_status, None, reboot_cycle)
	sys.exit(result)
コード例 #57
0
def soap_login(options):
    run_delay(options)

    if options.has_key("--ssl") or options.has_key(
            "--ssl-secure") or options.has_key("--ssl-insecure"):
        if options.has_key("--ssl-insecure"):
            verify = False
        else:
            verify = True
        url = "https://"
    else:
        verify = False
        url = "http://"

    url += options["--ip"] + ":" + str(options["--ipport"]) + "/sdk"

    tmp_dir = tempfile.mkdtemp()
    tempfile.tempdir = tmp_dir
    atexit.register(remove_tmp_dir, tmp_dir)

    try:
        headers = {"Content-Type": "text/xml;charset=UTF-8", "SOAPAction": ""}
        conn = Client(url + "/vimService.wsdl",
                      location=url,
                      transport=RequestsTransport(verify=verify),
                      headers=headers)

        mo_ServiceInstance = Property('ServiceInstance')
        mo_ServiceInstance._type = 'ServiceInstance'
        ServiceContent = conn.service.RetrieveServiceContent(
            mo_ServiceInstance)
        mo_SessionManager = Property(ServiceContent.sessionManager.value)
        mo_SessionManager._type = 'SessionManager'

        conn.service.Login(mo_SessionManager, options["--username"],
                           options["--password"])
    except requests.exceptions.SSLError, ex:
        fail_usage("Server side certificate verification failed")
コード例 #58
0
def main():
    device_opt = [
        "apikey",
        "instance",
        "region",
        "limit",
        "port",
        "no_password",
    ]

    atexit.register(atexit_handler)
    define_new_opts()

    all_opt["shell_timeout"]["default"] = "15"
    all_opt["power_timeout"]["default"] = "30"
    all_opt["power_wait"]["default"] = "1"

    options = check_input(device_opt, process_input(device_opt))

    docs = {}
    docs["shortdesc"] = "Fence agent for IBM Cloud VPC"
    docs["longdesc"] = """fence_ibm_vpc is an I/O Fencing agent which can be \
used with IBM Cloud VPC to fence virtual machines."""
    docs["vendorurl"] = "https://www.ibm.com"
    show_docs(options, docs)

    ####
    ## Fence operations
    ####
    run_delay(options)

    conn = connect(options)
    atexit.register(disconnect, conn)

    result = fence_action(conn, options, set_power_status, get_power_status,
                          get_list)

    sys.exit(result)
コード例 #59
0
def main():
	device_opt = [
		"ipaddr",
		"api_path",
		"login",
		"passwd",
		"ssl",
		"notls",
		"web",
		"port",
	]

	atexit.register(atexit_handler)
	define_new_opts()

	all_opt["shell_timeout"]["default"] = "5"
	all_opt["power_wait"]["default"] = "1"

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for VMware REST API"
	docs["longdesc"] = "fence_vmware_rest is an I/O Fencing agent which can be \
used with VMware API to fence virtual machines."
	docs["vendorurl"] = "https://www.vmware.com"
	show_docs(options, docs)

	####
	## Fence operations
	####
	run_delay(options)

	conn = connect(options)
	atexit.register(disconnect, conn)

	result = fence_action(conn, options, set_power_status, get_power_status, get_list)

	sys.exit(result)
コード例 #60
0
ファイル: fence_gce.py プロジェクト: cymen/fence-agents
def main():
	conn = None

	device_opt = ["port", "no_password", "zone", "project"]

	atexit.register(atexit_handler)

	define_new_opts()

	all_opt["power_timeout"]["default"] = "60"

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for GCE (Google Cloud Engine)"
	docs["longdesc"] = "fence_gce is an I/O Fencing agent for GCE (Google Cloud " \
			   "Engine). It uses the googleapiclient library to connect to GCE.\n" \
			   "googleapiclient can be configured with Google SDK CLI or by " \
			   "executing 'gcloud auth application-default login'.\n" \
			   "For instructions see: https://cloud.google.com/compute/docs/tutorials/python-guide"
	docs["vendorurl"] = "http://cloud.google.com"
	show_docs(options, docs)

	run_delay(options)

	try:
		credentials = None
		if tuple(googleapiclient.__version__) < tuple("1.6.0"):
			import oauth2client.client
			credentials = oauth2client.client.GoogleCredentials.get_application_default()
		conn = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
	except Exception as err:
		fail_usage("Failed: Create GCE compute v1 connection: {}".format(str(err)))

	# Operate the fencing device
	result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list)
	sys.exit(result)