示例#1
0
def is_cleanup_host(config):
    """
    decide which gateway host should be responsible for any non-specific
    updates to the config object
    :param config: configuration dict from the rados pool
    :return: boolean indicating whether the addition cleanup should be
    performed by the running host
    """
    cleanup = False

    if 'ip_list' in config.config["gateways"]:

        gw_1 = config.config["gateways"]["ip_list"][0]

        local_ips = ip_addresses()
        usable_ips = resolve_ip_addresses(gw_1)
        for ip in usable_ips:
            if ip in local_ips:
                cleanup = True
                break

    return cleanup
示例#2
0
    def __init__(self, logger, iqn, gateway_ip_list, enable_portal=True):
        """
        Instantiate the class
        :param iqn: iscsi iqn name for the gateway
        :param gateway_ip_list: list of IP addresses to be defined as portals
                to LIO
        :return: gateway object
        """

        self.error = False
        self.error_msg = ''

        self.enable_portal = enable_portal  # boolean to trigger portal IP creation
        self.logger = logger  # logger object

        try:
            iqn, iqn_type = normalize_wwn(['iqn'], iqn)
        except RTSLibError as err:
            self.error = True
            self.error_msg = "Invalid iSCSI target name - {}".format(err)
        self.iqn = iqn

        # Ensure IPv6 addresses are in the normalized address (not literal) format
        gateway_ip_list = [normalize_ip_address(x) for x in gateway_ip_list]

        # If the ip list received has data in it, this is a target we need to
        # act on the IP's provided, otherwise just set to null
        if gateway_ip_list:
            # if the ip list provided doesn't match any ip of this host, abort
            # the assumption here is that we'll only have one matching ip in
            # the list!
            matching_ip = set(gateway_ip_list).intersection(ip_addresses())
            if len(list(matching_ip)) == 0:
                self.error = True
                self.error_msg = ("gateway IP addresses provided do not match"
                                  " any ip on this host")
                return

            self.active_portal_ip = list(matching_ip)[0]
            self.logger.debug("active portal will use "
                              "{}".format(self.active_portal_ip))

            self.gateway_ip_list = gateway_ip_list
            self.logger.debug("tpg's will be defined in this order"
                              " - {}".format(self.gateway_ip_list))
        else:
            # without gateway_ip_list passed in this is a 'init' or
            # 'clearconfig' request
            self.gateway_ip_list = []
            self.active_portal_ip = []

        self.changes_made = False
        self.config_updated = False

        # self.portal = None
        self.target = None
        self.tpg = None
        self.tpg_list = []

        try:
            super(GWTarget, self).__init__('targets', iqn, logger,
                                           GWTarget.SETTINGS)
        except CephiSCSIError as err:
            self.error = True
            self.error_msg = err
示例#3
0
    def define_luns(logger, config, gateway):
        """
        define the disks in the config to LIO
        :param logger: logger object to print to
        :param config: configuration dict from the rados pool
        :param gateway: (object) gateway object - used for mapping
        :raises CephiSCSIError.
        """

        local_gw = this_host()

        # sort the disks dict keys, so the disks are registered in a specific
        # sequence
        disks = config.config['disks']
        srtd_disks = sorted(disks)
        pools = {disks[disk_key]['pool'] for disk_key in srtd_disks}

        if pools is None:
            logger.info("No LUNs to export")
            return True

        ips = ip_addresses()

        with rados.Rados(conffile=settings.config.cephconf) as cluster:

            for pool in pools:

                logger.debug("Processing rbd's in '{}' pool".format(pool))

                with cluster.open_ioctx(pool) as ioctx:

                    pool_disks = [
                        disk_key for disk_key in srtd_disks
                        if disk_key.startswith(pool + '.')
                    ]
                    for disk_key in pool_disks:

                        is_lun_mapped = False
                        for _, target_config in config.config['targets'].items(
                        ):
                            if local_gw in target_config['portals'] \
                                    and disk_key in target_config['disks']:
                                is_lun_mapped = True
                                break
                        if is_lun_mapped:
                            pool, image_name = disk_key.split('.')

                            try:
                                with rbd.Image(ioctx, image_name) as rbd_image:
                                    RBDDev.rbd_lock_cleanup(
                                        logger, ips, rbd_image)

                                    backstore = config.config['disks'][
                                        disk_key]['backstore']
                                    lun = LUN(logger, pool, image_name,
                                              rbd_image.size(), local_gw,
                                              backstore)
                                    if lun.error:
                                        raise CephiSCSIError(
                                            "Error defining rbd "
                                            "image {}".format(disk_key))

                                    lun.allocate()

                                    if lun.error:
                                        raise CephiSCSIError(
                                            "Error unable to "
                                            "register  {} with "
                                            "LIO - {}".format(
                                                disk_key, lun.error_msg))

                            except rbd.ImageNotFound:
                                raise CephiSCSIError(
                                    "Disk '{}' defined to the "
                                    "config, but image '{}' can "
                                    "not be found in '{}' "
                                    "pool".format(disk_key, image_name, pool))

        if gateway:
            # Gateway Mapping : Map the LUN's registered to all tpg's within the
            # LIO target
            gateway.manage('map')
            if gateway.error:
                raise CephiSCSIError(
                    "Error mapping the LUNs to the tpg's within "
                    "the iscsi Target")
示例#4
0
    def define_luns(logger, config, target):
        """
        define the disks in the config to LIO and map to a LUN
        :param logger: logger object to print to
        :param config: configuration dict from the rados pool
        :param target: (object) gateway object - used for mapping
        :raises CephiSCSIError.
        """

        ips = ip_addresses()
        local_gw = this_host()

        target_disks = config.config["targets"][target.iqn]['disks']
        if not target_disks:
            logger.info("No LUNs to export")
            return

        disks = {}
        for disk in target_disks:
            disks[disk] = config.config['disks'][disk]

        # sort the disks dict keys, so the disks are registered in a specific
        # sequence
        srtd_disks = sorted(disks)
        pools = {disks[disk_key]['pool'] for disk_key in srtd_disks}

        ips = ip_addresses()

        with rados.Rados(conffile=settings.config.cephconf,
                         name=settings.config.cluster_client_name) as cluster:

            for pool in pools:

                logger.debug("Processing rbd's in '{}' pool".format(pool))

                with cluster.open_ioctx(pool) as ioctx:

                    pool_disks = [
                        disk_key for disk_key in srtd_disks
                        if disk_key.startswith(pool + '/')
                    ]
                    for disk_key in pool_disks:

                        pool, image_name = disk_key.split('/')
                        with rbd.Image(ioctx, image_name) as rbd_image:

                            disk_config = config.config['disks'][disk_key]
                            backstore = disk_config['backstore']
                            backstore_object_name = disk_config[
                                'backstore_object_name']

                            lun = LUN(logger, pool, image_name,
                                      rbd_image.size(), local_gw, backstore,
                                      backstore_object_name)

                            if lun.error:
                                raise CephiSCSIError(
                                    "Error defining rbd image {}".format(
                                        disk_key))

                            so = lun.allocate()
                            if lun.error:
                                raise CephiSCSIError("Unable to register {} "
                                                     "with LIO: {}".format(
                                                         disk_key,
                                                         lun.error_msg))

                            # If not in use by another target on this gw
                            # clean up stale locks.
                            if so.status != 'activated':
                                RBDDev.rbd_lock_cleanup(logger, ips, rbd_image)

                            target._map_lun(config, so)
                            if target.error:
                                raise CephiSCSIError(
                                    "Mapping for {} failed: {}".format(
                                        disk_key, target.error_msg))