def copy_ceph_config_from_mon(): cluster_config = configuration() cluster_name = cluster_config.get_cluster_name() ceph_mon_keyring = ConfigAPI().get_ceph_mon_keyring(cluster_name) ceph_client_admin_keyring = ConfigAPI().get_ceph_keyring_path(cluster_name) remot_mon_ip = cluster_config.get_remote_ips( cluster_config.get_node_info().name)[0] status = StatusReport() ssh_obj = ssh() config_api = ConfigAPI() if not os.path.exists(config_api.get_cluster_ceph_dir_path()): os.makedirs(config_api.get_cluster_ceph_dir_path(), exist_ok=True) if not os.path.exists("/var/lib/ceph/bootstrap-osd/"): os.makedirs("/var/lib/ceph/bootstrap-osd/") if not ssh_obj.copy_file_from_host(remot_mon_ip, "{}".format(ceph_client_admin_keyring)): logger.error("Cannot copy {} from {}".format(ceph_client_admin_keyring, remot_mon_ip)) status.success = False elif not ssh_obj.copy_file_from_host( remot_mon_ip, "/etc/ceph/{}.conf".format(cluster_name)): logger.error("Cannot copy ceph.conf from {}".format(remot_mon_ip)) status.success = False elif not ssh_obj.copy_file_from_host( remot_mon_ip, "/var/lib/ceph/bootstrap-osd/{}.keyring".format(cluster_name)): logger.error("Cannot copy ceph.keyring from {}".format(remot_mon_ip)) status.success = False return status
def build_monitors(): cluster_name = configuration().get_cluster_name() ceph_mon_keyring = ConfigAPI().get_ceph_mon_keyring(cluster_name) ceph_client_admin_keyring = ConfigAPI().get_ceph_keyring_path(cluster_name) status = StatusReport() try: _fsid = uuid.uuid4() content = "[global]\n\ fsid = {fsid}\n\ mon_host = {mon_host}\n\ \n\ public_network = {public_network}\n\ cluster_network = {cluster_network}\n\ \n" cluster_config = configuration() current_node_info = cluster_config.get_node_info() current_node_name = current_node_info.name current_cluster_info = cluster_config.get_cluster_info() config_api = ConfigAPI() mon_hosts_backend_ip = [] remote_mons_management_ips = [] for i in current_cluster_info.management_nodes: node_info = NodeInfo() node_info.load_json(json.dumps(i)) mon_hosts_backend_ip.append(node_info.backend_1_ip) if current_node_name != node_info.name: remote_mons_management_ips.append(node_info.management_ip) if not os.path.exists(config_api.get_cluster_ceph_dir_path()): os.makedirs(os.path.dirname( config_api.get_cluster_ceph_dir_path())) with open( config_api.get_cluster_ceph_dir_path() + "{}.conf".format(cluster_name), 'w', ) as f: f.write( content.format( fsid=_fsid, public_network=str( current_cluster_info.backend_1_base_ip) + "/" + __get_net_size(str(current_cluster_info.backend_1_mask)), cluster_network=str( current_cluster_info.backend_2_base_ip) + "/" + __get_net_size(str(current_cluster_info.backend_2_mask)), mon_initial=cluster_config.get_node_name(), mon_host=cluster_config.get_node_info().backend_1_ip + ',' + ','.join(mon_hosts_backend_ip)) + cluster_config.get_ceph_tunings() + "\n") if not call_cmd( "ceph-authtool --create-keyring /tmp/{} --gen-key -n mon. --cap mon 'allow *'" .format(ceph_mon_keyring)): logger.error( "ceph-authtool --create-keyring for mon returned error") status.success = False # elif not call_cmd("".join(["ceph-authtool --create-keyring {}".format(ceph_client_admin_keyring), # " --gen-key -n client.admin --set-uid=0 --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow'"])) : # Nautilius remove --set-uid=0 elif not call_cmd("".join([ "ceph-authtool --create-keyring {}".format( ceph_client_admin_keyring), " --gen-key -n client.admin --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow'" ])): logger.error( "ceph-authtool --create-keyring for admin returned error") status.success = False elif not call_cmd("ceph-authtool /tmp/{} --import-keyring {}".format( ceph_mon_keyring, ceph_client_admin_keyring)): logger.error("ceph-authtool --import-keyring returned error") status.success = False elif not call_cmd( "monmaptool --create --add {} {} --fsid {} /tmp/monmap".format( cluster_config.get_node_name(), cluster_config.get_node_info().backend_1_ip, _fsid)): logger.error("monmaptool --create --add returned error") status.success = False if not os.path.exists("/var/lib/ceph/mon/{}-{}".format( cluster_name, current_node_name)): os.makedirs("/var/lib/ceph/mon/{}-{}".format( cluster_name, current_node_name)) if not status.success or not call_cmd( "ceph-mon --cluster {} --mkfs -i {} --monmap /tmp/monmap --keyring /tmp/{}" .format(cluster_name, current_node_name, ceph_mon_keyring)): logger.error("ceph-mon --mkfs --add returned error") status.success = False open( "/var/lib/ceph/mon/{}-{}/done".format(cluster_name, current_node_name), 'w+').close() open( "/var/lib/ceph/mon/{}-{}/systemd".format(cluster_name, current_node_name), 'w+').close() call_cmd("chown -R ceph:ceph /var/lib/ceph/mon") call_cmd("systemctl enable ceph.target ") call_cmd("systemctl enable ceph-mon.target ") call_cmd("systemctl enable ceph-mon@{} ".format(current_node_name)) if not status.success or not call_cmd( "systemctl start ceph-mon@{} ".format(current_node_name)): status.success = False if not status.success: status.failed_tasks.append( "Create ceph mon on {} returned error.".format( current_node_name)) return status logger.info("First monitor started successfully") # create local manager : call_cmd('/opt/petasan/scripts/create_mgr.py') logger.info("Starting to deploy remote monitors") # call_cmd("ceph-create-keys --cluster {} -i {} ".format(cluster_name,current_node_name)) # Nautilius copy bootstrap-osd ourselves if not os.path.exists("/var/lib/ceph/bootstrap-osd/"): os.makedirs("/var/lib/ceph/bootstrap-osd/") call_cmd( 'ceph auth get client.bootstrap-osd > /var/lib/ceph/bootstrap-osd/ceph.keyring' ) for remote_mon in remote_mons_management_ips: ssh_obj = ssh() if not ssh_obj.copy_file_to_host( remote_mon, "{}".format(ceph_client_admin_keyring)): logger.error("Cannot copy {} to {}".format( ceph_client_admin_keyring, remote_mon)) status.success = False elif not ssh_obj.copy_file_to_host( remote_mon, "/etc/ceph/{}.conf".format(cluster_name)): logger.error("Cannot copy ceph.conf to {}".format(remote_mon)) status.success = False elif not ssh_obj.call_command( remote_mon, " python {} ".format( config_api.get_node_create_mon_script_path())): logger.error("Cannot create monitor on remote node {}".format( remote_mon)) status.success = False # Nautilius copy bootstrap-osd ourselves : elif not ssh_obj.call_command( remote_mon, 'mkdir -p /var/lib/ceph/bootstrap-osd'): logger.error( "Cannot create bootstrap-osd dir on remote node {}".format( remote_mon)) status.success = False elif not ssh_obj.copy_file_to_host( remote_mon, '/var/lib/ceph/bootstrap-osd/ceph.keyring'): logger.error("Cannot copy bootstrap-osd keyring to {}".format( remote_mon)) status.success = False if not status.success: status.failed_tasks.append( "core_cluster_deploy_monitor_create_err" + "%" + remote_mon) return status if not __test_mons(): status.success = False status.failed_tasks.append("core_cluster_deploy_monitors_down_err") return status # Nautilius enable msgr2 : call_cmd('ceph mon enable-msgr2') except Exception as ex: status.success = False logger.exception(ex.message) status.failed_tasks.append( "core_cluster_deploy_monitor_exception_occurred" + "%" + current_node_name) return status status.success = True return status