blob: fc56eed7bb561b8d6440410b72ad8194bbe0d66d [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 devicemenu
18
19import (
20 "context"
21 "fmt"
22 "strconv"
23
24 "github.com/opencord/voltha-go/cli/util"
Scott Baker555307d2019-11-04 08:58:01 -080025 "github.com/opencord/voltha-protos/v2/go/common"
26 "github.com/opencord/voltha-protos/v2/go/voltha"
Don Newton2bdfd3f2019-04-08 17:06:33 -040027)
28
29func doShow(enterPressed bool) {
30 client := voltha.NewVolthaServiceClient(Conn)
npujar16d6d5c2019-10-30 16:45:06 +053031 fmt.Println(*DeviceID)
32 device, err := client.GetDevice(context.Background(), &common.ID{Id: *DeviceID})
Don Newton2bdfd3f2019-04-08 17:06:33 -040033 if err != nil {
34 fmt.Println(err)
35 }
36 fields := []string{"field", "value"}
37 var rows []map[string]string
38
39 id := make(map[string]string)
40 id["field"] = "id"
41 id["value"] = device.Id
42 rows = append(rows, id)
43
44 Type := make(map[string]string)
45 Type["field"] = "type"
46 Type["value"] = device.Type
47 rows = append(rows, Type)
48
npujar16d6d5c2019-10-30 16:45:06 +053049 parentID := make(map[string]string)
50 parentID["field"] = "parent_id"
51 parentID["value"] = device.ParentId
52 rows = append(rows, parentID)
Don Newton2bdfd3f2019-04-08 17:06:33 -040053
54 vlan := make(map[string]string)
55 vlan["field"] = "vlan"
56 vlan["value"] = strconv.FormatUint(uint64(device.Vlan), 10)
57 rows = append(rows, vlan)
58
59 adminState := make(map[string]string)
60 adminState["field"] = "admin_state"
61 adminState["value"] = strconv.FormatUint(uint64(device.AdminState), 10)
62 rows = append(rows, adminState)
63
64 proxyAddress := device.GetProxyAddress()
npujar16d6d5c2019-10-30 16:45:06 +053065 proxyDeviceID := make(map[string]string)
66 proxyDeviceID["field"] = "proxy_address.device_id"
67 proxyDeviceID["value"] = proxyAddress.DeviceId
68 rows = append(rows, proxyDeviceID)
Don Newton2bdfd3f2019-04-08 17:06:33 -040069
70 proxyDeviceType := make(map[string]string)
71 proxyDeviceType["field"] = "proxy_address.device_type"
72 proxyDeviceType["value"] = proxyAddress.DeviceType
73 rows = append(rows, proxyDeviceType)
74
npujar16d6d5c2019-10-30 16:45:06 +053075 proxyChannelID := make(map[string]string)
76 proxyChannelID["field"] = "proxy_address.channel_id"
77 proxyChannelID["value"] = strconv.FormatUint(uint64(proxyAddress.ChannelId), 10)
78 rows = append(rows, proxyChannelID)
Don Newton2bdfd3f2019-04-08 17:06:33 -040079
80 parentPortNumber := make(map[string]string)
81 parentPortNumber["field"] = "parent_port_no"
82 parentPortNumber["value"] = strconv.FormatUint(uint64(device.GetParentPortNo()), 10)
83 rows = append(rows, parentPortNumber)
84
85 output, _ := util.BuildTable(fields, rows)
86
87 fmt.Println(output)
88}