fab-user
[Top][All Lists]
Advanced

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

Re: [Fab-user] Keeping remote path (or remote context) for next command


From: Jeff Forcier
Subject: Re: [Fab-user] Keeping remote path (or remote context) for next command
Date: Mon, 16 Feb 2015 09:23:08 -0800

On Mon, Feb 16, 2015 at 2:04 AM, Jörg Schneider <address@hidden> wrote:
> Thank you Jeff, this is a useful hint. But unfortunately the switches don’t 
> allow concatenated commands like shells '&&’ :-/

Ah sorry, I totally flaked on that detail. Yes, prefix() is oriented
towards shells, so it won't work there.

If you need this command prefix most/all of the time for these hosts,
you could just do something like this (possibly even importing fab's
run() as a different name and defining this as the local name 'run',
if you wanted):

    def netrun(command, **kwargs):
         command = "configure {0}".format(command)
         return run(command, **kwargs)

Basically, regular Python tricks for working around APIs that don't
quite fit your needs, should apply here.

Best,
Jeff


>
>> Am 14.02.2015 um 00:00 schrieb Jeff Forcier <address@hidden>:
>>
>> Executing commands over SSH doesn't keep a real shell around (this is
>> true for other SSH automation too - think of it as a series of "ssh
>> <hostname> <command>" calls in your shell).
>>
>> So - typically you have to fake it by generating prefixed commands.
>> E.g. Fabric's cd() helper just updates run() calls within its block so
>> they all actually start with "cd <path> && ...".
>>
>> You can do this with arbitrary commands by using the prefix() helper -
>> http://docs.fabfile.org/en/1.10/api/core/context_managers.html#fabric.context_managers.prefix
>>
>> Best,
>> Jeff
>>
>> On Fri, Feb 13, 2015 at 5:36 AM, Jörg Schneider <address@hidden> wrote:
>>> For managing some network devices I have to send something like „configure“ 
>>> command at first before I can do the real magic with fab.
>>> Does fabric „keep“ the remote context (or „path" if you see it as „cd 
>>> something“)?
>>>
>>> J. Schneider
>>>
>>>
>>> _______________________________________________
>>> Fab-user mailing list
>>> address@hidden
>>> https://lists.nongnu.org/mailman/listinfo/fab-user
>>
>>
>>
>> --
>> Jeff Forcier
>> Unix sysadmin; Python/Ruby engineer
>> http://bitprophet.org
>>
>



-- 
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org



reply via email to

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