Display records for a domain.
185882
def list(gandi, fqdn, name, sort, type, rrset_type, text):
    """"""
    domains = gandi.dns.list()
    domains = [domain['fqdn'] for domain in domains]
    if fqdn not in domains:
        gandi.echo('Sorry domain %s does not exist' % fqdn)
        gandi.echo('Please use one of the following: %s' % ', '.join(domains))
        return

    output_keys = ['name', 'ttl', 'type', 'values']

    result = gandi.dns.records(fqdn, sort_by=sort, text=text)
    if text:
        gandi.echo(result)
        return result

    for num, rec in enumerate(result):
        if type and rec['rrset_type'] != type:
            continue
        if rrset_type and rec['rrset_type'] != rrset_type:
            continue
        if name and rec['rrset_name'] != name:
            continue
        if num:
            gandi.separator_line()
        output_dns_records(gandi, rec, output_keys)

    return result
474926
def _list_records_internal(self, identifier=None, rtype=None, name=None, content=None):
        """"""
        response = self._request_get_dns_zone()
        if 'records' in response:
            # Interpret empty string as None because zeep does so too
            content_check = content if content != "" else None
            name_check = self._relative_name(name)

            # Stringize the identifier to prevent any rtype differences
            identifier_check = str(
                identifier) if identifier is not None else None

            filtered_records = [
                record for record in response['records'] if (
                    identifier is None or str(
                        record['id']) == identifier_check) and (
                            rtype is None or record['type'] == rtype) and (
                                name is None or record['name'] == name_check) and (
                                    content is None or (
                                        'content' in record
                                        and record['content'] == content_check))]
            records = [self._create_response_record(
                filtered_record) for filtered_record in filtered_records]
        else:
            records = []
        return records
1098401
def search_records(self, domain, record_type, name=None, data=None):
        
        return domain.search_records(record_type=record_type,
                name=name, data=data)
1311896
def _raw_records(self, identifier=None, rtype=None, name=None, content=None):
        """"""
        record_fields = {
            'id': identifier,
            'type': rtype,
            'hostname': name and self._relative_name(name),
            'destination': content,
        }
        # type/hostname/destination of the dnsrecord type are mandatory (even
        # when deleting), and must be queried if not all were specified:
        if all(record_fields.values()):
            return [record_fields]
        data = self._apicall('infoDnsRecords', domainname=self.domain)
        records = data.get('dnsrecords', [])
        return [
            record for record in records
            if all(record[k] == v for k, v in record_fields.items() if v)
        ]
602933
def filter_by_domain(self, domain):
        
        query = self._copy()
        query.domain = domain
        return query
396944
def domain_whois_history(self, domain, limit=None):
        ''''''

        params = dict()
        if limit is not None:
            params['limit'] = limit

        uri = self._uris["whois_domain_history"].format(domain)
        resp_json = self.get_parse(uri, params)
        return resp_json
129613
def create_record(self, domain, name, _type, data, params=None):
        ''' 
        '''
        params = update_params(params, {
            'domain': domain,
            'name': name,
            'type': _type,
            'data': data
        })
        return self.request('/v1/dns/create_record', params, 'POST')
783438
def index():
    """"""
    # Prepare mappings from configuration.
    mapping = cfg['UNAPI_FORMAT_MAPPING']
    names = {mapping[k]: k for k in mapping}
    # Clean request arguments.
    identifier = request.values.get('id', type=int)
    format_ = request.values.get('format')
    format_ = mapping.get(format_, format_)
    # Redirect to correct record format.
    if identifier and format_:
        return redirect(url_for('record.metadata', recid=identifier,
                                of=format_))

    formats = [{
        'name': names[of],
        'type': values['content_type'],
        'docs': values.get('url'),
    } for of, values in iteritems(output_formats) if of in names]

    response = make_response(render_template(
        'unapi/index.xml', identifier=identifier, formats=formats))
    response.headers['Content-Type'] = 'application/xml'
    return response
488584
def _request_add_dns_record(self, record):
        """"""
        return self._request_internal("Add_DNS_Record",
                                      domain=self.domain,
                                      record=record)
227471
def _list_records(self, rtype=None, name=None, content=None):
        
        with self._session(self.domain, self.domain_id) as ddata:
            name = self._fqdn_name(name) if name else None
            return self._list_records_in_zone(ddata['zone']['data'], rtype, name, content)
