From: Michael Tremer Date: Mon, 27 Dec 2010 17:06:21 +0000 (+0100) Subject: Add network information to profile. X-Git-Tag: v2.0.0~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4cb619656bae4624f9af81d920cd8cda5e754687;p=oddments%2Ffireinfo.git Add network information to profile. --- diff --git a/fireinfo/network.py b/fireinfo/network.py new file mode 100644 index 0000000..063e9ec --- /dev/null +++ b/fireinfo/network.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +############################################################################### +# # +# Fireinfo # +# Copyright (C) 2010, 2011 IPFire Team (www.ipfire.org) # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +import os + +SYS_CLASS_NET = "/sys/class/net" + +class Network(object): + def __init__(self): + self._devices = os.listdir(SYS_CLASS_NET) + + def has_green(self): + return "green0" in self._devices + + def has_red(self): + for i in ("red0", "ppp0"): + if i in self._devices: + return True + + return False + + def has_blue(self): + return "blue0" in self._devices + + def has_orange(self): + return "orange0" in self._devices + + +if __name__ == "__main__": + n = Network() + + print "has_green", n.has_green() + print "has_red", n.has_red() + print "has_blue", n.has_blue() + print "has_orange", n.has_orange() diff --git a/fireinfo/system.py b/fireinfo/system.py index 862aace..d711ba0 100644 --- a/fireinfo/system.py +++ b/fireinfo/system.py @@ -29,6 +29,7 @@ import _fireinfo import cpu import device import hypervisor +import network PROFILE_VERSION = 0 @@ -129,6 +130,13 @@ class System(object): "count" : self.cpu.count } + p["network"] = { + "green" : self.network.has_green(), + "blue" : self.network.has_blue(), + "orange" : self.network.has_orange(), + "red" : self.network.has_red(), + } + # Only append hypervisor information if we are virtualized. if self.virtual: p["hypervisor"] = { @@ -379,7 +387,13 @@ class System(object): """ return self.hypervisor.virtual - + @property + def network(self): + """ + Reference to the network class. + """ + return network.Network() + if __name__ == "__main__": s=System()