def show_conflicts(request): """ This view is temporary. It can be used to convert a system using KV objects for dhcp into the new Sreg and HW scheme. """ if request.GET: search = request.GET.get('search', '') records, error = search_type(search, 'SYS') try: total = records.count() records = records except MySQLdb.OperationalError, e: if "Got error " in str(e) and " from regexp" in str(e): # This is nasty. If the user is using an invalid regex # patter, the db might shit a brick total = 0 records = [] else: raise return render(request, 'slurpee/conflicts.html', { 'search': search, 'total': total, 'records': records, 'get_conflicts': get_conflicts, 'getattr': getattr })
def record_search_ajax(request): """ This function will return a list of records matching the 'query' of type 'record_type'. It's used for ajaxy stuff. """ query = request.GET.get('query', '') record_type = request.GET.get('record_type', '') obj_meta = get_obj_meta(record_type) if not record_type: raise Http404 if not query and record_type: return render(request, 'record/record_search_results.html', { 'objs': [], 'record_type': record_type, }) if not obj_meta.Klass: raise Http404 records, error = search_type(query, record_type) if error: total_obj_count = 0 records = [] else: try: total_obj_count = records.count() records = records[:50] except DatabaseError, e: if "Got error " in str(e) and " from regexp" in str(e): # This is nasty. If the user is using an invalid regex patter, # the db might shit a brick total_obj_count = 0 records = [] else: raise
def show_conflicts(request): """ This view is temporary. It can be used to convert a system using KV objects for dhcp into the new Sreg and HW scheme. """ if request.GET: search = request.GET.get('search', '') records, error = search_type(search, 'SYS') try: total = records.count() records = records except MySQLdb.OperationalError, e: if "Got error " in str(e) and " from regexp" in str(e): # This is nasty. If the user is using an invalid regex # patter, the db might shit a brick total = 0 records = [] else: raise return render( request, 'slurpee/conflicts.html', { 'search': search, 'total': total, 'records': records, 'get_conflicts': get_conflicts, 'getattr': getattr })
def record_search_ajax(request): """ This function will return a list of records matching the 'query' of type 'record_type'. It's used for ajaxy stuff. """ query = request.GET.get("query", "") record_type = request.GET.get("record_type", "") obj_meta = get_obj_meta(record_type) if not record_type: raise Http404 if not query and record_type: return render(request, "record/record_search_results.html", {"objs": [], "record_type": record_type}) if not obj_meta.Klass: raise Http404 records, error = search_type(query, record_type) if error: records = [] else: try: records = records[:50] except MySQLdb.OperationalError, e: if "Got error " in str(e) and " from regexp" in str(e): # This is nasty. If the user is using an invalid regex patter, # the db might shit a brick records = [] else: raise
def combine_status_list(request): """ This view is temporary. It can be used to convert a system using KV objects for dhcp into the new Sreg and HW scheme. """ def get(thing, default): if thing in request.POST: return request.POST.get(thing) return request.GET.get(thing, default) qd = request.POST or request.GET if qd: convert_everything = get('convert-everything', False) search = get('search', '') records, error = search_type(search, 'SYS') if not search or error: records = [] total = 0 else: try: total = records.count() records = records except MySQLdb.OperationalError, e: if "Got error " in str(e) and " from regexp" in str(e): # This is nasty. If the user is using an invalid regex # patter, the db might shit a brick total = 0 records = [] else: raise bundles = [] for system in records: for name in generate_possible_names(system.hostname): bundles += generate_sreg_bundles(system, name) if convert_everything: combine_multiple(bundles, rollback=False) bundles = [] else: combine_multiple(bundles, rollback=True) return render(request, 'static_reg/combine_status_list.html', { 'bundles': bundles, 'search': search, 'total': total })
def service_export(request): if request.method == 'POST': return HttpResponse(status=405) # Method Not Allowed search = request.GET.get('search', '') if not search: return HttpResponse( {'errors': "Please query about a service to export"}, status=400) services, error = search_type(search, 'SERVICE') if error: return HttpResponse(json.dumps({'errors': str(error)}), status=400) return HttpResponse( json.dumps({'services': Service.export_services(services)}))
def ajax_type_search(request): query = request.GET.get('query', '') record_type = request.GET.get('record_type', '') if not record_type: raise Http404 records, error = search_type(query, record_type) if not query: return HttpResponse(json.dumps({record_type: []})) if error: records = [] else: try: records = records[:50] except DatabaseError, e: if "Got error " in str(e) and " from regexp" in str(e): # This is nasty. If the user is using an invalid regex patter, # the db might shit a brick records = [] else: raise
def service_export(request): if request.method == 'POST': return HttpResponse(status=405) # Method Not Allowed search = request.GET.get('search', '') if not search: return HttpResponse( {'errors': "Please query about a service to export"}, status=400 ) services, error = search_type(search, 'SERVICE') if error: return HttpResponse( json.dumps({'errors': str(error)}), status=400 ) return HttpResponse(json.dumps({ 'services': Service.export_services(services) }))
def iql_to_service(cls, iql_stmt, bad_iql_error=None, no_services_error=None, ambiguous_error=None): # Note: there is an import loop in the global scope from core.search.compiler.django_compile import search_type services, error = search_type(iql_stmt, 'SERVICE') if error: raise bad_iql_error or ValueError( "When resolving IQL '{0}' got error " "'{1}'".format(iql_stmt, error) ) if not services: raise no_services_error or ValueError( "When resolving IQL '{0}' no services were found" .format(iql_stmt) ) if len(services) > 1: raise ambiguous_error or ValueError( "When resolving IQL '{0}' multiple services were returned" .format(iql_stmt) ) return services[0]
def iql_to_service(cls, iql_stmt, bad_iql_error=None, no_services_error=None, ambiguous_error=None): # Note: there is an import loop in the global scope from core.search.compiler.django_compile import search_type services, error = search_type(iql_stmt, 'SERVICE') if error: raise bad_iql_error or ValueError( "When resolving IQL '{0}' got error " "'{1}'".format(iql_stmt, error)) if not services: raise no_services_error or ValueError( "When resolving IQL '{0}' no services were found".format( iql_stmt)) if len(services) > 1: raise ambiguous_error or ValueError( "When resolving IQL '{0}' multiple services were returned". format(iql_stmt)) return services[0]