-
-def usage():
- '''Print usage information for the program'''
- argv0 = basename(sys.argv[0])
- print("""
-Usage:
-------
-
- %(argv0)s [options] DEVICE1 DEVICE2 ....
-
-where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax
-or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may
-also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc.
-
-Options:
- --help, --usage:
- Display usage information and quit
-
- -s, --status:
- Print the current status of all known network, crypto, event
- and mempool devices.
- For each device, it displays the PCI domain, bus, slot and function,
- along with a text description of the device. Depending upon whether the
- device is being used by a kernel driver, the igb_uio driver, or no
- driver, other relevant information will be displayed:
- * the Linux interface name e.g. if=eth0
- * the driver being used e.g. drv=igb_uio
- * any suitable drivers not currently using that device
- e.g. unused=igb_uio
- NOTE: if this flag is passed along with a bind/unbind option, the
- status display will always occur after the other operations have taken
- place.
-
- --status-dev:
- Print the status of given device group. Supported device groups are:
- "net", "baseband", "crypto", "event", "mempool" and "compress"
-
- -b driver, --bind=driver:
- Select the driver to use or \"none\" to unbind the device
-
- -u, --unbind:
- Unbind a device (Equivalent to \"-b none\")
-
- --force:
- By default, network devices which are used by Linux - as indicated by
- having routes in the routing table - cannot be modified. Using the
- --force flag overrides this behavior, allowing active links to be
- forcibly unbound.
- WARNING: This can lead to loss of network connection and should be used
- with caution.
-
-Examples:
----------
-
-To display current device status:
- %(argv0)s --status
-
-To display current network device status:
- %(argv0)s --status-dev net
-
-To bind eth1 from the current driver and move to use igb_uio
- %(argv0)s --bind=igb_uio eth1
-
-To unbind 0000:01:00.0 from using any driver
- %(argv0)s -u 0000:01:00.0
-
-To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver
- %(argv0)s -b ixgbe 02:00.0 02:00.1
-
- """ % locals()) # replace items from local variables
-
-
-# This is roughly compatible with check_output function in subprocess module
-# which is only available in python 2.7.
-def check_output(args, stderr=None):
- '''Run a command and capture its output'''
- return subprocess.Popen(args, stdout=subprocess.PIPE,
- stderr=stderr).communicate()[0]
-