def _destroy_pcmk_remote_env(env, node_names_list, skip_offline_nodes, allow_fails): actions = node_communication_format.create_pcmk_remote_actions([ "stop", "disable", ]) files = { "pacemaker_remote authkey": { "type": "pcmk_remote_authkey" }, } target_list = env.get_node_target_factory().get_target_list( node_names_list, skip_non_existing=skip_offline_nodes, ) com_cmd = ServiceAction( env.report_processor, actions, skip_offline_targets=skip_offline_nodes, allow_fails=allow_fails, ) com_cmd.set_targets(target_list) run_and_raise(env.get_node_communicator(), com_cmd) com_cmd = RemoveFiles( env.report_processor, files, skip_offline_targets=skip_offline_nodes, allow_fails=allow_fails, ) com_cmd.set_targets(target_list) run_and_raise(env.get_node_communicator(), com_cmd)
def _start_and_enable_pacemaker_remote(env, node_list, skip_offline_nodes=False, allow_fails=False): com_cmd = ServiceAction( env.report_processor, node_communication_format.create_pcmk_remote_actions([ "start", "enable", ]), skip_offline_targets=skip_offline_nodes, allow_fails=allow_fails, description="start of service pacemaker_remote") com_cmd.set_targets( env.get_node_target_factory().get_target_list(node_list)) run_and_raise(env.get_node_communicator(), com_cmd)
def _prepare_pacemaker_remote_environment( env, report_processor, existing_nodes_target_list, new_node_target, new_node_name, skip_offline_nodes, allow_incomplete_distribution, allow_fails, ): if new_node_target: com_cmd = GetOnlineTargets( report_processor, ignore_offline_targets=skip_offline_nodes, ) com_cmd.set_targets([new_node_target]) online_new_target_list = run_com(env.get_node_communicator(), com_cmd) if not online_new_target_list and not skip_offline_nodes: raise LibraryError() else: online_new_target_list = [] # check new nodes if online_new_target_list: com_cmd = GetHostInfo(report_processor) com_cmd.set_targets(online_new_target_list) report_processor.report_list( _host_check_remote_node( run_com(env.get_node_communicator(), com_cmd))) if report_processor.has_errors: raise LibraryError() else: report_processor.report_list( _reports_skip_new_node(new_node_name, "unreachable")) # share pacemaker authkey authkey_file = FileInstance.for_pacemaker_key() try: if authkey_file.raw_file.exists(): authkey_content = authkey_file.read_raw() authkey_targets = online_new_target_list else: authkey_content = generate_binary_key( random_bytes_count=settings.pacemaker_authkey_bytes) authkey_targets = (existing_nodes_target_list + online_new_target_list) except RawFileError as e: report_processor.report(raw_file_error_report(e)) if report_processor.has_errors: raise LibraryError() if authkey_targets: com_cmd = DistributeFiles( report_processor, node_communication_format.pcmk_authkey_file(authkey_content), skip_offline_targets=skip_offline_nodes, allow_fails=allow_incomplete_distribution, ) com_cmd.set_targets(authkey_targets) run_and_raise(env.get_node_communicator(), com_cmd) # start and enable pacemaker_remote if online_new_target_list: com_cmd = ServiceAction( report_processor, node_communication_format.create_pcmk_remote_actions([ "start", "enable", ]), allow_fails=allow_fails, ) com_cmd.set_targets(online_new_target_list) run_and_raise(env.get_node_communicator(), com_cmd)