]> git.ipfire.org Git - oddments/fireinfo.git/commitdiff
Add network information to profile.
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 27 Dec 2010 17:06:21 +0000 (18:06 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 27 Dec 2010 17:11:01 +0000 (18:11 +0100)
fireinfo/network.py [new file with mode: 0644]
fireinfo/system.py

diff --git a/fireinfo/network.py b/fireinfo/network.py
new file mode 100644 (file)
index 0000000..063e9ec
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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()
index 862aace762cfc846a4e4bd546c95393c15bbbadf..d711ba0127c468180808be157a406b3ce87e9413 100644 (file)
@@ -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()