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