예제 #1
0
파일: dns.py 프로젝트: LukeCarrier/hn
    def do_add_record(params):
        """
        Add a record to an existing zone.
        """

        config = ConfigurationFactory.get('hypernova')
        server = get_authoritative_server(config['dns']['adapter'],
                                          config['dns'])

        try:
            zone = server.get_zone(params['zone'])
            record = Record(params['record']['name'],
                            params['record']['type'],
                            params['record']['content'],
                            params['record']['ttl'],
                            params['record']['priority'])
            server.add_record(zone, record)

            successful = True
            result = {'record': record.to_encodable()}
        except NonexistentZoneError:
            successful = False
            result = {'error': 'NonexistentZone'}

        return AgentRequestHandler._format_response(
            result,
            successful=successful
        )
예제 #2
0
파일: dns.py 프로젝트: LukeCarrier/hn
    def do_rm_record(params):
        """
        Remove a record.
        """

        config = ConfigurationFactory.get('hypernova')
        server = get_authoritative_server(config['dns']['adapter'],
                                          config['dns'])

        result = {'records': []}

        try:
            zone = server.get_zone(params['zone'])
            params['rtype'] = params['record'].pop('type')

            records = zone.filter_records_for(params['record'])
            for r in records:
                result['records'].append(r.to_encodable())
                server.rm_record(zone, r)

            successful = True

            if len(result['records']) == 0:
                successful = False
                result['error'] = 'NoMatchingRecords'

        except NonexistentZoneError:
            successful = False
            result = {'error': 'NonexistentZoneError'}

        return AgentRequestHandler._format_response(
            result,
            successful=successful
        )
예제 #3
0
파일: dns.py 프로젝트: LukeCarrier/hn
    def do_get_zone(params):
        """
        Get a zone.
        """

        config = ConfigurationFactory.get('hypernova')

        try:
            server = get_authoritative_server(config['dns']['adapter'],
                                              config['dns'])

            try:
                successful = True
                result     = {
                    'zone': server.get_zone(params['domain']).to_encodable(),
                }
            except NonexistentZoneError:
                successful = False
                result     = {'error': 'NonexistentZone'}
        except ServerCommunicationError:
            successful = False
            result     = {'error': 'ServerCommunication'}

        return AgentRequestHandler._format_response(
            result,
            successful=successful,
            error_code=0
        )
예제 #4
0
파일: dns.py 프로젝트: LukeCarrier/hn
    def do_add_zone(params):
        """
        Add a zone.
        """

        config = ConfigurationFactory.get('hypernova')

        try:
            result = {'error': 'ValidationError'}

            server = get_authoritative_server(config['dns']['adapter'],
                                              config['dns'])
            zone = Zone(new_domain=params['zone']['domain'],
                        new_origin=params['zone']['origin'],
                        new_ttl=params['zone']['ttl'])
            zone.soa_record = SoaRecord(new_primary_ns=params['soa']['primary_ns'],
                                        new_responsible_person=params['soa']['responsible_person'],
                                        new_serial=params['soa']['serial'],
                                        new_refresh=params['soa']['refresh'],
                                        new_retry=params['soa']['retry'],
                                        new_expire=params['soa']['expire'],
                                        new_min_ttl=params['soa']['min_ttl'])

            try:
                server.add_zone(zone)
                successful = True
                result = {'zone': zone.to_encodable()}
            except DuplicateZoneError:
                successful = False
                result = {'error': 'DuplicateZone'}

        except ServerCommunicationError:
            successful = False
            result = {'error': 'ServerCommunicationError'}

        return AgentRequestHandler._format_response(
            result,
            successful=successful,
            error_code=0
        )