Ignore:
Timestamp:
08/19/09 10:53:16 (15 years ago)
Author:
bas
Message:

configure. configure.in, Makefile.in:

  • added new files

src/pxeconfigd.in:

  • new daemon code, like client side

src/pxeconfigd.py:

  • use the common function defined in pxe_global.py
  • reformat the code
  • added daemon hook script

setup.py:

  • added some new modules


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/pxeconfigd.py

    r169 r171  
    2929
    3030        command line option:
    31           -d/--directory <dir>
    32             Where <dir> is the directory where the pxe config files reside.
    3331          -V/--version
    3432            Prints the version number and exits
     
    4543import getopt
    4644
     45# PXE modules
     46from pxe_global import *
     47
    4748# DEBUG
    4849#
     
    5455STDIN=0
    5556STDOUT=1
    56 SHORTOPT_LIST='Vd:'
    57 LONGOPT_LIST=['version', 'directory=']
     57SHORTOPT_LIST='V'
     58LONGOPT_LIST=['version']
    5859
    5960PXE_CONF_DIR = '/tftpboot/pxelinux.cfg'
    60 VERSION = '2.0.0'
     61VERSION = '3.0.0'
    6162
    6263# Give the current time
     
    9293# the connection if there is no data
    9394#
    94 def handleConnection():
    95   """Determines which host connects to the server
    96   """
     95def handleConnection(settings):
     96        """
     97        Determines which host connects to the server
     98        """
     99       
     100        # Determine client address
     101        #
     102        try:
     103                client_addr = socket.fromfd(sys.stdin.fileno(), socket.AF_INET,
     104                          socket.SOCK_STREAM)
     105                client_ip = client_addr.getpeername()[0]
     106        except socket.error, detail:
     107                error =  "pxeconfigd can only be started from inetd!!!"
     108                raise PxeConfig, error
     109               
     110        # translate ip address ---> hex address
     111        #
     112        d = string.split(client_ip, '.')
     113        client_haddr = '%02X%02X%02X%02X' %(int(d[0]), int(d[1]), int(d[2]), int(d[3]))
     114       
     115        if DEBUG:
     116                print 'ip = %s, hex = %s' %(client_ip, client_haddr)
    97117
    98   # Determine client address
    99   #
    100   try:
    101     client_addr = socket.fromfd(sys.stdin.fileno(), socket.AF_INET,
    102                           socket.SOCK_STREAM)
    103     client_ip = client_addr.getpeername()[0]
     118        if settings['daemon_script_hook']:
     119                cmd = '%s %s' %(settings['daemon_script_hook'], client_ip)
     120                print cmd
     121                os.system(cmd)
    104122
    105   except socket.error, detail:
    106     print "pxeconfigd can only be started from inetd!!!"
    107     sys.exit(1)
     123        remove_link(client_haddr)
     124        sys.exit(0)
    108125
     126def check_args(argv, settings):
     127        """
     128        Must we use another directory for the PXE configuration
     129        """
     130        global PXE_CONF_DIR
     131       
     132        try:
     133                opts, args = getopt.getopt(argv[1:], SHORTOPT_LIST, LONGOPT_LIST)
     134        except getopt.error, detail:
     135                print __doc__
     136                print detail
     137                sys.exit(1)
     138               
     139        for opt, value in opts:
     140                if opt in ['-V', '--version']:
     141                        print VERSION
     142                        sys.exit(0)
    109143
    110   # translate ip address ---> hex address
    111   #
    112   d = string.split(client_ip, '.')
    113   client_haddr = '%02X%02X%02X%02X' %(int(d[0]), int(d[1]), int(d[2]), int(d[3]))
    114 
    115   if DEBUG:
    116     print 'ip = %s, hex = %s' %(client_ip, client_haddr)
    117 
    118   remove_link(client_haddr)
    119   sys.exit(0)
    120 
    121 def check_args(argv):
    122   """
    123   Must we use another directory for the PXE configuration
    124   """
    125   global PXE_CONF_DIR
    126 
    127   try:
    128     opts, args = getopt.getopt(argv[1:], SHORTOPT_LIST, LONGOPT_LIST)
    129   except getopt.error, detail:
    130     print __doc__
    131     print detail
    132     sys.exit(1)
    133 
    134   for opt, value in opts:
    135 
    136     if opt in ['-d', '--directory']:
    137       if not os.path.isdir(value):
    138         os.write(STDOUT, "PXE booting is not configured")
    139         sys.exit(1)
    140       else:
    141         PXE_CONF_DIR = value
    142 
    143     elif opt in ['-V', '--version']:
    144       print VERSION
    145       sys.exit(0)
     144        try:
     145                PXE_CONF_DIR = settings['pxe_config_dir']
     146        except KeyError:
     147                pass
     148               
     149        PXE_CONF_DIR = os.path.realpath(PXE_CONF_DIR)
     150        if not os.path.isdir(PXE_CONF_DIR):
     151                error =  'pxeconfig directory: %s does not exists' %(PXE_CONF_DIR)
     152                raise PxeConfig, error
    146153
    147154def server():
    148155  """Start the daemon
    149156  """
    150   check_args(sys.argv)
    151   handleConnection()
     157  config = ReadConfig()
     158  check_args(sys.argv, config)
     159  handleConnection(config)
    152160
    153161if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.