aboutsummaryrefslogtreecommitdiff
path: root/admin.py
diff options
context:
space:
mode:
authorSteve McIntyre <steve.mcintyre@linaro.org>2014-12-16 18:23:15 +0000
committerSteve McIntyre <steve.mcintyre@linaro.org>2014-12-16 18:23:15 +0000
commitf1c04f905ceeebc350dce1885f93d4ac46c410a2 (patch)
tree79e4c1cd8a327aea034b2c7809406a5279ebbe7a /admin.py
parent21f0270546733a0caa44c898adc1aae8d5c61860 (diff)
Sea change in how admin code calls the database layer
Add IPC to VLANd All read-only admin DB query calls are now routed to the core VLANd process via IPC, and responses come back from there. Part-way to removing direct DB calls from admin.py, next is the DB calls that make changes. They're more involved. Change-Id: I6a993cd4c7b4e85c2a489ac96f9f0f58f087ca1d
Diffstat (limited to 'admin.py')
-rw-r--r--admin.py66
1 files changed, 54 insertions, 12 deletions
diff --git a/admin.py b/admin.py
index 66a00a6..9569395 100644
--- a/admin.py
+++ b/admin.py
@@ -54,6 +54,23 @@ def dump_port(port):
def dump_vlan(vlan):
print vlan
+def call_vland(msgtype, msg):
+ ipc = VlanIpc()
+ ipc.client_connect('localhost', config.vland.port)
+ msg['client_name'] = 'admin.py'
+ msg['type'] = msgtype
+# print 'Sending:'
+# print msg
+ ipc.client_send(msg)
+ ret = ipc.client_recv_and_close()
+ if 'response' not in ret:
+ raise SocketError("Badly-formed response from VLANd server")
+ if ret['response'] == "ERROR":
+ raise InputError("VLANd server said: %s" % ret['error'])
+# print 'VLANd said in reply:'
+# print ret
+ return ret['data']
+
#print '%s' % banner
config = VlanConfig(filenames=('./vland.cfg',))
@@ -258,21 +275,21 @@ parser.add_option_group(vlan_group)
(opts, args) = parser.parse_args()
if opts.list_all_switches:
- result = db.all_switches()
+ result = call_vland('query', {'command':'db.all_switches', 'data':None})
count = 0;
for line in result:
print line
count += 1
print '%d entries' % count
elif opts.list_all_ports:
- result = db.all_ports()
+ result = call_vland('query', {'command':'db.all_ports', 'data':None})
count = 0;
for line in result:
print line
count += 1
print '%d entries' % count
elif opts.list_all_vlans:
- result = db.all_vlans()
+ result = call_vland('query', {'command':'db.all_vlans', 'data':None})
count = 0;
for line in result:
print line
@@ -320,16 +337,18 @@ elif opts.delete_vlan is not None:
print 'Failed: %s' % inst
elif opts.lookup_switch_by_name is not None:
try:
- switch_id = db.get_switch_id_by_name(opts.lookup_switch_by_name)
+ switch_id = call_vland('query', {'command':'db.get_switch_id_by_name', 'data':{'name':opts.lookup_switch_by_name}})
if switch_id is not None:
- print 'Switch %s has switch_id %d' % (opts.lookup_switch_by_name, switch_id)
+ print '%d' % switch_id
else:
print 'No switch found for name %s' % opts.lookup_switch_by_name
except InputError as inst:
print 'Failed: %s' % inst
elif opts.show_switch is not None:
try:
- switch = db.get_switch_by_id(opts.show_switch)
+ switch = call_vland('query',
+ {'command':'db.get_switch_by_id',
+ 'data':{'switch_id': opts.show_switch}})
if switch is not None:
dump_switch(switch)
else:
@@ -338,7 +357,9 @@ elif opts.show_switch is not None:
print 'Failed: %s' % inst
elif opts.list_switch_ports is not None:
try:
- ports = db.get_ports_by_switch(opts.list_switch_ports)
+ ports = call_vland('query',
+ {'command':'db.get_ports_by_switch',
+ 'data':{'switch_id': opts.list_switch_ports}})
if ports is not None:
for port in ports:
dump_port(port)
@@ -348,7 +369,9 @@ elif opts.list_switch_ports is not None:
print 'Failed: %s' % inst
elif opts.show_port is not None:
try:
- port = db.get_port_by_id(opts.show_port)
+ port = call_vland('query',
+ {'command':'db.get_port_by_id',
+ 'data':{'port_id': opts.show_port}})
if port is not None:
dump_port(port)
else:
@@ -357,7 +380,11 @@ elif opts.show_port is not None:
print 'Failed: %s' % inst
elif opts.lookup_port_by_switch_and_name is not None:
try:
- port = db.get_port_by_switch_and_name(opts.lookup_port_by_switch_and_name[0], opts.lookup_port_by_switch_and_name[1])
+ port = call_vland('query',
+ {'command':'db.get_port_by_switch_and_name',
+ 'data':
+ {'switch_id': opts.lookup_port_by_switch_and_name[0],
+ 'name': opts.lookup_port_by_switch_and_name[1]}})
if port is not None:
print port
else:
@@ -390,7 +417,9 @@ elif opts.set_port_current_vlan is not None:
print 'Failed: %s' % inst
elif opts.get_port_current_vlan is not None:
try:
- vlan_id = db.get_current_vlan_id_by_port(opts.get_port_current_vlan)
+ vlan_id = call_vland('query',
+ {'command':'db.get_current_vlan_id_by_port',
+ 'data':{'port_id': opts.get_port_current_vlan}})
if vlan_id is not None:
print vlan_id
else:
@@ -405,7 +434,9 @@ elif opts.set_port_base_vlan is not None:
print 'Failed: %s' % inst
elif opts.get_port_base_vlan is not None:
try:
- vlan_id = db.get_base_vlan_id_by_port(opts.get_port_base_vlan)
+ vlan_id = call_vland('query',
+ {'command':'db.get_base_vlan_id_by_port',
+ 'data':{'port_id': opts.get_port_base_vlan}})
if vlan_id is not None:
print vlan_id
else:
@@ -420,7 +451,9 @@ elif opts.restore_port_to_base_vlan is not None:
print 'Failed: %s' % inst
elif opts.show_vlan is not None:
try:
- vlan = db.get_vlan_by_id(opts.show_vlan)
+ vlan = call_vland('query',
+ {'command':'db.get_vlan_by_id',
+ 'data':{'vlan_id': opts.show_vlan}})
if vlan is not None:
dump_vlan(vlan)
else:
@@ -439,5 +472,14 @@ elif opts.status:
vlans = db.all_vlans()
print ' DB knows about %d vlan(s)' % len(vlans)
print 'The default vlan tag (%d) is vlan_id %d' % (config.vland.default_vlan_tag, default_vlan_id)
+ ret = call_vland('query', {'command':'status', 'data': None})
+ print 'VLANd is running %s' % ret['running']
+ print 'DB via VLANd:'
+ switches = call_vland('query', {'command':'db.all_switches', 'data':None})
+ print ' knows about %d switch(es)' % len(switches)
+ ports = call_vland('query', {'command':'db.all_ports', 'data':None})
+ print ' knows about %d port(s)' % len(ports)
+ vlans = call_vland('query', {'command':'db.all_vlans', 'data':None})
+ print ' DB knows about %d vlan(s)' % len(vlans)
else:
print 'No recognised command given. Try -h for help'