aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve McIntyre <steve.mcintyre@linaro.org>2014-12-15 15:00:12 +0000
committerSteve McIntyre <steve.mcintyre@linaro.org>2014-12-15 15:00:12 +0000
commitc12f631675916d07018be3a2f99bae50511d345c (patch)
tree1f9faa72c74967ea42f22f1ebdfa4a1723ea490a
parent31f3528df2946710ad2d504843fd1e7f7da91000 (diff)
Move initialisation of the default VLAN to vland main
Change-Id: Iba1d9d3a6d1d56bfe4d45119e289f8a26d7dc9ee
-rw-r--r--admin.py22
-rw-r--r--config/config.py10
-rw-r--r--vland.cfg1
-rw-r--r--vland.py10
4 files changed, 31 insertions, 12 deletions
diff --git a/admin.py b/admin.py
index 8e9902b..c442681 100644
--- a/admin.py
+++ b/admin.py
@@ -24,7 +24,8 @@ import os, sys, types
import time
import logging
import optparse
-from errors import CriticalError, InputError
+from config.config import VlanConfig
+from errors import CriticalError, InputError, ConfigError, SocketError
vlandpath = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
sys.path.insert(0, vlandpath)
@@ -54,20 +55,19 @@ def dump_vlan(vlan):
#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()
-# For sanity, we need to know the vlan_id for the default vlan (tag
-# 1). Make sure we know that before anybody attempts to create things
-# that depend on it.
-default_vlan_tag = 1
-default_vlan_id = db.get_vlan_id_by_tag(default_vlan_tag)
+# We need to know the vlan_id for the default vlan (tag 1). Make sure
+# we know that before anybody attempts to create things that depend on
+# it.
+default_vlan_id = db.get_vlan_id_by_tag(config.vland.default_vlan_tag)
if default_vlan_id is None:
- # It doesn't exist - create it and try again
- default_vlan_id = db.create_vlan("DEFAULT",
- default_vlan_tag,
- True)
-
+ raise ConfigError("No vlan ID found for default VLAN tag %d" % config.vland.default_vlan_tag)
usage = 'Usage: %prog --command [command options]'
parser = optparse.OptionParser(usage=usage, description=banner)
diff --git a/config/config.py b/config/config.py
index 08d78f8..4cf06c2 100644
--- a/config/config.py
+++ b/config/config.py
@@ -77,9 +77,10 @@ class VlanConfig:
# No DB-specific defaults to set
self.database = DBConfigClass()
- # Set default port number
+ # Set default port number and VLAN tag
self.vland = DaemonConfigClass()
self.vland.port = 3080
+ self.vland.default_vlan_tag = 1
# No switch-specific defaults to set
self.switches = {}
@@ -139,6 +140,13 @@ class VlanConfig:
except:
raise ConfigError('Invalid vland configuration (port)')
+ try:
+ self.vland.port = config.getint(section, 'default_vlan_tag')
+ except ConfigParser.NoOptionError:
+ pass
+ except:
+ raise ConfigError('Invalid vland configuration (default_vlan_tag)')
+
else:
match = sw_regex.match(section)
if match:
diff --git a/vland.cfg b/vland.cfg
index 00ee9fc..b9d9a7e 100644
--- a/vland.cfg
+++ b/vland.cfg
@@ -9,6 +9,7 @@ username = vland
[vland]
port = 3080
+#default_vlan_tag = 1
[switch foo]
name = 10.172.2.51
diff --git a/vland.py b/vland.py
index c74324c..631f5cb 100644
--- a/vland.py
+++ b/vland.py
@@ -62,6 +62,16 @@ print ' DB knows about %d vlans' % len(vlans)
# Initial startup sanity chacking
+# For sanity, we need to know the vlan_id for the default vlan (tag
+# 1). Make sure we know that before anybody attempts to create things
+# that depend on it.
+default_vlan_id = db.get_vlan_id_by_tag(config.vland.default_vlan_tag)
+if default_vlan_id is None:
+ # It doesn't exist - create it and try again
+ default_vlan_id = db.create_vlan("DEFAULT",
+ config.vland.default_vlan_tag,
+ True)
+
if len(switches) != len(config.switches):
print 'You have configured access details for %d switches, ' % len(config.switches)
print 'but have %d switches registered in your database.' % len(switches)