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