fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fab-user] Equivalent of fabric.tasks.execute in 2.0 API?


From: Abhijeet Rastogi
Subject: [Fab-user] Equivalent of fabric.tasks.execute in 2.0 API?
Date: Tue, 15 May 2018 17:53:25 +0530

Hi everyone, 

What's the equivalent of fabric.tasks.execute in the new API? One convenience of that function is, you can create a task assuming that you're working on only one host at a time and then seamlessly execute it across a list of hosts. For ex, 

from fabric.api import run
from fabric.tasks import execute


def do_something():
    uptime_result = run("uptime").stdout
    # Do more with uptime_result later in code. 
if __name__ == "__main__":
    execute(do_something, hosts=["address@hidden"])
When working on multiple hosts, I know we've a fabric.group.ThreadingGroup which has a run method but this forces us handle fabric.group.GroupResult which means handling outputs of all hosts in one place which is added complexity. For ex, 

try:
    results = connections_array.run('pidof foobar', hide="both")
except GroupException as e:
    results = e.result
pids = []
for _, result in results.items():
    # do what I want. capture outputs of various connections in above array.

# Reusing of previous outputs in series of operations gets hard. 
# Do second operations by capturing previous output. 


Any suggestions on how to make the new API friendly to use when using multiple hosts?

--
Cheers,
Abhijeet Rastogi (shadyabhi)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]