Take a device "name" - a string passed in by user to identify a NIC device, and determine the device id - i.e. the domain:bus:slot.func - for it, which can then be used to index into the devices array
(dev_name)
| 302 | |
| 303 | |
| 304 | def dev_id_from_dev_name(dev_name): |
| 305 | '''Take a device "name" - a string passed in by user to identify a NIC |
| 306 | device, and determine the device id - i.e. the domain:bus:slot.func - for |
| 307 | it, which can then be used to index into the devices array''' |
| 308 | |
| 309 | # check if it's already a suitable index |
| 310 | if dev_name in devices: |
| 311 | return dev_name |
| 312 | # check if it's an index just missing the domain part |
| 313 | if "0000:" + dev_name in devices: |
| 314 | return "0000:" + dev_name |
| 315 | |
| 316 | # check if it's an interface name, e.g. eth1 |
| 317 | for d in devices.keys(): |
| 318 | if dev_name in devices[d]["Interface"].split(","): |
| 319 | return devices[d]["Slot"] |
| 320 | # if nothing else matches - error |
| 321 | raise ValueError("Unknown device: %s. " |
| 322 | "Please specify device in \"bus:slot.func\" format" % dev_name) |
| 323 | |
| 324 | |
| 325 | def unbind_one(dev_id, force): |