Changeset 186 for trunk/src/pxeconfig.py
- Timestamp:
- 10/28/10 16:04:25 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/pxeconfig.py
r179 r186 174 174 return r 175 175 176 def host s_2_hex(hosts, options):176 def host_2_hex(host, options): 177 177 """ 178 178 Convert hostname(s) to a net address that can be handled by manage_links function … … 182 182 print str 183 183 184 for host in hosts: 185 try: 186 addr = socket.gethostbyname(host) 187 except socket.error,detail: 188 error = '%s not an valid hostname: %s' %(host,detail) 189 raise PxeConfig, error 190 191 net = string.splitfields(addr, '.') 192 cnet = string.joinfields(net[0:3], '.') 193 194 if options.SCRIPT_HOOK: 195 if options.DEBUG or options.DRY_RUN or options.VERBOSE: 196 print 'Executing client script hook: %s with arg: %s' %(options.SCRIPT_HOOK, addr) 197 if not options.DRY_RUN: 198 cmd = '%s %s' %(options.SCRIPT_HOOK, addr) 199 os.system(cmd) 200 201 haddr = '%s%02X' %(net_2_hex(cnet, options), int(net[3])) 202 manage_links(haddr, options) 184 try: 185 addr = socket.gethostbyname(host) 186 except socket.error,detail: 187 error = '%s not an valid hostname: %s' %(host,detail) 188 raise PxeConfig, error 189 190 net = string.splitfields(addr, '.') 191 cnet = string.joinfields(net[0:3], '.') 192 193 if options.SCRIPT_HOOK: 194 if options.DEBUG or options.DRY_RUN or options.VERBOSE: 195 print 'Executing client script hook: %s with arg: %s' %(options.SCRIPT_HOOK, addr) 196 if not options.DRY_RUN: 197 cmd = '%s %s' %(options.SCRIPT_HOOK, addr) 198 os.system(cmd) 199 200 haddr = '%s%02X' %(net_2_hex(cnet, options), int(net[3])) 201 manage_links(haddr, options) 202 203 204 def mac_2_hex(mac_addr, options): 205 """ 206 Convert mac address to pxeconfig address 207 """ 208 if options.DEBUG: 209 str = 'mac_2_hex: %s' %mac_addr 210 print mac_addr 211 212 haddr = '01-%s' %(mac_addr.replace(':', '-').lower()) 213 manage_links(haddr, options) 203 214 204 215 def add_options(p): … … 251 262 ) 252 263 253 def parser(argv, settings):264 def parser(argv, config, defaults): 254 265 """ 255 266 Make use of sara advance parser module. It can handle regex in hostnames … … 272 283 if not options.DEBUG: 273 284 try: 274 if settings['debug']:275 options.DEBUG = int( settings['debug'])285 if defaults['debug']: 286 options.DEBUG = int(defaults['debug']) 276 287 except KeyError: 277 288 pass … … 290 301 # ... 291 302 try: 292 options.SCRIPT_HOOK = settings['client_script_hook']303 options.SCRIPT_HOOK = defaults['client_script_hook'] 293 304 except KeyError, detail: 294 305 pass … … 297 308 print args, options 298 309 299 hosts_2_hex(args, options) 300 310 ## 311 # Are the hosts wiht only mac addresses defined in the configuration file 312 313 for host in args: 314 if host in config.sections(): 315 mac_addr = config.get(host, 'mac_address') 316 mac_2_hex(mac_addr, options) 317 else: 318 host_2_hex(host, options) 301 319 302 320 def main(): … … 304 322 # 305 323 global PXE_CONF_DIR 306 settings = ReadConfig()307 308 try: 309 PXE_CONF_DIR = settings['pxe_config_dir']324 parser_config, default_settings = ReadConfig() 325 326 try: 327 PXE_CONF_DIR = default_settings['pxe_config_dir'] 310 328 311 329 except KeyError: … … 317 335 raise PxeConfig, error 318 336 319 parser(sys.argv, settings)337 parser(sys.argv, parser_config, default_settings) 320 338 321 339
Note: See TracChangeset
for help on using the changeset viewer.