CliMultiRunner

class CliMultiRunner(provider, ips, actions=None, workers=4, DEBUG=False, verbosity=3, netmiko_params={})

Bases: object

This class allows running set of CLI commands on multiple devices in parallel, using Worker threads

Parameters:
  • provider (dict) – Dictionary with necessary info for creating connection
  • ips (list) – List of IP addresses of the device
  • actions (list) – List of actions to be run in each connection
  • workers (int) – Number of worker threads to spawn
  • DEBUG (bool) – Enables/disables debugging output
fill_queue()

This function builds device-specific providers for CliConnection and adds them to Queue object.

Returns:None
run(adjust_worker_count=True)

Main entry function, puts all pieces together. Firs populates Queue with IP addreses and connection information, spawns threads and starts them. Blocks until self.queue is empty.

Parameters:adjust_worker_count (bool) – If set to True (default), number of workers will be reduced if number of given hosts is lower than number of workers.
Returns:
thread_factory()

Function for spawning worker threads based on number of workers in self.workers

Returns:
worker()

Worker function to handle individual connections. Based on provider object from Queue establishes connection to device and runs defined set of commands. Received data are stored in self.data as a list of dictionaries, each dictionary representing one device.

Returns:None