Пример #1
0
 def __getRecordValue(self):
     self.__requireParmSet()
     # create request and set parm
     request = DescribeDomainRecordsRequest()
     request.set_DomainName(self.domain_name)
     request.set_TypeKeyWord(self.record_type)
     request.set_RRKeyWord(self.sub_domain_name)
     # execute
     res = self.__tryExecute(request)
     if res[0]:
         print "ok: " + res[1]
         resJsonObj = json.loads(res[1])
         for record in resJsonObj["DomainRecords"]["Record"]:
             if record["RR"] == self.sub_domain_name:
                 self.has_remote_record = True
                 self.record_id = record["RecordId"]
                 self.remote_record_value = record["Value"]
                 return True, record["Value"]
         self.has_remote_record = False
         self.record_id = ""
         self.remote_record_value = ""
         return True, None
     else:
         print "error: " + res[1]
         return res
Пример #2
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
Пример #3
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)
Пример #4
0
    def _find_domain_record_id(self, domain, rr='', typ='', value=''):
        request = DescribeDomainRecordsRequest()
        request.set_accept_format("json")

        request.set_DomainName(domain)
        request.set_TypeKeyWord(typ)
        request.set_RRKeyWord(rr)
        request.set_ValueKeyWord(value)

        records = json.loads(self._client.do_action_with_exception(request))

        for record in records['DomainRecords']['Record']:
            if record['RR'] == rr:
                return record['RecordId']
        raise errors.PluginError(
            'Unexpected error determining record identifier for {0}: {1}'.
            format(rr, 'record not found'))
Пример #5
0
    def get_domain_records(self,
                           domain_name: str,
                           host_record_keyword: str = None,
                           type_keyword: str = 'A',
                           value_keyword: str = None) -> dict:
        if not self._data_valid(domain_name):
            raise RuntimeError('缺少域名名称')

        request = DescribeDomainRecordsRequest()
        request.set_accept_format('json')

        request.set_DomainName(domain_name)
        # request.set_PageSize('100')
        if self._data_valid(host_record_keyword):
            request.set_RRKeyWord(host_record_keyword)
        request.set_TypeKeyWord(type_keyword)
        if self._data_valid(value_keyword):
            request.set_ValueKeyWord(value_keyword)

        response = self.client.do_action_with_exception(request)  # type: bytes
        response_data = json.loads(response.decode('utf-8'))
        return response_data
Пример #6
0
def get_domain_ip(domainname, rrkeyworld, _type):
    try:
        request = DescribeDomainRecordsRequest()
        request.set_accept_format('json')
        request.set_TypeKeyWord(_type)
        request.set_DomainName(domainname)
        request.set_RRKeyWord(rrkeyworld)

        response = client.do_action_with_exception(request)
        try:
            source_data = str(response, encoding='utf-8')
            print('请求数据成功')
        except Exception as e:
            print('请求数据失败')
            print(e)
            sys.exit()
        try:
            datas = json.loads(source_data)['DomainRecords']['Record'][0]
            print('找到主机记录')
        except Exception:
            print('没有找到主机记录')
            sys.exit()

        if datas:
            print('\t域名\t: ' + str(datas['RR'] + '.' + datas['DomainName']))
            print('\t类型\t: ' + str(datas['Type']))
            print('\t记录值\t: ' + str(datas['Value']))
            print('\tTTL\t: ' + str(datas['TTL']))
            print('\tStatus\t: ' + str(datas['Status']))
            return str(datas['Value']), str(datas['RR']), str(
                datas['RecordId']), str(datas['Type'])
        else:
            print('请求数据失败')
            print(source_data)
    except Exception as e:
        print('请求数据失败')
        print(e)