Changeset 19
- Timestamp:
- 09/27/02 16:47:36 (21 years ago)
- Location:
- trunk/pxeconfig
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/pxeconfig/changelog
r18 r19 1 Always edit this file when changes are commited: 1 Always edit this file when changes are commited:: 2 2 3 3 $Log: changelog,v $ 4 Revision 1.17 2002/09/27 14:47:36 sscpbas 5 pxeconfig: 6 Added command line options so that we can use the program interactivly 7 and via command line 8 9 changed the info structure of a lot of functions. So the functions can 10 report different error messages for interactive usage and command line 11 usage. 12 4 13 Revision 1.16 2002/09/11 12:59:19 sscpbas 5 14 Change some header info for hexls -
trunk/pxeconfig/pxeconfig
r16 r19 7 7 # 8 8 # CVS info 9 # $Date: 2002/0 8/16 07:43:21$10 # $Revision: 1. 9$9 # $Date: 2002/09/27 14:47:36 $ 10 # $Revision: 1.10 $ 11 11 # 12 12 # Copyright (C) 2002 … … 29 29 # 30 30 """ 31 Usage: pxeconfig [-d|--directory <pxe_config_dir> ] 32 33 With this program you can configure which PXE configuration file 34 to use when a node boots. The program will ask the following questions: 31 Usage: pxeconfig 32 [-d|--directory <pxe_config_dir>] 33 [-n|--net <C-net> -s|--start <number> -e|--end <number> -f|--file <filename>] 34 35 With this program you can configure which PXE configuration file a node 36 will use when it boots. The program can be started interactivly or via 37 command line options. 38 39 When this program is started interactive it will ask the following questions: 35 40 1) Network address (Class C-network address only) 36 41 2) Starting number … … 63 68 # 64 69 PXE_CONF_DIR='/tftpboot/pxelinux.cfg' 65 NADDR=0 66 PXEFILE=1 67 START=2 68 END=3 69 SHORTOPT_LIST='d:' 70 LONGOPT_LIST=['directory='] 71 72 def choice_pxe_configfile(): 70 NETWORK='network' 71 FILENAME='filename' 72 START='start' 73 END='end' 74 75 SHORTOPT_LIST='d:n:s:e:f:' 76 LONGOPT_LIST=['directory=', 'net=', 'start=', 'end=', 'file='] 77 78 def select_pxe_configfile(): 73 79 """ 74 80 Let user choose which pxeconfig file to use. … … 115 121 return files[index-1] 116 122 117 def create_links( list):123 def create_links(dict): 118 124 """ 119 125 Create the links in the PXE_CONF_DIR, … … 122 128 """ 123 129 os.chdir(PXE_CONF_DIR) 124 naddr = list[NADDR]125 pxe_filename = list[PXEFILE]126 for i in range( list[START], list[END]+1):130 naddr = dict[NETWORK] 131 pxe_filename = dict[FILENAME] 132 for i in range(dict[START], dict[END]+1): 127 133 haddr = '%s%02X' %(naddr, i) 128 134 if DEBUG: … … 135 141 136 142 137 def check_network(net ):143 def check_network(net, prefix=''): 138 144 """ 139 145 This function checks if the give network is a Class C-network and will … … 143 149 144 150 if len(d) != 3: 145 print('Only C-class nerwork addresses are supported!!!') 146 sys.exit(1) 151 if prefix: 152 net = prefix + ' : ' + net 153 154 print '%s is not a valid C-class network address!!!' %net 155 sys.exit(1) 156 157 158 # Display right message for interactive/commandline 159 if prefix: 160 prefix = prefix + ' ' + net 161 else: 162 prefix = net 147 163 148 164 # Check if we have valid network values 149 165 r = '' 150 166 for i in d: 151 i = check_number(i )167 i = check_number(i, prefix) 152 168 r = '%s%02X' %(r,i) 153 169 … … 157 173 return r 158 174 159 def check_number(number ):175 def check_number(number, prefix=''): 160 176 """ 161 177 This functions checks if the input is between 0 < number < 255: 162 178 number : is a string 179 prefix ; a string that must be displayed if an error occurs 163 180 """ 164 181 try: 165 182 n = int(number) 166 183 except ValueError, detail: 167 print detail184 print prefix,detail 168 185 sys.exit(1) 169 186 … … 171 188 return n 172 189 else: 190 191 if prefix: 192 number = prefix +' : ' + number 193 173 194 print '%s is not a valid number, must be between 0 and 255' %number 174 195 sys.exit(1) 175 196 176 def interactive(): 177 178 iptable = {} 197 def interactive(binfo): 179 198 180 199 print __doc__ … … 189 208 end = check_number(end) 190 209 191 pxe_filename = choice_pxe_configfile() 192 193 iptable[network] = [] 194 iptable[network].append(naddr) 195 iptable[network].append(pxe_filename) 196 iptable[network].append(int(start)) 197 iptable[network].append(int(end)) 198 199 for net in iptable.keys(): 200 if DEBUG: 201 print net, iptable[net] 202 create_links(iptable[net]) 203 204 205 def check_args(argv): 210 pxe_filename = select_pxe_configfile() 211 212 binfo[NETWORK] = naddr 213 binfo[START] = int(start) 214 binfo[END] = int(end) 215 binfo[FILENAME] = pxe_filename 216 217 if DEBUG: 218 print network, binfo 219 220 def check_cmd_line(binfo): 221 if len(binfo.keys()) != 4: 222 print 'Not enough arguments to create the links' 223 print __doc__ 224 sys.exit(1) 225 226 # check_filename 227 # 228 if not os.path.isfile(os.path.join(PXE_CONF_DIR, binfo[FILENAME])): 229 print '%s: Filename does not exists' %binfo[FILENAME] 230 sys.exit(1) 231 232 def check_args(argv, binfo): 206 233 """ 207 234 command line option: 208 -d /--directory <dir>235 -d|--directory <dir> 209 236 Where <dir> is the directory where the pxe config files reside. 210 237 """ 211 238 global PXE_CONF_DIR 239 212 240 try: 213 241 opts, args = getopt.getopt(argv[1:], SHORTOPT_LIST, LONGOPT_LIST) … … 217 245 sys.exit(1) 218 246 219 if opts: 220 opt, PXE_CONF_DIR = opts[0] 221 222 if not os.path.isdir(PXE_CONF_DIR): 223 print 'Directory %s does not exists' %PXE_CONF_DIR 224 sys.exit(1) 247 # Check given options 248 # 249 for opt,value in opts: 250 if opt in ['-d', '--directory']: 251 if os.path.isdir(value): 252 PXE_CONF_DIR = value 253 else: 254 print 'Directory %s does not exists\n' %value 255 sys.exit(1) 256 257 elif opt in ['-n', '--net']: 258 network = value 259 binfo[NETWORK] = check_network(value, opt) 260 261 elif opt in ['-s', '--start']: 262 binfo[START] = check_number(value, opt) 263 264 elif opt in ['-e', '--end']: 265 binfo[END] = check_number(value, opt) 266 267 elif opt in ['-f', '--file']: 268 binfo[FILENAME] = value 269 225 270 226 271 def main(): 227 check_args(sys.argv) 228 interactive() 272 # A dictionary holding the boot info 273 # 274 bootinfo = {} 275 check_args(sys.argv, bootinfo) 276 277 if bootinfo: 278 check_cmd_line(bootinfo) 279 else: 280 interactive(bootinfo) 281 282 create_links(bootinfo) 229 283 230 284 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.