Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-present Ciena Corporation |
| 3 | * |
| 4 | * 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * 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 | */ |
| 16 | package commands |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "fmt" |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 21 | "os" |
| 22 | "strconv" |
| 23 | "strings" |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 24 | "time" |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 25 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 26 | "github.com/golang/protobuf/ptypes/empty" |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 27 | flags "github.com/jessevdk/go-flags" |
Scott Baker | 2b0ad65 | 2019-08-21 14:57:07 -0700 | [diff] [blame] | 28 | "github.com/opencord/voltctl/pkg/format" |
David K. Bainbridge | bd6b288 | 2021-08-26 13:31:02 +0000 | [diff] [blame] | 29 | "github.com/opencord/voltha-protos/v5/go/common" |
| 30 | "github.com/opencord/voltha-protos/v5/go/extension" |
| 31 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | const ( |
David K. Bainbridge | 89003c4 | 2020-02-27 17:22:49 -0800 | [diff] [blame] | 35 | DEFAULT_DEVICE_FORMAT = "table{{ .Id }}\t{{.Type}}\t{{.Root}}\t{{.ParentId}}\t{{.SerialNumber}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.ConnectStatus}}\t{{.Reason}}" |
Hardik Windlass | 9361bb8 | 2022-03-23 05:58:48 +0000 | [diff] [blame] | 36 | DEFAULT_DEVICE_ORDER = "Type,Id" |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 37 | DEFAULT_DEVICE_PORTS_FORMAT = "table{{.PortNo}}\t{{.Label}}\t{{.Type}}\t{{.AdminState}}\t{{.OperStatus}}\t{{.DeviceId}}\t{{.Peers}}" |
| 38 | DEFAULT_DEVICE_INSPECT_FORMAT = `ID: {{.Id}} |
| 39 | TYPE: {{.Type}} |
| 40 | ROOT: {{.Root}} |
| 41 | PARENTID: {{.ParentId}} |
| 42 | SERIALNUMBER: {{.SerialNumber}} |
| 43 | VLAN: {{.Vlan}} |
| 44 | ADMINSTATE: {{.AdminState}} |
| 45 | OPERSTATUS: {{.OperStatus}} |
| 46 | CONNECTSTATUS: {{.ConnectStatus}}` |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 47 | DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT = "table{{.DefaultFreq}}\t{{.Grouped}}\t{{.FreqOverride}}" |
| 48 | DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT = "table{{.Name}}\t{{.Type}}\t{{.Enabled}}\t{{.SampleFreq}}" |
| 49 | DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT = "table{{.GroupName}}\t{{.Enabled}}\t{{.GroupFreq}}" |
| 50 | DEFAULT_DEVICE_VALUE_GET_FORMAT = "table{{.Name}}\t{{.Result}}" |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 51 | DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT = "table{{.Name}}\t{{.Url}}\t{{.Crc}}\t{{.DownloadState}}\t{{.ImageVersion}}\t{{.LocalDir}}\t{{.ImageState}}\t{{.FileSize}}" |
ssiddiqui | 7bc89e9 | 2021-05-20 20:58:02 +0530 | [diff] [blame] | 52 | ONU_IMAGE_LIST_FORMAT = "table{{.Version}}\t{{.IsCommited}}\t{{.IsActive}}\t{{.IsValid}}\t{{.ProductCode}}\t{{.Hash}}" |
| 53 | ONU_IMAGE_STATUS_FORMAT = "table{{.DeviceId}}\t{{.ImageState.Version}}\t{{.ImageState.DownloadState}}\t{{.ImageState.Reason}}\t{{.ImageState.ImageState}}\t" |
kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 54 | DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT = ` |
| 55 | TXBYTES: {{.TxBytes}} |
| 56 | TXPACKETS: {{.TxPackets}} |
| 57 | TXERRPACKETS: {{.TxErrorPackets}} |
| 58 | TXBCASTPACKETS: {{.TxBcastPackets}} |
| 59 | TXUCASTPACKETS: {{.TxUcastPackets}} |
| 60 | TXMCASTPACKETS: {{.TxMcastPackets}} |
| 61 | RXBYTES: {{.RxBytes}} |
| 62 | RXPACKETS: {{.RxPackets}} |
| 63 | RXERRPACKETS: {{.RxErrorPackets}} |
| 64 | RXBCASTPACKETS: {{.RxBcastPackets}} |
| 65 | RXUCASTPACKETS: {{.RxUcastPackets}} |
| 66 | RXMCASTPACKETS: {{.RxMcastPackets}}` |
kesavand | 6d1131f | 2021-02-05 22:38:15 +0530 | [diff] [blame] | 67 | DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT = ` |
| 68 | ADMIN_STATE: {{.AdmState}} |
| 69 | OPERATIONAL_STATE: {{.OperState}} |
| 70 | CONFIG_IND: {{.ConfigInd}}` |
Girish Gowdra | 4f5ce7c | 2021-04-29 18:53:21 -0700 | [diff] [blame] | 71 | DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT = ` |
| 72 | POWER_FEED_VOLTAGE__VOLTS: {{.PowerFeedVoltage}} |
| 73 | RECEIVED_OPTICAL_POWER__dBm: {{.ReceivedOpticalPower}} |
| 74 | MEAN_OPTICAL_LAUNCH_POWER__dBm: {{.MeanOpticalLaunchPower}} |
| 75 | LASER_BIAS_CURRENT__mA: {{.LaserBiasCurrent}} |
| 76 | TEMPERATURE__Celsius: {{.Temperature}}` |
Gamze Abaka | c857a46 | 2021-05-26 13:45:54 +0000 | [diff] [blame] | 77 | DEFAULT_RX_POWER_STATUS_FORMAT = ` |
| 78 | INTF_ID: {{.IntfId}} |
| 79 | ONU_ID: {{.OnuId}} |
| 80 | STATUS: {{.Status}} |
| 81 | FAIL_REASON: {{.FailReason}} |
| 82 | RX_POWER : {{.RxPower}}` |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 83 | DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT = `Upstream_Drop_Events: {{.UDropEvents}} |
| 84 | Upstream_Octets: {{.UOctets}} |
| 85 | UFrames: {{.UFrames}} |
| 86 | UBroadcastFrames: {{.UBroadcastFrames}} |
| 87 | UMulticastFrames: {{.UMulticastFrames}} |
| 88 | UCrcErroredFrames: {{.UCrcErroredFrames}} |
| 89 | UUndersizeFrames: {{.UUndersizeFrames}} |
| 90 | UOversizeFrames: {{.UOversizeFrames}} |
| 91 | UFrames_64Octets: {{.UFrames_64Octets}} |
| 92 | UFrames_65To_127Octets: {{.UFrames_65To_127Octets}} |
| 93 | UFrames_128To_255Octets: {{.UFrames_128To_255Octets}} |
| 94 | UFrames_256To_511Octets: {{.UFrames_256To_511Octets}} |
| 95 | UFrames_512To_1023Octets: {{.UFrames_512To_1023Octets}} |
| 96 | UFrames_1024To_1518Octets: {{.UFrames_1024To_1518Octets}} |
| 97 | DDropEvents: {{.DDropEvents}} |
| 98 | DOctets: {{.DOctets}} |
| 99 | DFrames: {{.DFrames}} |
| 100 | DBroadcastFrames: {{.DBroadcastFrames}} |
| 101 | DMulticastFrames: {{.DMulticastFrames}} |
| 102 | DCrcErroredFrames: {{.DCrcErroredFrames}} |
| 103 | DUndersizeFrames: {{.DUndersizeFrames}} |
| 104 | DOversizeFrames: {{.DOversizeFrames}} |
| 105 | DFrames_64Octets: {{.DFrames_64Octets}} |
| 106 | DFrames_65To_127Octets: {{.DFrames_65To_127Octets}} |
| 107 | DFrames_128To_255Octets: {{.DFrames_128To_255Octets}} |
| 108 | DFrames_256To_511Octets: {{.DFrames_256To_511Octets}} |
| 109 | DFrames_512To_1023Octets: {{.DFrames_512To_1023Octets}} |
Himani Chawla | bac0f89 | 2021-08-25 17:14:06 +0530 | [diff] [blame] | 110 | DFrames_1024To_1518Octets: {{.DFrames_1024To_1518Octets}} |
| 111 | PmFormat: {{.PmFormat}}` |
serkantul | 3d22fc7 | 2022-09-14 12:22:56 +0300 | [diff] [blame] | 112 | DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT = `BaseTxArFrames: {{.BaseTxArFrames}} |
| 113 | BaseRxAkFrames: {{.BaseRxAkFrames}} |
| 114 | BaseTxNoArFrames: {{.BaseTxNoArFrames}} |
| 115 | BaseRxNoAkFrames: {{.BaseRxNoAkFrames}} |
| 116 | ExtTxArFrames: {{.ExtTxArFrames}} |
| 117 | ExtRxAkFrames: {{.ExtRxAkFrames}} |
| 118 | ExtTxNoArFrames: {{.ExtTxNoArFrames}} |
| 119 | ExtRxNoAkFrames: {{.ExtRxNoAkFrames}} |
| 120 | TxOmciCounterRetries: {{.TxOmciCounterRetries}} |
| 121 | TxOmciCounterTimeouts: {{.TxOmciCounterTimeouts}}` |
praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 122 | DEFAULT_DEVICE_ALARMS_FORMAT = "table{{ .ClassId }}\t{{.InstanceId}}\t{{.Name}}\t{{.Description}}" |
| 123 | DEFAULT_DEVICE_ALARMS_ORDER = "ClassId,InstanceId" |
| 124 | DEFAULT_PON_RX_POWER_STATUS_FORMAT = "table{{.OnuSn}}\t{{.Status}}\t{{.FailReason}}\t{{.RxPower}}\t" |
Akash Soni | 66db963 | 2024-04-15 09:05:15 +0530 | [diff] [blame] | 125 | DEFAULT_ONU_DISTANCE_FORMAT = `Distance` |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 126 | ) |
| 127 | |
| 128 | type DeviceList struct { |
| 129 | ListOutputOptions |
| 130 | } |
| 131 | |
| 132 | type DeviceCreate struct { |
David Bainbridge | 1a51439 | 2020-06-23 11:12:51 -0700 | [diff] [blame] | 133 | DeviceType string `short:"t" required:"true" long:"devicetype" description:"Device type"` |
David Bainbridge | 835dd0e | 2020-04-01 10:30:09 -0700 | [diff] [blame] | 134 | MACAddress string `short:"m" long:"macaddress" default:"" description:"MAC Address"` |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 135 | IPAddress string `short:"i" long:"ipaddress" default:"" description:"IP Address"` |
| 136 | HostAndPort string `short:"H" long:"hostandport" default:"" description:"Host and port"` |
| 137 | } |
| 138 | |
| 139 | type DeviceId string |
Akash Soni | 66db963 | 2024-04-15 09:05:15 +0530 | [diff] [blame] | 140 | type OnuId string |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 141 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 142 | type MetricName string |
| 143 | type GroupName string |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 144 | type PortNum uint32 |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 145 | type ValueFlag string |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 146 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 147 | type DeviceDelete struct { |
Himani Chawla | 9933ddc | 2020-10-12 23:53:27 +0530 | [diff] [blame] | 148 | Force bool `long:"force" description:"Delete device forcefully"` |
| 149 | Args struct { |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 150 | Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 151 | } `positional-args:"yes"` |
| 152 | } |
| 153 | |
| 154 | type DeviceEnable struct { |
| 155 | Args struct { |
| 156 | Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 157 | } `positional-args:"yes"` |
| 158 | } |
| 159 | |
| 160 | type DeviceDisable struct { |
| 161 | Args struct { |
| 162 | Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 163 | } `positional-args:"yes"` |
| 164 | } |
| 165 | |
| 166 | type DeviceReboot struct { |
| 167 | Args struct { |
| 168 | Ids []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 169 | } `positional-args:"yes"` |
| 170 | } |
| 171 | |
| 172 | type DeviceFlowList struct { |
| 173 | ListOutputOptions |
Maninder | 045921e | 2020-09-29 16:46:02 +0530 | [diff] [blame] | 174 | FlowIdOptions |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 175 | Args struct { |
| 176 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 177 | } `positional-args:"yes"` |
| 178 | } |
| 179 | |
Himani Chawla | 3c161c6 | 2021-05-13 16:36:51 +0530 | [diff] [blame] | 180 | type DeviceFlowGroupList struct { |
| 181 | ListOutputOptions |
| 182 | GroupListOptions |
| 183 | Args struct { |
| 184 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 185 | } `positional-args:"yes"` |
| 186 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 187 | type DevicePortList struct { |
| 188 | ListOutputOptions |
| 189 | Args struct { |
| 190 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 191 | } `positional-args:"yes"` |
| 192 | } |
| 193 | |
| 194 | type DeviceInspect struct { |
| 195 | OutputOptionsJson |
| 196 | Args struct { |
| 197 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 198 | } `positional-args:"yes"` |
| 199 | } |
| 200 | |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 201 | type DevicePortEnable struct { |
| 202 | Args struct { |
| 203 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 204 | PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"` |
| 205 | } `positional-args:"yes"` |
| 206 | } |
| 207 | |
| 208 | type DevicePortDisable struct { |
| 209 | Args struct { |
| 210 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 211 | PortId PortNum `positional-arg-name:"PORT_NUMBER" required:"yes"` |
| 212 | } `positional-args:"yes"` |
| 213 | } |
| 214 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 215 | type DevicePmConfigsGet struct { |
| 216 | ListOutputOptions |
| 217 | Args struct { |
| 218 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 219 | } `positional-args:"yes"` |
| 220 | } |
| 221 | |
| 222 | type DevicePmConfigMetricList struct { |
| 223 | ListOutputOptions |
| 224 | Args struct { |
| 225 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 226 | } `positional-args:"yes"` |
| 227 | } |
| 228 | |
| 229 | type DevicePmConfigGroupList struct { |
| 230 | ListOutputOptions |
| 231 | Args struct { |
| 232 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 233 | } `positional-args:"yes"` |
| 234 | } |
| 235 | |
| 236 | type DevicePmConfigGroupMetricList struct { |
| 237 | ListOutputOptions |
| 238 | Args struct { |
| 239 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 240 | Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"` |
| 241 | } `positional-args:"yes"` |
| 242 | } |
| 243 | |
| 244 | type DevicePmConfigFrequencySet struct { |
| 245 | OutputOptions |
| 246 | Args struct { |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 247 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 248 | Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"` |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 249 | } `positional-args:"yes"` |
| 250 | } |
| 251 | |
| 252 | type DevicePmConfigMetricEnable struct { |
| 253 | Args struct { |
| 254 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 255 | Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"` |
| 256 | } `positional-args:"yes"` |
| 257 | } |
| 258 | |
| 259 | type DevicePmConfigMetricDisable struct { |
| 260 | Args struct { |
| 261 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 262 | Metrics []MetricName `positional-arg-name:"METRIC_NAME" required:"yes"` |
| 263 | } `positional-args:"yes"` |
| 264 | } |
| 265 | |
| 266 | type DevicePmConfigGroupEnable struct { |
| 267 | Args struct { |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 268 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 269 | Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"` |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 270 | } `positional-args:"yes"` |
| 271 | } |
| 272 | |
| 273 | type DevicePmConfigGroupDisable struct { |
| 274 | Args struct { |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 275 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 276 | Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"` |
| 277 | } `positional-args:"yes"` |
| 278 | } |
| 279 | |
| 280 | type DevicePmConfigGroupFrequencySet struct { |
| 281 | OutputOptions |
| 282 | Args struct { |
| 283 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 284 | Group GroupName `positional-arg-name:"GROUP_NAME" required:"yes"` |
| 285 | Interval time.Duration `positional-arg-name:"INTERVAL" required:"yes"` |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 286 | } `positional-args:"yes"` |
| 287 | } |
| 288 | |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 289 | type DeviceGetExtValue struct { |
| 290 | ListOutputOptions |
| 291 | Args struct { |
| 292 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 293 | Valueflag ValueFlag `positional-arg-name:"VALUE_FLAG" required:"yes"` |
| 294 | } `positional-args:"yes"` |
| 295 | } |
Rohan Agrawal | d7df377 | 2020-06-29 11:23:36 +0000 | [diff] [blame] | 296 | |
| 297 | type DevicePmConfigSetMaxSkew struct { |
| 298 | Args struct { |
| 299 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 300 | MaxSkew uint32 `positional-arg-name:"MAX_SKEW" required:"yes"` |
| 301 | } `positional-args:"yes"` |
| 302 | } |
| 303 | |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 304 | type DeviceOnuListImages struct { |
| 305 | ListOutputOptions |
| 306 | Args struct { |
| 307 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 308 | } `positional-args:"yes"` |
| 309 | } |
| 310 | |
| 311 | type DeviceOnuDownloadImage struct { |
| 312 | Args struct { |
| 313 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 314 | Name string `positional-arg-name:"IMAGE_NAME" required:"yes"` |
| 315 | Url string `positional-arg-name:"IMAGE_URL" required:"yes"` |
| 316 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| 317 | Crc uint32 `positional-arg-name:"IMAGE_CRC" required:"yes"` |
| 318 | LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"` |
| 319 | } `positional-args:"yes"` |
| 320 | } |
| 321 | |
| 322 | type DeviceOnuActivateImageUpdate struct { |
| 323 | Args struct { |
| 324 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 325 | Name string `positional-arg-name:"IMAGE_NAME" required:"yes"` |
| 326 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| 327 | SaveConfig bool `positional-arg-name:"SAVE_EXISTING_CONFIG"` |
| 328 | LocalDir string `positional-arg-name:"IMAGE_LOCAL_DIRECTORY"` |
Andrea Campanella | 7b2ecf4 | 2021-02-25 12:27:15 +0100 | [diff] [blame] | 329 | } `positional-args:"yes"` |
kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 330 | } |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 331 | |
| 332 | type OnuDownloadImage struct { |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 333 | ListOutputOptions |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 334 | Args struct { |
| 335 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| 336 | Url string `positional-arg-name:"IMAGE_URL" required:"yes"` |
ssiddiqui | 7bc89e9 | 2021-05-20 20:58:02 +0530 | [diff] [blame] | 337 | Vendor string `positional-arg-name:"IMAGE_VENDOR"` |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 338 | ActivateOnSuccess bool `positional-arg-name:"IMAGE_ACTIVATE_ON_SUCCESS"` |
| 339 | CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"` |
| 340 | Crc uint32 `positional-arg-name:"IMAGE_CRC"` |
| 341 | IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 342 | } `positional-args:"yes"` |
| 343 | } |
| 344 | |
| 345 | type OnuActivateImage struct { |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 346 | ListOutputOptions |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 347 | Args struct { |
| 348 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| 349 | CommitOnSuccess bool `positional-arg-name:"IMAGE_COMMIT_ON_SUCCESS"` |
| 350 | IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 351 | } `positional-args:"yes"` |
| 352 | } |
| 353 | |
| 354 | type OnuAbortUpgradeImage struct { |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 355 | ListOutputOptions |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 356 | Args struct { |
| 357 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| 358 | IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 359 | } `positional-args:"yes"` |
| 360 | } |
| 361 | |
| 362 | type OnuCommitImage struct { |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 363 | ListOutputOptions |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 364 | Args struct { |
| 365 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
| 366 | IDs []DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 367 | } `positional-args:"yes"` |
| 368 | } |
| 369 | |
| 370 | type OnuImageStatus struct { |
| 371 | ListOutputOptions |
| 372 | Args struct { |
| 373 | ImageVersion string `positional-arg-name:"IMAGE_VERSION" required:"yes"` |
Elia Battiston | 859f3e6 | 2022-02-08 15:57:52 +0100 | [diff] [blame] | 374 | IDs []DeviceId `positional-arg-name:"DEVICE_ID"` |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 375 | } `positional-args:"yes"` |
| 376 | } |
| 377 | |
| 378 | type OnuListImages struct { |
| 379 | ListOutputOptions |
| 380 | Args struct { |
| 381 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 382 | } `positional-args:"yes"` |
| 383 | } |
| 384 | |
kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 385 | type DeviceGetPortStats struct { |
| 386 | ListOutputOptions |
| 387 | Args struct { |
| 388 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 389 | PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"` |
| 390 | PortType string `positional-arg-name:"PORT_TYPE" required:"yes"` |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 391 | } `positional-args:"yes"` |
| 392 | } |
kesavand | 6d1131f | 2021-02-05 22:38:15 +0530 | [diff] [blame] | 393 | type UniStatus struct { |
| 394 | ListOutputOptions |
| 395 | Args struct { |
| 396 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 397 | UniIndex uint32 `positional-arg-name:"UNI_INDEX" required:"yes"` |
| 398 | } `positional-args:"yes"` |
| 399 | } |
Girish Gowdra | 4f5ce7c | 2021-04-29 18:53:21 -0700 | [diff] [blame] | 400 | type OnuPonOpticalInfo struct { |
| 401 | ListOutputOptions |
| 402 | Args struct { |
| 403 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 404 | } `positional-args:"yes"` |
| 405 | } |
Himani Chawla | 40acc12 | 2021-05-26 18:52:29 +0530 | [diff] [blame] | 406 | |
| 407 | type GetOnuStats struct { |
| 408 | ListOutputOptions |
| 409 | Args struct { |
| 410 | OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"` |
| 411 | IntfId uint32 `positional-arg-name:"PON_INTF_ID" required:"yes"` |
| 412 | OnuId uint32 `positional-arg-name:"ONU_ID" required:"yes"` |
| 413 | } `positional-args:"yes"` |
| 414 | } |
| 415 | |
Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame^] | 416 | type GetOffloadAppStats struct { |
| 417 | ListOutputOptions |
| 418 | Args struct { |
| 419 | OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"` |
| 420 | StatsFor extension.GetOffloadedAppsStatisticsRequest_OffloadedApp `positional-arg-name:"OFFLOADED_APP" required:"yes"` |
| 421 | } `positional-args:"yes"` |
| 422 | } |
| 423 | |
| 424 | type SetOffloadAppState struct { |
| 425 | Args struct { |
| 426 | OltId DeviceId `positional-arg-name:"OLT_DEVICE_ID" required:"yes"` |
| 427 | Config extension.AppOffloadConfig `json:"config" required:"yes"` |
| 428 | } `positional-args:"yes"` |
| 429 | } |
| 430 | |
| 431 | type SetOnuOffloadState struct { |
| 432 | Args struct { |
| 433 | OnuDeviceId string `positional-arg-name:"ONU_DEVICE_ID" required:"yes"` |
| 434 | PerUniInfo []extension.AppOffloadOnuConfig_PerUniConfig `json:"per_uni_info" required:"yes"` |
| 435 | } `positional-args:"yes"` |
| 436 | } |
| 437 | |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 438 | type GetOnuEthernetFrameExtendedPmCounters struct { |
| 439 | ListOutputOptions |
Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 440 | Reset bool `long:"reset" description:"Reset the counters"` |
| 441 | Args struct { |
| 442 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 443 | UniIndex *uint32 `positional-arg-name:"UNI_INDEX"` |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 444 | } `positional-args:"yes"` |
| 445 | } |
| 446 | |
Gamze Abaka | c857a46 | 2021-05-26 13:45:54 +0000 | [diff] [blame] | 447 | type RxPower struct { |
| 448 | ListOutputOptions |
| 449 | Args struct { |
| 450 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 451 | PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"` |
| 452 | OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"` |
| 453 | } `positional-args:"yes"` |
| 454 | } |
| 455 | |
praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 456 | type PonRxPower struct { |
| 457 | ListOutputOptions |
| 458 | Args struct { |
| 459 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 460 | PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"` |
| 461 | SerialNo string `positional-arg-name:"ONU_SERIAL_NUMBER"` |
| 462 | } `positional-args:"yes"` |
| 463 | } |
| 464 | |
serkantul | 3d22fc7 | 2022-09-14 12:22:56 +0300 | [diff] [blame] | 465 | type OnuOmciTxRxStats struct { |
| 466 | ListOutputOptions |
| 467 | Args struct { |
| 468 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 469 | } `positional-args:"yes"` |
| 470 | } |
| 471 | |
praneeth nalmas | 1dd094c | 2022-12-22 14:15:13 +0530 | [diff] [blame] | 472 | type GetOnuOmciActiveAlarms struct { |
| 473 | ListOutputOptions |
| 474 | Args struct { |
| 475 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 476 | } `positional-args:"yes"` |
| 477 | } |
| 478 | |
Akash Soni | 66db963 | 2024-04-15 09:05:15 +0530 | [diff] [blame] | 479 | type GetOnuDistance struct { |
| 480 | ListOutputOptions |
| 481 | Args struct { |
| 482 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 483 | OnuId OnuId `positional-arg-name:"ONU_ID" required:"yes"` |
| 484 | } `positional-args:"yes"` //onu device id |
| 485 | } |
| 486 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 487 | type DeviceOpts struct { |
Himani Chawla | 3c161c6 | 2021-05-13 16:36:51 +0530 | [diff] [blame] | 488 | List DeviceList `command:"list"` |
| 489 | Create DeviceCreate `command:"create"` |
| 490 | Delete DeviceDelete `command:"delete"` |
| 491 | Enable DeviceEnable `command:"enable"` |
| 492 | Disable DeviceDisable `command:"disable"` |
| 493 | Flows DeviceFlowList `command:"flows"` |
| 494 | Groups DeviceFlowGroupList `command:"groups"` |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 495 | Port struct { |
| 496 | List DevicePortList `command:"list"` |
| 497 | Enable DevicePortEnable `command:"enable"` |
| 498 | Disable DevicePortDisable `command:"disable"` |
| 499 | } `command:"port"` |
| 500 | Inspect DeviceInspect `command:"inspect"` |
| 501 | Reboot DeviceReboot `command:"reboot"` |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 502 | Value struct { |
| 503 | Get DeviceGetExtValue `command:"get"` |
| 504 | } `command:"value"` |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 505 | PmConfig struct { |
Rohan Agrawal | d7df377 | 2020-06-29 11:23:36 +0000 | [diff] [blame] | 506 | Get DevicePmConfigsGet `command:"get"` |
| 507 | MaxSkew struct { |
| 508 | Set DevicePmConfigSetMaxSkew `command:"set"` |
| 509 | } `command:"maxskew"` |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 510 | Frequency struct { |
| 511 | Set DevicePmConfigFrequencySet `command:"set"` |
| 512 | } `command:"frequency"` |
| 513 | Metric struct { |
| 514 | List DevicePmConfigMetricList `command:"list"` |
| 515 | Enable DevicePmConfigMetricEnable `command:"enable"` |
| 516 | Disable DevicePmConfigMetricDisable `command:"disable"` |
| 517 | } `command:"metric"` |
| 518 | Group struct { |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 519 | List DevicePmConfigGroupList `command:"list"` |
| 520 | Enable DevicePmConfigGroupEnable `command:"enable"` |
| 521 | Disable DevicePmConfigGroupDisable `command:"disable"` |
| 522 | Set DevicePmConfigGroupFrequencySet `command:"set"` |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 523 | } `command:"group"` |
| 524 | GroupMetric struct { |
| 525 | List DevicePmConfigGroupMetricList `command:"list"` |
| 526 | } `command:"groupmetric"` |
| 527 | } `command:"pmconfig"` |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 528 | Image struct { |
| 529 | Get DeviceOnuListImages `command:"list"` |
| 530 | Download DeviceOnuDownloadImage `command:"download"` |
| 531 | Activate DeviceOnuActivateImageUpdate `command:"activate"` |
| 532 | } `command:"image"` |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 533 | DownloadImage struct { |
| 534 | Download OnuDownloadImage `command:"download"` |
| 535 | Activate OnuActivateImage `command:"activate"` |
| 536 | Commit OnuCommitImage `command:"commit"` |
| 537 | AbortUpgrade OnuAbortUpgradeImage `command:"abort"` |
| 538 | Status OnuImageStatus `command:"status"` |
| 539 | List OnuListImages `command:"list" ` |
| 540 | } `command:"onuimage"` |
kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 541 | GetExtVal struct { |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 542 | Stats DeviceGetPortStats `command:"portstats"` |
| 543 | UniStatus UniStatus `command:"unistatus"` |
| 544 | OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"` |
| 545 | OnuStats GetOnuStats `command:"onu_stats"` |
| 546 | EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"` |
| 547 | RxPower RxPower `command:"rxpower"` |
serkantul | 3d22fc7 | 2022-09-14 12:22:56 +0300 | [diff] [blame] | 548 | OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"` |
praneeth nalmas | 1dd094c | 2022-12-22 14:15:13 +0530 | [diff] [blame] | 549 | OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"` |
praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 550 | PonRxPower PonRxPower `command:"pon_rx_power"` |
Akash Soni | 66db963 | 2024-04-15 09:05:15 +0530 | [diff] [blame] | 551 | OnuDistance GetOnuDistance `command:"onu_distance"` |
Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame^] | 552 | OffloadAppStats GetOffloadAppStats `command:"offload_app_stats"` |
kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 553 | } `command:"getextval"` |
Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame^] | 554 | SetExtVal struct { |
| 555 | OffloadAppStatsSet SetOffloadAppState `command:"set_offload_app_stats"` |
| 556 | OnuOffloadStatsSet SetOnuOffloadState `command:"set_onu_offload_stats"` |
| 557 | } `command:"setextval"` |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | var deviceOpts = DeviceOpts{} |
| 561 | |
| 562 | func RegisterDeviceCommands(parser *flags.Parser) { |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 563 | if _, err := parser.AddCommand("device", "device commands", "Commands to query and manipulate VOLTHA devices", &deviceOpts); err != nil { |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 564 | Error.Fatalf("Unexpected error while attempting to register device commands : %s", err) |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 565 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 568 | func (i *MetricName) Complete(match string) []flags.Completion { |
| 569 | conn, err := NewConnection() |
| 570 | if err != nil { |
| 571 | return nil |
| 572 | } |
| 573 | defer conn.Close() |
| 574 | |
| 575 | client := voltha.NewVolthaServiceClient(conn) |
| 576 | |
| 577 | var deviceId string |
| 578 | found: |
| 579 | for i := len(os.Args) - 1; i >= 0; i -= 1 { |
| 580 | switch os.Args[i] { |
| 581 | case "enable": |
| 582 | fallthrough |
| 583 | case "disable": |
| 584 | if len(os.Args) > i+1 { |
| 585 | deviceId = os.Args[i+1] |
| 586 | } else { |
| 587 | return nil |
| 588 | } |
| 589 | break found |
| 590 | default: |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | if len(deviceId) == 0 { |
| 595 | return nil |
| 596 | } |
| 597 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 598 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 599 | defer cancel() |
| 600 | |
| 601 | id := voltha.ID{Id: string(deviceId)} |
| 602 | |
| 603 | pmconfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 604 | |
| 605 | if err != nil { |
| 606 | return nil |
| 607 | } |
| 608 | |
| 609 | list := make([]flags.Completion, 0) |
| 610 | for _, metrics := range pmconfigs.Metrics { |
| 611 | if strings.HasPrefix(metrics.Name, match) { |
| 612 | list = append(list, flags.Completion{Item: metrics.Name}) |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | return list |
| 617 | } |
| 618 | |
| 619 | func (i *GroupName) Complete(match string) []flags.Completion { |
| 620 | conn, err := NewConnection() |
| 621 | if err != nil { |
| 622 | return nil |
| 623 | } |
| 624 | defer conn.Close() |
| 625 | |
| 626 | client := voltha.NewVolthaServiceClient(conn) |
| 627 | |
| 628 | var deviceId string |
| 629 | found: |
| 630 | for i := len(os.Args) - 1; i >= 0; i -= 1 { |
| 631 | switch os.Args[i] { |
| 632 | case "list": |
| 633 | fallthrough |
| 634 | case "enable": |
| 635 | fallthrough |
| 636 | case "disable": |
| 637 | if len(os.Args) > i+1 { |
| 638 | deviceId = os.Args[i+1] |
| 639 | } else { |
| 640 | return nil |
| 641 | } |
| 642 | break found |
| 643 | default: |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | if len(deviceId) == 0 { |
| 648 | return nil |
| 649 | } |
| 650 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 651 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 652 | defer cancel() |
| 653 | |
| 654 | id := voltha.ID{Id: string(deviceId)} |
| 655 | |
| 656 | pmconfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 657 | |
| 658 | if err != nil { |
| 659 | return nil |
| 660 | } |
| 661 | |
| 662 | list := make([]flags.Completion, 0) |
| 663 | for _, group := range pmconfigs.Groups { |
| 664 | if strings.HasPrefix(group.GroupName, match) { |
| 665 | list = append(list, flags.Completion{Item: group.GroupName}) |
| 666 | } |
| 667 | } |
| 668 | return list |
| 669 | } |
| 670 | |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 671 | func (i *PortNum) Complete(match string) []flags.Completion { |
| 672 | conn, err := NewConnection() |
| 673 | if err != nil { |
| 674 | return nil |
| 675 | } |
| 676 | defer conn.Close() |
| 677 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 678 | client := voltha.NewVolthaServiceClient(conn) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 679 | |
| 680 | /* |
| 681 | * The command line args when completing for PortNum will be a DeviceId |
| 682 | * followed by one or more PortNums. So walk the argument list from the |
| 683 | * end and find the first argument that is enable/disable as those are |
| 684 | * the subcommands that come before the positional arguments. It would |
| 685 | * be nice if this package gave us the list of optional arguments |
| 686 | * already parsed. |
| 687 | */ |
| 688 | var deviceId string |
| 689 | found: |
| 690 | for i := len(os.Args) - 1; i >= 0; i -= 1 { |
| 691 | switch os.Args[i] { |
| 692 | case "enable": |
| 693 | fallthrough |
| 694 | case "disable": |
| 695 | if len(os.Args) > i+1 { |
| 696 | deviceId = os.Args[i+1] |
| 697 | } else { |
| 698 | return nil |
| 699 | } |
| 700 | break found |
| 701 | default: |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | if len(deviceId) == 0 { |
| 706 | return nil |
| 707 | } |
| 708 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 709 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 710 | defer cancel() |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 711 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 712 | id := voltha.ID{Id: string(deviceId)} |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 713 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 714 | ports, err := client.ListDevicePorts(ctx, &id) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 715 | if err != nil { |
| 716 | return nil |
| 717 | } |
| 718 | |
| 719 | list := make([]flags.Completion, 0) |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 720 | for _, item := range ports.Items { |
| 721 | pn := strconv.FormatUint(uint64(item.PortNo), 10) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 722 | if strings.HasPrefix(pn, match) { |
| 723 | list = append(list, flags.Completion{Item: pn}) |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | return list |
| 728 | } |
| 729 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 730 | func (i *DeviceId) Complete(match string) []flags.Completion { |
| 731 | conn, err := NewConnection() |
| 732 | if err != nil { |
| 733 | return nil |
| 734 | } |
| 735 | defer conn.Close() |
| 736 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 737 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 738 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 739 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 740 | defer cancel() |
| 741 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 742 | devices, err := client.ListDevices(ctx, &empty.Empty{}) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 743 | if err != nil { |
| 744 | return nil |
| 745 | } |
| 746 | |
| 747 | list := make([]flags.Completion, 0) |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 748 | for _, item := range devices.Items { |
| 749 | if strings.HasPrefix(item.Id, match) { |
| 750 | list = append(list, flags.Completion{Item: item.Id}) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | |
| 754 | return list |
| 755 | } |
| 756 | |
| 757 | func (options *DeviceList) Execute(args []string) error { |
| 758 | |
| 759 | conn, err := NewConnection() |
| 760 | if err != nil { |
| 761 | return err |
| 762 | } |
| 763 | defer conn.Close() |
| 764 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 765 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 766 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 767 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 768 | defer cancel() |
| 769 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 770 | devices, err := client.ListDevices(ctx, &empty.Empty{}) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 771 | if err != nil { |
| 772 | return err |
| 773 | } |
| 774 | |
| 775 | outputFormat := CharReplacer.Replace(options.Format) |
| 776 | if outputFormat == "" { |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 777 | outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 778 | } |
| 779 | if options.Quiet { |
| 780 | outputFormat = "{{.Id}}" |
| 781 | } |
| 782 | |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 783 | orderBy := options.OrderBy |
| 784 | if orderBy == "" { |
Hardik Windlass | 9361bb8 | 2022-03-23 05:58:48 +0000 | [diff] [blame] | 785 | orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER) |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 788 | // Make sure json output prints an empty list, not "null" |
| 789 | if devices.Items == nil { |
| 790 | devices.Items = make([]*voltha.Device, 0) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | result := CommandResult{ |
| 794 | Format: format.Format(outputFormat), |
| 795 | Filter: options.Filter, |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 796 | OrderBy: orderBy, |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 797 | OutputAs: toOutputType(options.OutputAs), |
| 798 | NameLimit: options.NameLimit, |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 799 | Data: devices.Items, |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | GenerateOutput(&result) |
| 803 | return nil |
| 804 | } |
| 805 | |
| 806 | func (options *DeviceCreate) Execute(args []string) error { |
| 807 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 808 | device := voltha.Device{} |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 809 | if options.HostAndPort != "" { |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 810 | device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort} |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 811 | } else if options.IPAddress != "" { |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 812 | device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress} |
Hardik Windlass | ce1de34 | 2020-02-04 21:58:07 +0000 | [diff] [blame] | 813 | } |
| 814 | if options.MACAddress != "" { |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 815 | device.MacAddress = strings.ToLower(options.MACAddress) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 816 | } |
| 817 | if options.DeviceType != "" { |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 818 | device.Type = options.DeviceType |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | conn, err := NewConnection() |
| 822 | if err != nil { |
| 823 | return err |
| 824 | } |
| 825 | defer conn.Close() |
| 826 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 827 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 828 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 829 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 830 | defer cancel() |
| 831 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 832 | createdDevice, err := client.CreateDevice(ctx, &device) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 833 | if err != nil { |
| 834 | return err |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 837 | fmt.Printf("%s\n", createdDevice.Id) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 838 | |
| 839 | return nil |
| 840 | } |
| 841 | |
| 842 | func (options *DeviceDelete) Execute(args []string) error { |
| 843 | |
| 844 | conn, err := NewConnection() |
| 845 | if err != nil { |
| 846 | return err |
| 847 | } |
| 848 | defer conn.Close() |
| 849 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 850 | client := voltha.NewVolthaServiceClient(conn) |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 851 | var lastErr error |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 852 | for _, i := range options.Args.Ids { |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 853 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 854 | defer cancel() |
| 855 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 856 | id := voltha.ID{Id: string(i)} |
Himani Chawla | 9933ddc | 2020-10-12 23:53:27 +0530 | [diff] [blame] | 857 | if options.Force { |
| 858 | _, err = client.ForceDeleteDevice(ctx, &id) |
| 859 | } else { |
| 860 | _, err = client.DeleteDevice(ctx, &id) |
| 861 | } |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 862 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 863 | if err != nil { |
David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 864 | Error.Printf("Error while deleting '%s': %s\n", i, err) |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 865 | lastErr = err |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 866 | continue |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 867 | } |
| 868 | fmt.Printf("%s\n", i) |
| 869 | } |
| 870 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 871 | if lastErr != nil { |
| 872 | return NoReportErr |
| 873 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 874 | return nil |
| 875 | } |
| 876 | |
| 877 | func (options *DeviceEnable) Execute(args []string) error { |
| 878 | conn, err := NewConnection() |
| 879 | if err != nil { |
| 880 | return err |
| 881 | } |
| 882 | defer conn.Close() |
| 883 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 884 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 885 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 886 | var lastErr error |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 887 | for _, i := range options.Args.Ids { |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 888 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 889 | defer cancel() |
| 890 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 891 | id := voltha.ID{Id: string(i)} |
| 892 | |
| 893 | _, err := client.EnableDevice(ctx, &id) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 894 | if err != nil { |
David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 895 | Error.Printf("Error while enabling '%s': %s\n", i, err) |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 896 | lastErr = err |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 897 | continue |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 898 | } |
| 899 | fmt.Printf("%s\n", i) |
| 900 | } |
| 901 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 902 | if lastErr != nil { |
| 903 | return NoReportErr |
| 904 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 905 | return nil |
| 906 | } |
| 907 | |
| 908 | func (options *DeviceDisable) Execute(args []string) error { |
| 909 | conn, err := NewConnection() |
| 910 | if err != nil { |
| 911 | return err |
| 912 | } |
| 913 | defer conn.Close() |
| 914 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 915 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 916 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 917 | var lastErr error |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 918 | for _, i := range options.Args.Ids { |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 919 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 920 | defer cancel() |
| 921 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 922 | id := voltha.ID{Id: string(i)} |
| 923 | |
| 924 | _, err := client.DisableDevice(ctx, &id) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 925 | if err != nil { |
David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 926 | Error.Printf("Error while disabling '%s': %s\n", i, err) |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 927 | lastErr = err |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 928 | continue |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 929 | } |
| 930 | fmt.Printf("%s\n", i) |
| 931 | } |
| 932 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 933 | if lastErr != nil { |
| 934 | return NoReportErr |
| 935 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 936 | return nil |
| 937 | } |
| 938 | |
| 939 | func (options *DeviceReboot) Execute(args []string) error { |
| 940 | conn, err := NewConnection() |
| 941 | if err != nil { |
| 942 | return err |
| 943 | } |
| 944 | defer conn.Close() |
| 945 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 946 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 947 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 948 | var lastErr error |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 949 | for _, i := range options.Args.Ids { |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 950 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 951 | defer cancel() |
| 952 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 953 | id := voltha.ID{Id: string(i)} |
| 954 | |
| 955 | _, err := client.RebootDevice(ctx, &id) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 956 | if err != nil { |
David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 957 | Error.Printf("Error while rebooting '%s': %s\n", i, err) |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 958 | lastErr = err |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 959 | continue |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 960 | } |
| 961 | fmt.Printf("%s\n", i) |
| 962 | } |
| 963 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 964 | if lastErr != nil { |
| 965 | return NoReportErr |
| 966 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 967 | return nil |
| 968 | } |
| 969 | |
| 970 | func (options *DevicePortList) Execute(args []string) error { |
| 971 | |
| 972 | conn, err := NewConnection() |
| 973 | if err != nil { |
| 974 | return err |
| 975 | } |
| 976 | defer conn.Close() |
| 977 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 978 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 979 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 980 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 981 | defer cancel() |
| 982 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 983 | id := voltha.ID{Id: string(options.Args.Id)} |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 984 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 985 | ports, err := client.ListDevicePorts(ctx, &id) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 986 | if err != nil { |
| 987 | return err |
| 988 | } |
| 989 | |
| 990 | outputFormat := CharReplacer.Replace(options.Format) |
| 991 | if outputFormat == "" { |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 992 | outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 993 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 994 | |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 995 | orderBy := options.OrderBy |
| 996 | if orderBy == "" { |
| 997 | orderBy = GetCommandOptionWithDefault("device-ports", "order", "") |
| 998 | } |
| 999 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1000 | result := CommandResult{ |
| 1001 | Format: format.Format(outputFormat), |
| 1002 | Filter: options.Filter, |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 1003 | OrderBy: orderBy, |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1004 | OutputAs: toOutputType(options.OutputAs), |
| 1005 | NameLimit: options.NameLimit, |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1006 | Data: ports.Items, |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | GenerateOutput(&result) |
| 1010 | return nil |
| 1011 | } |
| 1012 | |
| 1013 | func (options *DeviceFlowList) Execute(args []string) error { |
| 1014 | fl := &FlowList{} |
| 1015 | fl.ListOutputOptions = options.ListOutputOptions |
Maninder | 045921e | 2020-09-29 16:46:02 +0530 | [diff] [blame] | 1016 | fl.FlowIdOptions = options.FlowIdOptions |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1017 | fl.Args.Id = string(options.Args.Id) |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 1018 | fl.Method = "device-flows" |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1019 | return fl.Execute(args) |
| 1020 | } |
| 1021 | |
Himani Chawla | 3c161c6 | 2021-05-13 16:36:51 +0530 | [diff] [blame] | 1022 | func (options *DeviceFlowGroupList) Execute(args []string) error { |
| 1023 | grp := &GroupList{} |
| 1024 | grp.ListOutputOptions = options.ListOutputOptions |
| 1025 | grp.GroupListOptions = options.GroupListOptions |
| 1026 | grp.Args.Id = string(options.Args.Id) |
| 1027 | grp.Method = "device-groups" |
| 1028 | return grp.Execute(args) |
| 1029 | } |
| 1030 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1031 | func (options *DeviceInspect) Execute(args []string) error { |
| 1032 | if len(args) > 0 { |
| 1033 | return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided") |
| 1034 | } |
| 1035 | |
| 1036 | conn, err := NewConnection() |
| 1037 | if err != nil { |
| 1038 | return err |
| 1039 | } |
| 1040 | defer conn.Close() |
| 1041 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1042 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1043 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1044 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1045 | defer cancel() |
| 1046 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1047 | id := voltha.ID{Id: string(options.Args.Id)} |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1048 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1049 | device, err := client.GetDevice(ctx, &id) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1050 | if err != nil { |
| 1051 | return err |
| 1052 | } |
| 1053 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1054 | outputFormat := CharReplacer.Replace(options.Format) |
| 1055 | if outputFormat == "" { |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 1056 | outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1057 | } |
| 1058 | if options.Quiet { |
| 1059 | outputFormat = "{{.Id}}" |
| 1060 | } |
| 1061 | |
| 1062 | result := CommandResult{ |
| 1063 | Format: format.Format(outputFormat), |
| 1064 | OutputAs: toOutputType(options.OutputAs), |
| 1065 | NameLimit: options.NameLimit, |
| 1066 | Data: device, |
| 1067 | } |
| 1068 | GenerateOutput(&result) |
| 1069 | return nil |
| 1070 | } |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1071 | |
| 1072 | /*Device Port Enable */ |
| 1073 | func (options *DevicePortEnable) Execute(args []string) error { |
| 1074 | conn, err := NewConnection() |
| 1075 | if err != nil { |
| 1076 | return err |
| 1077 | } |
| 1078 | defer conn.Close() |
| 1079 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1080 | client := voltha.NewVolthaServiceClient(conn) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1081 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1082 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1083 | defer cancel() |
| 1084 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1085 | port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)} |
| 1086 | |
| 1087 | _, err = client.EnablePort(ctx, &port) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1088 | if err != nil { |
| 1089 | Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err)) |
| 1090 | return err |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | return nil |
| 1094 | } |
| 1095 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1096 | /*Device Port Disable */ |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1097 | func (options *DevicePortDisable) Execute(args []string) error { |
| 1098 | conn, err := NewConnection() |
| 1099 | if err != nil { |
| 1100 | return err |
| 1101 | } |
| 1102 | defer conn.Close() |
| 1103 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1104 | client := voltha.NewVolthaServiceClient(conn) |
| 1105 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1106 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1107 | defer cancel() |
| 1108 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1109 | port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)} |
| 1110 | |
| 1111 | _, err = client.DisablePort(ctx, &port) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1112 | if err != nil { |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1113 | Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err)) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1114 | return err |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1115 | } |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1116 | |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1117 | return nil |
| 1118 | } |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 1119 | |
Rohan Agrawal | d7df377 | 2020-06-29 11:23:36 +0000 | [diff] [blame] | 1120 | func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error { |
| 1121 | conn, err := NewConnection() |
| 1122 | if err != nil { |
| 1123 | return err |
| 1124 | } |
| 1125 | defer conn.Close() |
| 1126 | |
| 1127 | client := voltha.NewVolthaServiceClient(conn) |
| 1128 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1129 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | d7df377 | 2020-06-29 11:23:36 +0000 | [diff] [blame] | 1130 | defer cancel() |
| 1131 | |
| 1132 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1133 | |
| 1134 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1135 | if err != nil { |
| 1136 | return err |
| 1137 | } |
| 1138 | |
| 1139 | pmConfigs.MaxSkew = options.Args.MaxSkew |
| 1140 | |
| 1141 | _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1142 | if err != nil { |
| 1143 | return err |
| 1144 | } |
| 1145 | |
| 1146 | return nil |
| 1147 | } |
| 1148 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1149 | func (options *DevicePmConfigsGet) Execute(args []string) error { |
| 1150 | |
| 1151 | conn, err := NewConnection() |
| 1152 | if err != nil { |
| 1153 | return err |
| 1154 | } |
| 1155 | defer conn.Close() |
| 1156 | |
| 1157 | client := voltha.NewVolthaServiceClient(conn) |
| 1158 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1159 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1160 | defer cancel() |
| 1161 | |
| 1162 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1163 | |
| 1164 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1165 | if err != nil { |
| 1166 | return err |
| 1167 | } |
| 1168 | |
| 1169 | outputFormat := CharReplacer.Replace(options.Format) |
| 1170 | if outputFormat == "" { |
| 1171 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT) |
| 1172 | } |
| 1173 | |
| 1174 | orderBy := options.OrderBy |
| 1175 | if orderBy == "" { |
| 1176 | orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "") |
| 1177 | } |
| 1178 | |
| 1179 | result := CommandResult{ |
| 1180 | Format: format.Format(outputFormat), |
| 1181 | Filter: options.Filter, |
| 1182 | OrderBy: orderBy, |
| 1183 | OutputAs: toOutputType(options.OutputAs), |
| 1184 | NameLimit: options.NameLimit, |
| 1185 | Data: pmConfigs, |
| 1186 | } |
| 1187 | |
| 1188 | GenerateOutput(&result) |
| 1189 | return nil |
| 1190 | |
| 1191 | } |
| 1192 | |
| 1193 | func (options *DevicePmConfigMetricList) Execute(args []string) error { |
| 1194 | |
| 1195 | conn, err := NewConnection() |
| 1196 | if err != nil { |
| 1197 | return err |
| 1198 | } |
| 1199 | defer conn.Close() |
| 1200 | |
| 1201 | client := voltha.NewVolthaServiceClient(conn) |
| 1202 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1203 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1204 | defer cancel() |
| 1205 | |
| 1206 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1207 | |
| 1208 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1209 | if err != nil { |
| 1210 | return err |
| 1211 | } |
| 1212 | |
| 1213 | if !pmConfigs.Grouped { |
| 1214 | for _, metric := range pmConfigs.Metrics { |
| 1215 | if metric.SampleFreq == 0 { |
| 1216 | metric.SampleFreq = pmConfigs.DefaultFreq |
| 1217 | } |
| 1218 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1219 | outputFormat := CharReplacer.Replace(options.Format) |
| 1220 | if outputFormat == "" { |
| 1221 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT) |
| 1222 | } |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1223 | |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1224 | orderBy := options.OrderBy |
| 1225 | if orderBy == "" { |
| 1226 | orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "") |
| 1227 | } |
| 1228 | |
| 1229 | result := CommandResult{ |
| 1230 | Format: format.Format(outputFormat), |
| 1231 | Filter: options.Filter, |
| 1232 | OrderBy: orderBy, |
| 1233 | OutputAs: toOutputType(options.OutputAs), |
| 1234 | NameLimit: options.NameLimit, |
| 1235 | Data: pmConfigs.Metrics, |
| 1236 | } |
| 1237 | |
| 1238 | GenerateOutput(&result) |
| 1239 | return nil |
| 1240 | } else { |
| 1241 | return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1242 | } |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | func (options *DevicePmConfigMetricEnable) Execute(args []string) error { |
| 1246 | |
| 1247 | conn, err := NewConnection() |
| 1248 | if err != nil { |
| 1249 | return err |
| 1250 | } |
| 1251 | defer conn.Close() |
| 1252 | |
| 1253 | client := voltha.NewVolthaServiceClient(conn) |
| 1254 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1255 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1256 | defer cancel() |
| 1257 | |
| 1258 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1259 | |
| 1260 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1261 | if err != nil { |
| 1262 | return err |
| 1263 | } |
| 1264 | |
| 1265 | if !pmConfigs.Grouped { |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1266 | metrics := make(map[string]struct{}) |
| 1267 | for _, metric := range pmConfigs.Metrics { |
| 1268 | metrics[metric.Name] = struct{}{} |
| 1269 | } |
| 1270 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1271 | for _, metric := range pmConfigs.Metrics { |
| 1272 | for _, mName := range options.Args.Metrics { |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1273 | if _, exist := metrics[string(mName)]; !exist { |
| 1274 | return fmt.Errorf("Metric Name '%s' does not exist", mName) |
| 1275 | } |
| 1276 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1277 | if string(mName) == metric.Name && !metric.Enabled { |
| 1278 | metric.Enabled = true |
| 1279 | _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1280 | if err != nil { |
| 1281 | return err |
| 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1286 | } else { |
| 1287 | return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1288 | } |
| 1289 | return nil |
| 1290 | } |
| 1291 | |
| 1292 | func (options *DevicePmConfigMetricDisable) Execute(args []string) error { |
| 1293 | |
| 1294 | conn, err := NewConnection() |
| 1295 | if err != nil { |
| 1296 | return err |
| 1297 | } |
| 1298 | defer conn.Close() |
| 1299 | |
| 1300 | client := voltha.NewVolthaServiceClient(conn) |
| 1301 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1302 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1303 | defer cancel() |
| 1304 | |
| 1305 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1306 | |
| 1307 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1308 | if err != nil { |
| 1309 | return err |
| 1310 | } |
| 1311 | |
| 1312 | if !pmConfigs.Grouped { |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1313 | metrics := make(map[string]struct{}) |
| 1314 | for _, metric := range pmConfigs.Metrics { |
| 1315 | metrics[metric.Name] = struct{}{} |
| 1316 | } |
| 1317 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1318 | for _, metric := range pmConfigs.Metrics { |
| 1319 | for _, mName := range options.Args.Metrics { |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1320 | if _, have := metrics[string(mName)]; !have { |
| 1321 | return fmt.Errorf("Metric Name '%s' does not exist", mName) |
| 1322 | } |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1323 | if string(mName) == metric.Name && metric.Enabled { |
| 1324 | metric.Enabled = false |
| 1325 | _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1326 | if err != nil { |
| 1327 | return err |
| 1328 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1329 | } else { |
| 1330 | return fmt.Errorf("Metric '%s' cannot be disabled", string(mName)) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1334 | } else { |
| 1335 | return fmt.Errorf("Device '%s' does not have Non Grouped Metrics", options.Args.Id) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1336 | } |
| 1337 | return nil |
| 1338 | } |
| 1339 | |
| 1340 | func (options *DevicePmConfigGroupEnable) Execute(args []string) error { |
| 1341 | |
| 1342 | conn, err := NewConnection() |
| 1343 | if err != nil { |
| 1344 | return err |
| 1345 | } |
| 1346 | defer conn.Close() |
| 1347 | |
| 1348 | client := voltha.NewVolthaServiceClient(conn) |
| 1349 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1350 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1351 | defer cancel() |
| 1352 | |
| 1353 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1354 | |
| 1355 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1356 | if err != nil { |
| 1357 | return err |
| 1358 | } |
| 1359 | |
| 1360 | if pmConfigs.Grouped { |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1361 | groups := make(map[string]struct{}) |
| 1362 | for _, group := range pmConfigs.Groups { |
| 1363 | groups[group.GroupName] = struct{}{} |
| 1364 | } |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1365 | for _, group := range pmConfigs.Groups { |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1366 | if _, have := groups[string(options.Args.Group)]; !have { |
| 1367 | return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group) |
| 1368 | } |
| 1369 | if string(options.Args.Group) == group.GroupName && !group.Enabled { |
| 1370 | group.Enabled = true |
| 1371 | _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1372 | if err != nil { |
| 1373 | return err |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1374 | } |
| 1375 | } |
| 1376 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1377 | } else { |
| 1378 | return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1379 | } |
| 1380 | return nil |
| 1381 | } |
| 1382 | |
| 1383 | func (options *DevicePmConfigGroupDisable) Execute(args []string) error { |
| 1384 | |
| 1385 | conn, err := NewConnection() |
| 1386 | if err != nil { |
| 1387 | return err |
| 1388 | } |
| 1389 | defer conn.Close() |
| 1390 | |
| 1391 | client := voltha.NewVolthaServiceClient(conn) |
| 1392 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1393 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1394 | defer cancel() |
| 1395 | |
| 1396 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1397 | |
| 1398 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1399 | if err != nil { |
| 1400 | return err |
| 1401 | } |
| 1402 | |
| 1403 | if pmConfigs.Grouped { |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1404 | groups := make(map[string]struct{}) |
| 1405 | for _, group := range pmConfigs.Groups { |
| 1406 | groups[group.GroupName] = struct{}{} |
| 1407 | } |
| 1408 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1409 | for _, group := range pmConfigs.Groups { |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1410 | if _, have := groups[string(options.Args.Group)]; !have { |
| 1411 | return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group) |
| 1412 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1413 | |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1414 | if string(options.Args.Group) == group.GroupName && group.Enabled { |
| 1415 | group.Enabled = false |
| 1416 | _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1417 | if err != nil { |
| 1418 | return err |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1419 | } |
| 1420 | } |
| 1421 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1422 | } else { |
| 1423 | return fmt.Errorf("Device '%s' does not have Group Metrics", options.Args.Id) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1424 | } |
| 1425 | return nil |
| 1426 | } |
| 1427 | |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1428 | func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error { |
| 1429 | |
| 1430 | conn, err := NewConnection() |
| 1431 | if err != nil { |
| 1432 | return err |
| 1433 | } |
| 1434 | defer conn.Close() |
| 1435 | |
| 1436 | client := voltha.NewVolthaServiceClient(conn) |
| 1437 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1438 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1439 | defer cancel() |
| 1440 | |
| 1441 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1442 | |
| 1443 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1444 | if err != nil { |
| 1445 | return err |
| 1446 | } |
| 1447 | |
| 1448 | if pmConfigs.Grouped { |
| 1449 | groups := make(map[string]struct{}) |
| 1450 | for _, group := range pmConfigs.Groups { |
| 1451 | groups[group.GroupName] = struct{}{} |
| 1452 | } |
| 1453 | |
| 1454 | for _, group := range pmConfigs.Groups { |
| 1455 | if _, have := groups[string(options.Args.Group)]; !have { |
| 1456 | return fmt.Errorf("group name '%s' does not exist", options.Args.Group) |
| 1457 | } |
| 1458 | |
| 1459 | if string(options.Args.Group) == group.GroupName { |
| 1460 | if !group.Enabled { |
| 1461 | return fmt.Errorf("group '%s' is not enabled", options.Args.Group) |
| 1462 | } |
| 1463 | group.GroupFreq = uint32(options.Args.Interval.Seconds()) |
| 1464 | _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1465 | if err != nil { |
| 1466 | return err |
| 1467 | } |
| 1468 | } |
| 1469 | } |
| 1470 | } else { |
| 1471 | return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id) |
| 1472 | } |
| 1473 | return nil |
| 1474 | } |
| 1475 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1476 | func (options *DevicePmConfigGroupList) Execute(args []string) error { |
| 1477 | |
| 1478 | conn, err := NewConnection() |
| 1479 | if err != nil { |
| 1480 | return err |
| 1481 | } |
| 1482 | defer conn.Close() |
| 1483 | |
| 1484 | client := voltha.NewVolthaServiceClient(conn) |
| 1485 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1486 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1487 | defer cancel() |
| 1488 | |
| 1489 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1490 | |
| 1491 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1492 | if err != nil { |
| 1493 | return err |
| 1494 | } |
| 1495 | |
| 1496 | if pmConfigs.Grouped { |
| 1497 | for _, group := range pmConfigs.Groups { |
| 1498 | if group.GroupFreq == 0 { |
| 1499 | group.GroupFreq = pmConfigs.DefaultFreq |
| 1500 | } |
| 1501 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1502 | outputFormat := CharReplacer.Replace(options.Format) |
| 1503 | if outputFormat == "" { |
| 1504 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT) |
| 1505 | } |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1506 | |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1507 | orderBy := options.OrderBy |
| 1508 | if orderBy == "" { |
| 1509 | orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "") |
| 1510 | } |
| 1511 | |
| 1512 | result := CommandResult{ |
| 1513 | Format: format.Format(outputFormat), |
| 1514 | Filter: options.Filter, |
| 1515 | OrderBy: orderBy, |
| 1516 | OutputAs: toOutputType(options.OutputAs), |
| 1517 | NameLimit: options.NameLimit, |
| 1518 | Data: pmConfigs.Groups, |
| 1519 | } |
| 1520 | |
| 1521 | GenerateOutput(&result) |
| 1522 | } else { |
| 1523 | return fmt.Errorf("Device '%s' does not have Group Metrics", string(options.Args.Id)) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1524 | } |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1525 | return nil |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | func (options *DevicePmConfigGroupMetricList) Execute(args []string) error { |
| 1529 | |
| 1530 | var metrics []*voltha.PmConfig |
| 1531 | conn, err := NewConnection() |
| 1532 | if err != nil { |
| 1533 | return err |
| 1534 | } |
| 1535 | defer conn.Close() |
| 1536 | |
| 1537 | client := voltha.NewVolthaServiceClient(conn) |
| 1538 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1539 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1540 | defer cancel() |
| 1541 | |
| 1542 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1543 | |
| 1544 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1545 | if err != nil { |
| 1546 | return err |
| 1547 | } |
| 1548 | |
| 1549 | for _, groups := range pmConfigs.Groups { |
| 1550 | |
| 1551 | if string(options.Args.Group) == groups.GroupName { |
| 1552 | for _, metric := range groups.Metrics { |
| 1553 | if metric.SampleFreq == 0 && groups.GroupFreq == 0 { |
| 1554 | metric.SampleFreq = pmConfigs.DefaultFreq |
| 1555 | } else { |
| 1556 | metric.SampleFreq = groups.GroupFreq |
| 1557 | } |
| 1558 | } |
| 1559 | metrics = groups.Metrics |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | outputFormat := CharReplacer.Replace(options.Format) |
| 1564 | if outputFormat == "" { |
| 1565 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT) |
| 1566 | } |
| 1567 | |
| 1568 | orderBy := options.OrderBy |
| 1569 | if orderBy == "" { |
| 1570 | orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "") |
| 1571 | } |
| 1572 | |
| 1573 | result := CommandResult{ |
| 1574 | Format: format.Format(outputFormat), |
| 1575 | Filter: options.Filter, |
| 1576 | OrderBy: orderBy, |
| 1577 | OutputAs: toOutputType(options.OutputAs), |
| 1578 | NameLimit: options.NameLimit, |
| 1579 | Data: metrics, |
| 1580 | } |
| 1581 | |
| 1582 | GenerateOutput(&result) |
| 1583 | return nil |
| 1584 | |
| 1585 | } |
| 1586 | |
| 1587 | func (options *DevicePmConfigFrequencySet) Execute(args []string) error { |
| 1588 | |
| 1589 | conn, err := NewConnection() |
| 1590 | if err != nil { |
| 1591 | return err |
| 1592 | } |
| 1593 | defer conn.Close() |
| 1594 | |
| 1595 | client := voltha.NewVolthaServiceClient(conn) |
| 1596 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1597 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1598 | defer cancel() |
| 1599 | |
| 1600 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1601 | |
| 1602 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1603 | if err != nil { |
| 1604 | return err |
| 1605 | } |
| 1606 | |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1607 | pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds()) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1608 | |
| 1609 | _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1610 | if err != nil { |
| 1611 | return err |
| 1612 | } |
| 1613 | |
| 1614 | outputFormat := CharReplacer.Replace(options.Format) |
| 1615 | if outputFormat == "" { |
| 1616 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT) |
| 1617 | } |
| 1618 | if options.Quiet { |
| 1619 | outputFormat = "{{.Id}}" |
| 1620 | } |
| 1621 | |
| 1622 | result := CommandResult{ |
| 1623 | Format: format.Format(outputFormat), |
| 1624 | OutputAs: toOutputType(options.OutputAs), |
| 1625 | NameLimit: options.NameLimit, |
| 1626 | Data: pmConfigs, |
| 1627 | } |
| 1628 | |
| 1629 | GenerateOutput(&result) |
| 1630 | return nil |
| 1631 | |
| 1632 | } |
| 1633 | |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1634 | func (options *OnuDownloadImage) Execute(args []string) error { |
| 1635 | |
| 1636 | conn, err := NewConnection() |
| 1637 | if err != nil { |
| 1638 | return err |
| 1639 | } |
| 1640 | defer conn.Close() |
| 1641 | |
| 1642 | client := voltha.NewVolthaServiceClient(conn) |
| 1643 | |
| 1644 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1645 | defer cancel() |
| 1646 | |
| 1647 | var devIDList []*common.ID |
| 1648 | for _, i := range options.Args.IDs { |
| 1649 | |
| 1650 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1651 | } |
| 1652 | |
| 1653 | downloadImage := voltha.DeviceImageDownloadRequest{ |
| 1654 | DeviceId: devIDList, |
| 1655 | Image: &voltha.Image{ |
| 1656 | Url: options.Args.Url, |
| 1657 | Crc32: options.Args.Crc, |
ssiddiqui | 7bc89e9 | 2021-05-20 20:58:02 +0530 | [diff] [blame] | 1658 | Vendor: options.Args.Vendor, |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1659 | Version: options.Args.ImageVersion, |
| 1660 | }, |
| 1661 | ActivateOnSuccess: options.Args.ActivateOnSuccess, |
| 1662 | CommitOnSuccess: options.Args.CommitOnSuccess, |
| 1663 | } |
| 1664 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1665 | deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage) |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1666 | if err != nil { |
| 1667 | return err |
| 1668 | } |
| 1669 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1670 | outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1671 | // Make sure json output prints an empty list, not "null" |
| 1672 | if deviceImageResp.DeviceImageStates == nil { |
| 1673 | deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1674 | } |
| 1675 | result := CommandResult{ |
| 1676 | Format: format.Format(outputFormat), |
| 1677 | OutputAs: toOutputType(options.OutputAs), |
| 1678 | NameLimit: options.NameLimit, |
| 1679 | Data: deviceImageResp.DeviceImageStates, |
| 1680 | } |
| 1681 | GenerateOutput(&result) |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1682 | return nil |
| 1683 | |
| 1684 | } |
| 1685 | |
| 1686 | func (options *OnuActivateImage) Execute(args []string) error { |
| 1687 | |
| 1688 | conn, err := NewConnection() |
| 1689 | if err != nil { |
| 1690 | return err |
| 1691 | } |
| 1692 | defer conn.Close() |
| 1693 | |
| 1694 | client := voltha.NewVolthaServiceClient(conn) |
| 1695 | |
| 1696 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1697 | defer cancel() |
| 1698 | |
| 1699 | var devIDList []*common.ID |
| 1700 | for _, i := range options.Args.IDs { |
| 1701 | |
| 1702 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1703 | } |
| 1704 | |
| 1705 | downloadImage := voltha.DeviceImageRequest{ |
| 1706 | DeviceId: devIDList, |
| 1707 | Version: options.Args.ImageVersion, |
| 1708 | CommitOnSuccess: options.Args.CommitOnSuccess, |
| 1709 | } |
| 1710 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1711 | deviceImageResp, err := client.ActivateImage(ctx, &downloadImage) |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1712 | if err != nil { |
| 1713 | return err |
| 1714 | } |
| 1715 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1716 | outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1717 | // Make sure json output prints an empty list, not "null" |
| 1718 | if deviceImageResp.DeviceImageStates == nil { |
| 1719 | deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1720 | } |
| 1721 | result := CommandResult{ |
| 1722 | Format: format.Format(outputFormat), |
| 1723 | OutputAs: toOutputType(options.OutputAs), |
| 1724 | NameLimit: options.NameLimit, |
| 1725 | Data: deviceImageResp.DeviceImageStates, |
| 1726 | } |
| 1727 | GenerateOutput(&result) |
| 1728 | |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1729 | return nil |
| 1730 | |
| 1731 | } |
| 1732 | |
| 1733 | func (options *OnuAbortUpgradeImage) Execute(args []string) error { |
| 1734 | |
| 1735 | conn, err := NewConnection() |
| 1736 | if err != nil { |
| 1737 | return err |
| 1738 | } |
| 1739 | defer conn.Close() |
| 1740 | |
| 1741 | client := voltha.NewVolthaServiceClient(conn) |
| 1742 | |
| 1743 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1744 | defer cancel() |
| 1745 | |
| 1746 | var devIDList []*common.ID |
| 1747 | for _, i := range options.Args.IDs { |
| 1748 | |
| 1749 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1750 | } |
| 1751 | |
| 1752 | downloadImage := voltha.DeviceImageRequest{ |
| 1753 | DeviceId: devIDList, |
| 1754 | Version: options.Args.ImageVersion, |
| 1755 | } |
| 1756 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1757 | deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage) |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1758 | if err != nil { |
| 1759 | return err |
| 1760 | } |
| 1761 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1762 | outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1763 | // Make sure json output prints an empty list, not "null" |
| 1764 | if deviceImageResp.DeviceImageStates == nil { |
| 1765 | deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1766 | } |
| 1767 | result := CommandResult{ |
| 1768 | Format: format.Format(outputFormat), |
| 1769 | OutputAs: toOutputType(options.OutputAs), |
| 1770 | NameLimit: options.NameLimit, |
| 1771 | Data: deviceImageResp.DeviceImageStates, |
| 1772 | } |
| 1773 | GenerateOutput(&result) |
| 1774 | |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1775 | return nil |
| 1776 | |
| 1777 | } |
| 1778 | |
| 1779 | func (options *OnuCommitImage) Execute(args []string) error { |
| 1780 | |
| 1781 | conn, err := NewConnection() |
| 1782 | if err != nil { |
| 1783 | return err |
| 1784 | } |
| 1785 | defer conn.Close() |
| 1786 | |
| 1787 | client := voltha.NewVolthaServiceClient(conn) |
| 1788 | |
| 1789 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1790 | defer cancel() |
| 1791 | |
| 1792 | var devIDList []*common.ID |
| 1793 | for _, i := range options.Args.IDs { |
| 1794 | |
| 1795 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1796 | } |
| 1797 | downloadImage := voltha.DeviceImageRequest{ |
| 1798 | DeviceId: devIDList, |
| 1799 | Version: options.Args.ImageVersion, |
| 1800 | } |
| 1801 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1802 | deviceImageResp, err := client.CommitImage(ctx, &downloadImage) |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1803 | if err != nil { |
| 1804 | return err |
| 1805 | } |
| 1806 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1807 | outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1808 | // Make sure json output prints an empty list, not "null" |
| 1809 | if deviceImageResp.DeviceImageStates == nil { |
| 1810 | deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1811 | } |
| 1812 | result := CommandResult{ |
| 1813 | Format: format.Format(outputFormat), |
| 1814 | OutputAs: toOutputType(options.OutputAs), |
| 1815 | NameLimit: options.NameLimit, |
| 1816 | Data: deviceImageResp.DeviceImageStates, |
| 1817 | } |
| 1818 | GenerateOutput(&result) |
| 1819 | |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1820 | return nil |
| 1821 | |
| 1822 | } |
| 1823 | |
| 1824 | func (options *OnuListImages) Execute(args []string) error { |
| 1825 | |
| 1826 | conn, err := NewConnection() |
| 1827 | if err != nil { |
| 1828 | return err |
| 1829 | } |
| 1830 | defer conn.Close() |
| 1831 | |
| 1832 | client := voltha.NewVolthaServiceClient(conn) |
| 1833 | |
| 1834 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1835 | defer cancel() |
| 1836 | |
| 1837 | id := common.ID{Id: string(options.Args.Id)} |
| 1838 | |
| 1839 | onuImages, err := client.GetOnuImages(ctx, &id) |
| 1840 | if err != nil { |
| 1841 | return err |
| 1842 | } |
| 1843 | |
| 1844 | outputFormat := CharReplacer.Replace(options.Format) |
| 1845 | if outputFormat == "" { |
| 1846 | outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT) |
| 1847 | } |
| 1848 | |
| 1849 | if options.Quiet { |
| 1850 | outputFormat = "{{.Id}}" |
| 1851 | } |
| 1852 | |
| 1853 | //TODO orderby |
| 1854 | |
| 1855 | // Make sure json output prints an empty list, not "null" |
| 1856 | if onuImages.Items == nil { |
| 1857 | onuImages.Items = make([]*voltha.OnuImage, 0) |
| 1858 | } |
| 1859 | |
| 1860 | result := CommandResult{ |
| 1861 | Format: format.Format(outputFormat), |
| 1862 | OutputAs: toOutputType(options.OutputAs), |
| 1863 | NameLimit: options.NameLimit, |
| 1864 | Data: onuImages.Items, |
| 1865 | } |
| 1866 | |
| 1867 | GenerateOutput(&result) |
| 1868 | return nil |
| 1869 | |
| 1870 | } |
| 1871 | |
| 1872 | func (options *OnuImageStatus) Execute(args []string) error { |
| 1873 | |
| 1874 | conn, err := NewConnection() |
| 1875 | if err != nil { |
| 1876 | return err |
| 1877 | } |
| 1878 | defer conn.Close() |
| 1879 | |
| 1880 | client := voltha.NewVolthaServiceClient(conn) |
| 1881 | |
| 1882 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1883 | defer cancel() |
| 1884 | |
| 1885 | var devIDList []*common.ID |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1886 | |
Elia Battiston | 859f3e6 | 2022-02-08 15:57:52 +0100 | [diff] [blame] | 1887 | if options.Args.IDs == nil { |
| 1888 | //Use an empty IDs list to retrieve the status of all devices |
| 1889 | //with the requested image version |
| 1890 | devIDList = []*common.ID{} |
| 1891 | } else { |
| 1892 | for _, i := range options.Args.IDs { |
| 1893 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1894 | } |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | imageStatusReq := voltha.DeviceImageRequest{ |
| 1898 | DeviceId: devIDList, |
| 1899 | Version: options.Args.ImageVersion, |
| 1900 | } |
| 1901 | imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq) |
| 1902 | if err != nil { |
| 1903 | return err |
| 1904 | } |
| 1905 | |
| 1906 | outputFormat := CharReplacer.Replace(options.Format) |
| 1907 | if outputFormat == "" { |
| 1908 | outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1909 | } |
| 1910 | |
| 1911 | if options.Quiet { |
| 1912 | outputFormat = "{{.Id}}" |
| 1913 | } |
| 1914 | |
| 1915 | //TODO orderby |
| 1916 | |
| 1917 | // Make sure json output prints an empty list, not "null" |
| 1918 | if imageStatus.DeviceImageStates == nil { |
| 1919 | imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1920 | } |
| 1921 | |
| 1922 | result := CommandResult{ |
| 1923 | Format: format.Format(outputFormat), |
| 1924 | OutputAs: toOutputType(options.OutputAs), |
| 1925 | NameLimit: options.NameLimit, |
| 1926 | Data: imageStatus.DeviceImageStates, |
| 1927 | } |
| 1928 | |
| 1929 | GenerateOutput(&result) |
| 1930 | return nil |
| 1931 | |
| 1932 | } |
| 1933 | |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 1934 | func (options *DeviceOnuListImages) Execute(args []string) error { |
| 1935 | |
| 1936 | conn, err := NewConnection() |
| 1937 | if err != nil { |
| 1938 | return err |
| 1939 | } |
| 1940 | defer conn.Close() |
| 1941 | |
| 1942 | client := voltha.NewVolthaServiceClient(conn) |
| 1943 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1944 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 1945 | defer cancel() |
| 1946 | |
| 1947 | id := common.ID{Id: string(options.Args.Id)} |
| 1948 | |
| 1949 | imageDownloads, err := client.ListImageDownloads(ctx, &id) |
| 1950 | if err != nil { |
| 1951 | return err |
| 1952 | } |
| 1953 | |
| 1954 | outputFormat := CharReplacer.Replace(options.Format) |
| 1955 | if outputFormat == "" { |
| 1956 | outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT) |
| 1957 | } |
| 1958 | |
| 1959 | if options.Quiet { |
| 1960 | outputFormat = "{{.Id}}" |
| 1961 | } |
| 1962 | |
| 1963 | //TODO orderby |
| 1964 | |
| 1965 | // Make sure json output prints an empty list, not "null" |
| 1966 | if imageDownloads.Items == nil { |
| 1967 | imageDownloads.Items = make([]*voltha.ImageDownload, 0) |
| 1968 | } |
| 1969 | |
| 1970 | result := CommandResult{ |
| 1971 | Format: format.Format(outputFormat), |
| 1972 | OutputAs: toOutputType(options.OutputAs), |
| 1973 | NameLimit: options.NameLimit, |
| 1974 | Data: imageDownloads.Items, |
| 1975 | } |
| 1976 | |
| 1977 | GenerateOutput(&result) |
| 1978 | return nil |
| 1979 | |
| 1980 | } |
| 1981 | |
| 1982 | func (options *DeviceOnuDownloadImage) Execute(args []string) error { |
| 1983 | |
| 1984 | conn, err := NewConnection() |
| 1985 | if err != nil { |
| 1986 | return err |
| 1987 | } |
| 1988 | defer conn.Close() |
| 1989 | |
| 1990 | client := voltha.NewVolthaServiceClient(conn) |
| 1991 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1992 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 1993 | defer cancel() |
| 1994 | |
| 1995 | downloadImage := voltha.ImageDownload{ |
| 1996 | Id: string(options.Args.Id), |
| 1997 | Name: options.Args.Name, |
| 1998 | Url: options.Args.Url, |
| 1999 | Crc: options.Args.Crc, |
| 2000 | LocalDir: options.Args.LocalDir, |
| 2001 | } |
| 2002 | |
| 2003 | _, err = client.DownloadImage(ctx, &downloadImage) |
| 2004 | if err != nil { |
| 2005 | return err |
| 2006 | } |
| 2007 | |
| 2008 | return nil |
| 2009 | |
| 2010 | } |
| 2011 | |
| 2012 | func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error { |
| 2013 | |
| 2014 | conn, err := NewConnection() |
| 2015 | if err != nil { |
| 2016 | return err |
| 2017 | } |
| 2018 | defer conn.Close() |
| 2019 | |
| 2020 | client := voltha.NewVolthaServiceClient(conn) |
| 2021 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2022 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 2023 | defer cancel() |
| 2024 | |
| 2025 | downloadImage := voltha.ImageDownload{ |
| 2026 | Id: string(options.Args.Id), |
| 2027 | Name: options.Args.Name, |
| 2028 | ImageVersion: options.Args.ImageVersion, |
| 2029 | SaveConfig: options.Args.SaveConfig, |
| 2030 | LocalDir: options.Args.LocalDir, |
| 2031 | } |
| 2032 | |
| 2033 | _, err = client.ActivateImageUpdate(ctx, &downloadImage) |
| 2034 | if err != nil { |
| 2035 | return err |
| 2036 | } |
| 2037 | |
| 2038 | return nil |
| 2039 | |
| 2040 | } |
| 2041 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2042 | type ReturnValueRow struct { |
| 2043 | Name string `json:"name"` |
| 2044 | Result interface{} `json:"result"` |
| 2045 | } |
| 2046 | |
kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 2047 | func (options *DeviceGetPortStats) Execute(args []string) error { |
| 2048 | conn, err := NewConnection() |
| 2049 | if err != nil { |
| 2050 | return err |
| 2051 | } |
| 2052 | defer conn.Close() |
| 2053 | client := extension.NewExtensionClient(conn) |
| 2054 | var portType extension.GetOltPortCounters_PortType |
| 2055 | |
| 2056 | if options.Args.PortType == "pon" { |
| 2057 | portType = extension.GetOltPortCounters_Port_PON_OLT |
| 2058 | } else if options.Args.PortType == "nni" { |
| 2059 | |
| 2060 | portType = extension.GetOltPortCounters_Port_ETHERNET_NNI |
| 2061 | } else { |
| 2062 | return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType) |
| 2063 | } |
| 2064 | |
| 2065 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2066 | TargetId: string(options.Args.Id), |
| 2067 | Request: &extension.GetValueRequest{ |
| 2068 | Request: &extension.GetValueRequest_OltPortInfo{ |
| 2069 | OltPortInfo: &extension.GetOltPortCounters{ |
| 2070 | PortNo: options.Args.PortNo, |
| 2071 | PortType: portType, |
| 2072 | }, |
| 2073 | }, |
| 2074 | }, |
| 2075 | } |
| 2076 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2077 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 2078 | defer cancel() |
| 2079 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2080 | if err != nil { |
| 2081 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2082 | return err |
| 2083 | } |
| 2084 | |
| 2085 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2086 | return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String()) |
| 2087 | } |
| 2088 | |
| 2089 | outputFormat := CharReplacer.Replace(options.Format) |
| 2090 | if outputFormat == "" { |
| 2091 | outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT) |
| 2092 | } |
| 2093 | |
| 2094 | result := CommandResult{ |
| 2095 | Format: format.Format(outputFormat), |
| 2096 | OutputAs: toOutputType(options.OutputAs), |
| 2097 | NameLimit: options.NameLimit, |
| 2098 | Data: rv.GetResponse().GetPortCoutners(), |
| 2099 | } |
| 2100 | GenerateOutput(&result) |
| 2101 | return nil |
| 2102 | } |
| 2103 | |
Himani Chawla | 40acc12 | 2021-05-26 18:52:29 +0530 | [diff] [blame] | 2104 | func (options *GetOnuStats) Execute(args []string) error { |
| 2105 | conn, err := NewConnection() |
| 2106 | if err != nil { |
| 2107 | return err |
| 2108 | } |
| 2109 | defer conn.Close() |
| 2110 | client := extension.NewExtensionClient(conn) |
| 2111 | |
| 2112 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2113 | TargetId: string(options.Args.OltId), |
| 2114 | Request: &extension.GetValueRequest{ |
| 2115 | Request: &extension.GetValueRequest_OnuPonInfo{ |
| 2116 | OnuPonInfo: &extension.GetOnuCountersRequest{ |
| 2117 | IntfId: options.Args.IntfId, |
| 2118 | OnuId: options.Args.OnuId, |
| 2119 | }, |
| 2120 | }, |
| 2121 | }, |
| 2122 | } |
| 2123 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2124 | defer cancel() |
| 2125 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2126 | if err != nil { |
| 2127 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err)) |
| 2128 | return err |
| 2129 | } |
| 2130 | |
| 2131 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2132 | return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String()) |
| 2133 | } |
| 2134 | outputFormat := CharReplacer.Replace(options.Format) |
| 2135 | data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters()) |
| 2136 | if outputFormat == "" { |
| 2137 | outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr) |
| 2138 | } |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2139 | result := CommandResult{ |
| 2140 | Format: format.Format(outputFormat), |
| 2141 | OutputAs: toOutputType(options.OutputAs), |
| 2142 | NameLimit: options.NameLimit, |
| 2143 | Data: data, |
| 2144 | } |
| 2145 | GenerateOutput(&result) |
| 2146 | return nil |
| 2147 | } |
Himani Chawla | 40acc12 | 2021-05-26 18:52:29 +0530 | [diff] [blame] | 2148 | |
Akash Soni | 51b6b7a | 2024-11-20 11:39:38 +0530 | [diff] [blame^] | 2149 | func (options *GetOffloadAppStats) Execute(args []string) error { |
| 2150 | // Establish a connection to the gRPC server |
| 2151 | conn, err := NewConnection() |
| 2152 | if err != nil { |
| 2153 | return err |
| 2154 | } |
| 2155 | defer conn.Close() |
| 2156 | |
| 2157 | client := extension.NewExtensionClient(conn) |
| 2158 | |
| 2159 | // Build the request |
| 2160 | singleGetValReq := &extension.SingleGetValueRequest{ |
| 2161 | TargetId: string(options.Args.OltId), |
| 2162 | Request: &extension.GetValueRequest{ |
| 2163 | Request: &extension.GetValueRequest_OffloadedAppsStats{ |
| 2164 | OffloadedAppsStats: &extension.GetOffloadedAppsStatisticsRequest{ |
| 2165 | StatsFor: options.Args.StatsFor, |
| 2166 | }, |
| 2167 | }, |
| 2168 | }, |
| 2169 | } |
| 2170 | |
| 2171 | // Set a context with timeout |
| 2172 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2173 | defer cancel() |
| 2174 | |
| 2175 | // Perform the gRPC call |
| 2176 | rv, err := client.GetExtValue(ctx, singleGetValReq) |
| 2177 | if err != nil { |
| 2178 | Error.Printf("Error getting value for device ID %s, err=%s\n", options.Args.OltId, ErrorToString(err)) |
| 2179 | return err |
| 2180 | } |
| 2181 | |
| 2182 | // Check response status |
| 2183 | if rv.GetResponse().GetStatus() != extension.GetValueResponse_OK { |
| 2184 | return fmt.Errorf("failed to get offloaded app stats: %v", rv.GetResponse().GetErrReason().String()) |
| 2185 | } |
| 2186 | |
| 2187 | // Process the response data |
| 2188 | stats, formatStr := buildOffloadAppStatsOutputFormat(rv.GetResponse().GetOffloadedAppsStats()) |
| 2189 | outputFormat := CharReplacer.Replace(options.Format) |
| 2190 | if outputFormat == "" { |
| 2191 | outputFormat = GetCommandOptionWithDefault("device-get-offload-app-stats", "format", formatStr) |
| 2192 | } |
| 2193 | |
| 2194 | // Generate and display the output |
| 2195 | result := CommandResult{ |
| 2196 | Format: format.Format(outputFormat), |
| 2197 | OutputAs: toOutputType(options.OutputAs), |
| 2198 | NameLimit: options.NameLimit, |
| 2199 | Data: stats, |
| 2200 | } |
| 2201 | GenerateOutput(&result) |
| 2202 | |
| 2203 | return nil |
| 2204 | } |
| 2205 | |
| 2206 | func (options *SetOffloadAppState) Execute(args []string) error { |
| 2207 | conn, err := NewConnection() |
| 2208 | if err != nil { |
| 2209 | return fmt.Errorf("failed to establish gRPC connection: %v", err) |
| 2210 | } |
| 2211 | defer conn.Close() |
| 2212 | |
| 2213 | client := extension.NewExtensionClient(conn) |
| 2214 | |
| 2215 | // Build the AppOffloadConfig request |
| 2216 | setValueRequest := &extension.SetValueRequest{ |
| 2217 | Request: &extension.SetValueRequest_AppOffloadConfig{ |
| 2218 | AppOffloadConfig: &options.Args.Config, |
| 2219 | }, |
| 2220 | } |
| 2221 | |
| 2222 | singleSetValReq := &extension.SingleSetValueRequest{ |
| 2223 | TargetId: string(options.Args.OltId), |
| 2224 | Request: setValueRequest, |
| 2225 | } |
| 2226 | |
| 2227 | // Make gRPC call |
| 2228 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2229 | defer cancel() |
| 2230 | |
| 2231 | resp, err := client.SetExtValue(ctx, singleSetValReq) |
| 2232 | if err != nil { |
| 2233 | return fmt.Errorf("failed to set AppOffloadConfig: %v", err) |
| 2234 | } |
| 2235 | |
| 2236 | if resp.Response.Status != extension.SetValueResponse_OK { |
| 2237 | return fmt.Errorf("failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason) |
| 2238 | } |
| 2239 | |
| 2240 | fmt.Printf("AppOffloadConfig successfully set for OLT ID: %s\n", options.Args.OltId) |
| 2241 | return nil |
| 2242 | } |
| 2243 | |
| 2244 | func (options *SetOnuOffloadState) Execute(args []string) error { |
| 2245 | conn, err := NewConnection() |
| 2246 | if err != nil { |
| 2247 | return fmt.Errorf("failed to establish gRPC connection: %v", err) |
| 2248 | } |
| 2249 | defer conn.Close() |
| 2250 | |
| 2251 | client := extension.NewExtensionClient(conn) |
| 2252 | |
| 2253 | // Convert PerUniInfo to []*extension.AppOffloadOnuConfig_PerUniConfig |
| 2254 | var perUniInfo []*extension.AppOffloadOnuConfig_PerUniConfig |
| 2255 | for i := range options.Args.PerUniInfo { |
| 2256 | perUniInfo = append(perUniInfo, &options.Args.PerUniInfo[i]) |
| 2257 | } |
| 2258 | // Build the AppOffloadOnuConfig request |
| 2259 | onuConfig := &extension.AppOffloadOnuConfig{ |
| 2260 | OnuDeviceId: options.Args.OnuDeviceId, |
| 2261 | PerUniInfo: perUniInfo, |
| 2262 | } |
| 2263 | |
| 2264 | setValueRequest := &extension.SetValueRequest{ |
| 2265 | Request: &extension.SetValueRequest_AppOffloadOnuConfig{ |
| 2266 | AppOffloadOnuConfig: onuConfig, |
| 2267 | }, |
| 2268 | } |
| 2269 | |
| 2270 | singleSetValReq := &extension.SingleSetValueRequest{ |
| 2271 | TargetId: options.Args.OnuDeviceId, |
| 2272 | Request: setValueRequest, |
| 2273 | } |
| 2274 | |
| 2275 | // Make gRPC call |
| 2276 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2277 | defer cancel() |
| 2278 | |
| 2279 | resp, err := client.SetExtValue(ctx, singleSetValReq) |
| 2280 | if err != nil { |
| 2281 | return fmt.Errorf("failed to set AppOffloadOnuConfig: %v", err) |
| 2282 | } |
| 2283 | |
| 2284 | if resp.Response.Status != extension.SetValueResponse_OK { |
| 2285 | return fmt.Errorf("failed with status %v: %s", resp.Response.Status, resp.Response.ErrReason) |
| 2286 | } |
| 2287 | |
| 2288 | fmt.Printf("AppOffloadOnuConfig successfully set for ONU ID: %s\n", options.Args.OnuDeviceId) |
| 2289 | return nil |
| 2290 | } |
| 2291 | |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2292 | func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error { |
| 2293 | conn, err := NewConnection() |
| 2294 | if err != nil { |
| 2295 | return err |
| 2296 | } |
| 2297 | defer conn.Close() |
| 2298 | client := extension.NewExtensionClient(conn) |
Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 2299 | var singleGetValReq extension.SingleGetValueRequest |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2300 | |
Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 2301 | if options.Args.UniIndex != nil { |
| 2302 | singleGetValReq = extension.SingleGetValueRequest{ |
| 2303 | TargetId: string(options.Args.Id), |
| 2304 | Request: &extension.GetValueRequest{ |
| 2305 | Request: &extension.GetValueRequest_OnuInfo{ |
| 2306 | OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{ |
| 2307 | OnuDeviceId: string(options.Args.Id), |
| 2308 | Reset_: options.Reset, |
| 2309 | IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{ |
| 2310 | UniIndex: *options.Args.UniIndex, |
| 2311 | }, |
| 2312 | }, |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2313 | }, |
| 2314 | }, |
Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 2315 | } |
| 2316 | } else { |
| 2317 | singleGetValReq = extension.SingleGetValueRequest{ |
| 2318 | TargetId: string(options.Args.Id), |
| 2319 | Request: &extension.GetValueRequest{ |
| 2320 | Request: &extension.GetValueRequest_OnuInfo{ |
| 2321 | OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{ |
| 2322 | OnuDeviceId: string(options.Args.Id), |
| 2323 | Reset_: options.Reset, |
| 2324 | }, |
| 2325 | }, |
| 2326 | }, |
| 2327 | } |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2328 | } |
Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 2329 | |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2330 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2331 | defer cancel() |
| 2332 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2333 | if err != nil { |
| 2334 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2335 | return err |
| 2336 | } |
| 2337 | |
| 2338 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2339 | return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String()) |
| 2340 | } |
| 2341 | outputFormat := CharReplacer.Replace(options.Format) |
| 2342 | data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters()) |
| 2343 | if outputFormat == "" { |
| 2344 | outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT) |
| 2345 | } |
Himani Chawla | 40acc12 | 2021-05-26 18:52:29 +0530 | [diff] [blame] | 2346 | result := CommandResult{ |
| 2347 | Format: format.Format(outputFormat), |
| 2348 | OutputAs: toOutputType(options.OutputAs), |
| 2349 | NameLimit: options.NameLimit, |
| 2350 | Data: data, |
| 2351 | } |
| 2352 | GenerateOutput(&result) |
| 2353 | return nil |
| 2354 | } |
| 2355 | |
kesavand | 6d1131f | 2021-02-05 22:38:15 +0530 | [diff] [blame] | 2356 | func (options *UniStatus) Execute(args []string) error { |
| 2357 | conn, err := NewConnection() |
| 2358 | if err != nil { |
| 2359 | return err |
| 2360 | } |
| 2361 | defer conn.Close() |
| 2362 | client := extension.NewExtensionClient(conn) |
| 2363 | |
| 2364 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2365 | TargetId: string(options.Args.Id), |
| 2366 | Request: &extension.GetValueRequest{ |
| 2367 | Request: &extension.GetValueRequest_UniInfo{ |
| 2368 | UniInfo: &extension.GetOnuUniInfoRequest{ |
| 2369 | UniIndex: options.Args.UniIndex, |
| 2370 | }, |
| 2371 | }, |
| 2372 | }, |
| 2373 | } |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2374 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
kesavand | 6d1131f | 2021-02-05 22:38:15 +0530 | [diff] [blame] | 2375 | defer cancel() |
| 2376 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2377 | if err != nil { |
| 2378 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2379 | return err |
| 2380 | } |
| 2381 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2382 | return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String()) |
| 2383 | } |
| 2384 | outputFormat := CharReplacer.Replace(options.Format) |
| 2385 | if outputFormat == "" { |
| 2386 | outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT) |
| 2387 | } |
| 2388 | result := CommandResult{ |
| 2389 | Format: format.Format(outputFormat), |
| 2390 | OutputAs: toOutputType(options.OutputAs), |
| 2391 | NameLimit: options.NameLimit, |
| 2392 | Data: rv.GetResponse().GetUniInfo(), |
| 2393 | } |
| 2394 | GenerateOutput(&result) |
| 2395 | return nil |
| 2396 | } |
| 2397 | |
Girish Gowdra | 4f5ce7c | 2021-04-29 18:53:21 -0700 | [diff] [blame] | 2398 | func (options *OnuPonOpticalInfo) Execute(args []string) error { |
| 2399 | conn, err := NewConnection() |
| 2400 | if err != nil { |
| 2401 | return err |
| 2402 | } |
| 2403 | defer conn.Close() |
| 2404 | client := extension.NewExtensionClient(conn) |
| 2405 | |
| 2406 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2407 | TargetId: string(options.Args.Id), |
| 2408 | Request: &extension.GetValueRequest{ |
| 2409 | Request: &extension.GetValueRequest_OnuOpticalInfo{ |
| 2410 | OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{}, |
| 2411 | }, |
| 2412 | }, |
| 2413 | } |
| 2414 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2415 | defer cancel() |
| 2416 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2417 | if err != nil { |
| 2418 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2419 | return err |
| 2420 | } |
| 2421 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2422 | return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String()) |
| 2423 | } |
| 2424 | outputFormat := CharReplacer.Replace(options.Format) |
| 2425 | if outputFormat == "" { |
| 2426 | outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT) |
| 2427 | } |
| 2428 | result := CommandResult{ |
| 2429 | Format: format.Format(outputFormat), |
| 2430 | OutputAs: toOutputType(options.OutputAs), |
| 2431 | NameLimit: options.NameLimit, |
| 2432 | Data: rv.GetResponse().GetOnuOpticalInfo(), |
| 2433 | } |
| 2434 | GenerateOutput(&result) |
| 2435 | return nil |
| 2436 | } |
| 2437 | |
Gamze Abaka | c857a46 | 2021-05-26 13:45:54 +0000 | [diff] [blame] | 2438 | func (options *RxPower) Execute(args []string) error { |
| 2439 | conn, err := NewConnection() |
| 2440 | if err != nil { |
| 2441 | return err |
| 2442 | } |
| 2443 | defer conn.Close() |
| 2444 | client := extension.NewExtensionClient(conn) |
| 2445 | |
| 2446 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2447 | TargetId: string(options.Args.Id), |
| 2448 | Request: &extension.GetValueRequest{ |
| 2449 | Request: &extension.GetValueRequest_RxPower{ |
| 2450 | RxPower: &extension.GetRxPowerRequest{ |
| 2451 | IntfId: options.Args.PortNo, |
| 2452 | OnuId: options.Args.OnuNo, |
| 2453 | }, |
| 2454 | }, |
| 2455 | }, |
| 2456 | } |
| 2457 | |
| 2458 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2459 | defer cancel() |
| 2460 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2461 | if err != nil { |
| 2462 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2463 | return err |
| 2464 | } |
| 2465 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2466 | return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String()) |
| 2467 | } |
| 2468 | outputFormat := CharReplacer.Replace(options.Format) |
| 2469 | if outputFormat == "" { |
| 2470 | outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT) |
| 2471 | } |
| 2472 | result := CommandResult{ |
| 2473 | Format: format.Format(outputFormat), |
| 2474 | OutputAs: toOutputType(options.OutputAs), |
| 2475 | NameLimit: options.NameLimit, |
| 2476 | Data: rv.GetResponse().GetRxPower(), |
| 2477 | } |
| 2478 | GenerateOutput(&result) |
| 2479 | return nil |
| 2480 | } |
| 2481 | |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2482 | /*Device get Onu Distance */ |
| 2483 | func (options *DeviceGetExtValue) Execute(args []string) error { |
| 2484 | conn, err := NewConnection() |
| 2485 | if err != nil { |
| 2486 | return err |
| 2487 | } |
| 2488 | defer conn.Close() |
| 2489 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2490 | client := voltha.NewVolthaServiceClient(conn) |
| 2491 | |
khenaidoo | 080ce88 | 2021-10-19 17:35:08 -0400 | [diff] [blame] | 2492 | valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)] |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2493 | if !okay { |
| 2494 | Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag) |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2495 | } |
| 2496 | |
khenaidoo | 080ce88 | 2021-10-19 17:35:08 -0400 | [diff] [blame] | 2497 | val := extension.ValueSpecifier{Id: string(options.Args.Id), Value: extension.ValueType_Type(valueflag)} |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2498 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2499 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2500 | defer cancel() |
| 2501 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2502 | rv, err := client.GetExtValue(ctx, &val) |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2503 | if err != nil { |
| 2504 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2505 | return err |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2506 | } |
| 2507 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2508 | var rows []ReturnValueRow |
khenaidoo | 080ce88 | 2021-10-19 17:35:08 -0400 | [diff] [blame] | 2509 | for name, num := range extension.ValueType_Type_value { |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2510 | if num == 0 { |
| 2511 | // EMPTY is not a real value |
| 2512 | continue |
| 2513 | } |
| 2514 | if (rv.Error & uint32(num)) != 0 { |
| 2515 | row := ReturnValueRow{Name: name, Result: "Error"} |
| 2516 | rows = append(rows, row) |
| 2517 | } |
| 2518 | if (rv.Unsupported & uint32(num)) != 0 { |
| 2519 | row := ReturnValueRow{Name: name, Result: "Unsupported"} |
| 2520 | rows = append(rows, row) |
| 2521 | } |
| 2522 | if (rv.Set & uint32(num)) != 0 { |
| 2523 | switch name { |
| 2524 | case "DISTANCE": |
| 2525 | row := ReturnValueRow{Name: name, Result: rv.Distance} |
| 2526 | rows = append(rows, row) |
| 2527 | default: |
| 2528 | row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"} |
| 2529 | rows = append(rows, row) |
| 2530 | } |
| 2531 | } |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2532 | } |
| 2533 | |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2534 | outputFormat := CharReplacer.Replace(options.Format) |
| 2535 | if outputFormat == "" { |
| 2536 | outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT) |
| 2537 | } |
| 2538 | |
| 2539 | result := CommandResult{ |
| 2540 | Format: format.Format(outputFormat), |
| 2541 | OutputAs: toOutputType(options.OutputAs), |
| 2542 | NameLimit: options.NameLimit, |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2543 | Data: rows, |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2544 | } |
| 2545 | GenerateOutput(&result) |
| 2546 | return nil |
| 2547 | } |
serkantul | 3d22fc7 | 2022-09-14 12:22:56 +0300 | [diff] [blame] | 2548 | |
| 2549 | /*Device get Onu OMCI TX RX Stats */ |
| 2550 | func (options *OnuOmciTxRxStats) Execute(args []string) error { |
| 2551 | conn, err := NewConnection() |
| 2552 | if err != nil { |
| 2553 | return err |
| 2554 | } |
| 2555 | defer conn.Close() |
| 2556 | client := extension.NewExtensionClient(conn) |
| 2557 | |
| 2558 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2559 | TargetId: string(options.Args.Id), |
| 2560 | Request: &extension.GetValueRequest{ |
| 2561 | Request: &extension.GetValueRequest_OnuOmciStats{ |
| 2562 | OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{}, |
| 2563 | }, |
| 2564 | }, |
| 2565 | } |
| 2566 | |
| 2567 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2568 | defer cancel() |
| 2569 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2570 | if err != nil { |
| 2571 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2572 | return err |
| 2573 | } |
| 2574 | |
| 2575 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2576 | return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String()) |
| 2577 | } |
| 2578 | outputFormat := CharReplacer.Replace(options.Format) |
| 2579 | if outputFormat == "" { |
| 2580 | outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT) |
| 2581 | } |
| 2582 | result := CommandResult{ |
| 2583 | Format: format.Format(outputFormat), |
| 2584 | OutputAs: toOutputType(options.OutputAs), |
| 2585 | NameLimit: options.NameLimit, |
| 2586 | Data: rv.GetResponse().GetOnuOmciStats(), |
| 2587 | } |
| 2588 | GenerateOutput(&result) |
| 2589 | return nil |
| 2590 | } |
praneeth nalmas | 1dd094c | 2022-12-22 14:15:13 +0530 | [diff] [blame] | 2591 | |
| 2592 | /*Device get Onu Active Alarms */ |
| 2593 | func (options *GetOnuOmciActiveAlarms) Execute(args []string) error { |
| 2594 | conn, err := NewConnection() |
| 2595 | if err != nil { |
| 2596 | return err |
| 2597 | } |
| 2598 | defer conn.Close() |
| 2599 | client := extension.NewExtensionClient(conn) |
| 2600 | |
| 2601 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2602 | TargetId: string(options.Args.Id), |
| 2603 | Request: &extension.GetValueRequest{ |
| 2604 | Request: &extension.GetValueRequest_OnuActiveAlarms{ |
| 2605 | OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{}, |
| 2606 | }, |
| 2607 | }, |
| 2608 | } |
| 2609 | Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id) |
| 2610 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2611 | defer cancel() |
| 2612 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2613 | if err != nil { |
| 2614 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2615 | return err |
| 2616 | } |
| 2617 | |
| 2618 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2619 | return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String()) |
| 2620 | } |
| 2621 | outputFormat := CharReplacer.Replace(options.Format) |
| 2622 | if outputFormat == "" { |
| 2623 | outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT) |
| 2624 | } |
| 2625 | |
| 2626 | orderBy := options.OrderBy |
| 2627 | if orderBy == "" { |
| 2628 | orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER) |
| 2629 | } |
| 2630 | |
| 2631 | result := CommandResult{ |
| 2632 | Format: format.Format(outputFormat), |
| 2633 | OutputAs: toOutputType(options.OutputAs), |
| 2634 | OrderBy: orderBy, |
| 2635 | NameLimit: options.NameLimit, |
| 2636 | Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(), |
| 2637 | } |
| 2638 | GenerateOutput(&result) |
| 2639 | return nil |
| 2640 | } |
praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 2641 | |
Akash Soni | 66db963 | 2024-04-15 09:05:15 +0530 | [diff] [blame] | 2642 | /*Device get Onu Active Alarms */ |
| 2643 | func (options *GetOnuDistance) Execute(args []string) error { |
| 2644 | conn, err := NewConnection() |
| 2645 | if err != nil { |
| 2646 | return err |
| 2647 | } |
| 2648 | defer conn.Close() |
| 2649 | client := extension.NewExtensionClient(conn) |
| 2650 | |
| 2651 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2652 | TargetId: string(options.Args.Id), |
| 2653 | Request: &extension.GetValueRequest{ |
| 2654 | Request: &extension.GetValueRequest_Distance{ |
| 2655 | Distance: &extension.GetDistanceRequest{ |
| 2656 | OnuDeviceId: string(options.Args.OnuId), |
| 2657 | }, |
| 2658 | }, |
| 2659 | }, |
| 2660 | } |
| 2661 | Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id) |
| 2662 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2663 | defer cancel() |
| 2664 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2665 | if err != nil { |
| 2666 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2667 | return err |
| 2668 | } |
| 2669 | |
| 2670 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2671 | return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String()) |
| 2672 | } |
| 2673 | outputFormat := CharReplacer.Replace(options.Format) |
| 2674 | if outputFormat == "" { |
| 2675 | outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT) |
| 2676 | } |
| 2677 | |
| 2678 | result := CommandResult{ |
| 2679 | Format: format.Format(outputFormat), |
| 2680 | OutputAs: toOutputType(options.OutputAs), |
| 2681 | NameLimit: options.NameLimit, |
| 2682 | Data: rv.GetResponse().GetDistance().GetDistance(), |
| 2683 | } |
| 2684 | fmt.Println("onu distance : ", rv) |
| 2685 | GenerateOutput(&result) |
| 2686 | return nil |
| 2687 | } |
| 2688 | |
praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 2689 | func (options *PonRxPower) Execute(args []string) error { |
| 2690 | conn, err := NewConnection() |
| 2691 | if err != nil { |
| 2692 | return err |
| 2693 | } |
| 2694 | defer conn.Close() |
| 2695 | client := extension.NewExtensionClient(conn) |
| 2696 | |
| 2697 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2698 | TargetId: string(options.Args.Id), |
| 2699 | Request: &extension.GetValueRequest{ |
| 2700 | Request: &extension.GetValueRequest_OltRxPower{ |
| 2701 | OltRxPower: &extension.GetOltRxPowerRequest{ |
| 2702 | PortLabel: options.Args.PortLabel, |
| 2703 | OnuSn: options.Args.SerialNo, |
| 2704 | }, |
| 2705 | }, |
| 2706 | }, |
| 2707 | } |
| 2708 | |
| 2709 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2710 | defer cancel() |
| 2711 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2712 | if err != nil { |
| 2713 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2714 | return err |
| 2715 | } |
| 2716 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2717 | return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String()) |
| 2718 | } |
| 2719 | outputFormat := CharReplacer.Replace(options.Format) |
| 2720 | if outputFormat == "" { |
| 2721 | outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT) |
| 2722 | } |
| 2723 | result := CommandResult{ |
| 2724 | Format: format.Format(outputFormat), |
| 2725 | OutputAs: toOutputType(options.OutputAs), |
| 2726 | NameLimit: options.NameLimit, |
| 2727 | Data: rv.GetResponse().GetOltRxPower().GetRxPower(), |
| 2728 | } |
| 2729 | GenerateOutput(&result) |
| 2730 | return nil |
| 2731 | } |