blob: d418987e2a05d58211605620804e19994f0a09c4 [file] [log] [blame]
Steve McIntyre844bfd42014-11-27 16:58:31 +00001#! /usr/bin/python
2
3# Copyright 2014 Linaro Limited
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18# MA 02110-1301, USA.
19#
20# VLANd admin interface
21#
22
23import os, sys, types
24import time
25import logging
26import optparse
27
28vlandpath = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0])))
29sys.path.insert(0, vlandpath)
30
31import drivers
Steve McIntyre21f02702014-12-16 18:19:47 +000032from errors import CriticalError, InputError, ConfigError, SocketError
Steve McIntyre21f02702014-12-16 18:19:47 +000033from config.config import VlanConfig
34from ipc.ipc import VlanIpc
Steve McIntyre844bfd42014-11-27 16:58:31 +000035
36version = "0.0.0-DEV"
37banner = "Linaro VLANd admin interface, version %s" % version
38
Steve McIntyreae95fd62014-12-05 16:51:41 +000039def is_positive(text):
40 if text in ('1', 'y', 'Y', 't', 'T', 'True'):
41 return True
42 elif text in ('0', 'n', 'N', 'f', 'F', 'False'):
43 return False
44 else:
45 raise InputError("Cannot parse \"%s\" as True or False" % text)
46
Steve McIntyrea132c362014-12-05 15:53:21 +000047def dump_switch(switch):
48 print switch
49
Steve McIntyre11e4cbd2014-12-05 16:03:03 +000050def dump_port(port):
51 print port
52
Steve McIntyree41e3f32014-12-05 18:08:21 +000053def dump_vlan(vlan):
54 print vlan
55
Steve McIntyref1c04f92014-12-16 18:23:15 +000056def call_vland(msgtype, msg):
57 ipc = VlanIpc()
58 ipc.client_connect('localhost', config.vland.port)
59 msg['client_name'] = 'admin.py'
60 msg['type'] = msgtype
61# print 'Sending:'
62# print msg
63 ipc.client_send(msg)
64 ret = ipc.client_recv_and_close()
65 if 'response' not in ret:
66 raise SocketError("Badly-formed response from VLANd server")
67 if ret['response'] == "ERROR":
68 raise InputError("VLANd server said: %s" % ret['error'])
69# print 'VLANd said in reply:'
70# print ret
71 return ret['data']
72
Steve McIntyre844bfd42014-11-27 16:58:31 +000073#print '%s' % banner
74
Steve McIntyrec12f6312014-12-15 15:00:12 +000075config = VlanConfig(filenames=('./vland.cfg',))
Steve McIntyrec12f6312014-12-15 15:00:12 +000076
Steve McIntyre844bfd42014-11-27 16:58:31 +000077usage = 'Usage: %prog --command [command options]'
Steve McIntyre844bfd42014-11-27 16:58:31 +000078parser = optparse.OptionParser(usage=usage, description=banner)
79
Steve McIntyre9cd6c3d2014-12-05 18:10:35 +000080# System commands
81system_group = optparse.OptionGroup(parser, "System commands")
82system_group.add_option("--status",
83 dest="status",
84 action = "store_true",
85 default = False,
86 help = "Describe current system status")
Steve McIntyrec00d4cf2014-12-16 19:23:39 +000087system_group.add_option("--statistics",
88 dest="statistics",
89 action = "store_true",
90 default = False,
91 help = "Print some system statistics")
92system_group.add_option("--version",
93 dest="version",
94 action = "store_true",
95 default = False,
96 help = "Describe the version of this admin interface")
97system_group.add_option("--vland_version",
98 dest="vland_version",
99 action = "store_true",
100 default = False,
101 help = "Describe the version of the running VLANd")
Steve McIntyre9cd6c3d2014-12-05 18:10:35 +0000102parser.add_option_group(system_group)
103# May add shutdown, self-check etc. later
104
Steve McIntyre844bfd42014-11-27 16:58:31 +0000105# Switch commands
106switch_group = optparse.OptionGroup(parser, "Switch commands")
107switch_group.add_option("--list_all_switches",
108 dest = "list_all_switches",
109 action = "store_true",
110 default = False,
111 help = "List all the existing switches in the system")
112switch_group.add_option("--create_switch",
113 dest = "create_switch",
114 action = "store",
115 type = "string",
116 help = "Add a new switch to the system",
117 nargs = 1,
118 metavar = "<name>")
Steve McIntyre99feaee2014-12-02 18:22:36 +0000119switch_group.add_option("--delete_switch",
120 dest = "delete_switch",
Steve McIntyre844bfd42014-11-27 16:58:31 +0000121 action = "store",
122 type = "int",
123 help = "Remove an existing switch from the system",
Steve McIntyre59e04632014-12-02 18:02:16 +0000124 default = None,
Steve McIntyre844bfd42014-11-27 16:58:31 +0000125 nargs = 1,
126 metavar = "<switch_id>")
127switch_group.add_option("--show_switch",
128 dest = "show_switch",
129 action = "store",
130 type = "int",
131 help = "Show the details of an existing switch in the system",
Steve McIntyre59e04632014-12-02 18:02:16 +0000132 default = None,
Steve McIntyre844bfd42014-11-27 16:58:31 +0000133 nargs = 1,
134 metavar = "<switch_id>")
135switch_group.add_option("--lookup_switch_by_name",
136 dest = "lookup_switch_by_name",
137 action = "store",
138 type = "string",
139 help = "Lookup a switch ID by name",
140 nargs = 1,
141 metavar = "<name>")
142switch_group.add_option("--list_switch_ports",
143 dest = "list_switch_ports",
144 action = "store",
145 type = "int",
Steve McIntyre11e4cbd2014-12-05 16:03:03 +0000146 help = "List the IDs of the ports on an existing switch in the system",
Steve McIntyre59e04632014-12-02 18:02:16 +0000147 default = None,
Steve McIntyre844bfd42014-11-27 16:58:31 +0000148 nargs = 1,
149 metavar = "<switch_id>")
150parser.add_option_group(switch_group)
151
152# Port commands
153port_group = optparse.OptionGroup(parser, "Port commands")
154port_group.add_option("--list_all_ports",
155 dest = "list_all_ports",
156 action = "store_true",
157 default = False,
158 help = "List all the existing ports in the system")
159port_group.add_option("--create_port",
160 dest = "create_port",
161 action = "store",
162 type = "string",
163 help = "Add a new port to the system",
164 nargs = 2,
165 metavar = "<switch_id> <name>")
Steve McIntyre99feaee2014-12-02 18:22:36 +0000166port_group.add_option("--delete_port",
167 dest = "delete_port",
Steve McIntyre844bfd42014-11-27 16:58:31 +0000168 action = "store",
169 type = "int",
170 help = "Remove an existing port from the system",
Steve McIntyre59e04632014-12-02 18:02:16 +0000171 default = None,
Steve McIntyre844bfd42014-11-27 16:58:31 +0000172 nargs = 1,
173 metavar = "<port_id>")
174port_group.add_option("--show_port",
175 dest = "show_port",
176 action = "store",
177 type = "int",
178 help = "Show the details of an existing port in the system",
Steve McIntyre59e04632014-12-02 18:02:16 +0000179 default = None,
Steve McIntyre844bfd42014-11-27 16:58:31 +0000180 nargs = 1,
181 metavar = "<port_id>")
182port_group.add_option("--lookup_port_by_switch_and_name",
183 dest = "lookup_port_by_switch_and_name",
184 action = "store",
185 type = "string",
186 help = "Lookup a port ID by switch and port name",
187 nargs = 2,
188 metavar = "<switch_id> <name>")
Steve McIntyre71b41022014-12-05 17:17:44 +0000189port_group.add_option("--set_port_mode",
190 dest = "set_port_mode",
Steve McIntyre844bfd42014-11-27 16:58:31 +0000191 action = "store",
192 type = "string",
193 help = "Set the mode of a port to 'trunk' or 'access'",
194 nargs = 2,
195 metavar = "<port_id> <mode>")
196port_group.add_option("--lock_port",
197 dest = "lock_port",
198 action = "store",
199 type = "string",
200 help = "Lock the settings on a port",
201 nargs = 1,
202 metavar = "<port_id>")
203port_group.add_option("--unlock_port",
204 dest = "unlock_port",
205 action = "store",
206 type = "string",
207 help = "Unock the settings on a port",
208 nargs = 1,
209 metavar = "<port_id>")
210port_group.add_option("--set_port_current_vlan",
211 dest = "set_port_current_vlan",
212 action = "store",
213 type = "int",
214 help = "Set the current VLAN assignment for a port",
215 nargs = 2,
216 metavar = "<port_id> <vlan_id>")
217port_group.add_option("--get_port_current_vlan",
218 dest = "get_port_current_vlan",
219 action = "store",
220 type = "int",
221 help = "Get the current VLAN assignment for a port",
222 nargs = 1,
223 metavar = "<port_id>")
224port_group.add_option("--set_port_base_vlan",
225 dest = "set_port_base_vlan",
226 action = "store",
227 type = "int",
228 help = "Set the base VLAN assignment for a port",
229 nargs = 2,
230 metavar = "<port_id> <vlan_id>")
231port_group.add_option("--get_port_base_vlan",
232 dest = "get_port_base_vlan",
233 action = "store",
234 type = "int",
235 help = "Get the base VLAN assignment for a port",
236 nargs = 1,
237 metavar = "<port_id>")
Steve McIntyrea2bbcda2014-12-05 17:57:36 +0000238port_group.add_option("--restore_port_to_base_vlan",
239 dest = "restore_port_to_base_vlan",
240 action = "store",
241 type = "int",
242 help = "Reset the port back to its base VLAN",
243 nargs = 1,
244 metavar = "<port_id>")
Steve McIntyre844bfd42014-11-27 16:58:31 +0000245parser.add_option_group(port_group)
246
247# VLAN commands
248vlan_group = optparse.OptionGroup(parser, "VLAN commands")
249vlan_group.add_option("--list_all_vlans",
250 dest = "list_all_vlans",
251 action = "store_true",
252 default = False,
253 help = "List all the existing vlans in the system")
254vlan_group.add_option("--create_vlan",
255 dest = "create_vlan",
256 action = "store",
257 type = "string",
258 help = "Add a new vlan to the system",
259 nargs = 3,
Steve McIntyre9f0bb602014-11-28 14:36:39 +0000260 metavar = "<name> <tag> <is_base_vlan>")
Steve McIntyre99feaee2014-12-02 18:22:36 +0000261vlan_group.add_option("--delete_vlan",
262 dest = "delete_vlan",
Steve McIntyre844bfd42014-11-27 16:58:31 +0000263 action = "store",
264 type = "int",
265 help = "Remove an existing vlan from the system",
Steve McIntyre59e04632014-12-02 18:02:16 +0000266 default = None,
Steve McIntyre844bfd42014-11-27 16:58:31 +0000267 nargs = 1,
268 metavar = "<vlan_id>")
269vlan_group.add_option("--show_vlan",
270 dest = "show_vlan",
271 action = "store",
272 type = "int",
273 help = "Show the details of an existing vlan in the system",
Steve McIntyre59e04632014-12-02 18:02:16 +0000274 default = None,
Steve McIntyre844bfd42014-11-27 16:58:31 +0000275 nargs = 1,
276 metavar = "<vlan_id>")
277parser.add_option_group(vlan_group)
278
279(opts, args) = parser.parse_args()
280
Steve McIntyre844bfd42014-11-27 16:58:31 +0000281if opts.list_all_switches:
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000282 result = call_vland('db_query', {'command':'db.all_switches', 'data':None})
Steve McIntyre844bfd42014-11-27 16:58:31 +0000283 count = 0;
284 for line in result:
285 print line
286 count += 1
287 print '%d entries' % count
Steve McIntyreaf2d5ed2014-12-02 12:42:28 +0000288elif opts.list_all_ports:
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000289 result = call_vland('db_query', {'command':'db.all_ports', 'data':None})
Steve McIntyreaf2d5ed2014-12-02 12:42:28 +0000290 count = 0;
291 for line in result:
292 print line
293 count += 1
294 print '%d entries' % count
295elif opts.list_all_vlans:
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000296 result = call_vland('db_query', {'command':'db.all_vlans', 'data':None})
Steve McIntyreaf2d5ed2014-12-02 12:42:28 +0000297 count = 0;
298 for line in result:
299 print line
300 count += 1
301 print '%d entries' % count
Steve McIntyre844bfd42014-11-27 16:58:31 +0000302elif opts.create_switch is not None:
Steve McIntyreaf2d5ed2014-12-02 12:42:28 +0000303 try:
Steve McIntyre7103de22014-12-17 13:16:48 +0000304 switch_id = call_vland('db_update',
305 {'command':'db.create_switch',
306 'data':
307 {'name':opts.create_switch}})
Steve McIntyreaf2d5ed2014-12-02 12:42:28 +0000308 print 'Created switch_id %d' % switch_id
309 except InputError as inst:
310 print 'Failed: %s' % inst
Steve McIntyre844bfd42014-11-27 16:58:31 +0000311elif opts.create_port is not None:
Steve McIntyreaf2d5ed2014-12-02 12:42:28 +0000312 try:
Steve McIntyre7103de22014-12-17 13:16:48 +0000313 port_id = call_vland('db_update',
314 {'command':'db.create_port',
315 'data':
316 {'switch_id': opts.create_port[0],
317 'name': opts.create_port[1]}})
Steve McIntyreaf2d5ed2014-12-02 12:42:28 +0000318 print 'Created port_id %d' % port_id
319 except InputError as inst:
320 print 'Failed: %s' % inst
Steve McIntyrec21d8d12014-11-28 14:42:40 +0000321elif opts.create_vlan is not None:
Steve McIntyrec8aba4c2014-12-02 12:48:51 +0000322 try:
323 vlan_id = db.create_vlan(opts.create_vlan[0],
324 opts.create_vlan[1],
Steve McIntyreae95fd62014-12-05 16:51:41 +0000325 is_positive(opts.create_vlan[2]))
Steve McIntyrec8aba4c2014-12-02 12:48:51 +0000326 print 'Created vlan_id %d' % vlan_id
327 except InputError as inst:
328 print 'Failed: %s' % inst
Steve McIntyre99feaee2014-12-02 18:22:36 +0000329elif opts.delete_switch is not None:
Steve McIntyre64e38862014-12-02 17:19:37 +0000330 try:
Steve McIntyre7103de22014-12-17 13:16:48 +0000331 switch_id = call_vland('db_update',
332 {'command':'db.delete_switch',
333 'data': {'switch_id': opts.delete_switch}})
Steve McIntyre64e38862014-12-02 17:19:37 +0000334 print 'Deleted switch_id %d' % switch_id
335 except InputError as inst:
336 print 'Failed: %s' % inst
Steve McIntyre99feaee2014-12-02 18:22:36 +0000337elif opts.delete_port is not None:
Steve McIntyre6f7ee5c2014-12-02 18:02:50 +0000338 try:
Steve McIntyre7103de22014-12-17 13:16:48 +0000339 port_id = call_vland('db_update',
340 {'command':'db.delete_port',
341 'data': {'port_id': opts.delete_port}})
Steve McIntyre6f7ee5c2014-12-02 18:02:50 +0000342 except InputError as inst:
343 print 'Failed: %s' % inst
Steve McIntyreed5cbea2014-12-02 18:23:00 +0000344elif opts.delete_vlan is not None:
345 try:
346 vlan_id = db.delete_vlan(opts.delete_vlan)
347 print 'Deleted vlan_id %d' % vlan_id
348 except InputError as inst:
349 print 'Failed: %s' % inst
Steve McIntyre8e839a62014-12-05 15:46:05 +0000350elif opts.lookup_switch_by_name is not None:
351 try:
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000352 switch_id = call_vland('db_query', {'command':'db.get_switch_id_by_name', 'data':{'name':opts.lookup_switch_by_name}})
Steve McIntyre8e839a62014-12-05 15:46:05 +0000353 if switch_id is not None:
Steve McIntyref1c04f92014-12-16 18:23:15 +0000354 print '%d' % switch_id
Steve McIntyre8e839a62014-12-05 15:46:05 +0000355 else:
356 print 'No switch found for name %s' % opts.lookup_switch_by_name
357 except InputError as inst:
358 print 'Failed: %s' % inst
Steve McIntyrea132c362014-12-05 15:53:21 +0000359elif opts.show_switch is not None:
360 try:
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000361 switch = call_vland('db_query',
Steve McIntyref1c04f92014-12-16 18:23:15 +0000362 {'command':'db.get_switch_by_id',
363 'data':{'switch_id': opts.show_switch}})
Steve McIntyrea132c362014-12-05 15:53:21 +0000364 if switch is not None:
365 dump_switch(switch)
366 else:
367 print 'No switch found for switch_id %d' % opts.show_switch
368 except InputError as inst:
369 print 'Failed: %s' % inst
Steve McIntyre11e4cbd2014-12-05 16:03:03 +0000370elif opts.list_switch_ports is not None:
371 try:
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000372 ports = call_vland('db_query',
Steve McIntyref1c04f92014-12-16 18:23:15 +0000373 {'command':'db.get_ports_by_switch',
374 'data':{'switch_id': opts.list_switch_ports}})
Steve McIntyre11e4cbd2014-12-05 16:03:03 +0000375 if ports is not None:
376 for port in ports:
377 dump_port(port)
378 else:
379 print 'No ports found for switch_id %d' % opts.list_switch_ports
380 except InputError as inst:
381 print 'Failed: %s' % inst
Steve McIntyre08dd8392014-12-05 16:07:20 +0000382elif opts.show_port is not None:
383 try:
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000384 port = call_vland('db_query',
Steve McIntyref1c04f92014-12-16 18:23:15 +0000385 {'command':'db.get_port_by_id',
386 'data':{'port_id': opts.show_port}})
Steve McIntyre08dd8392014-12-05 16:07:20 +0000387 if port is not None:
388 dump_port(port)
389 else:
390 print 'No port found for port_id %d' % opts.show_port
391 except InputError as inst:
392 print 'Failed: %s' % inst
Steve McIntyre73106572014-12-05 16:13:36 +0000393elif opts.lookup_port_by_switch_and_name is not None:
394 try:
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000395 port = call_vland('db_query',
Steve McIntyref1c04f92014-12-16 18:23:15 +0000396 {'command':'db.get_port_by_switch_and_name',
397 'data':
398 {'switch_id': opts.lookup_port_by_switch_and_name[0],
399 'name': opts.lookup_port_by_switch_and_name[1]}})
Steve McIntyre73106572014-12-05 16:13:36 +0000400 if port is not None:
401 print port
402 else:
403 print 'No port found for switch_id %d, name %s' % (int(opts.lookup_port_by_switch_and_name[0]), opts.lookup_port_by_switch_and_name[1])
404 except InputError as inst:
405 print 'Failed: %s' % inst
Steve McIntyre71b41022014-12-05 17:17:44 +0000406elif opts.set_port_mode is not None:
407 try:
408 port_id = db.set_port_mode(opts.set_port_mode[0], opts.set_port_mode[1])
409 print "Updated mode for port_id %d" % port_id
410 except InputError as inst:
411 print 'Failed: %s' % inst
Steve McIntyre75dc4ec2014-12-05 17:20:42 +0000412elif opts.lock_port is not None:
413 try:
Steve McIntyre7103de22014-12-17 13:16:48 +0000414 port_id = call_vland('db_update',
415 {'command':'db.set_port_is_locked',
416 'data':
417 {'port_id': opts.lock_port,
418 'is_locked': True}})
Steve McIntyre75dc4ec2014-12-05 17:20:42 +0000419 print "Locked port_id %d" % port_id
420 except InputError as inst:
421 print 'Failed: %s' % inst
422elif opts.unlock_port is not None:
423 try:
Steve McIntyre7103de22014-12-17 13:16:48 +0000424 port_id = call_vland('db_update',
425 {'command':'db.set_port_is_locked',
426 'data':
427 {'port_id': opts.unlock_port,
428 'is_locked': False}})
Steve McIntyre75dc4ec2014-12-05 17:20:42 +0000429 print "Unlocked port_id %d" % port_id
430 except InputError as inst:
431 print 'Failed: %s' % inst
Steve McIntyrea2bbcda2014-12-05 17:57:36 +0000432elif opts.set_port_current_vlan is not None:
433 try:
434 port_id = db.set_current_vlan(opts.set_port_current_vlan[0], opts.set_port_current_vlan[1])
435 print "Set current VLAN on port_id %d" % port_id
436 except InputError as inst:
437 print 'Failed: %s' % inst
438elif opts.get_port_current_vlan is not None:
439 try:
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000440 vlan_id = call_vland('db_query',
Steve McIntyref1c04f92014-12-16 18:23:15 +0000441 {'command':'db.get_current_vlan_id_by_port',
442 'data':{'port_id': opts.get_port_current_vlan}})
Steve McIntyrea2bbcda2014-12-05 17:57:36 +0000443 if vlan_id is not None:
444 print vlan_id
445 else:
446 print "No current_vlan_id found for port_id %d" % opts.get_port_current_vlan
447 except InputError as inst:
448 print 'Failed: %s' % inst
449elif opts.set_port_base_vlan is not None:
450 try:
Steve McIntyre7103de22014-12-17 13:16:48 +0000451 port_id = call_vland('db_update',
452 {'command':'db.set_base_vlan',
453 'data':
454 {'port_id': opts.set_base_vlan[0],
455 'base_vlan_id': opts.set_base_vlan[1]}})
Steve McIntyrea2bbcda2014-12-05 17:57:36 +0000456 print "Set base VLAN on port_id %d" % port_id
457 except InputError as inst:
458 print 'Failed: %s' % inst
459elif opts.get_port_base_vlan is not None:
460 try:
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000461 vlan_id = call_vland('db_query',
Steve McIntyref1c04f92014-12-16 18:23:15 +0000462 {'command':'db.get_base_vlan_id_by_port',
463 'data':{'port_id': opts.get_port_base_vlan}})
Steve McIntyrea2bbcda2014-12-05 17:57:36 +0000464 if vlan_id is not None:
465 print vlan_id
466 else:
467 print "No base_vlan_id found for port_id %d" % port_id
468 except InputError as inst:
469 print 'Failed: %s' % inst
470elif opts.restore_port_to_base_vlan is not None:
471 try:
472 port_id = db.restore_base_vlan(opts.restore_port_to_base_vlan)
473 print "Restored port_id %d back to base VLAN" % port_id
474 except InputError as inst:
475 print 'Failed: %s' % inst
Steve McIntyree41e3f32014-12-05 18:08:21 +0000476elif opts.show_vlan is not None:
477 try:
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000478 vlan = call_vland('db_query',
Steve McIntyref1c04f92014-12-16 18:23:15 +0000479 {'command':'db.get_vlan_by_id',
480 'data':{'vlan_id': opts.show_vlan}})
Steve McIntyree41e3f32014-12-05 18:08:21 +0000481 if vlan is not None:
482 dump_vlan(vlan)
483 else:
484 print 'No vlan found for vlan_id %d' % opts.show_vlan
485 except InputError as inst:
486 print 'Failed: %s' % inst
Steve McIntyre9cd6c3d2014-12-05 18:10:35 +0000487elif opts.status:
Steve McIntyrebb718cf2014-12-15 16:57:25 +0000488 print 'Config:'
489 print ' knows about %d switch(es)' % len(config.switches)
Steve McIntyre7103de22014-12-17 13:16:48 +0000490 default_vlan_id = call_vland('db_query',
491 {'command':'db.get_vlan_id_by_tag',
492 'data': {'tag': config.vland.default_vlan_tag}})
Steve McIntyre0abacac2014-12-15 16:51:38 +0000493 print 'The default vlan tag (%d) is vlan_id %d' % (config.vland.default_vlan_tag, default_vlan_id)
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000494 ret = call_vland('daemon_query', {'command':'daemon.status', 'data': None})
Steve McIntyref1c04f92014-12-16 18:23:15 +0000495 print 'VLANd is running %s' % ret['running']
496 print 'DB via VLANd:'
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000497 switches = call_vland('db_query', {'command':'db.all_switches', 'data':None})
Steve McIntyref1c04f92014-12-16 18:23:15 +0000498 print ' knows about %d switch(es)' % len(switches)
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000499 ports = call_vland('db_query', {'command':'db.all_ports', 'data':None})
Steve McIntyref1c04f92014-12-16 18:23:15 +0000500 print ' knows about %d port(s)' % len(ports)
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000501 vlans = call_vland('db_query', {'command':'db.all_vlans', 'data':None})
Steve McIntyref1c04f92014-12-16 18:23:15 +0000502 print ' DB knows about %d vlan(s)' % len(vlans)
Steve McIntyre091e2ac2014-12-16 19:20:07 +0000503elif opts.vland_version:
504 ret = call_vland('daemon_query', {'command':'daemon.version', 'data': None})
505 print 'VLANd version %s' % ret['version']
506elif opts.statistics:
507 ret = call_vland('daemon_query', {'command':'daemon.statistics', 'data': None})
508 print 'VLANd uptime: %d seconds' % ret['uptime']
509elif opts.version:
510 print 'VLANd admin interface version %s' % version
Steve McIntyrea0534a52014-12-05 17:58:40 +0000511else:
Steve McIntyre4a808912014-12-05 15:24:39 +0000512 print 'No recognised command given. Try -h for help'