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