diff --git a/agents/openstack/fence_openstack.py b/agents/openstack/fence_openstack.py index bcb13350..5257ec52 100755 --- a/agents/openstack/fence_openstack.py +++ b/agents/openstack/fence_openstack.py @@ -1,147 +1,160 @@ #!@PYTHON@ -tt import atexit import logging import os import re import sys from pipes import quote sys.path.append("/usr/share/fence") from fencing import * from fencing import fail_usage, is_executable, run_command, run_delay try: from novaclient import client as novaclient from keystoneauth1 import session as ksc_session from keystoneauth1 import loading legacy_import = False except ImportError: try: from novaclient import client as novaclient from keystoneclient import session as ksc_session from keystoneclient.auth.identity import v3 legacy_import = True except ImportError: pass -def get_name_or_uuid(options): - return options["--uuid"] if "--uuid" in options else options["--plug"] - def get_power_status(_, options): output = nova_run_command(options, "status") if (output == 'ACTIVE'): return 'on' else: return 'off' def set_power_status(_, options): nova_run_command(options, options["--action"]) return def nova_login(username,password,projectname,auth_url,user_domain_name,project_domain_name): if not legacy_import: loader = loading.get_plugin_loader('password') auth = loader.load_from_options(auth_url=auth_url, username=username, password=password, project_name=projectname, user_domain_name=user_domain_name, project_domain_name=project_domain_name) else: auth = v3.Password(username=username, password=password, project_name=projectname, user_domain_name=user_domain_name, project_domain_name=project_domain_name, auth_url=auth_url) session = ksc_session.Session(auth=auth) nova = novaclient.Client("2", session=session) return nova def nova_run_command(options,action,timeout=None): username=options["--username"] password=options["--password"] projectname=options["--project-name"] auth_url=options["--auth-url"] user_domain_name=options["--user-domain-name"] project_domain_name=options["--project-domain-name"] novaclient=nova_login(username,password,projectname,auth_url,user_domain_name,project_domain_name) - server = novaclient.servers.get(options["--uuid"]) + server = novaclient.servers.get(options["--plug"]) if action == "status": return server.status if action == "on": server.start() if action == "off": server.stop() if action == "reboot": server.reboot('REBOOT_HARD') def define_new_opts(): all_opt["auth-url"] = { "getopt" : ":", "longopt" : "auth-url", - "help" : "--auth-url=[authurl] Keystone Auth URL", + "help" : "--auth-url=[authurl] Keystone Auth URL", "required" : "1", "shortdesc" : "Keystone Auth URL", "order": 1 } all_opt["project-name"] = { "getopt" : ":", "longopt" : "project-name", - "help" : "--project-name=[project] Tenant Or Project Name", + "help" : "--project-name=[project] Tenant Or Project Name", "required" : "1", "shortdesc" : "Keystone Project", "default": "admin", "order": 1 } all_opt["user-domain-name"] = { "getopt" : ":", "longopt" : "user-domain-name", - "help" : "--user-domain-name=[user-domain] Keystone User Domain Name", + "help" : "--user-domain-name=[domain] Keystone User Domain Name", "required" : "0", "shortdesc" : "Keystone User Domain Name", "default": "Default", "order": 1 } all_opt["project-domain-name"] = { "getopt" : ":", "longopt" : "project-domain-name", - "help" : "--project-domain-name=[project-domain] Keystone Project Domain Name", + "help" : "--project-domain-name=[domain] Keystone Project Domain Name", "required" : "0", "shortdesc" : "Keystone Project Domain Name", "default": "Default", "order": 1 } all_opt["uuid"] = { "getopt" : ":", "longopt" : "uuid", - "help" : "--uuid=[uuid] UUID of the nova instance", - "required" : "1", - "shortdesc" : "UUID of the nova instance", + "help" : "--uuid=[uuid] Replaced by -n, --plug", + "required" : "0", + "shortdesc" : "Replaced by port", "order": 1 } def main(): atexit.register(atexit_handler) - device_opt = ["login", "passwd", "auth-url", "project-name", "user-domain-name", "project-domain-name", "uuid"] + device_opt = [ "login", "passwd", "auth-url", "project-name", + "user-domain-name", "project-domain-name", + "port", "no_port", "uuid" ] define_new_opts() + 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 options["--action"] in ["off", "on", "reboot", "status"] \ + and "--plug" not in options: + fail_usage("Failed: You have to enter plug number or machine identification", stop) + 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) if __name__ == "__main__": main() diff --git a/tests/data/metadata/fence_openstack.xml b/tests/data/metadata/fence_openstack.xml index bdc2e1bc..a7b25940 100644 --- a/tests/data/metadata/fence_openstack.xml +++ b/tests/data/metadata/fence_openstack.xml @@ -1,157 +1,167 @@ 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 https://wiki.openstack.org/wiki/Nova Fencing action Keystone Auth URL Keystone Auth URL Login name Login password or passphrase Script to run to retrieve password Login password or passphrase Script to run to retrieve password + + + + UUID of the node to be fenced. + + + + + UUID of the node to be fenced. + - + Keystone Project Domain Name Keystone Project - + Keystone Project Domain Name Keystone Project - + Keystone User Domain Name - + Keystone User Domain Name Login name - + - UUID of the nova instance + Replaced by port 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 Wait X seconds before fencing is started Wait X seconds for cmd prompt after login 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