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