Beispiel #1
0
def add_journal(args):
    try:
        di = ceph_disk_lib.get_disk_info(args.disk_name)

        if di is None:
            print(__output_split_text)
            print(gettext('core_scripts_admin_journal_adding_err'))
            logger.error("The disk does not exits.")
            return

        if di.usage == DiskUsage.osd or di.usage == DiskUsage.journal or di.usage == DiskUsage.system:
            print(__output_split_text)
            print(gettext('core_scripts_admin_add_journal_disk_on_use_err'))
            return

        if not ceph_disk_lib.clean_disk(args.disk_name):
            print(__output_split_text)
            print(gettext('core_scripts_admin_journal_adding_err'))
            return

        if not ceph_disk_lib.add_journal(args.disk_name):
            print(__output_split_text)
            print(gettext('core_scripts_admin_journal_adding_err'))
            return

        return

    except Exception as ex:
        err = "Cannot add journal for disk {} , Exception is {}".format(
            args.disk_name, ex.message)
        logger.error(err)
        print(err)
        print(__output_split_text)
        print(gettext('core_scripts_admin_add_journal_exception'))
Beispiel #2
0
def delete_journal(args):
    try:
        di = ceph_disk_lib.get_disk_info(args.disk_name)

        if di is None or di.usage != DiskUsage.journal:
            print(__output_split_text)
            print(gettext('core_scripts_admin_delete_journal_err'))
            return

        if not ceph_disk_lib.clean_disk(args.disk_name):
            print(__output_split_text)
            print(gettext('core_scripts_admin_delete_journal_err'))
            return

        return

    except Exception as ex:
        logger.exception(ex)
        print(__output_split_text)
        print(gettext('core_scripts_admin_delete_journal_err'))
        return
Beispiel #3
0
# print subprocess.call("ceph-disk prepare --cluster ceph --zap-disk --fs-type xfs /dev/sdj /dev/sdh",shell=True)
cluster_name = configuration().get_cluster_name()
status = StatusReport()

status.success = False

try:
    cm = CacheManager()
    node_name = configuration().get_node_info().name
    storage_engine = configuration().get_cluster_info().storage_engine
    if configuration().get_node_info().is_storage:
        disks = __get_pre_config_disks()

        if len(disks.journals) > 0:
            for d in disks.journals:
                ceph_disk_lib.clean_disk(d)
                add_journal(d)

        if len(disks.caches) > 0:
            for cache_disk in disks.caches:
                ceph_disk_lib.clean_disk(cache_disk.keys()[0])
                ceph_disk_lib.add_cache(cache_disk.keys()[0])

        journal = ""
        cache = ""
        cache_type = ""

        for disk_name in disks.osds:
            device_name = disk_name
            ceph_disk_lib.clean_disk(disk_name)
Beispiel #4
0
def add_osd(args):
    try:
        di = ceph_disk_lib.get_disk_info(args.disk_name)

        if di.usage == DiskUsage.osd:
            print(__output_split_text)
            print(gettext('core_scripts_admin_add_osd_disk_is_osd_err'))
            return

        if not ceph_disk_lib.clean_disk(args.disk_name):
            print(__output_split_text)
            print(gettext('core_scripts_admin_add_osd_cleaning_err'))
            return

        journal = str(args.journal)
        if journal == "":
            logger.info(
                "User didn't select a journal for disk {}, so the journal will be on the same disk."
                .format(args.disk_name))
        elif journal == "auto":
            logger.info("Auto select journal for disk {}.".format(
                args.disk_name))
            journal = ceph_disk_lib.get_valid_journal()
            if journal is None:
                print(__output_split_text)
                print(gettext('core_scripts_admin_add_osd_journal_err'))
                logger.error(gettext('core_scripts_admin_add_osd_journal_err'))
                return
            logger.info(
                "User selected Auto journal, selected device is {} disk for disk {}."
                .format(journal, args.disk_name))
        else:
            ji = ceph_disk_lib.get_disk_info(journal)
            if ji is None or ji.usage != DiskUsage.journal:
                print(__output_split_text)
                print(gettext('core_scripts_admin_osd_adding_err'))
                logger.info(
                    "User selected journal {} does not exist or is not a valid journal."
                    .format(journal))
                return

            if len(ji.linked_osds) == 0:
                ceph_disk_lib.clean_disk(journal)

            logger.info("User selected journal {} disk for disk {}.".format(
                journal, args.disk_name))

        if not ceph_disk_lib.prepare_osd(args.disk_name, journal):
            print(__output_split_text)
            print(gettext('core_scripts_admin_osd_adding_err'))
            return

        ceph_disk_lib.wait_for_osd_up(args.disk_name)

    except Exception as ex:
        err = "Cannot add osd for disk {} , Exception is {}".format(
            args.disk_name, ex.message)
        logger.error(err)
        print(err)
        print(__output_split_text)
        print(gettext('core_scripts_admin_add_osd_exception'))
