root/pxe/views.py

Revision 865eacece8d4895f3d906bce9125a262b0f1c5ac, 1.7 KB (checked in by Frederic Lepied <frederic.lepied@…>, 21 months ago)

localboot change the symlink only for real mac address else it will create a new symlink with the mac address from the request

  • Property mode set to 100644
Line 
1#---------------------------------------------------------------
2# Project         : pxemngr
3# File            : views.py
4# Copyright       : 2009-2010 Splitted-Desktop Systems
5# Author          : Frederic Lepied
6# Created On      : Sun Feb  1 13:54:41 2009
7# Purpose         : http logic
8#---------------------------------------------------------------
9
10from django.http import HttpResponse, Http404
11from django.shortcuts import get_object_or_404
12from pxe.common import *
13from pxe.models import *
14
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
30def localboot1(request):
31    return localboot(request, get_mac(request))
32   
33def localboot(request, mac):
34    try:
35        system = System.objects.get(macaddress__mac=simplify_mac(mac))
36        set_next_boot(system, settings.PXE_LOCAL)
37    except System.DoesNotExist:
38        fn = '%s/%s' % (settings.PXE_ROOT, mac2filename(simplify_mac(mac)))
39        create_symlink('%s/%s%s' % (settings.PXE_PROFILES, settings.PXE_LOCAL, settings.PXE_SUFFIX), fn)
40   
41    return HttpResponse("Next boot set to local", mimetype="text/plain")
42
43def profile1(request):
44    return profile(request, get_mac(request))
45   
46def profile(request, mac):
47    system = get_system(request, mac)
48    log = Log.objects.filter(system=system).order_by('-date')[0]
49    return HttpResponse(log.boot_name.name, mimetype="text/plain")
Note: See TracBrowser for help on using the browser.