root/pxe/dpysystem

Revision 9462a1ee61cb7c69c57720d39360f2d0765578a5, 2.0 kB (checked in by Frederic Lepied <frederic.lepied@…>, 3 months ago)

allow to lookup system by MAC or IPV4

  • Property mode set to 100755
Line 
1#!/usr/bin/python
2#---------------------------------------------------------------
3# Project         : pxemngr
4# File            : dpysystem
5# Copyright       : 2009-2010 Splitted-Desktop Systems
6# Author          : Frederic Lepied
7# Created On      : Sun Feb  1 13:54:41 2009
8#---------------------------------------------------------------
9
10"""Reports the list of systems or displays informations about one system."""
11
12import sys
13import settings
14from pxe.models import *
15from pxe.common import *
16
17if len(sys.argv) != 2:
18    error('Usage: %s <system name|MAC|IPV4>|-l' % sys.argv[0])
19
20if sys.argv[1] == '-l':
21    for s in System.objects.all():
22        print s.name
23else:
24    try:
25        system = System.objects.get(name=sys.argv[1])
26    except System.DoesNotExist:
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])
37   
38    print 'Name:', system.name
39   
40    for mac in MacAddress.objects.filter(system=system):
41        print 'Mac:',
42        r = ''
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           
55    logs = Log.objects.filter(system=system).order_by('-date')
56    if len(logs) >= 1:
57        print 'Next boot:', logs[0].boot_name.name
58   
59    print 'History:'
60    for l in logs[1:10]:
61        print l.date, l.boot_name.name
62   
63# addsystem ends here
Note: See TracBrowser for help on using the browser.