mirror of
				https://github.com/CumulusNetworks/ifupdown2.git
				synced 2024-05-06 15:54:50 +00:00 
			
		
		
		
	Ticket: CM-10292, CM-10282
Reviewed By: dsa, nikhil, julien
Testing Done: Tested dhcp config on an vrf slave
- Add support for policy module_globals variable
  "vrf-exec-cmd-prefix". It is read into per module
  self.vrf_exec_cmd_prefix variable
- If self.vrf_exec_cmd_prefix is present and interface is a
  vrf slave, use ifupdown2 will call such command in vrf
  context using:
    "%s %s %s" %(<vrf-exec-cmd-prefix>, <vrfname>, <cmd>)
- This also fixes calling of dhcp refresh when a dhcp slave is
  removed from a vrf
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
		
	
		
			
				
	
	
		
			106 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			106 lines
		
	
	
		
			3.8 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 _run_dhclient_cmd(self, cmd, cmd_prefix=None):
 | |
|         if not cmd_prefix:
 | |
|             cmd_aslist = []
 | |
|         else:
 | |
|             cmd_aslist = cmd_prefix.split()
 | |
|         if cmd_aslist:
 | |
|             cmd_aslist.extend(cmd)
 | |
|         else:
 | |
|             cmd_aslist = cmd
 | |
|         self.subprocess_check_call(cmd_aslist)
 | |
| 
 | |
|     def stop(self, ifacename, cmd_prefix=None):
 | |
|         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._run_dhclient_cmd(cmd, cmd_prefix)
 | |
| 
 | |
|     def start(self, ifacename, wait=True, cmd_prefix=None):
 | |
|         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._run_dhclient_cmd(cmd, cmd_prefix)
 | |
| 
 | |
|     def release(self, ifacename, cmd_prefix=None):
 | |
|         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._run_dhclient_cmd(cmd, cmd_prefix)
 | |
| 
 | |
|     def start6(self, ifacename, wait=True, cmd_prefix=None):
 | |
|         cmd = ['/sbin/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._run_dhclient_cmd(cmd, cmd_prefix)
 | |
| 
 | |
|     def stop6(self, ifacename, cmd_prefix=None):
 | |
|         cmd = ['/sbin/dhclient', '-6', '-x', '-pf',
 | |
|                '/run/dhclient.%s.pid' %ifacename, '-lf',
 | |
|                '/var/lib/dhcp/dhclient.%s.leases ' %ifacename,
 | |
|                '%s' %ifacename]
 | |
|         self._run_dhclient_cmd(cmd, cmd_prefix)
 | |
| 
 | |
|     def release6(self, ifacename, cmd_prefix=None):
 | |
|         cmd = ['/sbin/dhclient', '-6', '-r', '-pf',
 | |
|                '/run/dhclient6.%s.pid' %ifacename, '-lf',
 | |
|                '/var/lib/dhcp/dhclient6.%s.leases' %ifacename,
 | |
|                '%s' %ifacename]
 | |
|         self._run_dhclient_cmd(cmd, cmd_prefix)
 |