[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
This commit is contained in:
parent
15db0c7756
commit
27f5091ae3
1 changed files with 15 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
* nic.exclude: Comma-separated list of interface prefixes to exclude (defaults to "lo,virbr,docker,vboxnet,veth")
|
* 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:
|
try:
|
||||||
|
@ -21,6 +22,16 @@ class Module(bumblebee.engine.Module):
|
||||||
widgets = []
|
widgets = []
|
||||||
super(Module, self).__init__(engine, config, widgets)
|
super(Module, self).__init__(engine, config, widgets)
|
||||||
self._exclude = tuple(filter(len, self.parameter("exclude", "lo,virbr,docker,vboxnet,veth").split(",")))
|
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)
|
self._update_widgets(widgets)
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self, widgets):
|
||||||
|
@ -72,6 +83,10 @@ class Module(bumblebee.engine.Module):
|
||||||
for ip in self.get_addresses(intf):
|
for ip in self.get_addresses(intf):
|
||||||
addr.append(ip)
|
addr.append(ip)
|
||||||
state = "up"
|
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)
|
widget = self.widget(intf)
|
||||||
if not widget:
|
if not widget:
|
||||||
widget = bumblebee.output.Widget(name=intf)
|
widget = bumblebee.output.Widget(name=intf)
|
||||||
|
|
Loading…
Reference in a new issue