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