[core] Refactor engine
This is going to be a bit more comprehensive than anticipated. In order to cleanly refactor the core and the engine, basically start from scratch with the implementation. Goals: * Test coverage * Maintain backwards compatibility with module interface as much as possible (but still make modules easier to code) * Simplicity see #23
This commit is contained in:
parent
20858991b9
commit
a8a6c9bba2
72 changed files with 19 additions and 2155 deletions
|
@ -1,62 +0,0 @@
|
|||
import netifaces
|
||||
import bumblebee.module
|
||||
|
||||
def description():
|
||||
return "Displays the names, IP addresses and status of each available interface."
|
||||
|
||||
def parameters():
|
||||
return [
|
||||
"nic.exclude: Comma-separated list of interface prefixes to exlude (defaults to: \"lo,virbr,docker,vboxnet,veth\")"
|
||||
]
|
||||
|
||||
class Module(bumblebee.module.Module):
|
||||
def __init__(self, output, config):
|
||||
super(Module, self).__init__(output, config)
|
||||
self._exclude = tuple(filter(len, self._config.parameter("exclude", "lo,virbr,docker,vboxnet,veth").split(",")))
|
||||
|
||||
def widgets(self):
|
||||
result = []
|
||||
interfaces = [ i for i in netifaces.interfaces() if not i.startswith(self._exclude) ]
|
||||
for intf in interfaces:
|
||||
addr = []
|
||||
state = "down"
|
||||
try:
|
||||
if netifaces.AF_INET in netifaces.ifaddresses(intf):
|
||||
for ip in netifaces.ifaddresses(intf)[netifaces.AF_INET]:
|
||||
if "addr" in ip and ip["addr"] != "":
|
||||
addr.append(ip["addr"])
|
||||
state = "up"
|
||||
except Exception as e:
|
||||
addr = []
|
||||
widget = bumblebee.output.Widget(self, "{} {} {}".format(
|
||||
intf, state, ", ".join(addr)
|
||||
))
|
||||
widget.set("intf", intf)
|
||||
widget.set("state", state)
|
||||
result.append(widget)
|
||||
|
||||
return result
|
||||
|
||||
def _iswlan(self, intf):
|
||||
# wifi, wlan, wlp, seems to work for me
|
||||
if intf.startswith("w"): return True
|
||||
return False
|
||||
|
||||
def _istunnel(self, intf):
|
||||
return intf.startswith("tun")
|
||||
|
||||
def state(self, widget):
|
||||
intf = widget.get("intf")
|
||||
|
||||
iftype = "wireless" if self._iswlan(intf) else "wired"
|
||||
iftype = "tunnel" if self._istunnel(intf) else iftype
|
||||
|
||||
return "{}-{}".format(iftype, widget.get("state"))
|
||||
|
||||
def warning(self, widget):
|
||||
return widget.get("state") != "up"
|
||||
|
||||
def critical(self, widget):
|
||||
return widget.get("state") == "down"
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
Loading…
Add table
Add a link
Reference in a new issue