Show
Ignore:
Timestamp:
05/12/10 14:10:28 (2 years ago)
Author:
Frederic Lepied <frederic.lepied@…>
Children:
36e3187115d175e2667c28737fdaccbd1fed1723
Parents:
a37e6686ba85de9cf2e143a6485dd63bceff9404
git-committer:
Frederic Lepied <frederic.lepied@…> (05/12/10 14:10:28)
Message:

allow to use IP addresses and sub-adresses instead of mac addresses

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pxe/views.py

    r5fc8fc0 r73db309  
    1313from pxe.models import * 
    1414 
     15def get_system(request, mac): 
     16    try: 
     17        return System.objects.get(macaddress__mac=simplify_mac(mac)) 
     18    except System.DoesNotExist: 
     19        pass 
     20 
     21    addr = request.META['REMOTE_ADDR'] 
     22    l = map(lambda x: '%02x' % int(x), addr.split('.')) 
     23    for i in range(len(l), 1, -1): 
     24        try: 
     25            return System.objects.get(macaddress__mac=''.join(l[0:i])) 
     26        except System.DoesNotExist: 
     27            pass 
     28    raise Http404 
     29 
    1530def localboot1(request): 
    1631    return localboot(request, get_mac(request)) 
    1732     
    1833def localboot(request, mac): 
    19     system = get_object_or_404(System, macaddress__mac=simplify_mac(mac)) 
     34    system = get_system(request, mac) 
    2035    set_next_boot(system, settings.PXE_LOCAL) 
    2136    return HttpResponse("Next boot set to local", mimetype="text/plain") 
     
    2540     
    2641def profile(request, mac): 
    27     system = get_object_or_404(System, macaddress__mac=simplify_mac(mac)) 
     42    system = get_system(request, mac) 
    2843    log = Log.objects.filter(system=system).order_by('-date')[0] 
    2944    return HttpResponse(log.boot_name.name, mimetype="text/plain")