def batch(endpoints, commands, **kwargs): endpoints = to_list(endpoints) #pool_size = kwargs.pop('pool_size', None) or 10 delay = kwargs.pop('delay', None) or 0 pool = Pool(endpoints, commands, **kwargs) pool.run(delay=delay) for item in pool.results: yield item
def background(endpoints, commands, **kwargs): """Similar to batch, but the :class:`Pool` opject is returned before reading the results, non-blocking :param endpoint: remote host or URI to connect to :param commands: command or commands to send :param creds: (optional) :class:`Creds <Creds>` object with authentication credentials :param protocol: (optional) Protocol name, e.g. 'ssh' or 'eapi' :return: :class:`Pool <Pool>` object :rtype: arcomm.async.Pool Usage: >>> with arcomm.background('veos1', 'show version') as bg: ... # do other things... ... >>> for res in bg: ... print res.to_yaml() ... host: vswitch1 status: ok commands: - command: show version output: | Arista vEOS Hardware version: Serial number: System MAC address: 0800.2776.48c5 [ ...output omitted... ] """ return Pool(endpoints, commands, **kwargs)
def create_pool(hosts, creds, commands, **kwargs): """Return a `Pool` object of hosts and commands Example: pool = create_pool(["spine1a", "spine2a"], creds, "show version") pool.start() # do other stuff... pool.join() for result in pool.results: print result """ warnings.warn("deprecated", DeprecationWarning) pool = Pool(hosts, creds=creds, commands=commands, **kwargs) return pool
def batch(endpoints, commands, **kwargs): """Send commands to multiple endpoints :param endpoint: remote host or URI to connect to :param commands: command or commands to send :param creds: (optional) :class:`Creds <Creds>` object with authentication credentials :param protocol: (optional) Protocol name, e.g. 'ssh' or 'eapi' Usage: >>> pool = arcomm.batch(['veos1', 'veos2'], ['show version']) >>> for res in pool: ... print res.to_yaml() """ with Pool(endpoints, commands, **kwargs) as pool: try: for item in pool.results: yield item.get() except KeyboardInterrupt: print 'Caught interrupt' pool.kill() raise
def background(uri, commands, **kwargs): pool = Pool([uri], commands, **kwargs) pool.background = True return pool