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