How to run EdgeOS configuration commands in python fabric

15 Views Asked by At

I'm trying to programmatically update configuration in EdgeOS using a python script. I'm using fabric as an ssh client. https://docs.fabfile.org/en/latest/index.html

what I'd like to do is to create small configuration changes such as:

configure
set interfaces ethernet eth2 vif 20 disable
commit
save

However, the configure command fails when I run it through fabric. I notice, when I'm in an ssh session, the configure command creates a new sub-session or something. I'm not sure of the term.

$ configure
[edit]
#

script so far:

from fabric import Connection
c = Connection('routerip')
c.run("configure")

And the error:

vbash: configure: command not found
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/me/opt/anaconda3/lib/python3.8/site-packages/decorator.py", line 231, in fun
    return caller(func, *(extras + args), **kw)
  File "/Users/me/opt/anaconda3/lib/python3.8/site-packages/fabric/connection.py", line 23, in opens
    return method(self, *args, **kwargs)
  File "/Users/me/opt/anaconda3/lib/python3.8/site-packages/fabric/connection.py", line 763, in run
    return self._run(self._remote_runner(), command, **kwargs)
  File "/Users/me/opt/anaconda3/lib/python3.8/site-packages/invoke/context.py", line 113, in _run
    return runner.run(command, **kwargs)
  File "/Users/me/opt/anaconda3/lib/python3.8/site-packages/fabric/runners.py", line 83, in run
    return super().run(command, **kwargs)
  File "/Users/me/opt/anaconda3/lib/python3.8/site-packages/invoke/runners.py", line 395, in run
    return self._run_body(command, **kwargs)
  File "/Users/me/opt/anaconda3/lib/python3.8/site-packages/invoke/runners.py", line 451, in _run_body
    return self.make_promise() if self._asynchronous else self._finish()
  File "/Users/me/opt/anaconda3/lib/python3.8/site-packages/invoke/runners.py", line 518, in _finish
    raise UnexpectedExit(result)
invoke.exceptions.UnexpectedExit: Encountered a bad command exit code!

Command: 'configure'

Exit code: 127

Stdout: already printed

Stderr: already printed
0

There are 0 best solutions below