コード例 #1
0
def domain_list(request):
    ''' 二级域名列表 '''
    # 之前的不标准,又无调用记录,不确定也无妨如何调用的
    if True:
        key = request.GET.get('key', 'merchant_shop').strip()
        try:
            item = DnsApiZone.objects.get(key=key)
        except DnsApiZone.DoesNotExist:
            response = simplejson.dumps({'success': False, 'msg': u'无效的请求'})
            return HttpResponse(response)
        model = item.zone
        if not model:
            response = simplejson.dumps({'success': False, 'msg': u'Zone不存在'})
            return HttpResponse(response)
        zone = Zone(model)
        records = zone.get_records(search=None, temp=True, whole=True)
        lists = [
            record['domain'].split('.yhd.com.')[0] for record in records
            if record['rrtype'] == 'CNAME'
            and record['rrdata'] == 'merchant-shop.yhd.com.yhcdn.cn.'
        ]
        response = simplejson.dumps({
            'success': True,
            'total': len(lists),
            'lists': lists
        })
        return HttpResponse(response)
コード例 #2
0
def record_list(request):
    if request.method == 'GET':
        dns_zone_id = request.GET.get('dns_zone_id', 0)

        owner = None
        if is_dba(request):  # DB管理员所属组
            owner = 3
        # owner = 3  # debug
        search = request.GET.get('search', '').strip()

        try:
            model = DnsZone.objects.get(id=dns_zone_id)
        except DnsZone.DoesNotExist:
            return Response('Zone文件不存在', status=status.HTTP_404_NOT_FOUND)

        zone = Zone(model)
        if owner is not None:
            zone.owner = owner
            records = zone.get_records(search, whole=False)
        else:
            records = zone.get_records(search)

        id_ = request.GET.get('id', None)
        id_ = int(id_) if id_ and id_.isdigit() else None
        if id_ is not None:
            result = None
            for record in records:
                if record['id'] == id_:
                    result = record
                    break
            if result is not None:
                return Response(result, status=status.HTTP_200_OK)
            else:
                # 可能有问题!!!!!
                return Response('记录不存在,可能已被删除',
                                status=status.HTTP_404_NOT_FOUND)
        else:
            return Response({'count': len(records), 'results': records})