def _share_authkey(env, current_nodes, candidate_node_addresses, skip_offline_nodes=False, allow_incomplete_distribution=False): if env.pacemaker.has_authkey: authkey_content = env.pacemaker.get_authkey_content() node_addresses_list = NodeAddressesList([candidate_node_addresses]) else: authkey_content = generate_key() node_addresses_list = current_nodes + [candidate_node_addresses] com_cmd = DistributeFiles( env.report_processor, node_communication_format.pcmk_authkey_file(authkey_content), skip_offline_targets=skip_offline_nodes, allow_fails=allow_incomplete_distribution, description="remote node configuration files", ) com_cmd.set_targets( env.get_node_target_factory().get_target_list(node_addresses_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)