Changeset 171


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


Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile.in

    r144 r171  
    6565
    6666distclean:
    67         rm src/pxeconfig src/pxeconfig.py src/pxeconfigd src/hexls examples/pxeconfigd.xinetd config.log config.status Makefile
     67        rm src/pxeconfig src/pxe_global.py src/pxeconfigd src/hexls examples/pxeconfigd.xinetd config.log config.status Makefile
  • trunk/configure

    r167 r171  
    18001800
    18011801
    1802 ac_config_files="$ac_config_files Makefile src/pxeconfig src/pxeconfig.py src/pxeconfigd src/hexls examples/pxeconfigd.xinetd"
     1802ac_config_files="$ac_config_files Makefile src/pxeconfig src/pxe_global.py src/pxeconfigd src/hexls examples/pxeconfigd.xinetd"
    18031803
    18041804cat >confcache <<\_ACEOF
     
    23712371    "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
    23722372    "src/pxeconfig") CONFIG_FILES="$CONFIG_FILES src/pxeconfig" ;;
    2373     "src/pxeconfig.py") CONFIG_FILES="$CONFIG_FILES src/pxeconfig.py" ;;
     2373    "src/pxe_global.py") CONFIG_FILES="$CONFIG_FILES src/pxe_global.py" ;;
    23742374    "src/pxeconfigd") CONFIG_FILES="$CONFIG_FILES src/pxeconfigd" ;;
    23752375    "src/hexls") CONFIG_FILES="$CONFIG_FILES src/hexls" ;;
  • trunk/configure.in

    r167 r171  
    6060        Makefile
    6161        src/pxeconfig
    62         src/pxeconfig.py
     62        src/pxe_global.py
    6363        src/pxeconfigd
    6464        src/hexls
  • trunk/setup.py

    r162 r171  
    1313
    1414setup ( name = 'pxeconfig',
    15         version = '3.0.4',
     15        version = '3.1.0',
    1616        description = 'SARA pxeconfig utilities',
    1717        author = 'Bas van der Vlies',
     
    2222        extra_path = 'pxeconfig',
    2323                package_dir = { '' : 'src' },
    24                 py_modules = [ 'pxeconfig', 'AdvancedParser' ],
     24                py_modules = [ 'pxeconfig', 'pxeconfigd', 'pxe_global', 'AdvancedParser' ],
    2525)
  • 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.