def make_managed_host(self, hostname, domain="example.tld", save=True):
        """Create nodes, or reuse ones that are there already."""

        fqdn = "%s.%s" % (hostname, domain)
        host = ManagedHost(address=hostname, fqdn=fqdn, nodename=hostname)

        if save:
            host.save()

            CorosyncConfiguration(state="started", host=host).save()

            PacemakerConfiguration(state="started", host=host).save()

        return host
    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"])
示例#3
0
 def invoke(self, cmd, args={}, auth_args=None):
     host = ManagedHost(address=self.address)
     return MockAgentRpc._call(host, cmd, args)