fab-user
[Top][All Lists]
Advanced

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

[Fab-user] question about Fabric as a library


From: Vincent Derelle
Subject: [Fab-user] question about Fabric as a library
Date: Thu, 5 Sep 2013 16:45:55 -0400

Hello,

 

I’m developing an internal tool in our organisation. In a nutshell,  it’s a web app (using Python Django) which retrieves a set of nodes from a Chef server and then run commands on those selected nodes. I’m using Fabric

to execute those commands remotely. The recommended way to use Fabric as a library in the documentation is to use the execute  (http://docs.fabfile.org/en/1.7/api/core/tasks.html#fabric.tasks.execute)

function.

 

If I use the execute function like this:

nodes = [‘nodes1’, ‘node2’]  

 

result = execute(_fabric_execute, command, hosts=nodes)

 

@parallel

def _fabric_execute(command):

    result = sudo(command)

    return result

 

this will work and return to me a dictionary containing the output of those commands.

 

If I do it sequentially instead like this:

nodes = [‘nodes1’, ‘nodes2’]

 

results = []

 

for n in nodes:

    env.host_string = n

    result = _fabric_execute(command);

    results.append(result)

 

(in the django template iterate through the array and then display the different result object properties)

 

The individual result objects returned give me much more valuable information such as: result.succeeded if it succeeded , result.failed if it failed, result.real_command for the real command executed as well as the the output.

 

My question to you is, is there any way I can get that information when using the execute function? Because my web app allows people to execute commands, by default, in parallel which returns only the output but if they chose sequential execution but I’m able to display to them if it succeeded or not and the real command executed by fabric if they select sequential execution. Essentially I’d like to be able to display the same amount of information (mainly if it failed or not) in parallel execution using execute like sequential execution

 

Cheers,

I love fabric!

 

Vincent

 


reply via email to

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