Initial version of the main VLANd application

Just does a shakedown of each of the modules for now:
 * Parse config file
 * Connect to database
 * For each configured switch, connect through its driver and dump
   some state

Change-Id: I9c4fb7baf70f29b17bd30122ab0717b6babeec49
diff --git a/vland.py b/vland.py
new file mode 100644
index 0000000..a8d313f
--- /dev/null
+++ b/vland.py
@@ -0,0 +1,89 @@
+#! /usr/bin/python
+
+#  Copyright 2014 Linaro Limited
+#
+#  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 2 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, write to the Free Software
+#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+#  MA 02110-1301, USA.
+#
+#  Main VLANd module
+#
+
+import os, sys, types
+import time
+import logging
+
+vlandpath = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
+sys.path.insert(0, vlandpath)
+
+import drivers
+from config.config import VlanConfig
+from db.db import VlanDB
+from errors import CriticalError, InputError, ConfigError
+
+version = "0.0.0-DEV"
+banner = "Linaro VLANd version %s" % version
+
+def get_switch_driver(switch):
+    logging.debug("Trying to find a driver for %s" % switch)
+    driver = config.switches[switch].driver
+    logging.debug("Driver: %s" % driver)
+    module = __import__("drivers.%s" % driver, fromlist=[driver])
+    class_ = getattr(module, driver)
+    return class_(switch)
+
+print '%s' % banner
+
+print 'Parsing Config...'
+config = VlanConfig(filenames=('./vland.cfg',))
+print '  Config knows about %d switches' % len(config.switches)
+
+print 'Connecting to DB...'
+db = VlanDB(db_name=config.database.dbname, username=config.database.username)
+
+switches = db.all_switches()
+print '  DB knows about %d switches' % len(switches)
+ports = db.all_ports()
+print '  DB knows about %d ports' % len(ports)
+vlans = db.all_vlans()
+print '  DB knows about %d vlans' % len(vlans)
+
+for switch in sorted(config.switches):
+    print "Found switch %s:" % (switch)
+
+    print "  Probing:"
+
+    s = get_switch_driver(switch)
+    s.switch_connect(config.switches[switch].username, config.switches[switch].password)
+    print "  Found details of switch:"
+    s._dump_list(s._systemdata)
+    print "  Switch has %d ports:" % len(s.switch_get_port_names())
+    for port in s.switch_get_port_names():
+        print "  %s" % port
+        if 0 == 1:
+            mode = s.port_get_mode(port)
+            if mode == "trunk":
+                print "  port %s is in trunk mode, VLAN(s):" % port
+                vlans = s.port_get_trunk_vlan_list(port)
+                for vlan in vlans:
+                    name = s.vlan_get_name(vlan)
+                    print "    %d (%s)" % (vlan, name)
+                else:
+                    vlan = s.port_get_access_vlan(port)
+                    name = s.vlan_get_name(vlan)
+                    print "  port %s is in access mode, VLAN %d (%s):" % (port, vlan, name)
+        
+    s.switch_disconnect()
+    del(s)
+