blob: b59267ef67f58a7f04e6dc11551973d7a631e4b1 [file] [log] [blame]
Don Newton2bdfd3f2019-04-08 17:06:33 -04001/*
Kent Hagerman0ab4cb22019-04-24 13:13:35 -04002 * Copyright 2018-present Open Networking Foundation
Don Newton2bdfd3f2019-04-08 17:06:33 -04003
Kent Hagerman0ab4cb22019-04-24 13:13:35 -04004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Don Newton2bdfd3f2019-04-08 17:06:33 -04007
Kent Hagerman0ab4cb22019-04-24 13:13:35 -04008 * http://www.apache.org/licenses/LICENSE-2.0
Don Newton2bdfd3f2019-04-08 17:06:33 -04009
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Don Newton2bdfd3f2019-04-08 17:06:33 -040016
17package mainmenu
18
19import (
20 "context"
21 "fmt"
22 "strconv"
23
24 "github.com/golang/protobuf/ptypes/empty"
25 "github.com/opencord/voltha-go/cli/util"
Scott Baker555307d2019-11-04 08:58:01 -080026 "github.com/opencord/voltha-protos/v2/go/voltha"
Don Newton2bdfd3f2019-04-08 17:06:33 -040027)
28
29/*
30 reason | proxy_address.device_id | proxy_address.onu_id | proxy_address.onu_session_id |
31*/
32func doDevices(enterPressed bool) {
33
34 client := voltha.NewVolthaServiceClient(Conn)
35 devices, err := client.ListDevices(context.Background(), &empty.Empty{})
36 if err != nil {
37 fmt.Println(err)
38 }
39 var rows []map[string]string
40 items := devices.GetItems()
41 var fields = []string{"id", "type", "root", "parent_id", "serial_number", "admin_state", "oper_status", "connect_status", "parent_port_no", "host_and_port", "reason",
42 "proxy_address.device_id", "proxy_address.onu_id", "proxy_address.onu_session_id"}
43
44 for i := 0; i < len(items); i++ {
45 //fmt.Println(items[i])
46 device := items[i]
47 row := make(map[string]string)
48 row["id"] = device.Id
49 row["type"] = device.Type
50 row["root"] = strconv.FormatBool(device.Root)
51 row["parent_id"] = device.ParentId
52 row["serial_number"] = device.SerialNumber
53 row["admin_state"] = device.AdminState.String()
54 row["oper_status"] = device.OperStatus.String()
55 row["connect_status"] = device.ConnectStatus.String()
56 row["parent_port_no"] = strconv.FormatUint(uint64(device.GetParentPortNo()), 10)
57 row["host_and_port"] = device.GetHostAndPort()
58 row["reason"] = device.Reason
59 proxyAddress := device.GetProxyAddress()
60 if proxyAddress != nil {
61 row["proxy_address.device_id"] = proxyAddress.DeviceId
62 row["proxy_address.onu_id"] = strconv.FormatUint(uint64(proxyAddress.OnuId), 10)
63 row["proxy_address.onu_session_id"] = strconv.FormatUint(uint64(proxyAddress.OnuSessionId), 10)
64 } else {
65 row["proxy_address.device_id"] = ""
66 row["proxy_address.onu_id"] = ""
67 row["proxy_address.onu_session_id"] = ""
68 }
69
70 rows = append(rows, row)
71 }
72 output, err := util.BuildTable(fields, rows)
73 if err != nil {
74 fmt.Println(err)
75 }
76 fmt.Print(output)
77
78}