418711
def query_mxrecords(self):
        
        import dns.resolver
        logging.info('Resolving DNS query...')
        answers = dns.resolver.query(self.domain, 'MX')
        addresses = [answer.exchange.to_text() for answer in answers]
        logging.info(
            '{} records found:\n{}'.format(
                len(addresses), '\n  '.join(addresses)))
        return addresses
17502
def del_record(cls, fqdn, name, type):
        """"""
        meta = cls.get_fqdn_info(fqdn)
        url = meta['domain_records_href']
        delete_url = url
        if name:
            delete_url = '%s/%s' % (delete_url, name)
        if type:
            delete_url = '%s/%s' % (delete_url, type)
        return cls.json_delete(delete_url)
1206190
def get_subdomain_record(self, fqn, include_history=False):
        
        if not check_subdomain(fqn):
            return {'error': 'invalid subdomain', 'http_status': 400}
        
        fqn = str(fqn)

        # get current record
        subdomain_rec = get_subdomain_info(fqn, check_pending=True)
        if subdomain_rec is None:
            return {'error': 'Failed to load subdomain', 'http_status': 404}
   
        ret = subdomain_rec.to_json()
        if include_history:
            subdomain_hist = get_subdomain_history(fqn, json=True)
            ret['history'] = subdomain_hist

        return {'status': True, 'record': ret}
927470
def update_record(self, domain, record, data=None, priority=None,
            ttl=None, comment=None):
        
        rdict = {"id": record.id,
                "name": record.name,
                }
        pdict = {"data": data,
                "priority": priority,
                "ttl": ttl,
                "comment": comment,
                }
        utils.params_to_dict(pdict, rdict)
        return self.update_records(domain, [rdict])
1054954
def update_records(self, domain, records):
        
        if not isinstance(records, list):
            raise TypeError("Expected records of type list")
        uri = "/domains/%s/records" % utils.get_id(domain)
        resp, resp_body = self._async_call(uri, method="PUT",
                body={"records": records},
                error_class=exc.DomainRecordUpdateFailed, has_response=False)
        return resp_body
1188403
private String[] queryInternal(Domain domain) throws IOException {
        Record[] records = null;
        if (domain.hostsFirst) {
            String[] ret = hosts.query(domain.domain);
            if (ret != null && ret.length != 0) {
                return ret;
            }
        }
        synchronized (cache) {
            if (Network.isNetworkChanged()) {
                cache.clear();
                synchronized (resolvers) {
                    index = 0;
                }
            } else {
                records = cache.get(domain.domain);
                if (records != null && records.length != 0) {
                    if (!records[0].isExpired()) {
                        rotate(records);
                        return records2Ip(records);
                    } else {
                        records = null;
                    }
                }
            }
        }

        IOException lastE = null;
        int firstOk = index;
        for (int i = 0; i < resolvers.length; i++) {
            int pos = (firstOk + i) % resolvers.length;
            String ip = Network.getIp();
            try {
                records = resolvers[pos].resolve(domain);
            } catch (DomainNotOwn e) {
                continue;
            } catch (IOException e) {
                lastE = e;
                e.printStackTrace();
            } catch (Exception e) {
                lastE = new IOException(e);
                e.printStackTrace();
            }
            String ip2 = Network.getIp();
            if ((records == null || records.length == 0) && ip.equals(ip2)) {
                synchronized (resolvers) {
                    if (index == firstOk) {
                        index++;
                        if (index == resolvers.length) {
                            index = 0;
                        }
                    }
                }
            } else {
                break;
            }
        }

        if (records == null || records.length == 0) {
            if (!domain.hostsFirst) {
                String[] rs = hosts.query(domain.domain);
                if (rs != null && rs.length != 0) {
                    return rs;
                }
            }
            if (lastE != null) {
                throw lastE;
            }
            throw new UnknownHostException(domain.domain);
        }
        records = trimCname(records);
        if (records.length == 0) {
            throw new UnknownHostException("no A records");
        }
        synchronized (cache) {
            cache.put(domain.domain, records);
        }
        return records2Ip(records);
    }
334644
def _list_records(self, rtype=None, name=None, content=None):
        """"""
        records = [
            {
                'id': record['id'],
                'type': record['type'],
                'name': self._full_name(record['hostname']),
                'content': record['destination'],
                'priority': record['priority'],
                'ttl': self.zone_ttl,
            }
            for record in self._raw_records(None, rtype, name, content)
        ]
        LOGGER.debug('list_records: %s', records)
        return records