Beispiel #5
0
        return disks

#print subprocess.call("ceph-disk prepare --cluster ceph --zap-disk --fs-type xfs /dev/sdj /dev/sdh",shell=True)
cluster_name = configuration().get_cluster_info().name
status = StatusReport()

status.success = False

try:
    node_name = configuration().get_node_info().name
    if configuration().get_node_info().is_storage:
        disks = __get_pre_config_disks()

        if len(disks.journals) > 0:
            for d in disks.journals:
                ceph_disk_lib.clean_disk(d)
                add_journal(d)

        journal = ""
        for disk_name in disks.osds:
            ceph_disk_lib.clean_disk(disk_name)
            if len(disks.journals) == 0:
                journal = ""
            elif len(disks.journals) > 0:
                journal = get_valid_journal(journal_list=disks.journals)
                if journal is None:
                    status.failed_tasks.append("core_scripts_admin_add_osd_journal_err")
                    break

            if not ceph_disk_lib.prepare_osd(disk_name,journal) :
                status.failed_tasks.append(
def add_osd(args):
    # Read arguments #
    disk_name = str(args.disk_name)
    journal = str(args.journal)
    cache = str(args.cache)
    cache_type = str(args.cache_type)
    device_name = disk_name

    try:
        di = ceph_disk_lib.get_disk_info(disk_name)

        #  Check if disk is not used already as OSD #
        if di.usage == DiskUsage.osd:
            print(__output_split_text)
            print(gettext('core_scripts_admin_add_osd_disk_is_osd_err'))
            return

        #  Cleaning disk  #
        if not ceph_disk_lib.clean_disk(disk_name):
            print(__output_split_text)
            print(gettext('core_scripts_admin_add_osd_cleaning_err'))
            return

        # Journals #

        if journal == "" or journal is None:
            # If user didn't select a journal for disk and cluster is filestore
            logger.info(
                "User didn't select a journal for disk {}, so the journal will be on the same disk."
                .format(disk_name))
            config = configuration()
            storage_engine = config.get_cluster_info().storage_engine
            if storage_engine == "filestore":
                # manually create journal partition in the same disk for filestore
                journal_part_num = ceph_disk.create_journal_partition(
                    device_name, external=False)
                journal = ceph_disk.get_partition_name(device_name,
                                                       journal_part_num)

        # If journal value equals "auto" :
        elif journal == "auto":
            logger.info("Auto select journal for disk {}.".format(disk_name))
            journal = ceph_disk_lib.get_valid_journal()

            if journal is None:
                print(__output_split_text)
                print(gettext('core_scripts_admin_add_osd_journal_err'))
                logger.error(gettext('core_scripts_admin_add_osd_journal_err'))
                return
            logger.info(
                "User selected Auto journal, selected device is {} disk for disk {}."
                .format(journal, disk_name))

        # If user selected a specific journal for disk :
        else:
            ji = ceph_disk_lib.get_disk_info(journal)
            if ji is None or ji.usage != DiskUsage.journal:
                print(__output_split_text)
                print(gettext('core_scripts_admin_osd_adding_err'))
                logger.info(
                    "User selected journal {} does not exist or is not a valid journal."
                    .format(journal))
                return

            if len(ji.linked_osds) == 0:
                ceph_disk_lib.clean_disk(journal)

            logger.info("User selected journal {} disk for disk {}.".format(
                journal, disk_name))

        ############
        #  Caches  #
        ############
        # If user didn't select a cache for disk :
        if cache == "":
            logger.info(
                "User didn't select a cache for disk {}.".format(disk_name))

        # If cache value equals "auto" :
        elif cache == "auto":
            logger.info("Auto select cache for disk {}.".format(disk_name))
            cache = ceph_disk_lib.get_valid_cache()

            if cache is None:
                print(__output_split_text)
                print(gettext('core_scripts_admin_add_osd_cache_err'))
                logger.error(gettext('core_scripts_admin_add_osd_cache_err'))
                return

            logger.info(
                "User selected Auto cache, selected device is {} disk for disk {}."
                .format(cache, disk_name))

        # If user selected a specific cache for disk :
        else:
            selected_cache = ceph_disk_lib.get_disk_info(cache)

            if selected_cache is None or selected_cache.usage != DiskUsage.cache:
                print(__output_split_text)
                print(gettext('core_scripts_admin_osd_adding_err'))
                logger.info(
                    "User selected cache {} does not exist or is not a valid cache."
                    .format(cache))
                return

        logger.info("User selected cache {} disk for disk {}.".format(
            cache, disk_name))

        # Creating "write-lvm" before creating "OSD" #
        # where lv_name of HDD = main , lv_name of SSD = cache , and vg_name = ps-wc-osd_000{rand_num}
        # --------------------------------------------------------------------------------------------
        main_path = None
        cache_part = None
        vg_name = None

        if cache is not None and len(cache) > 0:
            # create cache #
            cm = CacheManager()
            main_path, cache_part = cm.create(
                disk_name, cache, cache_type)  # main_path = lv_path
            # = vg_name + "/" + main_lv_name
            if main_path is not None and cache_part is not None:
                vg_name = main_path.split("/")[
                    0]  # For renaming VG after the osd id later
                device_name = main_path

        #################
        # Preparing OSD #
        #################
        if not ceph_disk_lib.prepare_osd(device_name, journal):
            if cache_part is not None:
                cm = CacheManager()
                cm.delete(disk_name, cache_type)
                # After the failure of adding OSD , clean both disk & cache partition and
                # change ptype of cache partition to "cache_avail_ptype" :
                ceph_disk_lib.clean_disk(disk_name)
                ceph_disk_lib.clean_disk(cache_part)
                ceph_disk_lib.set_cache_part_avail(cache_part)

            print(__output_split_text)
            print(gettext('core_scripts_admin_osd_adding_err'))
            return

        ceph_disk_lib.wait_for_osd_up(disk_name)

    except Exception as ex:
        err = "Cannot add osd for disk {} , Exception is : {}".format(
            disk_name, ex.message)
        logger.exception(err)
        print(err)
        print(__output_split_text)
        print(gettext('core_scripts_admin_add_osd_exception'))
def delete_osd(args):
    try:
        disk_list = ceph_disk_lib.get_disk_list()
        journal_partition = "no_journal"
        linked_cache_list = []
        vg_name = ""

        for disk in disk_list:
            if disk.name == args.disk_name:
                if len(disk.linked_journal) > 0:
                    journal_partition = disk.linked_journal + disk.linked_journal_part_num

                if len(disk.linked_cache) > 0:
                    linked_cache_list = disk.linked_cache
                    vg_name = disk.vg_name

                if len(linked_cache_list
                       ) > 0 and journal_partition != "no_journal":
                    break

        # Remove OSD from Ceph Crush Map :
        # --------------------------------
        ceph_osd.delete_osd_from_crush_map(int(args.id))
        ceph_osd.delete_osd(int(args.id), args.disk_name)

        # If Cache was used :
        # -------------------
        if vg_name and len(linked_cache_list) > 0:
            cm = CacheManager()
            cache_type = cm.get_cache_type(args.disk_name)
            cm.delete(args.disk_name, cache_type)
            for cache_part in linked_cache_list:
                ceph_disk_lib.clean_disk(cache_part)
                stat = ceph_disk_lib.set_cache_part_avail(cache_part)
                if not stat:
                    logger.error(
                        "Can't set cache partition {} available for osd {}".
                        format(cache_part, args.disk_name))

        #  Get the Volume Group name (VG) of the selected OSD --> in order to deactivate it first before clean_disk() :
        # -------------------------------------------------------------------------------------------------------------
        osd_vg = get_vg_from_disk(args.disk_name)
        if osd_vg is not None:
            deactivate_vg(osd_vg)

        #  Clean Disk :
        # -------------
        ceph_disk_lib.clean_disk(args.disk_name)

        # Remove unused OSD Systemd Service after deleting the OSD :
        # ----------------------------------------------------------
        ceph_disk_lib.delete_unused_ceph_volume_services()

        if journal_partition is not "no_journal":
            journal_path = '/dev/' + journal_partition
            if ceph_disk.is_partition(journal_path):
                stat = ceph_disk_lib.set_journal_part_avail(journal_partition)
                if not stat:
                    logger.error(
                        "Can't set journal partition {} available for osd {}".
                        format(journal_partition, args.disk_name))

    except Exception as ex:
        logger.error(ex.message)
Beispiel #8
0
    def create(self, origin_device, cache_device):
        self.origin_device = origin_device
        self.cache_device = cache_device
        devices = []
        cluster_fsid = ceph_disk.get_fsid(configuration().get_cluster_name())

        logger.info("Getting the next OSD ID :")
        logger.info("-------------------------")

        next_osd_id = ceph_disk_lib.get_next_osd_id()
        if len(next_osd_id) == 0:
            logger.error("Can't get next OSD id.")
            return None

        logger.info("next_osd_id = {}\n".format(str(next_osd_id)))
        vg_name = "ps-" + cluster_fsid + "-wc-osd." + str(next_osd_id)
        logger.info("vg_name = {}\n".format(str(vg_name)))

        cache_lv_name = "cache"
        main_lv_name = "main"
        origin_part_name = ""
        cache_part = ""

        try:
            logger.info("==================================================")
            logger.info("=====          Building DM-Writecache        =====")
            logger.info("==================================================")

            # ======================================= Slow Device ======================================= #
            # (1) Zapping the slow disk device :
            # ----------------------------------
            logger.info("Step 1 : Preparing Slow Disk :")
            logger.info("------------------------------")

            # (2) Creating one partition for the slow disk ( with same size of disk size ) :
            # ------------------------------------------------------------------------------
            origin_part_num = ceph_disk.create_osd_partition(origin_device)
            origin_part = ceph_disk.get_partition_name(origin_device,
                                                       origin_part_num)

            if origin_part is not None:
                origin_part_name = '/dev/' + origin_part
                devices.append(origin_part_name)
                logger.info("origin_part_name = {}".format(
                    str(origin_part_name)))
                logger.info("done\n")

            else:
                logger.info(
                    "Creating partition for the slow disk has been failed.")
                ceph_disk_lib.clean_disk(origin_device)
                return None

            # ======================================= Fast Device ======================================= #
            # (4) Get available partition for cache disk :
            # --------------------------------------------
            logger.info("Step 2 : Preparing Fast Disk :")
            logger.info("------------------------------")
            avail_partitions_ls = ceph_disk_lib.get_partitions_by_type(
                cache_device, ceph_disk_lib.cache_avail_ptype)

            if len(avail_partitions_ls) > 0:
                # Sorting partitions list alphabetically :
                avail_partitions_ls.sort()

                cache_part = avail_partitions_ls[0]
                cache_part_path = '/dev/' + cache_part

                ceph_disk_lib.clean_disk(cache_part)

                # clean meta data super block
                self.clean_superblock(cache_part)

                devices.append(cache_part_path)
                logger.info("cache_part_path = {}".format(
                    str(cache_part_path)))
                logger.info("done\n")

            else:
                logger.info(
                    "Getting available partition for cache disk has been failed."
                )
                ceph_disk_lib.clean_disk(origin_device)
                return None

            # ==================================== Physical Volumes ===================================== #
            # (6) Creating Physical Volumes (pvs) :
            # -------------------------------------
            logger.info("Step 3 : Creating Physical Volumes :")
            logger.info("------------------------------------")
            if create_pv(origin_part_name) is None:
                logger.info(
                    "Creating Physical Volume on {} has been failed.".format(
                        origin_part_name))
                ceph_disk_lib.clean_disk(origin_device)
                return None

            if create_pv(cache_part_path) is None:
                logger.info(
                    "Creating Physical Volume on {} has been failed.".format(
                        cache_part_path))
                ceph_disk_lib.clean_disk(origin_device)
                ceph_disk_lib.clean_disk(cache_part)
                ceph_disk_lib.set_partition_type(
                    cache_part, ceph_disk_lib.cache_avail_ptype)
                return None

            logger.info("done\n")

            # ====================================== Volume Groups ====================================== #
            # (7) Creating Volume Groups (vgs) :
            # ----------------------------------
            logger.info("Step 4 : Creating Volume Group :")
            logger.info("--------------------------------")
            vg = get_vg(vg_name)

            while vg is not None:
                next_osd_id = ceph_disk_lib.get_next_osd_id()
                if len(next_osd_id) == 0:
                    logger.error("Can't get next OSD id.")
                    logger.error("Creating Volume Group has been failed.")
                    ceph_disk_lib.clean_disk(origin_device)
                    ceph_disk_lib.clean_disk(cache_part)
                    ceph_disk_lib.set_partition_type(
                        cache_part, ceph_disk_lib.cache_avail_ptype)
                    return None

                logger.info("new next_osd_id = {}\n".format(str(next_osd_id)))
                vg_name = "ps-" + cluster_fsid + "-wc-osd." + str(next_osd_id)
                logger.info("new vg_name = {}\n".format(str(vg_name)))

                vg = get_vg(vg_name)

            vg = create_vg(devices, vg_name)

            if vg is None:
                logger.info("Creating Volume Group has been failed.")
                ceph_disk_lib.clean_disk(origin_device)
                ceph_disk_lib.clean_disk(cache_part)
                ceph_disk_lib.set_partition_type(
                    cache_part, ceph_disk_lib.cache_avail_ptype)
                return None

            vg_name = vg.vg_name
            logger.info("vg_name = {}".format(str(vg_name)))
            logger.info("done\n")

            # ===================================== Logical Volumes ===================================== #
            # (8) Creating Logical Volumes (lvs) :
            # ------------------------------------
            logger.info("Step 5 : Creating Logical Volumes :")
            logger.info("-----------------------------------")
            main_lv_name = create_lv(main_lv_name, vg_name, origin_part_name)

            if main_lv_name is None:
                logger.info(
                    "Creating Logical Volume for main device has been failed.")
                activate_vg(vg_name)
                ceph_disk_lib.clean_disk(origin_device)
                ceph_disk_lib.clean_disk(cache_part)
                ceph_disk_lib.set_partition_type(
                    cache_part, ceph_disk_lib.cache_avail_ptype)

                return None

            logger.info("main_lv_name = {}".format(str(main_lv_name)))

            cache_lv_name = create_lv(cache_lv_name, vg_name, cache_part_path)

            if cache_lv_name is None:
                logger.info(
                    "Creating Logical Volume for cache device has been failed."
                )
                activate_vg(vg_name)
                ceph_disk_lib.clean_disk(origin_device)
                ceph_disk_lib.clean_disk(cache_part)
                ceph_disk_lib.set_partition_type(
                    cache_part, ceph_disk_lib.cache_avail_ptype)
                return None

            logger.info("cache_lv_name = {}".format(str(cache_lv_name)))
            logger.info("done\n")

            # =================================== Building writecache =================================== #
            logger.info("Step 6 : Building dm-writecache :")
            logger.info("---------------------------------")
            error = 0
            cmd = "lvchange -a n " + vg_name + "/" + cache_lv_name
            ret, stdout, stderr = exec_command_ex(cmd)

            if ret != 0:
                if stderr:
                    logger.info(
                        "Error running the command : {} , the error msg :\n{}".
                        format(cmd, stderr))
                    error += 1
            else:
                logger.info("cmd = {}  --->  done".format(str(cmd)))
                cmd = "modprobe dm-writecache"
                ret, stdout, stderr = exec_command_ex(cmd)

                if ret != 0:
                    if stderr:
                        logger.info(
                            "Error running the command : {} , the error msg :\n{}"
                            .format(cmd, stderr))
                        error += 1
                else:
                    logger.info("cmd = {}  --->  done".format(str(cmd)))
                    cmd = 'lvconvert --yes --type writecache --cachevol ' + cache_lv_name + \
                          " --cachesettings 'writeback_jobs=102400' " + vg_name + "/" + main_lv_name
                    ret, stdout, stderr = exec_command_ex(cmd)

                    if ret != 0:
                        if stderr:
                            logger.info(
                                "Error running the command : {} , the error msg :\n{}"
                                .format(cmd, stderr))
                            error += 1

            if error > 0:
                activate_vg(vg_name)
                ceph_disk_lib.clean_disk(origin_device)
                ceph_disk_lib.clean_disk(cache_part)

                ceph_disk_lib.set_partition_type(
                    cache_part, ceph_disk_lib.cache_avail_ptype)
                logger.info(
                    "Create WriteCache : Building writecache has been failed.")
                return None

            logger.info("cmd = {}  --->  done".format(str(cmd)))
            ceph_disk_lib.set_partition_type(cache_part,
                                             ceph_disk_lib.cache_used_ptype)

            lv_path = vg_name + "/" + main_lv_name
            logger.info("lv_path = {}".format(str(lv_path)))

            logger.info("done")
            logger.info("==================================================")

            return lv_path, cache_part

        except Exception as ex:
            err = "Cannot build writecache for disk {} and cache partition {} , Exception is : {}".format(
                origin_device, cache_device, ex.message)
            logger.exception(err)
            ceph_disk_lib.clean_disk(origin_device)
            ceph_disk_lib.clean_disk(cache_part)
            ceph_disk_lib.set_partition_type(cache_part,
                                             ceph_disk_lib.cache_avail_ptype)
            logger.info("==================================================")