def add_dns_record(ali_api_id, ali_api_secret, ip, request_domain, request_sub_domain): client = AcsClient(ali_api_id, ali_api_secret, 'cn-hangzhou') request = AddDomainRecordRequest() request.set_accept_format('json') request.set_DomainName(request_domain) request.set_RR(request_sub_domain) request.set_Type("A") request.set_Value(ip) try: response = client.do_action_with_exception(request) except (ClientException, ServerException) as reason: log.error("add dns failed. do_action_with_exception " + reason) return False result = str(response, encoding='utf-8') log.info("add dns record result: \r\n" + result) json_obj = json.loads(result) if len(json_obj['RecordId']) == 0: log.error("add dns failed. error code " + json_obj['code']) return False return True
def getRecords(client, rr, domain): request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(domain) request.set_RRKeyWord(rr) response = client.do_action_with_exception(request) print(str(response, encoding='utf-8')) jsonData = json.loads(response) return jsonData['DomainRecords']['Record']
def check_records(dns_domain): clt = client.AcsClient(access_key_id, access_key_secret, 'cn-hangzhou') request = DescribeDomainRecordsRequest.DescribeDomainRecordsRequest() request.set_DomainName(dns_domain) request.set_accept_format(ali_format) request.set_RRKeyWord(ali_domain_rr) result = clt.do_action(request) result = json.loads(result) return result
def addDomainRecord(client, rr, domain, ip, type): request = AddDomainRecordRequest() request.set_accept_format('json') request.set_Value(ip) request.set_Type(type) request.set_RR(rr) request.set_DomainName(domain) response = client.do_action_with_exception(request) print(str(response, encoding='utf-8')) return json.loads(response)['RecordId']
def getRecord(_rr): request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(domain) response = client.do_action_with_exception(request) response = json.loads(response.decode("UTF-8")) for item in response["DomainRecords"]["Record"]: if item['RR'] == _rr: return item
def add_record(client, priority, ttl, record_type, value, rr, domainname): request = AddDomainRecordRequest() request.set_accept_format('json') request.set_Priority(priority) request.set_TTL(ttl) request.set_Value(value) request.set_Type(record_type) request.set_RR(rr) request.set_DomainName(domainname) response = client.do_action_with_exception(request) response = str(response, encoding='utf-8') relsult = json.loads(response) return relsult
def getAliyunDnsRecord(self): try: request = DescribeDomainRecordsRequest.DescribeDomainRecordsRequest( ) request.set_PageSize(99) request.set_PageNumber(1) request.set_action_name("DescribeDomainRecords") request.set_DomainName(self.domain_name) # request.set_RRKeyWord(self.rr_keyword) request.set_TypeKeyWord(self.record_type) r = self.client.do_action_with_exception(request) return json.loads(r.decode('utf-8')) except Exception as e: print(e) return None
def GetDNSRecord(yaml_data, client, DomainName): try: request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(DomainName) response = client.do_action_with_exception(request) json_data = json.loads(str(response, encoding='utf-8')) for Record in json_data['DomainRecords']['Record']: if yaml_data['DnsData']['RR'] == Record['RR']: return Record except Exception as e: print("获取RecordId失败") print(e) sys.exit(-1)
def get_dns_record(ali_api_id, ali_api_secret, request_domain, request_sub_domain): client = AcsClient(ali_api_id, ali_api_secret, 'cn-hangzhou') request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(request_domain) request.set_PageSize("500") request.set_RRKeyWord(request_sub_domain) request.set_TypeKeyWord("A") try: response = client.do_action_with_exception(request) except (ClientException, ServerException) as reason: log.error("get dns failed. do_action_with_exception " + reason) return DnsRecord() result = str(response, encoding='utf-8') log.info("get dns record result: \r\n" + result) json_obj = json.loads(result) domain_records = json_obj['DomainRecords'] records = domain_records['Record'] ali_dns_record = DnsRecord() for record in records: if record['RR'] == request_sub_domain and record[ 'DomainName'] == request_domain: ali_dns_record.domain_name = record['DomainName'] ali_dns_record.record_id = record['RecordId'] ali_dns_record.rr = record['RR'] ali_dns_record.dr_type = record['Type'] ali_dns_record.value = record['Value'] else: continue return ali_dns_record