Move the database connection and default_vlan_id into state
Change-Id: I13d8fc54b1c8af1d211552a1c82a102e245c6708
diff --git a/vland.py b/vland.py
index aaca67f..15fddff 100644
--- a/vland.py
+++ b/vland.py
@@ -51,14 +51,14 @@
util = VlanUtil()
print 'Connecting to DB...'
-db = VlanDB(db_name=state.config.database.dbname,
- username=state.config.database.username)
+state.db = VlanDB(db_name=state.config.database.dbname,
+ username=state.config.database.username)
-switches = db.all_switches()
+switches = state.db.all_switches()
print ' DB knows about %d switches' % len(switches)
-ports = db.all_ports()
+ports = state.db.all_ports()
print ' DB knows about %d ports' % len(ports)
-vlans = db.all_vlans()
+vlans = state.db.all_vlans()
print ' DB knows about %d vlans' % len(vlans)
# Initial startup sanity chacking
@@ -66,12 +66,12 @@
# 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(state.config.vland.default_vlan_tag)
-if default_vlan_id is None:
+state.default_vlan_id = state.db.get_vlan_id_by_tag(state.config.vland.default_vlan_tag)
+if state.default_vlan_id is None:
# It doesn't exist - create it and try again
- default_vlan_id = db.create_vlan("DEFAULT",
- state.config.vland.default_vlan_tag,
- True)
+ state.default_vlan_id = state.db.create_vlan("DEFAULT",
+ state.config.vland.default_vlan_tag,
+ True)
if len(switches) != len(state.config.switches):
print 'You have configured access details for %d switch(es), ' % len(state.config.switches)