Exemple #1
0
 def get(self, request, domain_id):
     api = DomainInfo(domain_id, **get_login_pair(request))
     try:
         rep = api().get('domain')
     except Exception as e:
         rep = e.message
         return Response(rep, HTTP_406_NOT_ACCEPTABLE)
     return Response(rep)
Exemple #2
0
 def delete(self, request, domain_id):
     api = DomainRemove(domain_id, **get_login_pair(request))
     try:
         rep = api()
     except Exception as e:
         rep = e.message
         return Response(rep, HTTP_406_NOT_ACCEPTABLE)
     return Response(rep)
Exemple #3
0
 def get(self, request, domain_id):
     api = DomainInfo(domain_id, **get_login_pair(request))
     try:
         rep = api().get('domain')
     except Exception as e:
         rep = e.message
         return Response(rep, HTTP_406_NOT_ACCEPTABLE)
     return Response(rep)
Exemple #4
0
 def delete(self, request, domain_id):
     api = DomainRemove(domain_id, **get_login_pair(request))
     try:
         rep = api()
     except Exception as e:
         rep = e.message
         return Response(rep, HTTP_406_NOT_ACCEPTABLE)
     return Response(rep)
Exemple #5
0
    def get(self, request, domain_id, record_id):
        kwargs = get_login_pair(request)
        kwargs['domain_id'] = domain_id

        api = RecordInfo(record_id, **kwargs)
        try:
            rep = api().get('record')
        except Exception as e:
            rep = e.message
            return Response(rep, HTTP_406_NOT_ACCEPTABLE)
        return Response(rep)
Exemple #6
0
    def get(self, request, domain_id, record_id):
        kwargs = get_login_pair(request)
        kwargs['domain_id'] = domain_id

        api = RecordInfo(record_id, **kwargs)
        try:
            rep = api().get('record')
        except Exception as e:
            rep = e.message
            return Response(rep, HTTP_406_NOT_ACCEPTABLE)
        return Response(rep)
Exemple #7
0
 def post(self, request):
     try:
         domain = request.DATA['domain']
     except KeyError as e:
         return Response('need domain', HTTP_400_BAD_REQUEST)
     api = DomainCreate(domain, **get_login_pair(request))
     try:
         rep = api().get('domain')
     except Exception as e:
         rep = e.message
         return Response(rep, HTTP_406_NOT_ACCEPTABLE)
     return Response(rep)
Exemple #8
0
 def post(self, request):
     try:
         domain = request.DATA['domain']
     except KeyError as e:
         return Response('need domain', HTTP_400_BAD_REQUEST)
     api = DomainCreate(domain, **get_login_pair(request))
     try:
         rep = api().get('domain')
     except Exception as e:
         rep = e.message
         return Response(rep, HTTP_406_NOT_ACCEPTABLE)
     return Response(rep)
Exemple #9
0
 def put(self, request, domain_id):
     try:
         status = request.DATA['status']
     except KeyError as e:
         return Response('need status {enable, disable}', HTTP_400_BAD_REQUEST)
     kwargs = get_login_pair(request)
     kwargs['domain_id'] = domain_id
     api = DomainStatus(status, **kwargs)
     try:
         rep = api()
         rep = {'status': status}
     except Exception as e:
         rep = e.message
         return Response(rep, HTTP_406_NOT_ACCEPTABLE)
     return Response(rep)
Exemple #10
0
 def put(self, request, domain_id):
     try:
         status = request.DATA['status']
     except KeyError as e:
         return Response('need status {enable, disable}',
                         HTTP_400_BAD_REQUEST)
     kwargs = get_login_pair(request)
     kwargs['domain_id'] = domain_id
     api = DomainStatus(status, **kwargs)
     try:
         rep = api()
         rep = {'status': status}
     except Exception as e:
         rep = e.message
         return Response(rep, HTTP_406_NOT_ACCEPTABLE)
     return Response(rep)
Exemple #11
0
    def get(self, request, domain_id):
        '''
            获得domain列表
        '''
        offset = request.GET.get('offset', 0)
        length = request.GET.get('length', 100)
        sub_domain = request.GET.get('sub_domain', None)

        kwargs = get_login_pair(request)
        kwargs['offset'] = offset
        kwargs['length'] = length
        if sub_domain:
            kwargs['sub_domain'] = sub_domain

        api = RecordList(domain_id, **kwargs)
        try:
            rep = api().get('records')
        except Exception as e:
            rep = e.message
            return Response(rep, HTTP_406_NOT_ACCEPTABLE)
        return Response(rep)
