初始化3
This commit is contained in:
@@ -102,7 +102,7 @@ class DnsService:
|
||||
|
||||
def list_records(self, domain_zone, rr_keyword=None, record_type=None):
|
||||
"""
|
||||
获取域名解析记录列表
|
||||
获取域名解析记录列表(自动分页,拉取全部记录)
|
||||
|
||||
Args:
|
||||
domain_zone: 主域名 (如 zgitm.com)
|
||||
@@ -112,31 +112,53 @@ class DnsService:
|
||||
Returns:
|
||||
list[dict]: 解析记录列表
|
||||
"""
|
||||
params = {'DomainName': domain_zone}
|
||||
params = {
|
||||
'DomainName': domain_zone,
|
||||
'PageSize': '100', # 每页最大100条
|
||||
}
|
||||
if rr_keyword:
|
||||
params['RRKeyWord'] = rr_keyword
|
||||
if record_type:
|
||||
params['Type'] = record_type
|
||||
|
||||
resp = self._call('DescribeDomainRecords', params)
|
||||
records = resp.get('DomainRecords', {}).get('Record', [])
|
||||
# 统一转列表
|
||||
if isinstance(records, dict):
|
||||
records = [records]
|
||||
all_records = []
|
||||
page_number = 1
|
||||
total_count = None
|
||||
|
||||
result = []
|
||||
for r in records:
|
||||
result.append({
|
||||
'record_id': r.get('RecordId', ''),
|
||||
'rr': r.get('RR', ''),
|
||||
'type': r.get('Type', 'A'),
|
||||
'value': r.get('Value', ''),
|
||||
'ttl': r.get('TTL', 600),
|
||||
'line': r.get('Line', 'default'),
|
||||
'status': r.get('Status', 'ENABLE'),
|
||||
'full_domain': (r.get('RR', '') + '.' + domain_zone).strip('.'),
|
||||
})
|
||||
return result
|
||||
while True:
|
||||
params['PageNumber'] = str(page_number)
|
||||
resp = self._call('DescribeDomainRecords', params)
|
||||
|
||||
domain_records = resp.get('DomainRecords', {})
|
||||
records = domain_records.get('Record', [])
|
||||
|
||||
if total_count is None:
|
||||
total_count = domain_records.get('TotalCount', 0)
|
||||
logger.info(f'DNS 记录总数: {total_count}, 开始分页拉取...')
|
||||
|
||||
# 统一转列表(单条记录时阿里云返回 dict)
|
||||
if isinstance(records, dict):
|
||||
records = [records]
|
||||
|
||||
for r in records:
|
||||
all_records.append({
|
||||
'record_id': r.get('RecordId', ''),
|
||||
'rr': r.get('RR', ''),
|
||||
'type': r.get('Type', 'A'),
|
||||
'value': r.get('Value', ''),
|
||||
'ttl': r.get('TTL', 600),
|
||||
'line': r.get('Line', 'default'),
|
||||
'status': r.get('Status', 'ENABLE'),
|
||||
'full_domain': (r.get('RR', '') + '.' + domain_zone).strip('.'),
|
||||
})
|
||||
|
||||
# 判断是否还有下一页
|
||||
if len(all_records) >= total_count or len(records) < 100:
|
||||
break
|
||||
page_number += 1
|
||||
|
||||
logger.info(f'DNS 记录拉取完成: zone={domain_zone}, 共 {len(all_records)} 条')
|
||||
return all_records
|
||||
|
||||
def add_record(self, domain_zone, rr, record_type, value, ttl=600):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user