Giter Site home page Giter Site logo

python-vyos-mgmt's Introduction

VyMGMT

A python library for executing commands on VyOS systems.

Generic methods should also work with any of the Vyatta descendants (EdgeOS, Brocade vRouter).

The library is compatible with both python2 and python3.

It is released under the MIT license.

How it works

VyMGMT uses pexpect.pxssh library to login to VyOS and execute commands there. This approach has its downsides, but it's better than nothing.

Why is it better than using pxssh or another expect library directly? To make life easier for the user, it provides methods such as set(), delete(), and commit() that detect errors and raise appropriate exceptions when an error occurs.

API reference

...is kept on ReadTheDocs. http://vymgmt.readthedocs.io

Installation

The easiest way is to install from PyPI (https://pypi.python.org/pypi):

pip install vymgmt

Alternatively you can run the setup.py script to install it locally.

Usage example

import vymgmt

vyos = vymgmt.Router('192.0.2.1', 'vyos', password='vyos', port=22)

vyos.login()
vyos.configure()

vyos.set("protocols static route 203.0.113.0/25 next-hop 192.0.2.20")
vyos.delete("system options reboot-on-panic")

vyos.commit()
vyos.save()
vyos.exit()
vyos.logout()

If something goes wrong, an exception is raised and the original error message from VyOS is included in its error string:

>>> vyos.set("system foobar true")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../vymgmt/router.py", line 216, in set
    raise ConfigError(output)
vymgmt.router.ConfigError:  set system foobar true

  Configuration path: system [foobar] is not valid
  Set failed

[edit]

If you want to execute a command that is not yet supported explicitly, you can use run_op_mode_command() and run_conf_mode_command() methods that take a full command and execute it on the other side.

Behaviour

All methods raise a VyOSError exception if you try to use them when the Router object is in a wrong state, such as trying to run configure() before logging in, or trying to run set() before configure().

If something goes wrong on the other side, ConfigError or its subclass CommitError is raised. One special case, ConfigLocked (a subclass of CommitError) is raised when commit fails because there is another commit in progress. It's made a special case because it's the only commit error that can be recovered from easily (just wait a bit and retry).

By default, exit() will not let you exit and will raise a VyOSError is there are uncommited or unsaved changes. You can override it with exit(force=True).

Credits

This library was originally written by Hochikong ([email protected] (preferred), or [email protected]), and is now maintained by the VyOS project.

python-vyos-mgmt's People

Contributors

dmbaturin avatar hochikong avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.