mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
addons: usercmds: Set environment just like the original ifupdown
The original ifupdown sets all interface options as IF_<option> environment variable. Duplicate that behavior for compatibility.
This commit is contained in:
@@ -43,13 +43,14 @@ class usercmds(moduleBase):
|
||||
def _run_command(self, ifaceobj, op):
|
||||
cmd_list = ifaceobj.get_attr_value(op)
|
||||
if cmd_list:
|
||||
os.environ['IFACE'] = ifaceobj.name if ifaceobj.name else ''
|
||||
os.environ['LOGICAL'] = ifaceobj.name if ifaceobj.name else ''
|
||||
os.environ['METHOD'] = ifaceobj.addr_method if ifaceobj.addr_method else ''
|
||||
os.environ['ADDRFAM'] = ','.join(ifaceobj.addr_family) if ifaceobj.addr_family else ''
|
||||
env = os.environ | {
|
||||
'LOGICAL': ifaceobj.name if ifaceobj.name else '',
|
||||
'METHOD': ifaceobj.addr_method if ifaceobj.addr_method else '',
|
||||
'ADDRFAM': ','.join(ifaceobj.addr_family) if ifaceobj.addr_family else ''
|
||||
} | ifaceobj.get_env()
|
||||
for cmd in cmd_list:
|
||||
try:
|
||||
utils.exec_user_command(cmd)
|
||||
utils.exec_user_command(cmd, env=env)
|
||||
except Exception as e:
|
||||
if not self.ignore_error(str(e)):
|
||||
self.logger.warning('%s: %s %s' % (ifaceobj.name, op,
|
||||
|
@@ -392,11 +392,12 @@ class utils():
|
||||
return cmd_output_string
|
||||
|
||||
@classmethod
|
||||
def exec_user_command(cls, cmd, close_fds=False, stdout=True,
|
||||
def exec_user_command(cls, cmd, env=None, close_fds=False, stdout=True,
|
||||
stdin=None, stderr=subprocess.STDOUT):
|
||||
cls._log_command_exec(cmd, stdin)
|
||||
return cls._execute_subprocess(cmd,
|
||||
shell=True,
|
||||
env=env,
|
||||
close_fds=close_fds,
|
||||
stdout=stdout,
|
||||
stdin=stdin,
|
||||
|
Reference in New Issue
Block a user