From 27f5091ae3a629eba53a84c86655af416bda56fb Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Mon, 22 May 2017 18:09:00 +0200 Subject: [PATCH] [modules/nic] Add parameter to filter by state Allow the user to filter the state of devices that should be displayed. It's possible to use both white- and blacklists (and combinations). For example, to only show devices in state "up": -p nic.states=up To only show devices that are not down: -p nic.states=^down fixes #84 --- bumblebee/modules/nic.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bumblebee/modules/nic.py b/bumblebee/modules/nic.py index 2ca87a7..01a251f 100644 --- a/bumblebee/modules/nic.py +++ b/bumblebee/modules/nic.py @@ -4,6 +4,7 @@ Parameters: * nic.exclude: Comma-separated list of interface prefixes to exclude (defaults to "lo,virbr,docker,vboxnet,veth") + * nic.states: Comma-separated list of states to show (prefix with "^" to invert - i.e. ^down -> show all devices that are not in state down) """ try: @@ -21,6 +22,16 @@ class Module(bumblebee.engine.Module): widgets = [] super(Module, self).__init__(engine, config, widgets) self._exclude = tuple(filter(len, self.parameter("exclude", "lo,virbr,docker,vboxnet,veth").split(","))) + + self._states = {} + self._states["include"] = [] + self._states["exclude"] = [] + for state in tuple(filter(len, self.parameter("states", "").split(","))): + if state[0] == "^": + self._states["exclude"].append(state[1:]) + else: + self._states["include"].append(state) + self._update_widgets(widgets) def update(self, widgets): @@ -72,6 +83,10 @@ class Module(bumblebee.engine.Module): for ip in self.get_addresses(intf): addr.append(ip) state = "up" + + if len(self._states["exclude"]) > 0 and state in self._states["exclude"]: continue + if len(self._states["include"]) > 0 and state not in self._states["include"]: continue + widget = self.widget(intf) if not widget: widget = bumblebee.output.Widget(name=intf)