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