|
From: | Jon Mansey |
Subject: | Re: [Fab-user] fabric as library, access pool of connections indexed by host |
Date: | Sat, 22 Mar 2014 13:49:04 -0700 |
Gents, thanks for the feedback, the connections cache is just what I need to avoid setting up and tearing down connections every time I need a command run on a host. I managed to create a function to do command x on host y and get output, like this: from fabric.api import env, run, execute, settings, hide env.hosts = ['host1', 'host2'] def sshcmd(): return run(cmd) def ssh_execute(sshcmnd, host): with settings(hide('running', 'commands', 'stderr')): output = execute(sshcmd, hosts=[host]).values() return output cmd = 'uname -n' print ssh_execute(cmd, 'host2')[0] However I can’t seem to get it to work without cmd needing to be global. as you can see sshcmnd is not used. I can’t set any args to the sshcmd function call without breaking execute(). if I change this to def sshcmd(sshcmnd): return run(cmd) then try to execute(sshcmd(sshcmnd), hosts=[host]) it stops with this output No hosts found. Please specify (single) host string for connection: I can continue working around this with cmd as global but id prefer not to, if anyone can help out, thanks! Jon On Mar 21, 2014, at 11:16 PM, Jeff Forcier <address@hidden> wrote: Brandon is correct (thanks Brandon!), Fabric attempts to cache open |
[Prev in Thread] | Current Thread | [Next in Thread] |