blob: a8d313f116d33787f4eac175f8c5a3ba633889d8 [file] [log] [blame]
Steve McIntyree5043dd2014-12-10 16:49:28 +00001#! /usr/bin/python
2
3# Copyright 2014 Linaro Limited
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18# MA 02110-1301, USA.
19#
20# Main VLANd module
21#
22
23import os, sys, types
24import time
25import logging
26
27vlandpath = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
28sys.path.insert(0, vlandpath)
29
30import drivers
31from config.config import VlanConfig
32from db.db import VlanDB
33from errors import CriticalError, InputError, ConfigError
34
35version = "0.0.0-DEV"
36banner = "Linaro VLANd version %s" % version
37
38def get_switch_driver(switch):
39 logging.debug("Trying to find a driver for %s" % switch)
40 driver = config.switches[switch].driver
41 logging.debug("Driver: %s" % driver)
42 module = __import__("drivers.%s" % driver, fromlist=[driver])
43 class_ = getattr(module, driver)
44 return class_(switch)
45
46print '%s' % banner
47
48print 'Parsing Config...'
49config = VlanConfig(filenames=('./vland.cfg',))
50print ' Config knows about %d switches' % len(config.switches)
51
52print 'Connecting to DB...'
53db = VlanDB(db_name=config.database.dbname, username=config.database.username)
54
55switches = db.all_switches()
56print ' DB knows about %d switches' % len(switches)
57ports = db.all_ports()
58print ' DB knows about %d ports' % len(ports)
59vlans = db.all_vlans()
60print ' DB knows about %d vlans' % len(vlans)
61
62for switch in sorted(config.switches):
63 print "Found switch %s:" % (switch)
64
65 print " Probing:"
66
67 s = get_switch_driver(switch)
68 s.switch_connect(config.switches[switch].username, config.switches[switch].password)
69 print " Found details of switch:"
70 s._dump_list(s._systemdata)
71 print " Switch has %d ports:" % len(s.switch_get_port_names())
72 for port in s.switch_get_port_names():
73 print " %s" % port
74 if 0 == 1:
75 mode = s.port_get_mode(port)
76 if mode == "trunk":
77 print " port %s is in trunk mode, VLAN(s):" % port
78 vlans = s.port_get_trunk_vlan_list(port)
79 for vlan in vlans:
80 name = s.vlan_get_name(vlan)
81 print " %d (%s)" % (vlan, name)
82 else:
83 vlan = s.port_get_access_vlan(port)
84 name = s.vlan_get_name(vlan)
85 print " port %s is in access mode, VLAN %d (%s):" % (port, vlan, name)
86
87 s.switch_disconnect()
88 del(s)
89