fab-user
[Top][All Lists]
Advanced

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

Re: [Fab-user] HP switches and run() received nonzero return code -1 whi


From: Jeff Forcier
Subject: Re: [Fab-user] HP switches and run() received nonzero return code -1 while executing
Date: Fri, 18 Nov 2016 08:57:54 -0800

Grump, I didn't read the rest of the thread hard enough. If newlines don't work I'd double check the manual for your switch in case that continuation option exists - otherwise, as mentioned, you may be out of luck :( SSH simply isn't built the way you need it to be.

On Fri, Nov 18, 2016 at 8:52 AM, Jeff Forcier <address@hidden> wrote:
This isn't a limitation of Fabric itself, but is specific to how SSH works - to encapsulate each command as a discrete result of output, exit code, etc, one must use a distinct command-execution call to the SSH daemon for each command. (This is in the FAQ as http://www.fabfile.org/faq.html#my-cd-workon-export-etc-calls-don-t-seem-to-work though the title is a bit specific.)

If your use case can deal with that limitation - i.e. if your intent is to just run the commands and not do programmatic things with its output or exit codes partway through - you could try submitting a multiline string as the argument to `run`, e.g.:

    run("""screen-length disable
display current-configuration""")

(Or use '\n', etc.)

How well that will work depends on how your switch's shell behaves with that style of 'batched' input.

If the switch's shell supports any sort of single-line continuations (like '&&' or ';' in typical Unix shells) that's another approach. You could leverage the 'with prefix()' feature of Fabric then too (http://docs.fabfile.org/en/latest/api/core/context_managers.html#fabric.context_managers.prefix).

Good luck,
Jeff


On Fri, Nov 18, 2016 at 7:00 AM, Brandon Whaley <address@hidden> wrote:
You may be able to use the underlying paramiko library that Fabric itself relies on, but I don't have any personal experience with it.

On Fri, Nov 18, 2016 at 3:57 AM <address@hidden> wrote:
Hello Brandon,


(sorry for the direct reply, I didn't notice that the To: wasn't to the ML)

Thank you for your reply.
Unfortunately sending newlines (or carriage return) between two commands inside one run() didn't help.
Since between each run() I'm loosing my execution session, are you aware about another ssh module for Python that doesn't have this behaviour?

Many Thanks,

Regards,


Alexandre


----- Original Message -----
From: "Brandon Whaley" <address@hidden>
To: "a hocquel" <address@hidden>, address@hidden
Sent: Thursday, 17 November, 2016 7:54:24 PM
Subject: Re: [Fab-user] HP switches and run() received nonzero return code -1 while executing


Fabric was written with accessing *nix based servers in mind, so some things it does don't work correctly with non-standard ssh implementations. I'm not sure if HP is returning the -1 code or if Fabric is not getting one at all and as such returns -1 as an error value. Either way, it sounds like you'll always need to use warn_only=True for this device.


One of the biggest differences between an interactive ssh session and Fabric is that when you use run(), while only one ssh connection is ever made, a new command execution session is initiated over that connection for each operation. That means things like environment variables are "fresh" at every call to run(). I suspect this is why your "screen-length disable" command does not take effect, since HP's docs state "Note that this command is applicable to the current user only and when a user re-logs in, the settings restore to the system default."


Have you tried sending newlines between two commands in the same run()? That might be a workaround for you if the switch allows it.


On Thu, Nov 17, 2016 at 10:43 AM < address@hidden > wrote:


Hello,


I'm new here, and before writing this email I searched on the archives without success, so please excuse me if this question was already asked.

I'm trying to "display current-configuration" through ssh on HP 5820 series switches with this piece of code :

from fabric.api import *

env.user = 'toto'
env.hosts = ['192.168.72.10']
def displaycurr():
with settings(hide('warnings'), warn_only=True):
# below command is normally used to prevent the "more"
run('screen-length disable ', shell=False)
run('display current-configuration ', shell=False)


As written in the email's subject, every ran command returns a nonzero code, implying that even if I forced the "keep running" with the warn_only=True option, after each run command the ssh session is exited.
Therefore I lost the first command advantage and then I got the "more" during the second.

Same code (without warn_only) and the right Cisco commands does work well on Cisco switches.


By any chance, is there someone that experienced the same issue (not necessarily with HP switches) and managed to keep the ssh session opened between both commands?


Many Thanks,

Regards,


Alexandre




_______________________________________________
Fab-user mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/fab-user

_______________________________________________
Fab-user mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/fab-user

_______________________________________________
Fab-user mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/fab-user




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



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

reply via email to

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