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