Changeset 8784edeece399f9d7eae5a786ea7a0f30a7732da

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

Files:
4 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)) 
  • settings.py

    r693511a r8784ede  
    11# Django settings for pxemngr project. 
    22 
    3 DEBUG = False 
     3DEBUG = True 
    44TEMPLATE_DEBUG = DEBUG 
    55 
     
    1111 
    1212DATABASE_ENGINE = 'sqlite3'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 
    13 DATABASE_NAME = '/home/fred/work/pxemngr/pxe.db'             # Or path to database file if using sqlite3. 
     13DATABASE_NAME = '/home/flepied/work/pxemngr/pxe.db'             # Or path to database file if using sqlite3. 
    1414DATABASE_USER = ''             # Not used with sqlite3. 
    1515DATABASE_PASSWORD = ''         # Not used with sqlite3. 
     
    7070    # Always use forward slashes, even on Windows. 
    7171    # Don't forget to use absolute paths, not relative paths. 
    72     '/home/fred/work/pxemngr/pxe/templates', 
     72    '/home/flepied/work/pxemngr/pxe/templates', 
    7373) 
    7474 
     
    7979    'django.contrib.sites', 
    8080    'pxe', 
     81#    'django.contrib.admin', 
    8182) 
    8283 
  • urls.py

    r853b6ff r8784ede  
    22 
    33# Uncomment the next two lines to enable the admin: 
    4 # from django.contrib import admin 
    5 # admin.autodiscover() 
     4#from django.contrib import admin 
     5#admin.autodiscover() 
    66 
    77urlpatterns = patterns('', 
     
    1313    # (r'^admin/doc/', include('django.contrib.admindocs.urls')), 
    1414 
     15    (r'^localboot/(?P<mac>[a-fA-F0-9:-]+)/$', 'pxe.views.localboot'), 
     16    (r'^localboot/$', 'pxe.views.localboot1'), 
     17    (r'^profile/(?P<mac>[a-fA-F0-9:-]+)/$', 'pxe.views.profile'), 
     18    (r'^profile/$', 'pxe.views.profile1'), 
     19     
    1520    # Uncomment the next line to enable the admin: 
    16     # (r'^admin/(.*)', admin.site.root), 
    17     (r'^localboot/(?P<mac>[a-fA-F0-9:-]+)/$', 'pxe.views.localboot'), 
    18     (r'^profile/(?P<mac>[a-fA-F0-9:-]+)/$', 'pxe.views.profile'), 
     21    #(r'^admin/(.*)', admin.site.root), 
    1922)