mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
Ticket: None Reviewed By: CCR-4058 Testing Done: ifup'd interface with both dhcp-wait: "no" and dhcp-wait: "yes" and not specified at all. A previous patch implemented the nowait option for DHCP. This patch changes the name of the option to "dhcp-wait" and makes the default, if nothing is specified in the policy files, to be "yes", which means dhclient will be called without the "-nw" option, causing it to wait for up to a minute for a response from the DHCP server before continuing. The format of the JSON in the policy file for this option was also changed so that it conforms to the other ifupdown2 policy options. This format is now: { "dhcp": { "defaults": { "dhcp-wait": "no" } } } Also, the documented argument values are "yes" and "no". Any other values, will be interpreted as "yes". A subsequent patch in cl-basefiles will be made to include this fragment in /var/lib/ifupdown2/policy.d/dhcp.json so that Cumulus Linux will default to not waiting for DHCP to complete.
92 lines
3.3 KiB
Python
92 lines
3.3 KiB
Python
#!/usr/bin/python
|
|
#
|
|
# Copyright 2014 Cumulus Networks, Inc. All rights reserved.
|
|
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
|
|
#
|
|
|
|
from utilsbase import *
|
|
import subprocess
|
|
import os
|
|
|
|
FNULL = open(os.devnull, 'w')
|
|
|
|
class dhclient(utilsBase):
|
|
""" This class contains helper methods to interact with the dhclient
|
|
utility """
|
|
|
|
def _pid_exists(self, pidfilename):
|
|
if os.path.exists(pidfilename):
|
|
pid = self.read_file_oneline(pidfilename)
|
|
if not os.path.exists('/proc/%s' %pid):
|
|
return False
|
|
else:
|
|
return False
|
|
return True
|
|
|
|
def is_running(self, ifacename):
|
|
return self._pid_exists('/run/dhclient.%s.pid' %ifacename)
|
|
|
|
def is_running6(self, ifacename):
|
|
return self._pid_exists('/run/dhclient6.%s.pid' %ifacename)
|
|
|
|
def stop(self, ifacename):
|
|
if os.path.exists('/sbin/dhclient3'):
|
|
cmd = ['/sbin/dhclient3', '-x', '-pf',
|
|
'/run/dhclient.%s.pid' %ifacename, '-lf',
|
|
'/var/lib/dhcp3/dhclient.%s.leases' %ifacename,
|
|
'%s' %ifacename]
|
|
else:
|
|
cmd = ['/sbin/dhclient', '-x', '-pf',
|
|
'/run/dhclient.%s.pid' %ifacename,
|
|
'-lf', '/var/lib/dhcp/dhclient.%s.leases' %ifacename,
|
|
'%s' %ifacename]
|
|
self.subprocess_check_call(cmd)
|
|
|
|
def start(self, ifacename, wait=True):
|
|
if os.path.exists('/sbin/dhclient3'):
|
|
cmd = ['/sbin/dhclient3', '-pf',
|
|
'/run/dhclient.%s.pid' %ifacename,
|
|
'-lf', '/var/lib/dhcp3/dhclient.%s.leases' %ifacename,
|
|
'%s' %ifacename]
|
|
else:
|
|
cmd = ['/sbin/dhclient', '-pf', '/run/dhclient.%s.pid' %ifacename,
|
|
'-lf', '/var/lib/dhcp/dhclient.%s.leases' %ifacename,
|
|
'%s' %ifacename]
|
|
if not wait:
|
|
cmd.append('-nw')
|
|
self.subprocess_check_call(cmd)
|
|
|
|
def release(self, ifacename):
|
|
if os.path.exists('/sbin/dhclient3'):
|
|
cmd = ['/sbin/dhclient3', '-r', '-pf',
|
|
'/run/dhclient.%s.pid' %ifacename, '-lf',
|
|
'/var/lib/dhcp3/dhclient.%s.leases' %ifacename,
|
|
'%s' %ifacename]
|
|
else:
|
|
cmd = ['/sbin/dhclient', '-r', '-pf',
|
|
'/run/dhclient.%s.pid' %ifacename,
|
|
'-lf', '/var/lib/dhcp/dhclient.%s.leases' %ifacename,
|
|
'%s' %ifacename]
|
|
self.subprocess_check_call(cmd)
|
|
|
|
def start6(self, ifacename, wait=True):
|
|
cmd = ['dhclient', '-6', '-pf',
|
|
'/run/dhclient6.%s.pid' %ifacename, '-lf',
|
|
'/var/lib/dhcp/dhclient.%s.leases ' %ifacename,
|
|
'%s' %ifacename]
|
|
if not wait:
|
|
cmd.append('-nw')
|
|
self.subprocess_check_call(cmd)
|
|
|
|
def stop6(self, ifacename):
|
|
self.subprocess_check_call(['dhclient', '-6', '-x', '-pf',
|
|
'/run/dhclient.%s.pid' %ifacename, '-lf',
|
|
'/var/lib/dhcp/dhclient.%s.leases ' %ifacename,
|
|
'%s' %ifacename])
|
|
|
|
def release6(self, ifacename):
|
|
self.subprocess_check_call(['dhclient', '-6', '-r', '-pf',
|
|
'/run/dhclient6.%s.pid' %ifacename, '-lf',
|
|
'/var/lib/dhcp/dhclient6.%s.leases' %ifacename,
|
|
'%s' %ifacename])
|