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