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