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

Location:
pxe
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pxe/addsystem

    ra37e668 r73db309  
    1515from pxe.common import * 
    1616 
    17 if len(sys.argv) < 2: 
     17if len(sys.argv) < 3: 
    1818    error('Usage: %s <system name> <MAC> [<MAC2>...]' % sys.argv[0]) 
    1919 
     
    2828 
    2929for addr in sys.argv[2:]: 
    30     a = simplify_mac(addr) 
     30    if addr.index('.') >= 0: 
     31        a = simplify_ip(addr) 
     32    else: 
     33        a = simplify_mac(addr) 
    3134    try: 
    3235        mac = MacAddress.objects.get(mac=a) 
  • pxe/common.py

    rfa9915f r73db309  
    8080    create_symlink(prof, name_dst) 
    8181    for m in MacAddress.objects.filter(system=system): 
    82         dst = '%s/01-%s' % (settings.PXE_ROOT, mac2filename(m.mac)) 
     82        if len(m.mac) == 12: 
     83            dst = '%s/01-%s' % (settings.PXE_ROOT, mac2filename(m.mac)) 
     84        else: 
     85            dst = '%s/%s' % (settings.PXE_ROOT, m.mac) 
    8386        create_symlink(system.name, dst) 
    8487         
     
    8992    log.save() 
    9093 
     94def simplify_ip(ip): 
     95    '''Rertun a string containing the hexadecimal representation of an ipv4 address or a sub-part.''' 
     96    l = ip.split('.') 
     97    s = '' 
     98    for e in l: 
     99        s = s + '%02x' % int(e) 
     100    return s 
     101 
    91102# common.py ends here 
  • 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")