Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PATH to find tools primarily #257

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion ifupdown2/ifupdown/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from functools import partial
from ipaddress import IPv4Address
from shutil import which

try:
from ifupdown2.ifupdown.iface import *
Expand Down Expand Up @@ -108,6 +109,7 @@ class utils():
systemctl_cmd = '/bin/systemctl'
dpkg_cmd = '/usr/bin/dpkg'


logger.info("utils init command paths")
for cmd in ['bridge',
'ip',
Expand All @@ -125,6 +127,10 @@ class utils():
'systemctl',
'dpkg'
]:
# If we can find utilities in $PATH we take them.
if which(cmd):
vars()[cmd + '_cmd'] = which(cmd)
logger.debug('%s is set to %s through PATH', cmd + "_cmd", which(cmd))
Lillecarl marked this conversation as resolved.
Show resolved Hide resolved
if os.path.exists(vars()[cmd + '_cmd']):
continue
for path in ['/bin/',
Expand All @@ -133,8 +139,9 @@ class utils():
'/usr/sbin/',]:
if os.path.exists(path + cmd):
vars()[cmd + '_cmd'] = path + cmd
logger.debug('%s is set to %s through common bin paths', cmd + "_cmd", path + cmd)
else:
logger.debug('warning: path %s not found: %s won\'t be usable' % (path + cmd, cmd))
logger.debug('warning: path %s not found: %s won\'t be usable', path + cmd, cmd)

mac_translate_tab = str.maketrans(":.-,", " ")

Expand Down
2 changes: 1 addition & 1 deletion ifupdown2/ifupdownaddons/modulebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def _get_reserved_vlan_range(self):
def _get_vrf_context(self):
vrfid = 'default'
try:
vrfid = utils.exec_command('/usr/sbin/ip vrf id').strip()
vrfid = utils.exec_command('%s vrf id' % utils.ip_cmd).strip()
except Exception as e:
self.logger.debug('failed to get vrf id (%s)' %str(e))
# ignore errors
Expand Down