コード例 #1
0
    def target_available_here(self, host, mgs, local_info):
        if local_info["mounted"]:
            return True

        target_nids = []
        if "failover.node" in local_info["params"]:
            for failover_str in local_info["params"]["failover.node"]:
                target_nids.extend(failover_str.split(","))

        if mgs:
            mgs_host = mgs.primary_host
            fs_name, target_name = local_info["name"].rsplit("-", 1)
            try:
                mgs_target_info = None
                for t in self.all_hosts_data[mgs_host]["mgs_targets"][fs_name]:
                    if t["name"] == local_info["name"]:
                        mgs_target_info = t
                if not mgs_target_info:
                    raise KeyError
            except KeyError:
                log.warning(
                    "Saw target %s on %s:%s which is not known to mgs %s" %
                    (local_info["name"], host, local_info["device_paths"],
                     mgs_host))
                return False
            primary_nid = mgs_target_info["nid"]
            target_nids.append(primary_nid)

        target_nids = set(normalize_nid(nid) for nid in target_nids)
        if set(host.lnet_configuration.get_nids()) & target_nids:
            return True
        else:
            return False
コード例 #2
0
    def learn_primary_target(self, managed_target):

        primary_target = None
        managed_target.managedtargetmount_set.update(primary=False)
        for tm in managed_target.managedtargetmount_set.all():
            # We may well have scanned a subset of the hosts and so not have data for all the target mounts, if we
            # are rescanning we can know about targetmounts we didn't scan.
            if tm.host not in self.all_hosts_data:
                continue

            try:
                target_info = next(
                    dev
                    for dev in self.all_hosts_data[tm.host]["local_targets"]
                    if dev["uuid"] == managed_target.uuid)
            except StopIteration:
                # LV not in all_hosts_data
                continue
            local_nids = set(tm.host.lnet_configuration.get_nids())

            if not local_nids:
                raise NoNidsPresent("Host %s has no NIDS!" % tm.host)

            if "failover.node" in target_info["params"]:
                failover_nids = set(
                    normalize_nid(n)
                    for nids in target_info["params"]["failover.node"]
                    for n in nids.split(","))

                if not bool(local_nids & failover_nids):
                    # In the case the current nids is not shown in the failover nids
                    # This target is considered primary and has been created with mkfs.lustre --failnode
                    # There isn't any other possibilities to have another primary defined
                    primary_target = tm
                    break
                elif target_info["mounted"]:
                    # In the case the target has been created with 'mkfs.lustre --servicenodes'
                    # If it is mounted, we use the current target as primary until we found a better candidate
                    primary_target = tm
            else:
                # If there are no failover nids then this must be the primary.
                primary_target = tm
                break

        if primary_target != None:
            log.info("Target %s has been set to primary" % (primary_target))
            primary_target.primary = True
            primary_target.save()
            ObjectCache.update(primary_target)

        return primary_target
コード例 #3
0
    def _target_find_mgs(self, host, local_info):
        # Build a list of MGS nids for this local target
        tgt_mgs_nids = []
        try:
            # NB I'm not sure whether tunefs.lustre will give me
            # one comma-separated mgsnode, or a series of mgsnode
            # settings, so handle both
            for n in local_info["params"]["mgsnode"]:
                tgt_mgs_nids.extend(n.split(","))
        except KeyError:
            # 'mgsnode' doesn't have to be present
            pass

        tgt_mgs_nids = set(normalize_nid(nid) for nid in tgt_mgs_nids)
        return self._nids_to_mgs(host, tgt_mgs_nids)
コード例 #4
0
    def _substitutions(self, obj):
        message = obj.message
        from chroma_api import api_log
        from chroma_api.urls import api

        from chroma_core.models import ManagedHost, ManagedTarget
        import re

        substitutions = []

        def substitute(obj, match, group=1):
            resource_uri = api.get_resource_uri(obj)
            substitutions.append({
                "start": match.start(group),
                "end": match.end(group),
                "label": obj.get_label(),
                "resource_uri": resource_uri,
            })

        # TODO: detect other NID types (cray?)
        nid_regex = re.compile("(\d{1,3}\.){3}\d{1,3}@(tcp|ib)(_\d+)?")
        target_regex = re.compile("[^\w](\w{1,8}-(MDT|OST)[\da-f]{4})")
        for match in nid_regex.finditer(message):
            nid = match.group(0)
            nid = normalize_nid(nid)
            try:
                host = ManagedHost.get_by_nid(nid)
            except ManagedHost.DoesNotExist:
                api_log.warn("No host has NID %s" % nid)
                continue
            except ManagedHost.MultipleObjectsReturned:
                api_log.warn("Multiple hosts have NID %s" % nid)
                continue
            if host.state != "removed":
                substitute(host, match, 0)

        for match in target_regex.finditer(message):
            target_name = match.group(1)
            for target in ManagedTarget.objects.filter(name=target_name)[:1]:
                substitute(target, match)

        return sorted(substitutions, key=lambda sub: sub["start"])