Show
Ignore:
Timestamp:
05/31/10 10:39:01 (21 months ago)
Author:
Frederic Lepied <frederic.lepied@…>
Children:
72d673f0c5d7aa426dcd9ce67099813d1c7972d4
Parents:
17c79627d5d4c95f2428c5e361f8f06b64257983
git-committer:
Frederic Lepied <frederic.lepied@…> (05/31/10 10:39:01)
Message:

allow to lookup system by MAC or IPV4

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pxe/dpysystem

    r7741e41 r9462a1e  
    33# Project         : pxemngr 
    44# File            : dpysystem 
    5 # Copyright       : 2009 Splitted-Desktop Systems 
     5# Copyright       : 2009-2010 Splitted-Desktop Systems 
    66# Author          : Frederic Lepied 
    77# Created On      : Sun Feb  1 13:54:41 2009 
    8 # Purpose         : report the list of systems or informations 
    9 #                 about one system. 
    108#--------------------------------------------------------------- 
     9 
     10"""Reports the list of systems or displays informations about one system.""" 
    1111 
    1212import sys 
     
    1616 
    1717if len(sys.argv) != 2: 
    18     error('Usage: %s <system name>|-l' % sys.argv[0]) 
     18    error('Usage: %s <system name|MAC|IPV4>|-l' % sys.argv[0]) 
    1919 
    2020if sys.argv[1] == '-l': 
     
    2525        system = System.objects.get(name=sys.argv[1]) 
    2626    except System.DoesNotExist: 
    27         error('System %s not defined' % sys.argv[1]) 
     27        try: 
     28            if len(sys.argv[1]) == 17: 
     29                system = System.objects.get(macaddress__mac=simplify_mac(sys.argv[1])) 
     30            else: 
     31                if '.' in sys.argv[1]: 
     32                    system = System.objects.get(macaddress__mac=simplify_ip(sys.argv[1])) 
     33                else: 
     34                    system = System.objects.get(macaddress__mac=sys.argv[1].upper()) 
     35        except System.DoesNotExist: 
     36            error('System %s not defined' % sys.argv[1]) 
    2837     
    2938    print 'Name:', system.name 
     
    3241        print 'Mac:', 
    3342        r = '' 
    34         for i in range(0, 10, 2): 
    35             r = r +  '%s:' % mac.mac[i:i+2] 
    36         r = r + mac.mac[10:12] 
    37         print '%s (%s)' % (r, mac_to_ip(r)) 
    38      
     43        if len(mac.mac) == 12: 
     44            for i in range(0, 10, 2): 
     45                r = r +  '%s:' % mac.mac[i:i+2] 
     46            r = r + mac.mac[10:12] 
     47            print '%s (%s)' % (r, mac_to_ip(r)) 
     48        else: 
     49            l = len(mac.mac) 
     50            for i in range(0, l - 2, 2): 
     51                r = r +  '%d.' % int(mac.mac[i:i+2], 16) 
     52            r = r +  '%d (%s)' % (int(mac.mac[l-2:l], 16), mac.mac) 
     53            print r 
     54             
    3955    logs = Log.objects.filter(system=system).order_by('-date') 
    4056    if len(logs) >= 1: