blob: 286faf099bb3ae212f268bff5e19310c392db6ac [file] [log] [blame]
Zsolt Harasztid036b7e2016-12-23 15:36:01 -08001#!/usr/bin/env python
2#
3# Copyright 2016 the original author or authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18"""
19Logical device level CLI commands
20"""
21from cmd2 import Cmd
22from simplejson import dumps
23
24from cli.utils import pb2dict
25from cli.utils import print_flows
26from voltha.protos import third_party
27
28_ = third_party
29from voltha.protos import voltha_pb2
30
31
32class LogicalDeviceCli(Cmd):
33
34 def __init__(self, get_channel, logical_device_id):
35 Cmd.__init__(self)
36 self.get_channel = get_channel
37 self.logical_device_id = logical_device_id
38 self.prompt = '(' + self.colorize(
39 self.colorize('logical device {}'.format(logical_device_id), 'red'),
40 'bold') + ') '
41
42 def get_logical_device(self, depth=0):
43 stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel())
44 res = stub.GetLogicalDevice(voltha_pb2.ID(id=self.logical_device_id),
45 metadata=(('get-depth', str(depth)), ))
46 return res
47
Zsolt Haraszti80175202016-12-24 00:17:51 -080048 do_exit = Cmd.do_quit
49
Zsolt Harasztid036b7e2016-12-23 15:36:01 -080050 def do_show(self, arg):
51 """Show detailed logical device information"""
Zsolt Haraszti80175202016-12-24 00:17:51 -080052 self.poutput(dumps(pb2dict(self.get_logical_device(depth=-1)),
53 indent=4, sort_keys=True))
Zsolt Harasztid036b7e2016-12-23 15:36:01 -080054
55 def do_flows(self, arg):
56 """Show flow table for logical device"""
57 logical_device = pb2dict(self.get_logical_device(-1))
58 print_flows(
59 'Logical Device',
60 self.logical_device_id,
61 type='n/a',
62 flows=logical_device['flows']['items'],
63 groups=logical_device['flow_groups']['items']
64 )
65