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