Lines 270-279
Link Here
|
270 |
client = None |
270 |
client = None |
271 |
cmd = "" |
271 |
cmd = "" |
272 |
return (client, cmd) |
272 |
return (client, cmd) |
|
|
273 |
|
274 |
# probably /var/lib/wicd/dhclient.conf with defaults |
275 |
dhclient_conf_path = os.path.join( |
276 |
wpath.varlib, |
277 |
'dhclient.conf' |
278 |
) |
273 |
|
279 |
|
274 |
client_dict = { |
280 |
client_dict = { |
275 |
"dhclient" : |
281 |
"dhclient" : |
276 |
{'connect' : r"%(cmd)s %(iface)s", |
282 |
{'connect' : r"%(cmd)s -cf %(dhclientconf)s %(iface)s", |
277 |
'release' : r"%(cmd)s -r %(iface)s", |
283 |
'release' : r"%(cmd)s -r %(iface)s", |
278 |
'id' : misc.DHCLIENT, |
284 |
'id' : misc.DHCLIENT, |
279 |
}, |
285 |
}, |
Lines 294-305
Link Here
|
294 |
}, |
300 |
}, |
295 |
} |
301 |
} |
296 |
(client_name, cmd) = get_client_name(self.DHCP_CLIENT) |
302 |
(client_name, cmd) = get_client_name(self.DHCP_CLIENT) |
|
|
303 |
|
304 |
# cause dhclient doesn't have a handy dandy argument |
305 |
# for specifing the hostname to be sent |
306 |
if client_name == "dhclient" and flavor: |
307 |
if hostname == None: |
308 |
# <hostname> will use the system hostname |
309 |
# we'll use that if there is hostname passed |
310 |
# that shouldn't happen, though |
311 |
hostname = '<hostname>' |
312 |
print 'attempting to set hostname with dhclient' |
313 |
print 'using dhcpcd or another supported client may work better' |
314 |
dhclient_template = \ |
315 |
open(os.path.join(wpath.etc, 'dhclient.conf.template'), 'r') |
316 |
|
317 |
output_conf = open(dhclient_conf_path, 'w') |
318 |
|
319 |
for line in dhclient_template.readlines(): |
320 |
line = line.replace('$_HOSTNAME', hostname) |
321 |
output_conf.write(line) |
322 |
|
323 |
output_conf.close() |
324 |
dhclient_template.close() |
325 |
|
297 |
if not client_name or not cmd: |
326 |
if not client_name or not cmd: |
298 |
print "WARNING: Failed to find a valid dhcp client!" |
327 |
print "WARNING: Failed to find a valid dhcp client!" |
299 |
return "" |
328 |
return "" |
300 |
|
329 |
|
301 |
if flavor == "connect": |
330 |
if flavor == "connect": |
302 |
return client_dict[client_name]['connect'] % {"cmd":cmd, "iface":self.iface, "hostname":hostname} |
331 |
if not hostname: |
|
|
332 |
hostname = os.uname()[1] |
333 |
return client_dict[client_name]['connect'] % \ |
334 |
{ "cmd" : cmd, |
335 |
"iface" : self.iface, |
336 |
"hostname" : hostname, |
337 |
'dhclientconf' : dhclient_conf_path } |
303 |
elif flavor == "release": |
338 |
elif flavor == "release": |
304 |
return client_dict[client_name]['release'] % {"cmd":cmd, "iface":self.iface} |
339 |
return client_dict[client_name]['release'] % {"cmd":cmd, "iface":self.iface} |
305 |
else: |
340 |
else: |
Lines 535-541
Link Here
|
535 |
def _check_dhcp_result(self, success): |
570 |
def _check_dhcp_result(self, success): |
536 |
""" Print and return the correct DHCP connection result. |
571 |
""" Print and return the correct DHCP connection result. |
537 |
|
572 |
|
538 |
Keyword Arguents: |
573 |
Keyword Arguments: |
539 |
success -- boolean specifying if DHCP was succesful. |
574 |
success -- boolean specifying if DHCP was succesful. |
540 |
|
575 |
|
541 |
Returns: |
576 |
Returns: |
Lines 550-564
Link Here
|
550 |
return 'dhcp_failed' |
585 |
return 'dhcp_failed' |
551 |
|
586 |
|
552 |
@neediface(False) |
587 |
@neediface(False) |
553 |
def StartDHCP(self,hostname): |
588 |
def StartDHCP(self, hostname): |
554 |
""" Start the DHCP client to obtain an IP address. |
589 |
""" Start the DHCP client to obtain an IP address. |
|
|
590 |
|
591 |
Keyword Arguments: |
592 |
hostname -- the hostname to send to the DHCP server |
555 |
|
593 |
|
556 |
Returns: |
594 |
Returns: |
557 |
A string representing the result of the DHCP command. See |
595 |
A string representing the result of the DHCP command. See |
558 |
_check_dhcp_result for the possible values. |
596 |
_check_dhcp_result for the possible values. |
559 |
|
597 |
|
560 |
""" |
598 |
""" |
561 |
cmd = self._get_dhcp_command('connect',hostname) |
599 |
cmd = self._get_dhcp_command('connect', hostname) |
562 |
if self.verbose: print cmd |
600 |
if self.verbose: print cmd |
563 |
self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True) |
601 |
self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True) |
564 |
pipe = self.dhcp_object.stdout |
602 |
pipe = self.dhcp_object.stdout |