mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
some fixes + template support
Ticket: CM-1438 Reviewed By: Testing Done: This patch adds support for mako style templates. Example: % for v in [20,30,40]: auto vlan${v} iface vlan${v} inet static address 10.20.${v}.3/24 mstpctl_ports glob swp1-52.${v} mstpctl_stp on % endfor open items: - currently templates will only work if python-mako is installed (Its apt-gettable from debian wheezy).
This commit is contained in:
@ -22,6 +22,8 @@ CONFIGURE_INTERFACES=yes
|
||||
EXCLUDE_INTERFACES=
|
||||
VERBOSE=no
|
||||
|
||||
verbose=
|
||||
|
||||
[ -f /etc/default/networking ] && . /etc/default/networking
|
||||
|
||||
[ "$VERBOSE" = yes ] && verbose=-v
|
||||
@ -128,7 +130,7 @@ start)
|
||||
set -f
|
||||
exclusions=$(process_exclusions)
|
||||
log_action_begin_msg "Configuring network interfaces"
|
||||
if ifup -a $exclusions $verbose && ifup_hotplug $exclusions $verbose
|
||||
if ifup -a $verbose --perfmode
|
||||
then
|
||||
log_action_end_msg $?
|
||||
else
|
||||
@ -144,7 +146,7 @@ stop)
|
||||
check_network_swap
|
||||
|
||||
log_action_begin_msg "Deconfiguring network interfaces"
|
||||
if ifdown -a --exclude=lo $verbose; then
|
||||
if ifdown -a --exclude=lo $verbose --perfmode --force; then
|
||||
log_action_end_msg $?
|
||||
else
|
||||
log_action_end_msg $?
|
||||
@ -156,7 +158,7 @@ reload)
|
||||
|
||||
log_action_begin_msg "Reloading network interfaces configuration"
|
||||
state=$(cat /run/network/ifstate)
|
||||
ifdown -a --exclude=lo $verbose || true
|
||||
ifdown -a --exclude=lo $verbose --perfmode --force || true
|
||||
if ifup --exclude=lo $state $verbose ; then
|
||||
log_action_end_msg $?
|
||||
else
|
||||
@ -172,10 +174,10 @@ force-reload|restart)
|
||||
|
||||
#log_warning_msg "Running $0 $1 is deprecated because it may not re-enable some interfaces"
|
||||
log_action_begin_msg "Reconfiguring network interfaces"
|
||||
ifdown -a --exclude=lo $verbose || true
|
||||
ifdown -a --exclude=lo $verbose --perfmode --force || true
|
||||
set -f
|
||||
exclusions=$(process_exclusions)
|
||||
if ifup -a --exclude=lo $exclusions $verbose && ifup_hotplug $exclusions $verbose
|
||||
if ifup -a --exclude=lo $verbose --perfmode
|
||||
then
|
||||
log_action_end_msg $?
|
||||
else
|
||||
|
@ -259,7 +259,7 @@ class ifupdownMain():
|
||||
continue
|
||||
dlist = module.get_dependent_ifacenames(ifaceobj,
|
||||
self.ifaceobjdict.keys())
|
||||
if dlist:
|
||||
if dlist is not None:
|
||||
self.logger.debug('%s: ' %ifaceobj.get_name() +
|
||||
'got dependency list: %s' %str(dlist))
|
||||
break
|
||||
|
@ -89,6 +89,7 @@ class networkInterfaces():
|
||||
|
||||
def process_iface(self, lines, cur_idx, lineno):
|
||||
lines_consumed = 0
|
||||
line_idx = cur_idx
|
||||
|
||||
ifaceobj = iface()
|
||||
|
||||
@ -174,20 +175,12 @@ class networkInterfaces():
|
||||
|
||||
return classes
|
||||
|
||||
|
||||
def read_file(self, filename=None):
|
||||
def process_filedata(self, filedata):
|
||||
lineno = 0
|
||||
line_idx = 0
|
||||
lines_consumed = 0
|
||||
|
||||
ifaces_file = filename
|
||||
if ifaces_file == None:
|
||||
ifaces_file=self.ifaces_file
|
||||
|
||||
self.logger.debug('reading ifaces_file %s' %ifaces_file)
|
||||
|
||||
with open(ifaces_file) as f:
|
||||
raw_lines = f.readlines()
|
||||
raw_lines = filedata.split('\n')
|
||||
lines = [l.strip(' \n') for l in raw_lines]
|
||||
|
||||
while (line_idx < len(lines)):
|
||||
@ -201,21 +194,46 @@ class networkInterfaces():
|
||||
|
||||
# Check if first element is a supported keyword
|
||||
if self.is_keyword(words[0]):
|
||||
keyword_func = self.get_keyword_func(
|
||||
words[0])
|
||||
lines_consumed = keyword_func(self,
|
||||
lines, line_idx, lineno)
|
||||
|
||||
keyword_func = self.get_keyword_func(words[0])
|
||||
lines_consumed = keyword_func(self, lines, line_idx, lineno)
|
||||
line_idx += lines_consumed
|
||||
else:
|
||||
self.logger.warning('could not ' +
|
||||
'process line %s' %l + ' at' +
|
||||
self.logger.warning('could not process line %s' %l + ' at' +
|
||||
' lineno %d' %lineno)
|
||||
|
||||
line_idx += 1
|
||||
|
||||
return 0
|
||||
|
||||
def run_template_engine(self, textdata):
|
||||
try:
|
||||
from mako.template import Template
|
||||
except:
|
||||
self.logger.warning('template engine mako not found ' +
|
||||
'skipping template parsing');
|
||||
return textdata
|
||||
|
||||
t = Template(text=textdata, output_encoding='utf-8')
|
||||
return t.render()
|
||||
|
||||
def read_file(self, filename=None):
|
||||
ifaces_file = filename
|
||||
if ifaces_file == None:
|
||||
ifaces_file=self.ifaces_file
|
||||
|
||||
self.logger.debug('reading ifaces_file %s' %ifaces_file)
|
||||
f = open(ifaces_file)
|
||||
filedata = f.read()
|
||||
f.close()
|
||||
|
||||
# process line continuations
|
||||
filedata = ' '.join(d.strip() for d in filedata.split('\\'))
|
||||
|
||||
# run through template engine
|
||||
filedata = self.run_template_engine(filedata)
|
||||
|
||||
self.process_filedata(filedata)
|
||||
|
||||
|
||||
def load(self, filename=None):
|
||||
self.logger.debug('loading ifaces file ..')
|
||||
|
Reference in New Issue
Block a user