Move more of the admin calls to use call_vland
admin.py will no longer have any direct calls to the database. All
calls are now via IPC to the main process
Change-Id: I5fec80137f942fd81db12ac4d4a2dc8b9b9d423c
diff --git a/admin.py b/admin.py
index 1d20db5..d418987 100644
--- a/admin.py
+++ b/admin.py
@@ -30,7 +30,6 @@
import drivers
from errors import CriticalError, InputError, ConfigError, SocketError
-from db.db import VlanDB
from config.config import VlanConfig
from ipc.ipc import VlanIpc
@@ -75,16 +74,6 @@
config = VlanConfig(filenames=('./vland.cfg',))
-#print 'Connecting to DB...'
-db = VlanDB()
-
-# 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:
- 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)
@@ -312,15 +301,20 @@
print '%d entries' % count
elif opts.create_switch is not None:
try:
- switch_id = db.create_switch(opts.create_switch)
+ switch_id = call_vland('db_update',
+ {'command':'db.create_switch',
+ 'data':
+ {'name':opts.create_switch}})
print 'Created switch_id %d' % switch_id
except InputError as inst:
print 'Failed: %s' % inst
elif opts.create_port is not None:
try:
- port_id = db.create_port(opts.create_port[0],
- opts.create_port[1],
- default_vlan_id, default_vlan_id)
+ port_id = call_vland('db_update',
+ {'command':'db.create_port',
+ 'data':
+ {'switch_id': opts.create_port[0],
+ 'name': opts.create_port[1]}})
print 'Created port_id %d' % port_id
except InputError as inst:
print 'Failed: %s' % inst
@@ -334,14 +328,17 @@
print 'Failed: %s' % inst
elif opts.delete_switch is not None:
try:
- switch_id = db.delete_switch(opts.delete_switch)
+ switch_id = call_vland('db_update',
+ {'command':'db.delete_switch',
+ 'data': {'switch_id': opts.delete_switch}})
print 'Deleted switch_id %d' % switch_id
except InputError as inst:
print 'Failed: %s' % inst
elif opts.delete_port is not None:
try:
- port_id = db.delete_port(opts.delete_port)
- print 'Deleted port_id %d' % port_id
+ port_id = call_vland('db_update',
+ {'command':'db.delete_port',
+ 'data': {'port_id': opts.delete_port}})
except InputError as inst:
print 'Failed: %s' % inst
elif opts.delete_vlan is not None:
@@ -414,13 +411,21 @@
print 'Failed: %s' % inst
elif opts.lock_port is not None:
try:
- port_id = db.set_port_is_locked(opts.lock_port, True)
+ port_id = call_vland('db_update',
+ {'command':'db.set_port_is_locked',
+ 'data':
+ {'port_id': opts.lock_port,
+ 'is_locked': True}})
print "Locked port_id %d" % port_id
except InputError as inst:
print 'Failed: %s' % inst
elif opts.unlock_port is not None:
try:
- port_id = db.set_port_is_locked(opts.unlock_port, False)
+ port_id = call_vland('db_update',
+ {'command':'db.set_port_is_locked',
+ 'data':
+ {'port_id': opts.unlock_port,
+ 'is_locked': False}})
print "Unlocked port_id %d" % port_id
except InputError as inst:
print 'Failed: %s' % inst
@@ -443,7 +448,11 @@
print 'Failed: %s' % inst
elif opts.set_port_base_vlan is not None:
try:
- port_id = db.set_base_vlan(opts.set_port_base_vlan[0], opts.set_port_base_vlan[1])
+ port_id = call_vland('db_update',
+ {'command':'db.set_base_vlan',
+ 'data':
+ {'port_id': opts.set_base_vlan[0],
+ 'base_vlan_id': opts.set_base_vlan[1]}})
print "Set base VLAN on port_id %d" % port_id
except InputError as inst:
print 'Failed: %s' % inst
@@ -478,6 +487,9 @@
elif opts.status:
print 'Config:'
print ' knows about %d switch(es)' % len(config.switches)
+ default_vlan_id = call_vland('db_query',
+ {'command':'db.get_vlan_id_by_tag',
+ 'data': {'tag': config.vland.default_vlan_tag}})
print 'The default vlan tag (%d) is vlan_id %d' % (config.vland.default_vlan_tag, default_vlan_id)
ret = call_vland('daemon_query', {'command':'daemon.status', 'data': None})
print 'VLANd is running %s' % ret['running']