[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fab-user] question about Fabric as a library
From: |
Vincent Derelle |
Subject: |
Re: [Fab-user] question about Fabric as a library |
Date: |
Fri, 6 Sep 2013 09:46:17 -0400 |
You're right. I did a print on the dict mapping object returned by execute()
which gave me {u'node1': 'the output of the task that ran for node1', u'node2':
'the output of the task that ran for node2'}.
Then I did a:
foobar = results['node1']
print foobar
which displayed again the task output.
I got confused by the "to_string" methods of the objects. Sorry about that, I'm
relatively new to Python.
Thanks for the reply!
Vincent
-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of Jeff Forcier
Sent: 5 septembre 2013 19:30
To: Vincent Derelle
Cc: address@hidden
Subject: Re: [Fab-user] question about Fabric as a library
The values involved ought to be the same either way - have you verified this?
* sudo() returns an _AttributeString object which is the one you mentioned as
having useful attributes.
* execute() returns that dict mapping hostname to the return value of the task
function, for that hostname.
* Your task is returning the result of the sudo() calls, meaning they should
end up in the result of execute().
Therefore, you should be seeing e.g.:
{'node1': <_AttributeString object from the sudo()>, 'node2':
<_AttributeString object from the sudo()>}
Where those _AttributeStrings are the same values you would see if you ran your
2nd example snippet.
If you're seeing something different, clarification and specific output
examples would be great :)
Thanks,
Jeff
On Thu, Sep 5, 2013 at 1:45 PM, Vincent Derelle <address@hidden> wrote:
> 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.execu
> te)
>
> 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
>
>
>
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/fab-user
>
--
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org