Пример #1
0
 def _find_or_create_pool(self,
                          td,
                          pools,
                          label,
                          _type,
                          values,
                          monitor_id=None):
     for pool in pools:
         if pool.label != label:
             continue
         records = pool.rs_chains[0].record_sets[0].records
         record_values = sorted([r.address for r in records])
         if record_values == values:
             # it's a match
             return pool
     # we need to create the pool
     _class = {'A': DSFARecord, 'AAAA': DSFAAAARecord}[_type]
     records = [_class(v) for v in values]
     record_set = DSFRecordSet(_type,
                               label,
                               serve_count=len(records),
                               records=records,
                               dsf_monitor_id=monitor_id)
     chain = DSFFailoverChain(label, record_sets=[record_set])
     pool = DSFResponsePool(label, rs_chains=[chain])
     pool.create(td)
     return pool
Пример #2
0
    def _find_or_create_pool(self,
                             td,
                             pools,
                             label,
                             _type,
                             values,
                             monitor_id=None):
        for pool in pools:
            if pool.label != label:
                continue
            records = pool.rs_chains[0].record_sets[0].records

            def _filter_records(r):
                if hasattr(r, 'address'):
                    return r.address
                elif hasattr(r, 'cname'):
                    return r.cname
                elif hasattr(r, 'txtdata'):
                    return r.txtdata
                else:
                    return None

            record_values = sorted(map(_filter_records, records))
            if record_values == values:
                # it's a match
                return pool
        # we need to create the pool
        _class = {
            'A': DSFARecord,
            'AAAA': DSFAAAARecord,
            'CNAME': DSFCNAMERecord,
            'TXT': DSFTXTRecord
        }[_type]
        if isinstance(values, list):
            records = [_class(v) for v in values]
        else:
            records = [_class(values)]
        record_set = DSFRecordSet(_type,
                                  label,
                                  serve_count=len(records),
                                  records=records,
                                  dsf_monitor_id=monitor_id)
        chain = DSFFailoverChain(label, record_sets=[record_set])
        pool = DSFResponsePool(label, rs_chains=[chain])
        pool.create(td)
        return pool