Exemplo n.º 1
0
    def _get_mapping(self):
        mapping = Metric("LUN mapping state 0=unmapped, 1=mapped", "gauge")
        mapped_devices = [
            l.tpg_lun.storage_object.name for l in self._root.mapped_luns
        ]

        tpg_mappers = []
        for tpg in self._root.tpgs:
            mapper = TPGMapper(tpg)
            mapper.start()
            tpg_mappers.append(mapper)

        for mapper in tpg_mappers:
            mapper.join()

        if not tpg_mappers:
            raise CephiSCSIInval("Target not mapped to gateway.")

        # merge the tpg lun maps
        all_devs = tpg_mappers[0].owned_luns.copy()
        for mapper in tpg_mappers[1:]:
            all_devs.update(mapper.owned_luns)

        for so in self._root.storage_objects:

            so_state = 1 if so.name in mapped_devices else 0
            owner = all_devs[so.name]
            mapping.add(
                {
                    "lun_name": so.name,
                    "gw_name": self.gw_name,
                    "gw_owner": owner
                }, so_state)

        self.metrics["ceph_iscsi_lun_mapped"] = mapping
Exemplo n.º 2
0
    def _get_tpg(self):
        stat = Metric("target portal groups defined within gateway group",
                      "gauge")
        tgt = next(self._root.targets, None)
        if tgt is None:
            raise CephiSCSIInval("No targets setup.")

        labels = {"gw_iqn": tgt.wwn}
        v = len([tpg for tpg in self._root.tpgs])
        stat.add(labels, v)

        self.metrics["ceph_iscsi_gateway_tpg_total"] = stat
Exemplo n.º 3
0
def alua_create_group(failover_type, tpg, so, is_owner):
    group_name = alua_format_group_name(tpg, failover_type, is_owner)

    if failover_type == "explicit":
        alua_tpg = alua_create_explicit_group(tpg, so, group_name, is_owner)
    elif failover_type == "implicit":
        # tmp drop down to implicit. Next patch will check for "implicit"
        # and add error handling up the stack if the failover_type is invalid.
        alua_tpg = alua_create_implicit_group(tpg, so, group_name, is_owner)
    else:
        raise CephiSCSIInval("Invalid failover type {}".format(failover_type))

    alua_tpg.alua_support_active_optimized = 1
    alua_tpg.alua_support_offline = 0
    alua_tpg.alua_support_unavailable = 0
    alua_tpg.alua_support_transitioning = 1
    alua_tpg.nonop_delay_msecs = 0

    return alua_tpg
Exemplo n.º 4
0
    def bind_alua_group_to_lun(self, config, lun, tpg_ip_address=None):
        """
        bind lun to one of the alua groups. Query the config to see who
        'owns' the primary path for this LUN. Then either bind the LUN
        to the ALUA 'AO' group if the host matches, or default to the
        'ANO'/'Standby' alua group

        param config: Config object
        param lun: lun object on the tpg
        param tpg_ip: IP of Network Portal for the lun's tpg.
        """

        stg_object = lun.storage_object

        owning_gw = config.config['disks'][stg_object.name]['owner']
        tpg = lun.parent_tpg

        if not tpg_ip_address:
            # just need to check one portal
            for ip in tpg.network_portals:
                tpg_ip_address = normalize_ip_address(ip.ip_address)
                break

        if tpg_ip_address is None:
            # this is being run during boot so the NP is not setup yet.
            return

        target_config = config.config["targets"][self.iqn]

        is_owner = False
        if target_config['portals'][owning_gw][
                "portal_ip_address"] == tpg_ip_address:
            is_owner = True

        try:
            alua_tpg = alua_create_group(settings.config.alua_failover_type,
                                         tpg, stg_object, is_owner)
        except CephiSCSIInval:
            raise
        except RTSLibError:
            self.logger.info("ALUA group id {} for stg obj {} lun {} "
                             "already made".format(tpg.tag, stg_object, lun))
            group_name = alua_format_group_name(
                tpg, settings.config.alua_failover_type, is_owner)
            # someone mapped a LU then unmapped it without deleting the
            # stg_object, or we are reloading the config.
            alua_tpg = ALUATargetPortGroup(stg_object, group_name)
            if alua_tpg.tg_pt_gp_id != tpg.tag:
                # ports and owner were rearranged. Not sure we support that.
                raise CephiSCSIInval("Existing ALUA group tag for group {} "
                                     "in invalid state.\n".format(group_name))

            # drop down in case we are restarting due to error and we
            # were not able to bind to a lun last time.

        self.logger.info(
            "Setup group {} for {} on tpg {} (state {}, owner {}, "
            "failover type {})".format(alua_tpg.name, stg_object.name, tpg.tag,
                                       alua_tpg.alua_access_state, is_owner,
                                       alua_tpg.alua_access_type))

        self.logger.debug("Setting Luns tg_pt_gp to {}".format(alua_tpg.name))
        lun.alua_tg_pt_gp_name = alua_tpg.name
        self.logger.debug("Bound {} on tpg{} to {}".format(
            stg_object.name, tpg.tag, alua_tpg.name))