root/pxe/addsystem

Revision 55eb9b9aed51fb600b71624611330d5f3b1508cf, 1.2 KB (checked in by Frederic Lepied <frederic.lepied@…>, 21 months ago)

fix bad test to decide if we manage a mac address or an ip

  • Property mode set to 100755
Line 
1#!/usr/bin/python
2#---------------------------------------------------------------
3# Project         : pxemngr
4# File            : addsystem
5# Copyright       : 2009 Splitted-Desktop Systems
6# Author          : Frederic Lepied
7# Created On      : Sun Feb  1 13:54:41 2009
8# Purpose         : add a system and its mac addresses to the
9#                  database.
10#---------------------------------------------------------------
11
12import sys
13import settings
14from pxe.models import *
15from pxe.common import *
16
17if len(sys.argv) < 3:
18    error('Usage: %s <system name> <MAC> [<MAC2>...]' % sys.argv[0])
19
20if sys.argv[1] == 'default':
21    error('default is a reserved name and cannot be used for a system name')
22   
23try:
24    system = System.objects.get(name=sys.argv[1])
25except System.DoesNotExist:
26    system = System(name=sys.argv[1])
27    system.save()
28
29for addr in sys.argv[2:]:
30    if '.' in addr:
31        a = simplify_ip(addr)
32    else:
33        a = simplify_mac(addr)
34    try:
35        mac = MacAddress.objects.get(mac=a)
36        if mac.system != system:
37            mac.system = system
38            mac.save()
39    except MacAddress.DoesNotExist:
40        mac = MacAddress(mac=a, system=system)
41        mac.save()
42
43# addsystem ends here
Note: See TracBrowser for help on using the browser.