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