- Timestamp:
- 04/15/09 13:45:37 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/pxeconfig.in
r135 r136 87 87 """ 88 88 if not os.path.isfile(file): 89 print'File %s does not exist' %file90 sys.exit(1)89 error = 'File %s does not exist' %file 90 raise PxeConfig, error 91 91 92 92 config = ConfigParser.RawConfigParser() … … 94 94 config.read(file) 95 95 except ConfigParser.MissingSectionHeaderError,detail: 96 print detail 97 sys.exit(1) 96 raise PxeConfig, detail 98 97 99 98 # Not yet uses … … 126 125 files = glob.glob('default.*') 127 126 if not files: 128 print'There are no pxe config files starting with: default.'129 sys.exit(1)127 error = 'There are no pxe config files starting with: default.' 128 raise PxeConfig, error 130 129 131 130 if default_file: … … 170 169 171 170 if options.REMOVE: 172 if options.DEBUG or options.DRY_RUN :171 if options.DEBUG or options.DRY_RUN or options.VERBOSE: 173 172 print 'removing %s/%s' %(PXE_CONF_DIR, haddr) 174 173 … … 177 176 178 177 else: 179 if options.DEBUG or options.DRY_RUN :178 if options.DEBUG or options.DRY_RUN or options.VERBOSE: 180 179 print 'linking %s to %s' %(haddr, pxe_filename) 181 180 … … 190 189 convert the network address to a hex address if true. 191 190 """ 192 if options. VERBOSE:191 if options.DEBUG: 193 192 str = 'net_2_hex : %s' %(net) 194 193 print str … … 208 207 209 208 return r 209 210 def hosts_2_hex(hosts, options): 211 """ 212 Convert hostname(s) to a net address that can be handled by manage_links function 213 """ 214 if options.DEBUG: 215 str = 'host_2_hex: %s' %hosts 216 print str 217 218 for host in hosts: 219 try: 220 addr = socket.gethostbyname(host) 221 except socket.error,detail: 222 error = '%s not an valid hostname: %s' %(host,detail) 223 raise PxeConfig, error 224 225 net = string.splitfields(addr, '.') 226 cnet = string.joinfields(net[0:3], '.') 227 228 haddr = '%s%02X' %(net_2_hex(cnet, options), int(net[3])) 229 230 manage_links(haddr, options) 231 210 232 211 233 def add_options(p): … … 221 243 ) 222 244 223 p.add_option('- n', '--dry-run',224 action = 'store_true', 225 dest = 'D RY_RUN',226 help = ' Do not execute any command'245 p.add_option('-d', '--debug', 246 action = 'store_true', 247 dest = 'DEBUG', 248 help = 'Toggle debug mode (default : False)' 227 249 ) 228 250 … … 233 255 ) 234 256 257 p.add_option('-n', '--dry-run', 258 action = 'store_true', 259 dest = 'DRY_RUN', 260 help = 'Do not execute any command' 261 ) 262 235 263 p.add_option('-r', '--remove', 236 264 action = 'store_true', … … 242 270 action = 'store_true', 243 271 dest = 'VERBOSE', 244 help = 'Make the program more verbose '272 help = 'Make the program more verbose (default: False)' 245 273 ) 246 274 … … 251 279 ) 252 280 253 def parser(argv ):281 def parser(argv, settings): 254 282 """ 255 283 Make use of sara advance parser module. It can handle regex in hostnames … … 268 296 sys.exit(0) 269 297 298 # debug can be specified by the command line or options file 299 # 300 if not options.DEBUG: 301 try: 302 if settings['debug']: 303 options.DEBUG = int(settings['debug']) 304 except KeyError: 305 pass 306 270 307 if options.filename: 271 308 if not os.path.isfile(os.path.join(PXE_CONF_DIR, options.filename)): 272 309 error = '%s: Filename does not exists' %(options.filename) 273 print error 274 sys.exit(1) 310 raise PxeConfig, error 275 311 else: 276 312 options.filename = select_pxe_configfile() … … 281 317 hosts_2_hex(args, options) 282 318 283 def hosts_2_hex(hosts, options):284 """285 Convert hostname(s) to a net address that can be handled by manage_links function286 """287 if options.VERBOSE:288 str = 'host_2_hex: %s' %hosts289 print str290 291 for host in hosts:292 try:293 addr = socket.gethostbyname(host)294 except socket.error,detail:295 error = '%s not an valid hostname: %s' %(host,detail)296 print error297 sys.exit(1)298 299 net = string.splitfields(addr, '.')300 cnet = string.joinfields(net[0:3], '.')301 302 haddr = '%s%02X' %(net_2_hex(cnet, options), int(net[3]))303 304 manage_links(haddr, options)305 306 319 307 320 def main(): … … 324 337 raise PxeConfig, error 325 338 326 parser(sys.argv) 339 parser(sys.argv, settings) 340 327 341 328 342 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.