Changeset 8784edeece399f9d7eae5a786ea7a0f30a7732da for pxe
- Timestamp:
- 02/10/09 20:16:04 (3 years ago)
- Children:
- 7218e7ce77d425dcf3e8c6e1bea40242315868c4
- Parents:
- 0cdcde4b0b7371a511bb3681726d4102b8fac1af
- git-committer:
- Frederic Lepied <frederic.lepied@…> (02/10/09 20:16:04)
- Location:
- pxe
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
pxe/common.py
r1f8d77d r8784ede 10 10 import sys 11 11 import os 12 import re 12 13 import settings 13 from pxe.models import *14 from models import * 14 15 16 IP_REGEXP = re.compile('^.*\s([0-9A-F:]+)\s.*') 17 18 def 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 26 def 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 15 33 def error(str): 16 34 sys.stderr.write(str + '\n') … … 19 37 def simplify_mac(s): 20 38 '''Remove : or - between hexa numbers for a MAC address. Always return the address in lowercase''' 39 print 'simplify_mac', s 21 40 ss = s.replace('-', '') 22 41 sss = ss.replace(':', '') 23 42 if len(sss) != 12: 43 print 'invalid length (not 12)', sss, len(sss) 24 44 raise ValueError 25 45 return sss.lower() -
pxe/views.py
r1f8d77d r8784ede 8 8 #--------------------------------------------------------------- 9 9 10 from django.http import HttpResponse 10 from django.http import HttpResponse, Http404 11 11 from django.shortcuts import get_object_or_404 12 12 from common import * 13 13 from models import * 14 14 15 def localboot1(request): 16 return localboot(request, get_mac(request)) 17 15 18 def localboot(request, mac): 16 19 system = get_object_or_404(System, macaddress__mac=simplify_mac(mac)) … … 18 21 return HttpResponse("Next boot set to local", mimetype="text/plain") 19 22 23 def profile1(request): 24 return profile(request, get_mac(request)) 25 20 26 def profile(request, mac): 21 27 system = get_object_or_404(System, macaddress__mac=simplify_mac(mac))
