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 | |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 416 | type GetOnuEthernetFrameExtendedPmCounters struct { |
| 417 | ListOutputOptions |
Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 418 | Reset bool `long:"reset" description:"Reset the counters"` |
| 419 | Args struct { |
| 420 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 421 | UniIndex *uint32 `positional-arg-name:"UNI_INDEX"` |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 422 | } `positional-args:"yes"` |
| 423 | } |
| 424 | |
Gamze Abaka | c857a46 | 2021-05-26 13:45:54 +0000 | [diff] [blame] | 425 | type RxPower struct { |
| 426 | ListOutputOptions |
| 427 | Args struct { |
| 428 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 429 | PortNo uint32 `positional-arg-name:"PORT_NO" required:"yes"` |
| 430 | OnuNo uint32 `positional-arg-name:"ONU_NO" required:"yes"` |
| 431 | } `positional-args:"yes"` |
| 432 | } |
| 433 | |
praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 434 | type PonRxPower struct { |
| 435 | ListOutputOptions |
| 436 | Args struct { |
| 437 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 438 | PortLabel string `positional-arg-name:"PORT_LABEL" required:"yes"` |
| 439 | SerialNo string `positional-arg-name:"ONU_SERIAL_NUMBER"` |
| 440 | } `positional-args:"yes"` |
| 441 | } |
| 442 | |
serkantul | 3d22fc7 | 2022-09-14 12:22:56 +0300 | [diff] [blame] | 443 | type OnuOmciTxRxStats struct { |
| 444 | ListOutputOptions |
| 445 | Args struct { |
| 446 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 447 | } `positional-args:"yes"` |
| 448 | } |
| 449 | |
praneeth nalmas | 1dd094c | 2022-12-22 14:15:13 +0530 | [diff] [blame] | 450 | type GetOnuOmciActiveAlarms struct { |
| 451 | ListOutputOptions |
| 452 | Args struct { |
| 453 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 454 | } `positional-args:"yes"` |
| 455 | } |
| 456 | |
Akash Soni | 66db963 | 2024-04-15 09:05:15 +0530 | [diff] [blame^] | 457 | type GetOnuDistance struct { |
| 458 | ListOutputOptions |
| 459 | Args struct { |
| 460 | Id DeviceId `positional-arg-name:"DEVICE_ID" required:"yes"` |
| 461 | OnuId OnuId `positional-arg-name:"ONU_ID" required:"yes"` |
| 462 | } `positional-args:"yes"` //onu device id |
| 463 | } |
| 464 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 465 | type DeviceOpts struct { |
Himani Chawla | 3c161c6 | 2021-05-13 16:36:51 +0530 | [diff] [blame] | 466 | List DeviceList `command:"list"` |
| 467 | Create DeviceCreate `command:"create"` |
| 468 | Delete DeviceDelete `command:"delete"` |
| 469 | Enable DeviceEnable `command:"enable"` |
| 470 | Disable DeviceDisable `command:"disable"` |
| 471 | Flows DeviceFlowList `command:"flows"` |
| 472 | Groups DeviceFlowGroupList `command:"groups"` |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 473 | Port struct { |
| 474 | List DevicePortList `command:"list"` |
| 475 | Enable DevicePortEnable `command:"enable"` |
| 476 | Disable DevicePortDisable `command:"disable"` |
| 477 | } `command:"port"` |
| 478 | Inspect DeviceInspect `command:"inspect"` |
| 479 | Reboot DeviceReboot `command:"reboot"` |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 480 | Value struct { |
| 481 | Get DeviceGetExtValue `command:"get"` |
| 482 | } `command:"value"` |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 483 | PmConfig struct { |
Rohan Agrawal | d7df377 | 2020-06-29 11:23:36 +0000 | [diff] [blame] | 484 | Get DevicePmConfigsGet `command:"get"` |
| 485 | MaxSkew struct { |
| 486 | Set DevicePmConfigSetMaxSkew `command:"set"` |
| 487 | } `command:"maxskew"` |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 488 | Frequency struct { |
| 489 | Set DevicePmConfigFrequencySet `command:"set"` |
| 490 | } `command:"frequency"` |
| 491 | Metric struct { |
| 492 | List DevicePmConfigMetricList `command:"list"` |
| 493 | Enable DevicePmConfigMetricEnable `command:"enable"` |
| 494 | Disable DevicePmConfigMetricDisable `command:"disable"` |
| 495 | } `command:"metric"` |
| 496 | Group struct { |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 497 | List DevicePmConfigGroupList `command:"list"` |
| 498 | Enable DevicePmConfigGroupEnable `command:"enable"` |
| 499 | Disable DevicePmConfigGroupDisable `command:"disable"` |
| 500 | Set DevicePmConfigGroupFrequencySet `command:"set"` |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 501 | } `command:"group"` |
| 502 | GroupMetric struct { |
| 503 | List DevicePmConfigGroupMetricList `command:"list"` |
| 504 | } `command:"groupmetric"` |
| 505 | } `command:"pmconfig"` |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 506 | Image struct { |
| 507 | Get DeviceOnuListImages `command:"list"` |
| 508 | Download DeviceOnuDownloadImage `command:"download"` |
| 509 | Activate DeviceOnuActivateImageUpdate `command:"activate"` |
| 510 | } `command:"image"` |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 511 | DownloadImage struct { |
| 512 | Download OnuDownloadImage `command:"download"` |
| 513 | Activate OnuActivateImage `command:"activate"` |
| 514 | Commit OnuCommitImage `command:"commit"` |
| 515 | AbortUpgrade OnuAbortUpgradeImage `command:"abort"` |
| 516 | Status OnuImageStatus `command:"status"` |
| 517 | List OnuListImages `command:"list" ` |
| 518 | } `command:"onuimage"` |
kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 519 | GetExtVal struct { |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 520 | Stats DeviceGetPortStats `command:"portstats"` |
| 521 | UniStatus UniStatus `command:"unistatus"` |
| 522 | OpticalInfo OnuPonOpticalInfo `command:"onu_pon_optical_info"` |
| 523 | OnuStats GetOnuStats `command:"onu_stats"` |
| 524 | EthernetFrameExtendedPm GetOnuEthernetFrameExtendedPmCounters `command:"ethernet_frame_extended_pm"` |
| 525 | RxPower RxPower `command:"rxpower"` |
serkantul | 3d22fc7 | 2022-09-14 12:22:56 +0300 | [diff] [blame] | 526 | OnuOmciStats OnuOmciTxRxStats `command:"onu_omci_stats"` |
praneeth nalmas | 1dd094c | 2022-12-22 14:15:13 +0530 | [diff] [blame] | 527 | OnuOmciActiveAlarms GetOnuOmciActiveAlarms `command:"onu_omci_active_alarms"` |
praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 528 | PonRxPower PonRxPower `command:"pon_rx_power"` |
Akash Soni | 66db963 | 2024-04-15 09:05:15 +0530 | [diff] [blame^] | 529 | OnuDistance GetOnuDistance `command:"onu_distance"` |
kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 530 | } `command:"getextval"` |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | var deviceOpts = DeviceOpts{} |
| 534 | |
| 535 | func RegisterDeviceCommands(parser *flags.Parser) { |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 536 | 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] | 537 | Error.Fatalf("Unexpected error while attempting to register device commands : %s", err) |
David Bainbridge | 12f036f | 2019-10-15 22:09:04 +0000 | [diff] [blame] | 538 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 541 | func (i *MetricName) Complete(match string) []flags.Completion { |
| 542 | conn, err := NewConnection() |
| 543 | if err != nil { |
| 544 | return nil |
| 545 | } |
| 546 | defer conn.Close() |
| 547 | |
| 548 | client := voltha.NewVolthaServiceClient(conn) |
| 549 | |
| 550 | var deviceId string |
| 551 | found: |
| 552 | for i := len(os.Args) - 1; i >= 0; i -= 1 { |
| 553 | switch os.Args[i] { |
| 554 | case "enable": |
| 555 | fallthrough |
| 556 | case "disable": |
| 557 | if len(os.Args) > i+1 { |
| 558 | deviceId = os.Args[i+1] |
| 559 | } else { |
| 560 | return nil |
| 561 | } |
| 562 | break found |
| 563 | default: |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | if len(deviceId) == 0 { |
| 568 | return nil |
| 569 | } |
| 570 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 571 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 572 | defer cancel() |
| 573 | |
| 574 | id := voltha.ID{Id: string(deviceId)} |
| 575 | |
| 576 | pmconfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 577 | |
| 578 | if err != nil { |
| 579 | return nil |
| 580 | } |
| 581 | |
| 582 | list := make([]flags.Completion, 0) |
| 583 | for _, metrics := range pmconfigs.Metrics { |
| 584 | if strings.HasPrefix(metrics.Name, match) { |
| 585 | list = append(list, flags.Completion{Item: metrics.Name}) |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | return list |
| 590 | } |
| 591 | |
| 592 | func (i *GroupName) Complete(match string) []flags.Completion { |
| 593 | conn, err := NewConnection() |
| 594 | if err != nil { |
| 595 | return nil |
| 596 | } |
| 597 | defer conn.Close() |
| 598 | |
| 599 | client := voltha.NewVolthaServiceClient(conn) |
| 600 | |
| 601 | var deviceId string |
| 602 | found: |
| 603 | for i := len(os.Args) - 1; i >= 0; i -= 1 { |
| 604 | switch os.Args[i] { |
| 605 | case "list": |
| 606 | fallthrough |
| 607 | case "enable": |
| 608 | fallthrough |
| 609 | case "disable": |
| 610 | if len(os.Args) > i+1 { |
| 611 | deviceId = os.Args[i+1] |
| 612 | } else { |
| 613 | return nil |
| 614 | } |
| 615 | break found |
| 616 | default: |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | if len(deviceId) == 0 { |
| 621 | return nil |
| 622 | } |
| 623 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 624 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 625 | defer cancel() |
| 626 | |
| 627 | id := voltha.ID{Id: string(deviceId)} |
| 628 | |
| 629 | pmconfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 630 | |
| 631 | if err != nil { |
| 632 | return nil |
| 633 | } |
| 634 | |
| 635 | list := make([]flags.Completion, 0) |
| 636 | for _, group := range pmconfigs.Groups { |
| 637 | if strings.HasPrefix(group.GroupName, match) { |
| 638 | list = append(list, flags.Completion{Item: group.GroupName}) |
| 639 | } |
| 640 | } |
| 641 | return list |
| 642 | } |
| 643 | |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 644 | func (i *PortNum) Complete(match string) []flags.Completion { |
| 645 | conn, err := NewConnection() |
| 646 | if err != nil { |
| 647 | return nil |
| 648 | } |
| 649 | defer conn.Close() |
| 650 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 651 | client := voltha.NewVolthaServiceClient(conn) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 652 | |
| 653 | /* |
| 654 | * The command line args when completing for PortNum will be a DeviceId |
| 655 | * followed by one or more PortNums. So walk the argument list from the |
| 656 | * end and find the first argument that is enable/disable as those are |
| 657 | * the subcommands that come before the positional arguments. It would |
| 658 | * be nice if this package gave us the list of optional arguments |
| 659 | * already parsed. |
| 660 | */ |
| 661 | var deviceId string |
| 662 | found: |
| 663 | for i := len(os.Args) - 1; i >= 0; i -= 1 { |
| 664 | switch os.Args[i] { |
| 665 | case "enable": |
| 666 | fallthrough |
| 667 | case "disable": |
| 668 | if len(os.Args) > i+1 { |
| 669 | deviceId = os.Args[i+1] |
| 670 | } else { |
| 671 | return nil |
| 672 | } |
| 673 | break found |
| 674 | default: |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | if len(deviceId) == 0 { |
| 679 | return nil |
| 680 | } |
| 681 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 682 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 683 | defer cancel() |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 684 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 685 | id := voltha.ID{Id: string(deviceId)} |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 686 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 687 | ports, err := client.ListDevicePorts(ctx, &id) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 688 | if err != nil { |
| 689 | return nil |
| 690 | } |
| 691 | |
| 692 | list := make([]flags.Completion, 0) |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 693 | for _, item := range ports.Items { |
| 694 | pn := strconv.FormatUint(uint64(item.PortNo), 10) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 695 | if strings.HasPrefix(pn, match) { |
| 696 | list = append(list, flags.Completion{Item: pn}) |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | return list |
| 701 | } |
| 702 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 703 | func (i *DeviceId) Complete(match string) []flags.Completion { |
| 704 | conn, err := NewConnection() |
| 705 | if err != nil { |
| 706 | return nil |
| 707 | } |
| 708 | defer conn.Close() |
| 709 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 710 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 711 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 712 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 713 | defer cancel() |
| 714 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 715 | devices, err := client.ListDevices(ctx, &empty.Empty{}) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 716 | if err != nil { |
| 717 | return nil |
| 718 | } |
| 719 | |
| 720 | list := make([]flags.Completion, 0) |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 721 | for _, item := range devices.Items { |
| 722 | if strings.HasPrefix(item.Id, match) { |
| 723 | list = append(list, flags.Completion{Item: item.Id}) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 724 | } |
| 725 | } |
| 726 | |
| 727 | return list |
| 728 | } |
| 729 | |
| 730 | func (options *DeviceList) Execute(args []string) error { |
| 731 | |
| 732 | conn, err := NewConnection() |
| 733 | if err != nil { |
| 734 | return err |
| 735 | } |
| 736 | defer conn.Close() |
| 737 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 738 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 739 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 740 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 741 | defer cancel() |
| 742 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 743 | devices, err := client.ListDevices(ctx, &empty.Empty{}) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 744 | if err != nil { |
| 745 | return err |
| 746 | } |
| 747 | |
| 748 | outputFormat := CharReplacer.Replace(options.Format) |
| 749 | if outputFormat == "" { |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 750 | outputFormat = GetCommandOptionWithDefault("device-list", "format", DEFAULT_DEVICE_FORMAT) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 751 | } |
| 752 | if options.Quiet { |
| 753 | outputFormat = "{{.Id}}" |
| 754 | } |
| 755 | |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 756 | orderBy := options.OrderBy |
| 757 | if orderBy == "" { |
Hardik Windlass | 9361bb8 | 2022-03-23 05:58:48 +0000 | [diff] [blame] | 758 | orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ORDER) |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 759 | } |
| 760 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 761 | // Make sure json output prints an empty list, not "null" |
| 762 | if devices.Items == nil { |
| 763 | devices.Items = make([]*voltha.Device, 0) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | result := CommandResult{ |
| 767 | Format: format.Format(outputFormat), |
| 768 | Filter: options.Filter, |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 769 | OrderBy: orderBy, |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 770 | OutputAs: toOutputType(options.OutputAs), |
| 771 | NameLimit: options.NameLimit, |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 772 | Data: devices.Items, |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | GenerateOutput(&result) |
| 776 | return nil |
| 777 | } |
| 778 | |
| 779 | func (options *DeviceCreate) Execute(args []string) error { |
| 780 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 781 | device := voltha.Device{} |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 782 | if options.HostAndPort != "" { |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 783 | device.Address = &voltha.Device_HostAndPort{HostAndPort: options.HostAndPort} |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 784 | } else if options.IPAddress != "" { |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 785 | device.Address = &voltha.Device_Ipv4Address{Ipv4Address: options.IPAddress} |
Hardik Windlass | ce1de34 | 2020-02-04 21:58:07 +0000 | [diff] [blame] | 786 | } |
| 787 | if options.MACAddress != "" { |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 788 | device.MacAddress = strings.ToLower(options.MACAddress) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 789 | } |
| 790 | if options.DeviceType != "" { |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 791 | device.Type = options.DeviceType |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | conn, err := NewConnection() |
| 795 | if err != nil { |
| 796 | return err |
| 797 | } |
| 798 | defer conn.Close() |
| 799 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 800 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 801 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 802 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 803 | defer cancel() |
| 804 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 805 | createdDevice, err := client.CreateDevice(ctx, &device) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 806 | if err != nil { |
| 807 | return err |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 810 | fmt.Printf("%s\n", createdDevice.Id) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 811 | |
| 812 | return nil |
| 813 | } |
| 814 | |
| 815 | func (options *DeviceDelete) Execute(args []string) error { |
| 816 | |
| 817 | conn, err := NewConnection() |
| 818 | if err != nil { |
| 819 | return err |
| 820 | } |
| 821 | defer conn.Close() |
| 822 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 823 | client := voltha.NewVolthaServiceClient(conn) |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 824 | var lastErr error |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 825 | for _, i := range options.Args.Ids { |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 826 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 827 | defer cancel() |
| 828 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 829 | id := voltha.ID{Id: string(i)} |
Himani Chawla | 9933ddc | 2020-10-12 23:53:27 +0530 | [diff] [blame] | 830 | if options.Force { |
| 831 | _, err = client.ForceDeleteDevice(ctx, &id) |
| 832 | } else { |
| 833 | _, err = client.DeleteDevice(ctx, &id) |
| 834 | } |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 835 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 836 | if err != nil { |
David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 837 | Error.Printf("Error while deleting '%s': %s\n", i, err) |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 838 | lastErr = err |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 839 | continue |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 840 | } |
| 841 | fmt.Printf("%s\n", i) |
| 842 | } |
| 843 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 844 | if lastErr != nil { |
| 845 | return NoReportErr |
| 846 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 847 | return nil |
| 848 | } |
| 849 | |
| 850 | func (options *DeviceEnable) Execute(args []string) error { |
| 851 | conn, err := NewConnection() |
| 852 | if err != nil { |
| 853 | return err |
| 854 | } |
| 855 | defer conn.Close() |
| 856 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 857 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 858 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 859 | var lastErr error |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 860 | for _, i := range options.Args.Ids { |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 861 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 862 | defer cancel() |
| 863 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 864 | id := voltha.ID{Id: string(i)} |
| 865 | |
| 866 | _, err := client.EnableDevice(ctx, &id) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 867 | if err != nil { |
David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 868 | Error.Printf("Error while enabling '%s': %s\n", i, err) |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 869 | lastErr = err |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 870 | continue |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 871 | } |
| 872 | fmt.Printf("%s\n", i) |
| 873 | } |
| 874 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 875 | if lastErr != nil { |
| 876 | return NoReportErr |
| 877 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 878 | return nil |
| 879 | } |
| 880 | |
| 881 | func (options *DeviceDisable) Execute(args []string) error { |
| 882 | conn, err := NewConnection() |
| 883 | if err != nil { |
| 884 | return err |
| 885 | } |
| 886 | defer conn.Close() |
| 887 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 888 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 889 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 890 | var lastErr error |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 891 | for _, i := range options.Args.Ids { |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 892 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 893 | defer cancel() |
| 894 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 895 | id := voltha.ID{Id: string(i)} |
| 896 | |
| 897 | _, err := client.DisableDevice(ctx, &id) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 898 | if err != nil { |
David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 899 | Error.Printf("Error while disabling '%s': %s\n", i, err) |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 900 | lastErr = err |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 901 | continue |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 902 | } |
| 903 | fmt.Printf("%s\n", i) |
| 904 | } |
| 905 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 906 | if lastErr != nil { |
| 907 | return NoReportErr |
| 908 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 909 | return nil |
| 910 | } |
| 911 | |
| 912 | func (options *DeviceReboot) Execute(args []string) error { |
| 913 | conn, err := NewConnection() |
| 914 | if err != nil { |
| 915 | return err |
| 916 | } |
| 917 | defer conn.Close() |
| 918 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 919 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 920 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 921 | var lastErr error |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 922 | for _, i := range options.Args.Ids { |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 923 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 924 | defer cancel() |
| 925 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 926 | id := voltha.ID{Id: string(i)} |
| 927 | |
| 928 | _, err := client.RebootDevice(ctx, &id) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 929 | if err != nil { |
David Bainbridge | 0f758d4 | 2019-10-26 05:17:48 +0000 | [diff] [blame] | 930 | Error.Printf("Error while rebooting '%s': %s\n", i, err) |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 931 | lastErr = err |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 932 | continue |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 933 | } |
| 934 | fmt.Printf("%s\n", i) |
| 935 | } |
| 936 | |
David Bainbridge | 7052fe8 | 2020-03-25 10:37:00 -0700 | [diff] [blame] | 937 | if lastErr != nil { |
| 938 | return NoReportErr |
| 939 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 940 | return nil |
| 941 | } |
| 942 | |
| 943 | func (options *DevicePortList) Execute(args []string) error { |
| 944 | |
| 945 | conn, err := NewConnection() |
| 946 | if err != nil { |
| 947 | return err |
| 948 | } |
| 949 | defer conn.Close() |
| 950 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 951 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 952 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 953 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 954 | defer cancel() |
| 955 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 956 | id := voltha.ID{Id: string(options.Args.Id)} |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 957 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 958 | ports, err := client.ListDevicePorts(ctx, &id) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 959 | if err != nil { |
| 960 | return err |
| 961 | } |
| 962 | |
| 963 | outputFormat := CharReplacer.Replace(options.Format) |
| 964 | if outputFormat == "" { |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 965 | outputFormat = GetCommandOptionWithDefault("device-ports", "format", DEFAULT_DEVICE_PORTS_FORMAT) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 966 | } |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 967 | |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 968 | orderBy := options.OrderBy |
| 969 | if orderBy == "" { |
| 970 | orderBy = GetCommandOptionWithDefault("device-ports", "order", "") |
| 971 | } |
| 972 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 973 | result := CommandResult{ |
| 974 | Format: format.Format(outputFormat), |
| 975 | Filter: options.Filter, |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 976 | OrderBy: orderBy, |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 977 | OutputAs: toOutputType(options.OutputAs), |
| 978 | NameLimit: options.NameLimit, |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 979 | Data: ports.Items, |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | GenerateOutput(&result) |
| 983 | return nil |
| 984 | } |
| 985 | |
| 986 | func (options *DeviceFlowList) Execute(args []string) error { |
| 987 | fl := &FlowList{} |
| 988 | fl.ListOutputOptions = options.ListOutputOptions |
Maninder | 045921e | 2020-09-29 16:46:02 +0530 | [diff] [blame] | 989 | fl.FlowIdOptions = options.FlowIdOptions |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 990 | fl.Args.Id = string(options.Args.Id) |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 991 | fl.Method = "device-flows" |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 992 | return fl.Execute(args) |
| 993 | } |
| 994 | |
Himani Chawla | 3c161c6 | 2021-05-13 16:36:51 +0530 | [diff] [blame] | 995 | func (options *DeviceFlowGroupList) Execute(args []string) error { |
| 996 | grp := &GroupList{} |
| 997 | grp.ListOutputOptions = options.ListOutputOptions |
| 998 | grp.GroupListOptions = options.GroupListOptions |
| 999 | grp.Args.Id = string(options.Args.Id) |
| 1000 | grp.Method = "device-groups" |
| 1001 | return grp.Execute(args) |
| 1002 | } |
| 1003 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1004 | func (options *DeviceInspect) Execute(args []string) error { |
| 1005 | if len(args) > 0 { |
| 1006 | return fmt.Errorf("only a single argument 'DEVICE_ID' can be provided") |
| 1007 | } |
| 1008 | |
| 1009 | conn, err := NewConnection() |
| 1010 | if err != nil { |
| 1011 | return err |
| 1012 | } |
| 1013 | defer conn.Close() |
| 1014 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1015 | client := voltha.NewVolthaServiceClient(conn) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1016 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1017 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1018 | defer cancel() |
| 1019 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1020 | id := voltha.ID{Id: string(options.Args.Id)} |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1021 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1022 | device, err := client.GetDevice(ctx, &id) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1023 | if err != nil { |
| 1024 | return err |
| 1025 | } |
| 1026 | |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1027 | outputFormat := CharReplacer.Replace(options.Format) |
| 1028 | if outputFormat == "" { |
David Bainbridge | a672234 | 2019-10-24 23:55:53 +0000 | [diff] [blame] | 1029 | outputFormat = GetCommandOptionWithDefault("device-inspect", "format", DEFAULT_DEVICE_INSPECT_FORMAT) |
Zack Williams | e940c7a | 2019-08-21 14:25:39 -0700 | [diff] [blame] | 1030 | } |
| 1031 | if options.Quiet { |
| 1032 | outputFormat = "{{.Id}}" |
| 1033 | } |
| 1034 | |
| 1035 | result := CommandResult{ |
| 1036 | Format: format.Format(outputFormat), |
| 1037 | OutputAs: toOutputType(options.OutputAs), |
| 1038 | NameLimit: options.NameLimit, |
| 1039 | Data: device, |
| 1040 | } |
| 1041 | GenerateOutput(&result) |
| 1042 | return nil |
| 1043 | } |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1044 | |
| 1045 | /*Device Port Enable */ |
| 1046 | func (options *DevicePortEnable) Execute(args []string) error { |
| 1047 | conn, err := NewConnection() |
| 1048 | if err != nil { |
| 1049 | return err |
| 1050 | } |
| 1051 | defer conn.Close() |
| 1052 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1053 | client := voltha.NewVolthaServiceClient(conn) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1054 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1055 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1056 | defer cancel() |
| 1057 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1058 | port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)} |
| 1059 | |
| 1060 | _, err = client.EnablePort(ctx, &port) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1061 | if err != nil { |
| 1062 | Error.Printf("Error enabling port number %v on device Id %s,err=%s\n", options.Args.PortId, options.Args.Id, ErrorToString(err)) |
| 1063 | return err |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | return nil |
| 1067 | } |
| 1068 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1069 | /*Device Port Disable */ |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1070 | func (options *DevicePortDisable) Execute(args []string) error { |
| 1071 | conn, err := NewConnection() |
| 1072 | if err != nil { |
| 1073 | return err |
| 1074 | } |
| 1075 | defer conn.Close() |
| 1076 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1077 | client := voltha.NewVolthaServiceClient(conn) |
| 1078 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1079 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1080 | defer cancel() |
| 1081 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1082 | port := voltha.Port{DeviceId: string(options.Args.Id), PortNo: uint32(options.Args.PortId)} |
| 1083 | |
| 1084 | _, err = client.DisablePort(ctx, &port) |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1085 | if err != nil { |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1086 | 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] | 1087 | return err |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1088 | } |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 1089 | |
kesavand | 12cd8eb | 2020-01-20 22:25:22 -0500 | [diff] [blame] | 1090 | return nil |
| 1091 | } |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 1092 | |
Rohan Agrawal | d7df377 | 2020-06-29 11:23:36 +0000 | [diff] [blame] | 1093 | func (options *DevicePmConfigSetMaxSkew) Execute(args []string) error { |
| 1094 | conn, err := NewConnection() |
| 1095 | if err != nil { |
| 1096 | return err |
| 1097 | } |
| 1098 | defer conn.Close() |
| 1099 | |
| 1100 | client := voltha.NewVolthaServiceClient(conn) |
| 1101 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1102 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | d7df377 | 2020-06-29 11:23:36 +0000 | [diff] [blame] | 1103 | defer cancel() |
| 1104 | |
| 1105 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1106 | |
| 1107 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1108 | if err != nil { |
| 1109 | return err |
| 1110 | } |
| 1111 | |
| 1112 | pmConfigs.MaxSkew = options.Args.MaxSkew |
| 1113 | |
| 1114 | _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1115 | if err != nil { |
| 1116 | return err |
| 1117 | } |
| 1118 | |
| 1119 | return nil |
| 1120 | } |
| 1121 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1122 | func (options *DevicePmConfigsGet) Execute(args []string) error { |
| 1123 | |
| 1124 | conn, err := NewConnection() |
| 1125 | if err != nil { |
| 1126 | return err |
| 1127 | } |
| 1128 | defer conn.Close() |
| 1129 | |
| 1130 | client := voltha.NewVolthaServiceClient(conn) |
| 1131 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1132 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1133 | defer cancel() |
| 1134 | |
| 1135 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1136 | |
| 1137 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1138 | if err != nil { |
| 1139 | return err |
| 1140 | } |
| 1141 | |
| 1142 | outputFormat := CharReplacer.Replace(options.Format) |
| 1143 | if outputFormat == "" { |
| 1144 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT) |
| 1145 | } |
| 1146 | |
| 1147 | orderBy := options.OrderBy |
| 1148 | if orderBy == "" { |
| 1149 | orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "") |
| 1150 | } |
| 1151 | |
| 1152 | result := CommandResult{ |
| 1153 | Format: format.Format(outputFormat), |
| 1154 | Filter: options.Filter, |
| 1155 | OrderBy: orderBy, |
| 1156 | OutputAs: toOutputType(options.OutputAs), |
| 1157 | NameLimit: options.NameLimit, |
| 1158 | Data: pmConfigs, |
| 1159 | } |
| 1160 | |
| 1161 | GenerateOutput(&result) |
| 1162 | return nil |
| 1163 | |
| 1164 | } |
| 1165 | |
| 1166 | func (options *DevicePmConfigMetricList) Execute(args []string) error { |
| 1167 | |
| 1168 | conn, err := NewConnection() |
| 1169 | if err != nil { |
| 1170 | return err |
| 1171 | } |
| 1172 | defer conn.Close() |
| 1173 | |
| 1174 | client := voltha.NewVolthaServiceClient(conn) |
| 1175 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1176 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1177 | defer cancel() |
| 1178 | |
| 1179 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1180 | |
| 1181 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1182 | if err != nil { |
| 1183 | return err |
| 1184 | } |
| 1185 | |
| 1186 | if !pmConfigs.Grouped { |
| 1187 | for _, metric := range pmConfigs.Metrics { |
| 1188 | if metric.SampleFreq == 0 { |
| 1189 | metric.SampleFreq = pmConfigs.DefaultFreq |
| 1190 | } |
| 1191 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1192 | outputFormat := CharReplacer.Replace(options.Format) |
| 1193 | if outputFormat == "" { |
| 1194 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT) |
| 1195 | } |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1196 | |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1197 | orderBy := options.OrderBy |
| 1198 | if orderBy == "" { |
| 1199 | orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "") |
| 1200 | } |
| 1201 | |
| 1202 | result := CommandResult{ |
| 1203 | Format: format.Format(outputFormat), |
| 1204 | Filter: options.Filter, |
| 1205 | OrderBy: orderBy, |
| 1206 | OutputAs: toOutputType(options.OutputAs), |
| 1207 | NameLimit: options.NameLimit, |
| 1208 | Data: pmConfigs.Metrics, |
| 1209 | } |
| 1210 | |
| 1211 | GenerateOutput(&result) |
| 1212 | return nil |
| 1213 | } else { |
| 1214 | 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] | 1215 | } |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | func (options *DevicePmConfigMetricEnable) Execute(args []string) error { |
| 1219 | |
| 1220 | conn, err := NewConnection() |
| 1221 | if err != nil { |
| 1222 | return err |
| 1223 | } |
| 1224 | defer conn.Close() |
| 1225 | |
| 1226 | client := voltha.NewVolthaServiceClient(conn) |
| 1227 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1228 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1229 | defer cancel() |
| 1230 | |
| 1231 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1232 | |
| 1233 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1234 | if err != nil { |
| 1235 | return err |
| 1236 | } |
| 1237 | |
| 1238 | if !pmConfigs.Grouped { |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1239 | metrics := make(map[string]struct{}) |
| 1240 | for _, metric := range pmConfigs.Metrics { |
| 1241 | metrics[metric.Name] = struct{}{} |
| 1242 | } |
| 1243 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1244 | for _, metric := range pmConfigs.Metrics { |
| 1245 | for _, mName := range options.Args.Metrics { |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1246 | if _, exist := metrics[string(mName)]; !exist { |
| 1247 | return fmt.Errorf("Metric Name '%s' does not exist", mName) |
| 1248 | } |
| 1249 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1250 | if string(mName) == metric.Name && !metric.Enabled { |
| 1251 | metric.Enabled = true |
| 1252 | _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1253 | if err != nil { |
| 1254 | return err |
| 1255 | } |
| 1256 | } |
| 1257 | } |
| 1258 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1259 | } else { |
| 1260 | 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] | 1261 | } |
| 1262 | return nil |
| 1263 | } |
| 1264 | |
| 1265 | func (options *DevicePmConfigMetricDisable) Execute(args []string) error { |
| 1266 | |
| 1267 | conn, err := NewConnection() |
| 1268 | if err != nil { |
| 1269 | return err |
| 1270 | } |
| 1271 | defer conn.Close() |
| 1272 | |
| 1273 | client := voltha.NewVolthaServiceClient(conn) |
| 1274 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1275 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1276 | defer cancel() |
| 1277 | |
| 1278 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1279 | |
| 1280 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1281 | if err != nil { |
| 1282 | return err |
| 1283 | } |
| 1284 | |
| 1285 | if !pmConfigs.Grouped { |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1286 | metrics := make(map[string]struct{}) |
| 1287 | for _, metric := range pmConfigs.Metrics { |
| 1288 | metrics[metric.Name] = struct{}{} |
| 1289 | } |
| 1290 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1291 | for _, metric := range pmConfigs.Metrics { |
| 1292 | for _, mName := range options.Args.Metrics { |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1293 | if _, have := metrics[string(mName)]; !have { |
| 1294 | return fmt.Errorf("Metric Name '%s' does not exist", mName) |
| 1295 | } |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1296 | if string(mName) == metric.Name && metric.Enabled { |
| 1297 | metric.Enabled = false |
| 1298 | _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1299 | if err != nil { |
| 1300 | return err |
| 1301 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1302 | } else { |
| 1303 | return fmt.Errorf("Metric '%s' cannot be disabled", string(mName)) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1304 | } |
| 1305 | } |
| 1306 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1307 | } else { |
| 1308 | 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] | 1309 | } |
| 1310 | return nil |
| 1311 | } |
| 1312 | |
| 1313 | func (options *DevicePmConfigGroupEnable) Execute(args []string) error { |
| 1314 | |
| 1315 | conn, err := NewConnection() |
| 1316 | if err != nil { |
| 1317 | return err |
| 1318 | } |
| 1319 | defer conn.Close() |
| 1320 | |
| 1321 | client := voltha.NewVolthaServiceClient(conn) |
| 1322 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1323 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1324 | defer cancel() |
| 1325 | |
| 1326 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1327 | |
| 1328 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1329 | if err != nil { |
| 1330 | return err |
| 1331 | } |
| 1332 | |
| 1333 | if pmConfigs.Grouped { |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1334 | groups := make(map[string]struct{}) |
| 1335 | for _, group := range pmConfigs.Groups { |
| 1336 | groups[group.GroupName] = struct{}{} |
| 1337 | } |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1338 | for _, group := range pmConfigs.Groups { |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1339 | if _, have := groups[string(options.Args.Group)]; !have { |
| 1340 | return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group) |
| 1341 | } |
| 1342 | if string(options.Args.Group) == group.GroupName && !group.Enabled { |
| 1343 | group.Enabled = true |
| 1344 | _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1345 | if err != nil { |
| 1346 | return err |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1347 | } |
| 1348 | } |
| 1349 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1350 | } else { |
| 1351 | 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] | 1352 | } |
| 1353 | return nil |
| 1354 | } |
| 1355 | |
| 1356 | func (options *DevicePmConfigGroupDisable) Execute(args []string) error { |
| 1357 | |
| 1358 | conn, err := NewConnection() |
| 1359 | if err != nil { |
| 1360 | return err |
| 1361 | } |
| 1362 | defer conn.Close() |
| 1363 | |
| 1364 | client := voltha.NewVolthaServiceClient(conn) |
| 1365 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1366 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1367 | defer cancel() |
| 1368 | |
| 1369 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1370 | |
| 1371 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1372 | if err != nil { |
| 1373 | return err |
| 1374 | } |
| 1375 | |
| 1376 | if pmConfigs.Grouped { |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1377 | groups := make(map[string]struct{}) |
| 1378 | for _, group := range pmConfigs.Groups { |
| 1379 | groups[group.GroupName] = struct{}{} |
| 1380 | } |
| 1381 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1382 | for _, group := range pmConfigs.Groups { |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1383 | if _, have := groups[string(options.Args.Group)]; !have { |
| 1384 | return fmt.Errorf("Group Name '%s' does not exist", options.Args.Group) |
| 1385 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1386 | |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1387 | if string(options.Args.Group) == group.GroupName && group.Enabled { |
| 1388 | group.Enabled = false |
| 1389 | _, err := client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1390 | if err != nil { |
| 1391 | return err |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1392 | } |
| 1393 | } |
| 1394 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1395 | } else { |
| 1396 | 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] | 1397 | } |
| 1398 | return nil |
| 1399 | } |
| 1400 | |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1401 | func (options *DevicePmConfigGroupFrequencySet) Execute(args []string) error { |
| 1402 | |
| 1403 | conn, err := NewConnection() |
| 1404 | if err != nil { |
| 1405 | return err |
| 1406 | } |
| 1407 | defer conn.Close() |
| 1408 | |
| 1409 | client := voltha.NewVolthaServiceClient(conn) |
| 1410 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1411 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1412 | defer cancel() |
| 1413 | |
| 1414 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1415 | |
| 1416 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1417 | if err != nil { |
| 1418 | return err |
| 1419 | } |
| 1420 | |
| 1421 | if pmConfigs.Grouped { |
| 1422 | groups := make(map[string]struct{}) |
| 1423 | for _, group := range pmConfigs.Groups { |
| 1424 | groups[group.GroupName] = struct{}{} |
| 1425 | } |
| 1426 | |
| 1427 | for _, group := range pmConfigs.Groups { |
| 1428 | if _, have := groups[string(options.Args.Group)]; !have { |
| 1429 | return fmt.Errorf("group name '%s' does not exist", options.Args.Group) |
| 1430 | } |
| 1431 | |
| 1432 | if string(options.Args.Group) == group.GroupName { |
| 1433 | if !group.Enabled { |
| 1434 | return fmt.Errorf("group '%s' is not enabled", options.Args.Group) |
| 1435 | } |
| 1436 | group.GroupFreq = uint32(options.Args.Interval.Seconds()) |
| 1437 | _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1438 | if err != nil { |
| 1439 | return err |
| 1440 | } |
| 1441 | } |
| 1442 | } |
| 1443 | } else { |
| 1444 | return fmt.Errorf("device '%s' does not have group metrics", options.Args.Id) |
| 1445 | } |
| 1446 | return nil |
| 1447 | } |
| 1448 | |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1449 | func (options *DevicePmConfigGroupList) Execute(args []string) error { |
| 1450 | |
| 1451 | conn, err := NewConnection() |
| 1452 | if err != nil { |
| 1453 | return err |
| 1454 | } |
| 1455 | defer conn.Close() |
| 1456 | |
| 1457 | client := voltha.NewVolthaServiceClient(conn) |
| 1458 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1459 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1460 | defer cancel() |
| 1461 | |
| 1462 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1463 | |
| 1464 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1465 | if err != nil { |
| 1466 | return err |
| 1467 | } |
| 1468 | |
| 1469 | if pmConfigs.Grouped { |
| 1470 | for _, group := range pmConfigs.Groups { |
| 1471 | if group.GroupFreq == 0 { |
| 1472 | group.GroupFreq = pmConfigs.DefaultFreq |
| 1473 | } |
| 1474 | } |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1475 | outputFormat := CharReplacer.Replace(options.Format) |
| 1476 | if outputFormat == "" { |
| 1477 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GROUP_LIST_FORMAT) |
| 1478 | } |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1479 | |
Rohan Agrawal | bca6912 | 2020-06-17 14:59:03 +0000 | [diff] [blame] | 1480 | orderBy := options.OrderBy |
| 1481 | if orderBy == "" { |
| 1482 | orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "") |
| 1483 | } |
| 1484 | |
| 1485 | result := CommandResult{ |
| 1486 | Format: format.Format(outputFormat), |
| 1487 | Filter: options.Filter, |
| 1488 | OrderBy: orderBy, |
| 1489 | OutputAs: toOutputType(options.OutputAs), |
| 1490 | NameLimit: options.NameLimit, |
| 1491 | Data: pmConfigs.Groups, |
| 1492 | } |
| 1493 | |
| 1494 | GenerateOutput(&result) |
| 1495 | } else { |
| 1496 | 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] | 1497 | } |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1498 | return nil |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | func (options *DevicePmConfigGroupMetricList) Execute(args []string) error { |
| 1502 | |
| 1503 | var metrics []*voltha.PmConfig |
| 1504 | conn, err := NewConnection() |
| 1505 | if err != nil { |
| 1506 | return err |
| 1507 | } |
| 1508 | defer conn.Close() |
| 1509 | |
| 1510 | client := voltha.NewVolthaServiceClient(conn) |
| 1511 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1512 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1513 | defer cancel() |
| 1514 | |
| 1515 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1516 | |
| 1517 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1518 | if err != nil { |
| 1519 | return err |
| 1520 | } |
| 1521 | |
| 1522 | for _, groups := range pmConfigs.Groups { |
| 1523 | |
| 1524 | if string(options.Args.Group) == groups.GroupName { |
| 1525 | for _, metric := range groups.Metrics { |
| 1526 | if metric.SampleFreq == 0 && groups.GroupFreq == 0 { |
| 1527 | metric.SampleFreq = pmConfigs.DefaultFreq |
| 1528 | } else { |
| 1529 | metric.SampleFreq = groups.GroupFreq |
| 1530 | } |
| 1531 | } |
| 1532 | metrics = groups.Metrics |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | outputFormat := CharReplacer.Replace(options.Format) |
| 1537 | if outputFormat == "" { |
| 1538 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_METRIC_LIST_FORMAT) |
| 1539 | } |
| 1540 | |
| 1541 | orderBy := options.OrderBy |
| 1542 | if orderBy == "" { |
| 1543 | orderBy = GetCommandOptionWithDefault("device-pm-configs", "order", "") |
| 1544 | } |
| 1545 | |
| 1546 | result := CommandResult{ |
| 1547 | Format: format.Format(outputFormat), |
| 1548 | Filter: options.Filter, |
| 1549 | OrderBy: orderBy, |
| 1550 | OutputAs: toOutputType(options.OutputAs), |
| 1551 | NameLimit: options.NameLimit, |
| 1552 | Data: metrics, |
| 1553 | } |
| 1554 | |
| 1555 | GenerateOutput(&result) |
| 1556 | return nil |
| 1557 | |
| 1558 | } |
| 1559 | |
| 1560 | func (options *DevicePmConfigFrequencySet) Execute(args []string) error { |
| 1561 | |
| 1562 | conn, err := NewConnection() |
| 1563 | if err != nil { |
| 1564 | return err |
| 1565 | } |
| 1566 | defer conn.Close() |
| 1567 | |
| 1568 | client := voltha.NewVolthaServiceClient(conn) |
| 1569 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1570 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1571 | defer cancel() |
| 1572 | |
| 1573 | id := voltha.ID{Id: string(options.Args.Id)} |
| 1574 | |
| 1575 | pmConfigs, err := client.ListDevicePmConfigs(ctx, &id) |
| 1576 | if err != nil { |
| 1577 | return err |
| 1578 | } |
| 1579 | |
Girish Gowdra | 610acb4 | 2021-01-27 13:33:57 -0800 | [diff] [blame] | 1580 | pmConfigs.DefaultFreq = uint32(options.Args.Interval.Seconds()) |
Rohan Agrawal | 9228d2f | 2020-06-03 07:48:50 +0000 | [diff] [blame] | 1581 | |
| 1582 | _, err = client.UpdateDevicePmConfigs(ctx, pmConfigs) |
| 1583 | if err != nil { |
| 1584 | return err |
| 1585 | } |
| 1586 | |
| 1587 | outputFormat := CharReplacer.Replace(options.Format) |
| 1588 | if outputFormat == "" { |
| 1589 | outputFormat = GetCommandOptionWithDefault("device-pm-configs", "format", DEFAULT_DEVICE_PM_CONFIG_GET_FORMAT) |
| 1590 | } |
| 1591 | if options.Quiet { |
| 1592 | outputFormat = "{{.Id}}" |
| 1593 | } |
| 1594 | |
| 1595 | result := CommandResult{ |
| 1596 | Format: format.Format(outputFormat), |
| 1597 | OutputAs: toOutputType(options.OutputAs), |
| 1598 | NameLimit: options.NameLimit, |
| 1599 | Data: pmConfigs, |
| 1600 | } |
| 1601 | |
| 1602 | GenerateOutput(&result) |
| 1603 | return nil |
| 1604 | |
| 1605 | } |
| 1606 | |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1607 | func (options *OnuDownloadImage) Execute(args []string) error { |
| 1608 | |
| 1609 | conn, err := NewConnection() |
| 1610 | if err != nil { |
| 1611 | return err |
| 1612 | } |
| 1613 | defer conn.Close() |
| 1614 | |
| 1615 | client := voltha.NewVolthaServiceClient(conn) |
| 1616 | |
| 1617 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1618 | defer cancel() |
| 1619 | |
| 1620 | var devIDList []*common.ID |
| 1621 | for _, i := range options.Args.IDs { |
| 1622 | |
| 1623 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1624 | } |
| 1625 | |
| 1626 | downloadImage := voltha.DeviceImageDownloadRequest{ |
| 1627 | DeviceId: devIDList, |
| 1628 | Image: &voltha.Image{ |
| 1629 | Url: options.Args.Url, |
| 1630 | Crc32: options.Args.Crc, |
ssiddiqui | 7bc89e9 | 2021-05-20 20:58:02 +0530 | [diff] [blame] | 1631 | Vendor: options.Args.Vendor, |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1632 | Version: options.Args.ImageVersion, |
| 1633 | }, |
| 1634 | ActivateOnSuccess: options.Args.ActivateOnSuccess, |
| 1635 | CommitOnSuccess: options.Args.CommitOnSuccess, |
| 1636 | } |
| 1637 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1638 | deviceImageResp, err := client.DownloadImageToDevice(ctx, &downloadImage) |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1639 | if err != nil { |
| 1640 | return err |
| 1641 | } |
| 1642 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1643 | outputFormat := GetCommandOptionWithDefault("onu-image-download", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1644 | // Make sure json output prints an empty list, not "null" |
| 1645 | if deviceImageResp.DeviceImageStates == nil { |
| 1646 | deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1647 | } |
| 1648 | result := CommandResult{ |
| 1649 | Format: format.Format(outputFormat), |
| 1650 | OutputAs: toOutputType(options.OutputAs), |
| 1651 | NameLimit: options.NameLimit, |
| 1652 | Data: deviceImageResp.DeviceImageStates, |
| 1653 | } |
| 1654 | GenerateOutput(&result) |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1655 | return nil |
| 1656 | |
| 1657 | } |
| 1658 | |
| 1659 | func (options *OnuActivateImage) Execute(args []string) error { |
| 1660 | |
| 1661 | conn, err := NewConnection() |
| 1662 | if err != nil { |
| 1663 | return err |
| 1664 | } |
| 1665 | defer conn.Close() |
| 1666 | |
| 1667 | client := voltha.NewVolthaServiceClient(conn) |
| 1668 | |
| 1669 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1670 | defer cancel() |
| 1671 | |
| 1672 | var devIDList []*common.ID |
| 1673 | for _, i := range options.Args.IDs { |
| 1674 | |
| 1675 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1676 | } |
| 1677 | |
| 1678 | downloadImage := voltha.DeviceImageRequest{ |
| 1679 | DeviceId: devIDList, |
| 1680 | Version: options.Args.ImageVersion, |
| 1681 | CommitOnSuccess: options.Args.CommitOnSuccess, |
| 1682 | } |
| 1683 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1684 | deviceImageResp, err := client.ActivateImage(ctx, &downloadImage) |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1685 | if err != nil { |
| 1686 | return err |
| 1687 | } |
| 1688 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1689 | outputFormat := GetCommandOptionWithDefault("onu-image-activate", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1690 | // Make sure json output prints an empty list, not "null" |
| 1691 | if deviceImageResp.DeviceImageStates == nil { |
| 1692 | deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1693 | } |
| 1694 | result := CommandResult{ |
| 1695 | Format: format.Format(outputFormat), |
| 1696 | OutputAs: toOutputType(options.OutputAs), |
| 1697 | NameLimit: options.NameLimit, |
| 1698 | Data: deviceImageResp.DeviceImageStates, |
| 1699 | } |
| 1700 | GenerateOutput(&result) |
| 1701 | |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1702 | return nil |
| 1703 | |
| 1704 | } |
| 1705 | |
| 1706 | func (options *OnuAbortUpgradeImage) Execute(args []string) error { |
| 1707 | |
| 1708 | conn, err := NewConnection() |
| 1709 | if err != nil { |
| 1710 | return err |
| 1711 | } |
| 1712 | defer conn.Close() |
| 1713 | |
| 1714 | client := voltha.NewVolthaServiceClient(conn) |
| 1715 | |
| 1716 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1717 | defer cancel() |
| 1718 | |
| 1719 | var devIDList []*common.ID |
| 1720 | for _, i := range options.Args.IDs { |
| 1721 | |
| 1722 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1723 | } |
| 1724 | |
| 1725 | downloadImage := voltha.DeviceImageRequest{ |
| 1726 | DeviceId: devIDList, |
| 1727 | Version: options.Args.ImageVersion, |
| 1728 | } |
| 1729 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1730 | deviceImageResp, err := client.AbortImageUpgradeToDevice(ctx, &downloadImage) |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1731 | if err != nil { |
| 1732 | return err |
| 1733 | } |
| 1734 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1735 | outputFormat := GetCommandOptionWithDefault("onu-image-abort", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1736 | // Make sure json output prints an empty list, not "null" |
| 1737 | if deviceImageResp.DeviceImageStates == nil { |
| 1738 | deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1739 | } |
| 1740 | result := CommandResult{ |
| 1741 | Format: format.Format(outputFormat), |
| 1742 | OutputAs: toOutputType(options.OutputAs), |
| 1743 | NameLimit: options.NameLimit, |
| 1744 | Data: deviceImageResp.DeviceImageStates, |
| 1745 | } |
| 1746 | GenerateOutput(&result) |
| 1747 | |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1748 | return nil |
| 1749 | |
| 1750 | } |
| 1751 | |
| 1752 | func (options *OnuCommitImage) Execute(args []string) error { |
| 1753 | |
| 1754 | conn, err := NewConnection() |
| 1755 | if err != nil { |
| 1756 | return err |
| 1757 | } |
| 1758 | defer conn.Close() |
| 1759 | |
| 1760 | client := voltha.NewVolthaServiceClient(conn) |
| 1761 | |
| 1762 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1763 | defer cancel() |
| 1764 | |
| 1765 | var devIDList []*common.ID |
| 1766 | for _, i := range options.Args.IDs { |
| 1767 | |
| 1768 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1769 | } |
| 1770 | downloadImage := voltha.DeviceImageRequest{ |
| 1771 | DeviceId: devIDList, |
| 1772 | Version: options.Args.ImageVersion, |
| 1773 | } |
| 1774 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1775 | deviceImageResp, err := client.CommitImage(ctx, &downloadImage) |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1776 | if err != nil { |
| 1777 | return err |
| 1778 | } |
| 1779 | |
Andrea Campanella | eaf1e0c | 2021-06-07 14:41:34 +0200 | [diff] [blame] | 1780 | outputFormat := GetCommandOptionWithDefault("onu-image-commit", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1781 | // Make sure json output prints an empty list, not "null" |
| 1782 | if deviceImageResp.DeviceImageStates == nil { |
| 1783 | deviceImageResp.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1784 | } |
| 1785 | result := CommandResult{ |
| 1786 | Format: format.Format(outputFormat), |
| 1787 | OutputAs: toOutputType(options.OutputAs), |
| 1788 | NameLimit: options.NameLimit, |
| 1789 | Data: deviceImageResp.DeviceImageStates, |
| 1790 | } |
| 1791 | GenerateOutput(&result) |
| 1792 | |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1793 | return nil |
| 1794 | |
| 1795 | } |
| 1796 | |
| 1797 | func (options *OnuListImages) Execute(args []string) error { |
| 1798 | |
| 1799 | conn, err := NewConnection() |
| 1800 | if err != nil { |
| 1801 | return err |
| 1802 | } |
| 1803 | defer conn.Close() |
| 1804 | |
| 1805 | client := voltha.NewVolthaServiceClient(conn) |
| 1806 | |
| 1807 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1808 | defer cancel() |
| 1809 | |
| 1810 | id := common.ID{Id: string(options.Args.Id)} |
| 1811 | |
| 1812 | onuImages, err := client.GetOnuImages(ctx, &id) |
| 1813 | if err != nil { |
| 1814 | return err |
| 1815 | } |
| 1816 | |
| 1817 | outputFormat := CharReplacer.Replace(options.Format) |
| 1818 | if outputFormat == "" { |
| 1819 | outputFormat = GetCommandOptionWithDefault("onu-image-list", "format", ONU_IMAGE_LIST_FORMAT) |
| 1820 | } |
| 1821 | |
| 1822 | if options.Quiet { |
| 1823 | outputFormat = "{{.Id}}" |
| 1824 | } |
| 1825 | |
| 1826 | //TODO orderby |
| 1827 | |
| 1828 | // Make sure json output prints an empty list, not "null" |
| 1829 | if onuImages.Items == nil { |
| 1830 | onuImages.Items = make([]*voltha.OnuImage, 0) |
| 1831 | } |
| 1832 | |
| 1833 | result := CommandResult{ |
| 1834 | Format: format.Format(outputFormat), |
| 1835 | OutputAs: toOutputType(options.OutputAs), |
| 1836 | NameLimit: options.NameLimit, |
| 1837 | Data: onuImages.Items, |
| 1838 | } |
| 1839 | |
| 1840 | GenerateOutput(&result) |
| 1841 | return nil |
| 1842 | |
| 1843 | } |
| 1844 | |
| 1845 | func (options *OnuImageStatus) Execute(args []string) error { |
| 1846 | |
| 1847 | conn, err := NewConnection() |
| 1848 | if err != nil { |
| 1849 | return err |
| 1850 | } |
| 1851 | defer conn.Close() |
| 1852 | |
| 1853 | client := voltha.NewVolthaServiceClient(conn) |
| 1854 | |
| 1855 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 1856 | defer cancel() |
| 1857 | |
| 1858 | var devIDList []*common.ID |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1859 | |
Elia Battiston | 859f3e6 | 2022-02-08 15:57:52 +0100 | [diff] [blame] | 1860 | if options.Args.IDs == nil { |
| 1861 | //Use an empty IDs list to retrieve the status of all devices |
| 1862 | //with the requested image version |
| 1863 | devIDList = []*common.ID{} |
| 1864 | } else { |
| 1865 | for _, i := range options.Args.IDs { |
| 1866 | devIDList = append(devIDList, &common.ID{Id: string(i)}) |
| 1867 | } |
kesavand | 3e2f9f6 | 2021-04-22 11:06:38 +0530 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | imageStatusReq := voltha.DeviceImageRequest{ |
| 1871 | DeviceId: devIDList, |
| 1872 | Version: options.Args.ImageVersion, |
| 1873 | } |
| 1874 | imageStatus, err := client.GetImageStatus(ctx, &imageStatusReq) |
| 1875 | if err != nil { |
| 1876 | return err |
| 1877 | } |
| 1878 | |
| 1879 | outputFormat := CharReplacer.Replace(options.Format) |
| 1880 | if outputFormat == "" { |
| 1881 | outputFormat = GetCommandOptionWithDefault("device-image-list", "format", ONU_IMAGE_STATUS_FORMAT) |
| 1882 | } |
| 1883 | |
| 1884 | if options.Quiet { |
| 1885 | outputFormat = "{{.Id}}" |
| 1886 | } |
| 1887 | |
| 1888 | //TODO orderby |
| 1889 | |
| 1890 | // Make sure json output prints an empty list, not "null" |
| 1891 | if imageStatus.DeviceImageStates == nil { |
| 1892 | imageStatus.DeviceImageStates = make([]*voltha.DeviceImageState, 0) |
| 1893 | } |
| 1894 | |
| 1895 | result := CommandResult{ |
| 1896 | Format: format.Format(outputFormat), |
| 1897 | OutputAs: toOutputType(options.OutputAs), |
| 1898 | NameLimit: options.NameLimit, |
| 1899 | Data: imageStatus.DeviceImageStates, |
| 1900 | } |
| 1901 | |
| 1902 | GenerateOutput(&result) |
| 1903 | return nil |
| 1904 | |
| 1905 | } |
| 1906 | |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 1907 | func (options *DeviceOnuListImages) Execute(args []string) error { |
| 1908 | |
| 1909 | conn, err := NewConnection() |
| 1910 | if err != nil { |
| 1911 | return err |
| 1912 | } |
| 1913 | defer conn.Close() |
| 1914 | |
| 1915 | client := voltha.NewVolthaServiceClient(conn) |
| 1916 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1917 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 1918 | defer cancel() |
| 1919 | |
| 1920 | id := common.ID{Id: string(options.Args.Id)} |
| 1921 | |
| 1922 | imageDownloads, err := client.ListImageDownloads(ctx, &id) |
| 1923 | if err != nil { |
| 1924 | return err |
| 1925 | } |
| 1926 | |
| 1927 | outputFormat := CharReplacer.Replace(options.Format) |
| 1928 | if outputFormat == "" { |
| 1929 | outputFormat = GetCommandOptionWithDefault("device-image-list", "format", DEFAULT_DEVICE_IMAGE_LIST_GET_FORMAT) |
| 1930 | } |
| 1931 | |
| 1932 | if options.Quiet { |
| 1933 | outputFormat = "{{.Id}}" |
| 1934 | } |
| 1935 | |
| 1936 | //TODO orderby |
| 1937 | |
| 1938 | // Make sure json output prints an empty list, not "null" |
| 1939 | if imageDownloads.Items == nil { |
| 1940 | imageDownloads.Items = make([]*voltha.ImageDownload, 0) |
| 1941 | } |
| 1942 | |
| 1943 | result := CommandResult{ |
| 1944 | Format: format.Format(outputFormat), |
| 1945 | OutputAs: toOutputType(options.OutputAs), |
| 1946 | NameLimit: options.NameLimit, |
| 1947 | Data: imageDownloads.Items, |
| 1948 | } |
| 1949 | |
| 1950 | GenerateOutput(&result) |
| 1951 | return nil |
| 1952 | |
| 1953 | } |
| 1954 | |
| 1955 | func (options *DeviceOnuDownloadImage) Execute(args []string) error { |
| 1956 | |
| 1957 | conn, err := NewConnection() |
| 1958 | if err != nil { |
| 1959 | return err |
| 1960 | } |
| 1961 | defer conn.Close() |
| 1962 | |
| 1963 | client := voltha.NewVolthaServiceClient(conn) |
| 1964 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1965 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 1966 | defer cancel() |
| 1967 | |
| 1968 | downloadImage := voltha.ImageDownload{ |
| 1969 | Id: string(options.Args.Id), |
| 1970 | Name: options.Args.Name, |
| 1971 | Url: options.Args.Url, |
| 1972 | Crc: options.Args.Crc, |
| 1973 | LocalDir: options.Args.LocalDir, |
| 1974 | } |
| 1975 | |
| 1976 | _, err = client.DownloadImage(ctx, &downloadImage) |
| 1977 | if err != nil { |
| 1978 | return err |
| 1979 | } |
| 1980 | |
| 1981 | return nil |
| 1982 | |
| 1983 | } |
| 1984 | |
| 1985 | func (options *DeviceOnuActivateImageUpdate) Execute(args []string) error { |
| 1986 | |
| 1987 | conn, err := NewConnection() |
| 1988 | if err != nil { |
| 1989 | return err |
| 1990 | } |
| 1991 | defer conn.Close() |
| 1992 | |
| 1993 | client := voltha.NewVolthaServiceClient(conn) |
| 1994 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 1995 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Andrea Campanella | 791d88b | 2021-01-08 13:29:00 +0100 | [diff] [blame] | 1996 | defer cancel() |
| 1997 | |
| 1998 | downloadImage := voltha.ImageDownload{ |
| 1999 | Id: string(options.Args.Id), |
| 2000 | Name: options.Args.Name, |
| 2001 | ImageVersion: options.Args.ImageVersion, |
| 2002 | SaveConfig: options.Args.SaveConfig, |
| 2003 | LocalDir: options.Args.LocalDir, |
| 2004 | } |
| 2005 | |
| 2006 | _, err = client.ActivateImageUpdate(ctx, &downloadImage) |
| 2007 | if err != nil { |
| 2008 | return err |
| 2009 | } |
| 2010 | |
| 2011 | return nil |
| 2012 | |
| 2013 | } |
| 2014 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2015 | type ReturnValueRow struct { |
| 2016 | Name string `json:"name"` |
| 2017 | Result interface{} `json:"result"` |
| 2018 | } |
| 2019 | |
kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 2020 | func (options *DeviceGetPortStats) Execute(args []string) error { |
| 2021 | conn, err := NewConnection() |
| 2022 | if err != nil { |
| 2023 | return err |
| 2024 | } |
| 2025 | defer conn.Close() |
| 2026 | client := extension.NewExtensionClient(conn) |
| 2027 | var portType extension.GetOltPortCounters_PortType |
| 2028 | |
| 2029 | if options.Args.PortType == "pon" { |
| 2030 | portType = extension.GetOltPortCounters_Port_PON_OLT |
| 2031 | } else if options.Args.PortType == "nni" { |
| 2032 | |
| 2033 | portType = extension.GetOltPortCounters_Port_ETHERNET_NNI |
| 2034 | } else { |
| 2035 | return fmt.Errorf("expected interface type pon/nni, provided %s", options.Args.PortType) |
| 2036 | } |
| 2037 | |
| 2038 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2039 | TargetId: string(options.Args.Id), |
| 2040 | Request: &extension.GetValueRequest{ |
| 2041 | Request: &extension.GetValueRequest_OltPortInfo{ |
| 2042 | OltPortInfo: &extension.GetOltPortCounters{ |
| 2043 | PortNo: options.Args.PortNo, |
| 2044 | PortType: portType, |
| 2045 | }, |
| 2046 | }, |
| 2047 | }, |
| 2048 | } |
| 2049 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2050 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
kesavand | 8ec4fc0 | 2021-01-27 09:10:22 -0500 | [diff] [blame] | 2051 | defer cancel() |
| 2052 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2053 | if err != nil { |
| 2054 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2055 | return err |
| 2056 | } |
| 2057 | |
| 2058 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2059 | return fmt.Errorf("failed to get port stats %v", rv.Response.ErrReason.String()) |
| 2060 | } |
| 2061 | |
| 2062 | outputFormat := CharReplacer.Replace(options.Format) |
| 2063 | if outputFormat == "" { |
| 2064 | outputFormat = GetCommandOptionWithDefault("device-get-port-status", "format", DEFAULT_DEVICE_GET_PORT_STATUS_FORMAT) |
| 2065 | } |
| 2066 | |
| 2067 | result := CommandResult{ |
| 2068 | Format: format.Format(outputFormat), |
| 2069 | OutputAs: toOutputType(options.OutputAs), |
| 2070 | NameLimit: options.NameLimit, |
| 2071 | Data: rv.GetResponse().GetPortCoutners(), |
| 2072 | } |
| 2073 | GenerateOutput(&result) |
| 2074 | return nil |
| 2075 | } |
| 2076 | |
Himani Chawla | 40acc12 | 2021-05-26 18:52:29 +0530 | [diff] [blame] | 2077 | func (options *GetOnuStats) Execute(args []string) error { |
| 2078 | conn, err := NewConnection() |
| 2079 | if err != nil { |
| 2080 | return err |
| 2081 | } |
| 2082 | defer conn.Close() |
| 2083 | client := extension.NewExtensionClient(conn) |
| 2084 | |
| 2085 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2086 | TargetId: string(options.Args.OltId), |
| 2087 | Request: &extension.GetValueRequest{ |
| 2088 | Request: &extension.GetValueRequest_OnuPonInfo{ |
| 2089 | OnuPonInfo: &extension.GetOnuCountersRequest{ |
| 2090 | IntfId: options.Args.IntfId, |
| 2091 | OnuId: options.Args.OnuId, |
| 2092 | }, |
| 2093 | }, |
| 2094 | }, |
| 2095 | } |
| 2096 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2097 | defer cancel() |
| 2098 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2099 | if err != nil { |
| 2100 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.OltId, ErrorToString(err)) |
| 2101 | return err |
| 2102 | } |
| 2103 | |
| 2104 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2105 | return fmt.Errorf("failed to get onu stats %v", rv.Response.ErrReason.String()) |
| 2106 | } |
| 2107 | outputFormat := CharReplacer.Replace(options.Format) |
| 2108 | data, formatStr := buildOnuStatsOutputFormat(rv.GetResponse().GetOnuPonCounters()) |
| 2109 | if outputFormat == "" { |
| 2110 | outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", formatStr) |
| 2111 | } |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2112 | result := CommandResult{ |
| 2113 | Format: format.Format(outputFormat), |
| 2114 | OutputAs: toOutputType(options.OutputAs), |
| 2115 | NameLimit: options.NameLimit, |
| 2116 | Data: data, |
| 2117 | } |
| 2118 | GenerateOutput(&result) |
| 2119 | return nil |
| 2120 | } |
Himani Chawla | 40acc12 | 2021-05-26 18:52:29 +0530 | [diff] [blame] | 2121 | |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2122 | func (options *GetOnuEthernetFrameExtendedPmCounters) Execute(args []string) error { |
| 2123 | conn, err := NewConnection() |
| 2124 | if err != nil { |
| 2125 | return err |
| 2126 | } |
| 2127 | defer conn.Close() |
| 2128 | client := extension.NewExtensionClient(conn) |
Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 2129 | var singleGetValReq extension.SingleGetValueRequest |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2130 | |
Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 2131 | if options.Args.UniIndex != nil { |
| 2132 | singleGetValReq = extension.SingleGetValueRequest{ |
| 2133 | TargetId: string(options.Args.Id), |
| 2134 | Request: &extension.GetValueRequest{ |
| 2135 | Request: &extension.GetValueRequest_OnuInfo{ |
| 2136 | OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{ |
| 2137 | OnuDeviceId: string(options.Args.Id), |
| 2138 | Reset_: options.Reset, |
| 2139 | IsUniIndex: &extension.GetOmciEthernetFrameExtendedPmRequest_UniIndex{ |
| 2140 | UniIndex: *options.Args.UniIndex, |
| 2141 | }, |
| 2142 | }, |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2143 | }, |
| 2144 | }, |
Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 2145 | } |
| 2146 | } else { |
| 2147 | singleGetValReq = extension.SingleGetValueRequest{ |
| 2148 | TargetId: string(options.Args.Id), |
| 2149 | Request: &extension.GetValueRequest{ |
| 2150 | Request: &extension.GetValueRequest_OnuInfo{ |
| 2151 | OnuInfo: &extension.GetOmciEthernetFrameExtendedPmRequest{ |
| 2152 | OnuDeviceId: string(options.Args.Id), |
| 2153 | Reset_: options.Reset, |
| 2154 | }, |
| 2155 | }, |
| 2156 | }, |
| 2157 | } |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2158 | } |
Himani Chawla | 806aa89 | 2021-08-30 15:51:46 +0530 | [diff] [blame] | 2159 | |
Himani Chawla | 553a139 | 2021-06-10 23:39:17 +0530 | [diff] [blame] | 2160 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2161 | defer cancel() |
| 2162 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2163 | if err != nil { |
| 2164 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2165 | return err |
| 2166 | } |
| 2167 | |
| 2168 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2169 | return fmt.Errorf("failed to get ethernet frame extended pm counters %v", rv.Response.ErrReason.String()) |
| 2170 | } |
| 2171 | outputFormat := CharReplacer.Replace(options.Format) |
| 2172 | data := buildOnuEthernetFrameExtendedPmOutputFormat(rv.GetResponse().GetOnuCounters()) |
| 2173 | if outputFormat == "" { |
| 2174 | outputFormat = GetCommandOptionWithDefault("device-get-onu-status", "format", DEFAULT_ETHERNET_FRAME_EXTENDED_PM_COUNTERS_FORMAT) |
| 2175 | } |
Himani Chawla | 40acc12 | 2021-05-26 18:52:29 +0530 | [diff] [blame] | 2176 | result := CommandResult{ |
| 2177 | Format: format.Format(outputFormat), |
| 2178 | OutputAs: toOutputType(options.OutputAs), |
| 2179 | NameLimit: options.NameLimit, |
| 2180 | Data: data, |
| 2181 | } |
| 2182 | GenerateOutput(&result) |
| 2183 | return nil |
| 2184 | } |
| 2185 | |
kesavand | 6d1131f | 2021-02-05 22:38:15 +0530 | [diff] [blame] | 2186 | func (options *UniStatus) Execute(args []string) error { |
| 2187 | conn, err := NewConnection() |
| 2188 | if err != nil { |
| 2189 | return err |
| 2190 | } |
| 2191 | defer conn.Close() |
| 2192 | client := extension.NewExtensionClient(conn) |
| 2193 | |
| 2194 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2195 | TargetId: string(options.Args.Id), |
| 2196 | Request: &extension.GetValueRequest{ |
| 2197 | Request: &extension.GetValueRequest_UniInfo{ |
| 2198 | UniInfo: &extension.GetOnuUniInfoRequest{ |
| 2199 | UniIndex: options.Args.UniIndex, |
| 2200 | }, |
| 2201 | }, |
| 2202 | }, |
| 2203 | } |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2204 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
kesavand | 6d1131f | 2021-02-05 22:38:15 +0530 | [diff] [blame] | 2205 | defer cancel() |
| 2206 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2207 | if err != nil { |
| 2208 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2209 | return err |
| 2210 | } |
| 2211 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2212 | return fmt.Errorf("failed to get uni status %v", rv.Response.ErrReason.String()) |
| 2213 | } |
| 2214 | outputFormat := CharReplacer.Replace(options.Format) |
| 2215 | if outputFormat == "" { |
| 2216 | outputFormat = GetCommandOptionWithDefault("device-get-uni-status", "format", DEFAULT_DEVICE_GET_UNI_STATUS_FORMAT) |
| 2217 | } |
| 2218 | result := CommandResult{ |
| 2219 | Format: format.Format(outputFormat), |
| 2220 | OutputAs: toOutputType(options.OutputAs), |
| 2221 | NameLimit: options.NameLimit, |
| 2222 | Data: rv.GetResponse().GetUniInfo(), |
| 2223 | } |
| 2224 | GenerateOutput(&result) |
| 2225 | return nil |
| 2226 | } |
| 2227 | |
Girish Gowdra | 4f5ce7c | 2021-04-29 18:53:21 -0700 | [diff] [blame] | 2228 | func (options *OnuPonOpticalInfo) Execute(args []string) error { |
| 2229 | conn, err := NewConnection() |
| 2230 | if err != nil { |
| 2231 | return err |
| 2232 | } |
| 2233 | defer conn.Close() |
| 2234 | client := extension.NewExtensionClient(conn) |
| 2235 | |
| 2236 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2237 | TargetId: string(options.Args.Id), |
| 2238 | Request: &extension.GetValueRequest{ |
| 2239 | Request: &extension.GetValueRequest_OnuOpticalInfo{ |
| 2240 | OnuOpticalInfo: &extension.GetOnuPonOpticalInfo{}, |
| 2241 | }, |
| 2242 | }, |
| 2243 | } |
| 2244 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2245 | defer cancel() |
| 2246 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2247 | if err != nil { |
| 2248 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2249 | return err |
| 2250 | } |
| 2251 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2252 | return fmt.Errorf("failed to get onu pon optical info %v", rv.Response.ErrReason.String()) |
| 2253 | } |
| 2254 | outputFormat := CharReplacer.Replace(options.Format) |
| 2255 | if outputFormat == "" { |
| 2256 | outputFormat = GetCommandOptionWithDefault("device-get-onu-pon-optical-info", "format", DEFAULT_ONU_PON_OPTICAL_INFO_STATUS_FORMAT) |
| 2257 | } |
| 2258 | result := CommandResult{ |
| 2259 | Format: format.Format(outputFormat), |
| 2260 | OutputAs: toOutputType(options.OutputAs), |
| 2261 | NameLimit: options.NameLimit, |
| 2262 | Data: rv.GetResponse().GetOnuOpticalInfo(), |
| 2263 | } |
| 2264 | GenerateOutput(&result) |
| 2265 | return nil |
| 2266 | } |
| 2267 | |
Gamze Abaka | c857a46 | 2021-05-26 13:45:54 +0000 | [diff] [blame] | 2268 | func (options *RxPower) Execute(args []string) error { |
| 2269 | conn, err := NewConnection() |
| 2270 | if err != nil { |
| 2271 | return err |
| 2272 | } |
| 2273 | defer conn.Close() |
| 2274 | client := extension.NewExtensionClient(conn) |
| 2275 | |
| 2276 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2277 | TargetId: string(options.Args.Id), |
| 2278 | Request: &extension.GetValueRequest{ |
| 2279 | Request: &extension.GetValueRequest_RxPower{ |
| 2280 | RxPower: &extension.GetRxPowerRequest{ |
| 2281 | IntfId: options.Args.PortNo, |
| 2282 | OnuId: options.Args.OnuNo, |
| 2283 | }, |
| 2284 | }, |
| 2285 | }, |
| 2286 | } |
| 2287 | |
| 2288 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2289 | defer cancel() |
| 2290 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2291 | if err != nil { |
| 2292 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2293 | return err |
| 2294 | } |
| 2295 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2296 | return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String()) |
| 2297 | } |
| 2298 | outputFormat := CharReplacer.Replace(options.Format) |
| 2299 | if outputFormat == "" { |
| 2300 | outputFormat = GetCommandOptionWithDefault("device-get-rx-power", "format", DEFAULT_RX_POWER_STATUS_FORMAT) |
| 2301 | } |
| 2302 | result := CommandResult{ |
| 2303 | Format: format.Format(outputFormat), |
| 2304 | OutputAs: toOutputType(options.OutputAs), |
| 2305 | NameLimit: options.NameLimit, |
| 2306 | Data: rv.GetResponse().GetRxPower(), |
| 2307 | } |
| 2308 | GenerateOutput(&result) |
| 2309 | return nil |
| 2310 | } |
| 2311 | |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2312 | /*Device get Onu Distance */ |
| 2313 | func (options *DeviceGetExtValue) Execute(args []string) error { |
| 2314 | conn, err := NewConnection() |
| 2315 | if err != nil { |
| 2316 | return err |
| 2317 | } |
| 2318 | defer conn.Close() |
| 2319 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2320 | client := voltha.NewVolthaServiceClient(conn) |
| 2321 | |
khenaidoo | 080ce88 | 2021-10-19 17:35:08 -0400 | [diff] [blame] | 2322 | valueflag, okay := extension.ValueType_Type_value[string(options.Args.Valueflag)] |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2323 | if !okay { |
| 2324 | Error.Printf("Unknown valueflag %s\n", options.Args.Valueflag) |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2325 | } |
| 2326 | |
khenaidoo | 080ce88 | 2021-10-19 17:35:08 -0400 | [diff] [blame] | 2327 | 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] | 2328 | |
David K. Bainbridge | 9189c63 | 2021-03-26 21:52:21 +0000 | [diff] [blame] | 2329 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2330 | defer cancel() |
| 2331 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2332 | rv, err := client.GetExtValue(ctx, &val) |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 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 |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2336 | } |
| 2337 | |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2338 | var rows []ReturnValueRow |
khenaidoo | 080ce88 | 2021-10-19 17:35:08 -0400 | [diff] [blame] | 2339 | for name, num := range extension.ValueType_Type_value { |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2340 | if num == 0 { |
| 2341 | // EMPTY is not a real value |
| 2342 | continue |
| 2343 | } |
| 2344 | if (rv.Error & uint32(num)) != 0 { |
| 2345 | row := ReturnValueRow{Name: name, Result: "Error"} |
| 2346 | rows = append(rows, row) |
| 2347 | } |
| 2348 | if (rv.Unsupported & uint32(num)) != 0 { |
| 2349 | row := ReturnValueRow{Name: name, Result: "Unsupported"} |
| 2350 | rows = append(rows, row) |
| 2351 | } |
| 2352 | if (rv.Set & uint32(num)) != 0 { |
| 2353 | switch name { |
| 2354 | case "DISTANCE": |
| 2355 | row := ReturnValueRow{Name: name, Result: rv.Distance} |
| 2356 | rows = append(rows, row) |
| 2357 | default: |
| 2358 | row := ReturnValueRow{Name: name, Result: "Unimplemented-in-voltctl"} |
| 2359 | rows = append(rows, row) |
| 2360 | } |
| 2361 | } |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2362 | } |
| 2363 | |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2364 | outputFormat := CharReplacer.Replace(options.Format) |
| 2365 | if outputFormat == "" { |
| 2366 | outputFormat = GetCommandOptionWithDefault("device-value-get", "format", DEFAULT_DEVICE_VALUE_GET_FORMAT) |
| 2367 | } |
| 2368 | |
| 2369 | result := CommandResult{ |
| 2370 | Format: format.Format(outputFormat), |
| 2371 | OutputAs: toOutputType(options.OutputAs), |
| 2372 | NameLimit: options.NameLimit, |
Scott Baker | 9173ed8 | 2020-05-19 08:30:12 -0700 | [diff] [blame] | 2373 | Data: rows, |
Dinesh Belwalkar | c9aa6d8 | 2020-03-04 15:22:17 -0800 | [diff] [blame] | 2374 | } |
| 2375 | GenerateOutput(&result) |
| 2376 | return nil |
| 2377 | } |
serkantul | 3d22fc7 | 2022-09-14 12:22:56 +0300 | [diff] [blame] | 2378 | |
| 2379 | /*Device get Onu OMCI TX RX Stats */ |
| 2380 | func (options *OnuOmciTxRxStats) Execute(args []string) error { |
| 2381 | conn, err := NewConnection() |
| 2382 | if err != nil { |
| 2383 | return err |
| 2384 | } |
| 2385 | defer conn.Close() |
| 2386 | client := extension.NewExtensionClient(conn) |
| 2387 | |
| 2388 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2389 | TargetId: string(options.Args.Id), |
| 2390 | Request: &extension.GetValueRequest{ |
| 2391 | Request: &extension.GetValueRequest_OnuOmciStats{ |
| 2392 | OnuOmciStats: &extension.GetOnuOmciTxRxStatsRequest{}, |
| 2393 | }, |
| 2394 | }, |
| 2395 | } |
| 2396 | |
| 2397 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2398 | defer cancel() |
| 2399 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2400 | if err != nil { |
| 2401 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2402 | return err |
| 2403 | } |
| 2404 | |
| 2405 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2406 | return fmt.Errorf("failed to get onu omci tx rx stats %v", rv.Response.ErrReason.String()) |
| 2407 | } |
| 2408 | outputFormat := CharReplacer.Replace(options.Format) |
| 2409 | if outputFormat == "" { |
| 2410 | outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-tx-rx-stats", "format", DEFAULT_ONU_OMCI_TX_RX_STATS_FORMAT) |
| 2411 | } |
| 2412 | result := CommandResult{ |
| 2413 | Format: format.Format(outputFormat), |
| 2414 | OutputAs: toOutputType(options.OutputAs), |
| 2415 | NameLimit: options.NameLimit, |
| 2416 | Data: rv.GetResponse().GetOnuOmciStats(), |
| 2417 | } |
| 2418 | GenerateOutput(&result) |
| 2419 | return nil |
| 2420 | } |
praneeth nalmas | 1dd094c | 2022-12-22 14:15:13 +0530 | [diff] [blame] | 2421 | |
| 2422 | /*Device get Onu Active Alarms */ |
| 2423 | func (options *GetOnuOmciActiveAlarms) Execute(args []string) error { |
| 2424 | conn, err := NewConnection() |
| 2425 | if err != nil { |
| 2426 | return err |
| 2427 | } |
| 2428 | defer conn.Close() |
| 2429 | client := extension.NewExtensionClient(conn) |
| 2430 | |
| 2431 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2432 | TargetId: string(options.Args.Id), |
| 2433 | Request: &extension.GetValueRequest{ |
| 2434 | Request: &extension.GetValueRequest_OnuActiveAlarms{ |
| 2435 | OnuActiveAlarms: &extension.GetOnuOmciActiveAlarmsRequest{}, |
| 2436 | }, |
| 2437 | }, |
| 2438 | } |
| 2439 | Info.Printf("Getting omci_active_alarms for device Id %s\n", options.Args.Id) |
| 2440 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2441 | defer cancel() |
| 2442 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2443 | if err != nil { |
| 2444 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2445 | return err |
| 2446 | } |
| 2447 | |
| 2448 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2449 | return fmt.Errorf("failed to get onu omci active alarms list %v", rv.Response.ErrReason.String()) |
| 2450 | } |
| 2451 | outputFormat := CharReplacer.Replace(options.Format) |
| 2452 | if outputFormat == "" { |
| 2453 | outputFormat = GetCommandOptionWithDefault("device-get-onu-omci-active-alarms", "format", DEFAULT_DEVICE_ALARMS_FORMAT) |
| 2454 | } |
| 2455 | |
| 2456 | orderBy := options.OrderBy |
| 2457 | if orderBy == "" { |
| 2458 | orderBy = GetCommandOptionWithDefault("device-list", "order", DEFAULT_DEVICE_ALARMS_ORDER) |
| 2459 | } |
| 2460 | |
| 2461 | result := CommandResult{ |
| 2462 | Format: format.Format(outputFormat), |
| 2463 | OutputAs: toOutputType(options.OutputAs), |
| 2464 | OrderBy: orderBy, |
| 2465 | NameLimit: options.NameLimit, |
| 2466 | Data: rv.GetResponse().GetOnuActiveAlarms().GetActiveAlarms(), |
| 2467 | } |
| 2468 | GenerateOutput(&result) |
| 2469 | return nil |
| 2470 | } |
praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 2471 | |
Akash Soni | 66db963 | 2024-04-15 09:05:15 +0530 | [diff] [blame^] | 2472 | /*Device get Onu Active Alarms */ |
| 2473 | func (options *GetOnuDistance) Execute(args []string) error { |
| 2474 | conn, err := NewConnection() |
| 2475 | if err != nil { |
| 2476 | return err |
| 2477 | } |
| 2478 | defer conn.Close() |
| 2479 | client := extension.NewExtensionClient(conn) |
| 2480 | |
| 2481 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2482 | TargetId: string(options.Args.Id), |
| 2483 | Request: &extension.GetValueRequest{ |
| 2484 | Request: &extension.GetValueRequest_Distance{ |
| 2485 | Distance: &extension.GetDistanceRequest{ |
| 2486 | OnuDeviceId: string(options.Args.OnuId), |
| 2487 | }, |
| 2488 | }, |
| 2489 | }, |
| 2490 | } |
| 2491 | Info.Printf("Getting onu distance for device Id %s\n", options.Args.Id) |
| 2492 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2493 | defer cancel() |
| 2494 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2495 | if err != nil { |
| 2496 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2497 | return err |
| 2498 | } |
| 2499 | |
| 2500 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2501 | return fmt.Errorf("failed to get onu distance stats %v", rv.Response.ErrReason.String()) |
| 2502 | } |
| 2503 | outputFormat := CharReplacer.Replace(options.Format) |
| 2504 | if outputFormat == "" { |
| 2505 | outputFormat = GetCommandOptionWithDefault("get-onu-distance", "format", DEFAULT_ONU_DISTANCE_FORMAT) |
| 2506 | } |
| 2507 | |
| 2508 | result := CommandResult{ |
| 2509 | Format: format.Format(outputFormat), |
| 2510 | OutputAs: toOutputType(options.OutputAs), |
| 2511 | NameLimit: options.NameLimit, |
| 2512 | Data: rv.GetResponse().GetDistance().GetDistance(), |
| 2513 | } |
| 2514 | fmt.Println("onu distance : ", rv) |
| 2515 | GenerateOutput(&result) |
| 2516 | return nil |
| 2517 | } |
| 2518 | |
praneeth nalmas | 39c71ad | 2023-09-27 18:29:04 +0530 | [diff] [blame] | 2519 | func (options *PonRxPower) Execute(args []string) error { |
| 2520 | conn, err := NewConnection() |
| 2521 | if err != nil { |
| 2522 | return err |
| 2523 | } |
| 2524 | defer conn.Close() |
| 2525 | client := extension.NewExtensionClient(conn) |
| 2526 | |
| 2527 | singleGetValReq := extension.SingleGetValueRequest{ |
| 2528 | TargetId: string(options.Args.Id), |
| 2529 | Request: &extension.GetValueRequest{ |
| 2530 | Request: &extension.GetValueRequest_OltRxPower{ |
| 2531 | OltRxPower: &extension.GetOltRxPowerRequest{ |
| 2532 | PortLabel: options.Args.PortLabel, |
| 2533 | OnuSn: options.Args.SerialNo, |
| 2534 | }, |
| 2535 | }, |
| 2536 | }, |
| 2537 | } |
| 2538 | |
| 2539 | ctx, cancel := context.WithTimeout(context.Background(), GlobalConfig.Current().Grpc.Timeout) |
| 2540 | defer cancel() |
| 2541 | rv, err := client.GetExtValue(ctx, &singleGetValReq) |
| 2542 | if err != nil { |
| 2543 | Error.Printf("Error getting value on device Id %s,err=%s\n", options.Args.Id, ErrorToString(err)) |
| 2544 | return err |
| 2545 | } |
| 2546 | if rv.Response.Status != extension.GetValueResponse_OK { |
| 2547 | return fmt.Errorf("failed to get rx power %v", rv.Response.ErrReason.String()) |
| 2548 | } |
| 2549 | outputFormat := CharReplacer.Replace(options.Format) |
| 2550 | if outputFormat == "" { |
| 2551 | outputFormat = GetCommandOptionWithDefault("device-get-pon-rx-power", "format", DEFAULT_PON_RX_POWER_STATUS_FORMAT) |
| 2552 | } |
| 2553 | result := CommandResult{ |
| 2554 | Format: format.Format(outputFormat), |
| 2555 | OutputAs: toOutputType(options.OutputAs), |
| 2556 | NameLimit: options.NameLimit, |
| 2557 | Data: rv.GetResponse().GetOltRxPower().GetRxPower(), |
| 2558 | } |
| 2559 | GenerateOutput(&result) |
| 2560 | return nil |
| 2561 | } |