| 1 |
#! /usr/bin/env python |
| 2 |
""" |
| 3 |
Team monitor |
| 4 |
|
| 5 |
Copyright (C) 2011-2015 Jiri Pirko <[email protected]> |
| 6 |
|
| 7 |
This library is free software; you can redistribute it and/or |
| 8 |
modify it under the terms of the GNU Lesser General Public |
| 9 |
License as published by the Free Software Foundation; either |
| 10 |
version 2.1 of the License, or (at your option) any later version. |
| 11 |
|
| 12 |
This library is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
Lesser General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU Lesser General Public |
| 18 |
License along with this library; if not, write to the Free Software |
| 19 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
""" |
| 21 |
|
| 22 |
__author__ = """ |
| 23 |
[email protected] (Jiri Pirko) |
| 24 |
""" |
| 25 |
|
| 26 |
import sys |
| 27 |
import team |
| 28 |
|
| 29 |
def port_change_handler_func(t): |
| 30 |
print "------------------\nport change\n\tport list:" |
| 31 |
for port in t.port_list(): |
| 32 |
print ("\tifname %s, linkup %d, changed %d, speed %d, duplex %d, removed %d" % |
| 33 |
(port.ifname, port.linkup, port.changed, |
| 34 |
port.speed, port.duplex, port.removed)) |
| 35 |
return 0 |
| 36 |
|
| 37 |
def option_change_handler_func(t): |
| 38 |
print "------------------\noption change\n\toption list:" |
| 39 |
for option in t.option_list(): |
| 40 |
print ("\t%s = %s (changed %d)" % (option.name, option.value, |
| 41 |
option.changed)) |
| 42 |
return 0 |
| 43 |
|
| 44 |
def main(): |
| 45 |
appname = sys.argv[0] |
| 46 |
args = sys.argv[1:] |
| 47 |
|
| 48 |
if len(args) < 1: |
| 49 |
print "Usage: %s TEAMDEV" % appname |
| 50 |
sys.exit() |
| 51 |
|
| 52 |
ifname = args[0] |
| 53 |
|
| 54 |
t = team.Team(ifname) |
| 55 |
|
| 56 |
port_change_handler = team.TeamChangeHandler( |
| 57 |
port_change_handler_func, t, |
| 58 |
team.TEAM_PORT_CHANGE) |
| 59 |
t.change_handler_register(port_change_handler) |
| 60 |
option_change_handler = team.TeamChangeHandler( |
| 61 |
option_change_handler_func, t, |
| 62 |
team.TEAM_OPTION_CHANGE) |
| 63 |
t.change_handler_register(option_change_handler) |
| 64 |
|
| 65 |
t.loop_forever() |
| 66 |
|
| 67 |
if __name__ == "__main__": |
| 68 |
main() |