Show
Ignore:
Timestamp:
02/10/09 20:16:04 (3 years ago)
Author:
Frederic Lepied <frederic.lepied@…>
Children:
7218e7ce77d425dcf3e8c6e1bea40242315868c4
Parents:
0cdcde4b0b7371a511bb3681726d4102b8fac1af
git-committer:
Frederic Lepied <frederic.lepied@…> (02/10/09 20:16:04)
Message:

transparently find the mac address

Location:
pxe
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pxe/common.py

    r1f8d77d r8784ede  
    1010import sys 
    1111import os 
     12import re 
    1213import settings 
    13 from pxe.models import * 
     14from models import * 
    1415 
     16IP_REGEXP = re.compile('^.*\s([0-9A-F:]+)\s.*') 
     17 
     18def mac_to_ip(mac): 
     19    for line in open('/proc/net/arp').readlines(): 
     20        if line.find(mac) != -1: 
     21            res = IP_REGEXP.search(line) 
     22            if res: 
     23                return res.group(1) 
     24    return False 
     25 
     26def get_mac(request): 
     27    mac = mac_to_ip(request.META['REMOTE_ADDR']) 
     28    if not mac: 
     29        raise Http404 
     30    print 'get_mac', mac 
     31    return mac 
     32     
    1533def error(str): 
    1634    sys.stderr.write(str + '\n') 
     
    1937def simplify_mac(s): 
    2038    '''Remove : or - between hexa numbers for a MAC address. Always return the address in lowercase''' 
     39    print 'simplify_mac', s 
    2140    ss = s.replace('-', '') 
    2241    sss = ss.replace(':', '') 
    2342    if len(sss) != 12: 
     43        print 'invalid length (not 12)', sss, len(sss) 
    2444        raise ValueError 
    2545    return sss.lower() 
  • pxe/views.py

    r1f8d77d r8784ede  
    88#--------------------------------------------------------------- 
    99 
    10 from django.http import HttpResponse 
     10from django.http import HttpResponse, Http404 
    1111from django.shortcuts import get_object_or_404 
    1212from common import * 
    1313from models import * 
    1414 
     15def localboot1(request): 
     16    return localboot(request, get_mac(request)) 
     17     
    1518def localboot(request, mac): 
    1619    system = get_object_or_404(System, macaddress__mac=simplify_mac(mac)) 
     
    1821    return HttpResponse("Next boot set to local", mimetype="text/plain") 
    1922 
     23def profile1(request): 
     24    return profile(request, get_mac(request)) 
     25     
    2026def profile(request, mac): 
    2127    system = get_object_or_404(System, macaddress__mac=simplify_mac(mac))