Как запустить команды конфигурации EdgeOS в структуре PythonLinux

Ответить
Гость
 Как запустить команды конфигурации EdgeOS в структуре Python

Сообщение Гость »


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

Below "---original question---" describes the problem, but I think I've hit on the source of the issue, but not the solution. Fabric ssh's into the router in non-interactive mode, and as such doesn't get the full bash configuration. The

Код: Выделить всё

configure
command isn't available, nor nor other router management commands. The .bashrc file in the router is this:

Код: Выделить всё

# If not running interactively, don't do anything [ -z "$PS1" ] && return # enable completion source /etc/bash_completion.d/vyatta-cfg source /etc/bash_completion.d/vyatta-op unset HISTFILE 
So I can see I'm not sourcing the bash_completion files. I tried doing that manually in python:

Код: Выделить всё

c.run("source /etc/bash_completion.d/vyatta-cfg")
, but it doesn't seem to work. My next best solution is to find the hard path to those commands, but I'm not sure where to look.

---original question---

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 "", line 1, in    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 


Источник: https://stackoverflow.com/questions/781 ... hon-fabric
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Linux»