Exemplo n.º 1
0
def get_addAndModifyDomainList(ip, domainList):
    addDomainList = []
    modifyDomainList = []
    for domain in domainList:
        domain_name = domain['DomainName']
        # logger.debug('domain:{}',domain_name)
        describeDomainRecordsRequest = DescribeDomainRecordsRequest()
        describeDomainRecordsRequest.set_TypeKeyWord(type_keyWord)
        describeDomainRecordsRequest.set_RRKeyWord(rr_keyWord)
        describeDomainRecordsRequest.set_PageNumber(1)
        describeDomainRecordsRequest.set_PageSize(10)
        describeDomainRecordsRequest.set_DomainName(domain_name)
        describeDomainRecordsResponse = client.do_action_with_exception(
            describeDomainRecordsRequest)
        describeDomainRecords = json.loads(
            str(describeDomainRecordsResponse, encoding='utf-8'))
        # logger.debug('domain:{}',describeDomainRecords)
        if describeDomainRecords['TotalCount'] > 0:
            record = describeDomainRecords['DomainRecords']['Record'][0]
            # logger.debug('record :{}', record)
            if ip != record['Value']:
                {'domain_name': domain_name, 'old_ip': record['Value']}
                modifyDomainList.append({
                    'domain_name': domain_name,
                    'old_ip': record['Value']
                })
        else:
            addDomainList.append(domain_name)
    logger.debug('addDomainList:{}', addDomainList)
    logger.debug('modifyDomainList:{}', modifyDomainList)
    return addDomainList, modifyDomainList
Exemplo n.º 2
0
def fetch_records(domain: str, access_key_dict: dict, domain_dict: dict):
    item = domain_dict[domain]
    ak_ref = item['accesskey']
    ak_item = access_key_dict[ak_ref]
    client = AcsClient(ak_item['id'], ak_item['secret'], ak_item['area'])
    item['client'] = client
    request = DescribeDomainRecordsRequest()
    request.set_accept_format('json')
    request.set_DomainName(domain)
    request.set_PageNumber('1')
    request.set_Type('A')
    request.set_PageSize('500')
    all_records = []
    for host in item['hosts']:
        if item['hosts'][host] is not None:
            request.set_SearchMode('LIKE')
            request.set_KeyWord('.' + host)
        else:
            request.set_SearchMode('EXACT')
            request.set_KeyWord(host)
        try:
            resp = to_dict(client.do_action_with_exception(request))
            domain_records = resp['DomainRecords']
            if resp['TotalCount'] > 0 and domain_records is not None and len(
                    domain_records['Record']) > 0:
                all_records.extend(domain_records['Record'])
        except ServerException as err:
            print("   ERROR: {}".format(err.get_error_msg()))
    return all_records
Exemplo n.º 3
0
 def get_record_page(self, domain_name, page_number=1):
     request = DescribeDomainRecordsRequest()
     request.set_accept_format('json')
     request.set_PageNumber(page_number)
     request.set_PageSize(self.page_size)
     request.set_DomainName(domain_name)
     response = self.__client.do_action_with_exception(request)
     return json.loads(str(response, encoding="utf8"))['DomainRecords']
Exemplo n.º 4
0
 def _get_domain_records_by_page(self, domain, rr, record_type, page_no):
     desc_domain_req = DescribeDomainRecordsRequest()
     desc_domain_req.set_DomainName(domain)
     desc_domain_req.set_accept_format("JSON")
     desc_domain_req.set_PageNumber(page_no)
     if rr is not None:
         desc_domain_req.set_RRKeyWord(rr)
     if record_type is not None:
         desc_domain_req.set_TypeKeyWord(record_type)
     desc_domain_res = self.clt.do_action_with_exception(desc_domain_req)
     return json.loads(desc_domain_res)
Exemplo n.º 5
0
    def get_dns_domain(self, format, page, limit, domain):
        from aliyunsdkalidns.request.v20150109.DescribeDomainRecordsRequest import DescribeDomainRecordsRequest
        request = DescribeDomainRecordsRequest()

        request.set_accept_format(format)
        request.set_DomainName(domain)
        request.set_PageNumber(page)
        request.set_PageSize(limit)
        try:
            response = self.client.do_action_with_exception(request)
        except:
            return False
        return response
Exemplo n.º 6
0
    def get(self, request, format=None):
        domain_name = request.GET.get('domain_name')
        page = request.GET.get('page')
        per_page = request.GET.get('per_page')

        client = settings.ALIAPI_LINGFANNAO
        req = DescribeDomainRecordsRequest()
        req.set_accept_format('json')

        req.set_DomainName(domain_name)
        req.set_PageNumber(page)
        req.set_PageSize(per_page)

        res = client.do_action_with_exception(req).decode('utf-8')

        return Response(json.loads(res))
Exemplo n.º 7
0
    def get_domain_records(self, domain_name, page_num=1, page_size=20):
        '''
        获取域名解析记录列表
        '''
        request = DescribeDomainRecordsRequest()
        request.set_accept_format('json')
        request.set_DomainName(domain_name)
        request.set_PageNumber(page_num)
        request.set_PageSize(page_size)

        data = self._request(request)
        total = data.get('TotalCount')
        data = data.get('DomainRecords')
        data_list = data.get('Record')
        data = {
            'total': total,
            'data_list': data_list,
        }
        return data
    def __get_total_page_num(self, domainName, PageNum=1, PageSize=1):
        '''
        获取解析记录页数
        :param domainName: 域名
        :return:
        '''
        request = DescribeDomainRecordsRequest()
        request.set_DomainName(domainName)
        request.set_PageNumber(PageNum)
        request.set_PageSize(PageSize)
        response = self.__do_action(request)
        if self.TotalPageNum != 0:
            return response['DomainRecords']['Record']

        else:
            if int(response['TotalCount']) % self.PageSize != 0:
                self.TotalPageNum = int(
                    response['TotalCount'] / self.PageSize) + 1
            else:
                self.TotalPageNum = int(response['TotalCount'] / self.PageSize)
            return self.TotalPageNum