def get_fence_agent_info(argv): if len(argv) != 1: utils.err("One parameter expected") agent = argv[0] if not agent.startswith("stonith:"): utils.err("Invalid fence agent name") runner = utils.cmd_runner() try: metadata_dom = lib_ra.get_fence_agent_metadata( runner, agent.split("stonith:", 1)[1] ) metadata = lib_ra.get_agent_desc(metadata_dom) metadata["name"] = agent metadata["parameters"] = lib_ra.get_fence_agent_parameters( runner, metadata_dom ) print(json.dumps(metadata)) except lib_ra.ResourceAgentLibError as e: utils.process_library_reports( [lib_ra.resource_agent_lib_error_to_report_item(e)] ) except LibraryError as e: utils.process_library_reports(e.args)
def test_shortdesc_attribute(self): xml = '<resource-agent shortdesc="short description" />' expected = { "longdesc": "", "shortdesc": "short description" } self.assertEqual(expected, lib_ra.get_agent_desc(etree.XML(xml)))
def test_no_desc(self): xml = "<resource-agent />" expected = { "longdesc": "", "shortdesc": "" } self.assertEqual(expected, lib_ra.get_agent_desc(etree.XML(xml)))
def test_invalid_metadata_format(self): xml = "<xml />" self.assert_raise_library_error( lambda: lib_ra.get_agent_desc(etree.XML(xml)), ( Severities.ERROR, error_codes.INVALID_METADATA_FORMAT, {} ) )
def test_longdesc_and_shortdesc_attribute(self): xml = """ <resource-agent shortdesc="short_desc"> <longdesc>long description</longdesc> </resource-agent> """ expected = { "longdesc": "long description", "shortdesc": "short_desc" } self.assertEqual(expected, lib_ra.get_agent_desc(etree.XML(xml)))
def test_shortdesc_element(self): xml = """ <resource-agent> <shortdesc>short description</shortdesc> </resource-agent> """ expected = { "longdesc": "", "shortdesc": "short description" } self.assertEqual(expected, lib_ra.get_agent_desc(etree.XML(xml)))
def stonith_list_options(stonith_agent): runner = utils.cmd_runner() try: metadata = lib_ra.get_fence_agent_metadata(runner, stonith_agent) desc = lib_ra.get_agent_desc(metadata) params = lib_ra.get_fence_agent_parameters(runner, metadata) resource.resource_print_options(stonith_agent, desc, params) except lib_ra.ResourceAgentLibError as e: utils.process_library_reports( [lib_ra.resource_agent_lib_error_to_report_item(e)] ) except LibraryError as e: utils.process_library_reports(e.args)
def stonith_list_available(argv): if len(argv) != 0: filter_string = argv[0] else: filter_string = "" bad_fence_devices = ["kdump_send", "legacy", "na", "nss_wrapper", "pcmk", "vmware_helper", "ack_manual", "virtd", "sanlockd", "check", "tool", "node"] fence_devices = sorted(glob.glob(utils.fence_bin + "fence_*")) for bfd in bad_fence_devices: try: fence_devices.remove(utils.fence_bin + "fence_"+bfd) except ValueError: continue if not fence_devices: utils.err( "No stonith agents available. Do you have fence agents installed?" ) fence_devices_filtered = [fd for fd in fence_devices if filter_string in fd] if not fence_devices_filtered: utils.err("No stonith agents matching the filter.") for fd in fence_devices_filtered: sd = "" agent_name = os.path.basename(fd) if "--nodesc" not in utils.pcs_options: try: metadata = lib_ra.get_fence_agent_metadata( utils.cmd_runner(), agent_name ) shortdesc = lib_ra.get_agent_desc(metadata)["shortdesc"] if shortdesc: sd = " - " + resource.format_desc( len(agent_name) + 3, shortdesc ) except lib_ra.ResourceAgentLibError as e: utils.process_library_reports([ lib_ra.resource_agent_lib_error_to_report_item( e, ReportItemSeverity.WARNING ) ]) except LibraryError as e: utils.err( e.args[-1].message, False ) continue print(agent_name + sd)
def stonith_list_options(stonith_agent): runner = utils.cmd_runner() try: metadata = lib_ra.get_fence_agent_metadata(runner, stonith_agent) desc = lib_ra.get_agent_desc(metadata) params = lib_ra.get_fence_agent_parameters(runner, metadata) # Fence agents just list the actions, usually without any attributes. # We could print them but it wouldn't add any usefull information. resource.resource_print_options(stonith_agent, desc, params, actions=[]) except lib_ra.ResourceAgentLibError as e: utils.process_library_reports( [lib_ra.resource_agent_lib_error_to_report_item(e)] ) except LibraryError as e: utils.process_library_reports(e.args)
def get_fence_agent_info(argv): if len(argv) != 1: utils.err("One parameter expected") agent = argv[0] if not agent.startswith("stonith:"): utils.err("Invalid fence agent name") try: metadata_dom = lib_ra.get_fence_agent_metadata( agent.split("stonith:", 1)[1] ) metadata = lib_ra.get_agent_desc(metadata_dom) metadata["name"] = agent metadata["parameters"] = lib_ra.get_fence_agent_parameters( metadata_dom ) print(json.dumps(metadata)) except lib_ra.LibraryError as e: utils.process_library_reports(e.args)
def test_invalid_metadata_format(self): xml = "<xml />" self.assertRaises( lib_ra.InvalidMetadataFormat, lambda: lib_ra.get_agent_desc(etree.XML(xml)) )