Skip to content

Commit

Permalink
Implement new interfaces selection for ifreload
Browse files Browse the repository at this point in the history
Reload operation uses a -a/--all option without --allow auto as default.
This command has an impact on ALL interfaces by default.

The --allow can be set to filter the targetted interfaces.

I do not really understand why the IFLIST is disable on this operation.
It could be very useful.
  • Loading branch information
Olivier BLIN committed Jun 16, 2023
1 parent 4ba7555 commit fe811d2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
44 changes: 27 additions & 17 deletions ifupdown2/ifupdown/ifupdownmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@ def query(self, ops, all_itf=False, format_list=False, allow_classes=None,
if not iface_read_ret or not ret:
raise Exception()

def _reload_currentlyup(self, upops, downops, auto=False, allow=None,
def _reload_currentlyup(self, upops, downops, all_itf=False, allow_classes=None,
ifacenames=None, excludepats=None, usecurrentconfig=False,
syntaxcheck=False, **extra_args):
""" reload currently up interfaces """
Expand All @@ -2054,16 +2054,23 @@ def _reload_currentlyup(self, upops, downops, auto=False, allow=None,
if not self.ifaceobjdict:
self.logger.warning("nothing to reload ..exiting.")
return
already_up_ifacenames = []
if not ifacenames: ifacenames = list(self.ifaceobjdict.keys())

# Get a filtered list of interfaces to work on
filtered_ifacenames = self._get_filtered_ifacenames_with_classes(
all_itf, allow_classes, excludepats, ifacenames)

if not filtered_ifacenames:
self.logger.warning("nothing to reload ..exiting.")
return

already_up_ifacenames = []
if (not usecurrentconfig and self.flags.STATEMANAGER_ENABLE
and self.statemanager.ifaceobjdict):
already_up_ifacenames = list(self.statemanager.ifaceobjdict.keys())

# Get already up interfaces that still exist in the interfaces file
already_up_ifacenames_not_present = set(
already_up_ifacenames).difference(ifacenames)
already_up_ifacenames).difference(filtered_ifacenames)
already_up_ifacenames_still_present = set(
already_up_ifacenames).difference(
already_up_ifacenames_not_present)
Expand Down Expand Up @@ -2099,10 +2106,8 @@ def _reload_currentlyup(self, upops, downops, auto=False, allow=None,

# reinitialize dependency graph
self.dependency_graph = OrderedDict({})
falready_up_ifacenames_not_present = [i for i in
already_up_ifacenames_not_present
if self._iface_whitelisted(auto, allow,
excludepats, i)]
falready_up_ifacenames_not_present = self._get_filtered_ifacenames_with_classes(
False, allow_classes, excludepats, already_up_ifacenames_not_present)
self.populate_dependency_info(downops,
falready_up_ifacenames_not_present)
self._sched_ifaces(falready_up_ifacenames_not_present, downops,
Expand All @@ -2112,7 +2117,7 @@ def _reload_currentlyup(self, upops, downops, auto=False, allow=None,

# Now, run 'up' with new config dict
# reset statemanager update flag to default
if auto:
if all_itf:
ifupdownflags.flags.ALL = True
ifupdownflags.flags.WITH_DEPENDS = True
if new_ifaceobjdict:
Expand All @@ -2135,7 +2140,7 @@ def _reload_currentlyup(self, upops, downops, auto=False, allow=None,
if not iface_read_ret or not ret:
raise Exception()

def _reload_default(self, upops, downops, auto=False, allow=None,
def _reload_default(self, upops, downops, all_itf=False, allow_classes=None,
ifacenames=None, excludepats=None, usecurrentconfig=False,
syntaxcheck=False, **extra_args):
""" reload interface config """
Expand All @@ -2151,9 +2156,15 @@ def _reload_default(self, upops, downops, auto=False, allow=None,
return

if not ifacenames: ifacenames = list(self.ifaceobjdict.keys())
new_filtered_ifacenames = [i for i in ifacenames
if self._iface_whitelisted(auto, allow,
excludepats, i)]

# Get a filtered list of interfaces to work on
new_filtered_ifacenames = self._get_filtered_ifacenames_with_classes(
all_itf, allow_classes, excludepats, ifacenames)

if not new_filtered_ifacenames:
self.logger.warning("nothing to reload ..exiting.")
return

# generate dependency graph of interfaces
self.populate_dependency_info(upops)

Expand Down Expand Up @@ -2194,9 +2205,8 @@ def _reload_default(self, upops, downops, auto=False, allow=None,

if op == 'reload' and ifacenames:
ifacenames = list(self.ifaceobjdict.keys())
old_filtered_ifacenames = [i for i in ifacenames
if self._iface_whitelisted(auto, allow,
excludepats, i)]
old_filtered_ifacenames = self._get_filtered_ifacenames_with_classes(
all_itf, allow_classes, excludepats, ifacenames)

# generate dependency graph of old interfaces,
# This should make sure built in interfaces are
Expand Down Expand Up @@ -2365,7 +2375,7 @@ def _reload_default(self, upops, downops, auto=False, allow=None,
self.logger.debug('no interfaces to up')
return

if auto:
if all_itf:
ifupdownflags.flags.ALL = True
ifupdownflags.flags.WITH_DEPENDS = True
# and now, we are back to the current config in ifaceobjdict
Expand Down
2 changes: 1 addition & 1 deletion ifupdown2/ifupdown/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def run_reload(self, args):
dryrun=args.noact)
ifupdown_handle.reload(['pre-up', 'up', 'post-up'],
['pre-down', 'down', 'post-down'],
auto=args.all, allow=args.CLASS, ifacenames=None,
all_itf=args.all, allow_classes=args.CLASS, ifacenames=None,
excludepats=args.excludepats,
usecurrentconfig=args.usecurrentconfig,
syntaxcheck=args.syntaxcheck,
Expand Down

0 comments on commit fe811d2

Please sign in to comment.