Exemple #12
0
    def put(self, request, domain_id, record_id):
        # 必填项
        kwargs = {}
        for attr, default in RECORD_NEED_MAPPER.iteritems():
            kwargs[attr] = request.DATA.get(attr, default)
            if not kwargs[attr]:
                return Response(u'need {args}'.format(args=e.message),
                                HTTP_400_BAD_REQUEST)
        if kwargs['record_type'] == 'MX':
            request.DATA['mx']

        # 添加登录参数
        kwargs.update(get_login_pair(request))
        kwargs['domain_id'] = domain_id
        api = RecordModify(record_id, **kwargs)
        try:
            rep = api()
        except Exception as e:
            rep = e.message
            return Response(rep, HTTP_406_NOT_ACCEPTABLE)
        return Response(rep)
Exemple #13
0
    def get(self, request, domain_id):
        '''
            获得domain列表
        '''
        offset = request.GET.get('offset', 0)
        length = request.GET.get('length', 100)
        sub_domain = request.GET.get('sub_domain', None)

        kwargs = get_login_pair(request)
        kwargs['offset'] = offset
        kwargs['length'] = length
        if sub_domain:
            kwargs['sub_domain'] = sub_domain

        api = RecordList(domain_id, **kwargs)
        try:
            rep = api().get('records')
        except Exception as e:
            rep = e.message
            return Response(rep, HTTP_406_NOT_ACCEPTABLE)
        return Response(rep)
Exemple #14
0
    def put(self, request, domain_id, record_id):
        # 必填项
        kwargs = {}
        for attr, default in RECORD_NEED_MAPPER.iteritems():
            kwargs[attr] = request.DATA.get(attr, default)
            if not kwargs[attr]:
                return Response(u'need {args}'.format(args=e.message),
                                HTTP_400_BAD_REQUEST)
        if kwargs['record_type'] == 'MX':
            request.DATA['mx']

        # 添加登录参数
        kwargs.update(get_login_pair(request))
        kwargs['domain_id'] = domain_id
        api = RecordModify(record_id, **kwargs)
        try:
            rep = api()
        except Exception as e:
            rep = e.message
            return Response(rep, HTTP_406_NOT_ACCEPTABLE)
        return Response(rep)
Exemple #15
0
    def get(self, request):
        '''
            获得domain列表
        '''
        domain_type = request.GET.get('type', 'all')
        offset = request.GET.get('offset', 0)
        length = request.GET.get('length', 100)

        kwargs = get_login_pair(request)
        kwargs['type'] = domain_type
        kwargs['offset'] = offset
        kwargs['length'] = length

        api = DomainList(**kwargs)
        try:
            rep = api().get('domains')
        except Exception as e:
            rep = e.message
            # 没有域名时返回空列表
            if rep['status']['code'] == '9':
                return Response([])
            return Response(rep, HTTP_406_NOT_ACCEPTABLE)
        return Response(rep)
Exemple #16
0
    def post(self, request, domain_id):
        # 必填项
        params = {}
        for attr, default in RECORD_NEED_MAPPER.iteritems():
            params[attr] = request.DATA.get(attr, default)
            if not params[attr]:
                return Response(u'need {args}'.format(args=attr),
                                HTTP_400_BAD_REQUEST)
        if params['record_type'] == 'MX':
            request.DATA['mx']

        # 添加登录参数
        kwargs = get_login_pair(request)
        kwargs['domain_id'] = domain_id
        need_list = ('sub_domain', 'record_type', 'record_line', 'value', 'ttl')
        args = (params[need] for need in need_list)
        api = RecordCreate(*args, **kwargs)
        try:
            rep = api()
        except Exception as e:
            rep = e.message
            return Response(rep, HTTP_406_NOT_ACCEPTABLE)
        return Response(rep)
Exemple #17
0
    def get(self, request):
        '''
            获得domain列表
        '''
        domain_type = request.GET.get('type', 'all')
        offset = request.GET.get('offset', 0)
        length = request.GET.get('length', 100)

        kwargs = get_login_pair(request)
        kwargs['type'] = domain_type
        kwargs['offset'] = offset
        kwargs['length'] = length

        api = DomainList(**kwargs)
        try:
            rep = api().get('domains')
        except Exception as e:
            rep = e.message
            # 没有域名时返回空列表
            if rep['status']['code'] == '9':
                return Response([])
            return Response(rep, HTTP_406_NOT_ACCEPTABLE)
        return Response(rep)
Exemple #18
0
    def post(self, request, domain_id):
        # 必填项
        params = {}
        for attr, default in RECORD_NEED_MAPPER.iteritems():
            params[attr] = request.DATA.get(attr, default)
            if not params[attr]:
                return Response(u'need {args}'.format(args=attr),
                                HTTP_400_BAD_REQUEST)
        if params['record_type'] == 'MX':
            request.DATA['mx']

        # 添加登录参数
        kwargs = get_login_pair(request)
        kwargs['domain_id'] = domain_id
        need_list = ('sub_domain', 'record_type', 'record_line', 'value',
                     'ttl')
        args = (params[need] for need in need_list)
        api = RecordCreate(*args, **kwargs)
        try:
            rep = api()
        except Exception as e:
            rep = e.message
            return Response(rep, HTTP_406_NOT_ACCEPTABLE)
        return Response(rep)