Giter VIP home page Giter VIP logo

taskautom's Introduction

README

This idea was born because of a need for a simple tool to automate the execution of simple configuration templates on Nokia SROS based routers. Data provided on a DATA file (CSV or Excel) and the configuration templates written in pure Python. Configuration scripts are the result of these templates being rendered with the data.


Setup

System Libraries

These libraries have been tested under Ubuntu 20.04 and Windows10 with Python3.8.

Ubuntu
pip3 install taskAutom
Windows

For Windows users, make sure you have Python and PIP installed.

py -m pip install taskAutom

Edit servers.yml

This file has configuration parameters for the Jump Host(s). Add as many as needed. If more than one jump-host is declared, the connections will be load balanced sequentially among them. You can comment out some servers, if needed.

srvr0:
    name: 'myServer'
    user: 'myUser'
    password: 'myPass'
    ip: '1.1.1.1'
    port: 22
srvr1:
    name: 'myServer'
    user: 'myUser'
    password: 'myPass'
    ip: '2.2.2.2'
    port: 22    

When using a jumpHost, taskAutom will create a standard ssh-based tunnel (ie: TCP-port-forwarding) to the far-end, which is the router.


Bulk Script Execution on routers

The program needs two mandatory inputs: a) DATA file and b) a plugin, which is nothing but a configuration template.

DATA file

The DATA can be either a CSV file or an Excel file. There must be a column named ip with the IP addresses of the routers to which taskAutom will connect to. The name of this column can be changed using the configuration option -gc/--dataGroupColumn myColName.

The ip column (or eventually changed by -gc) allows taskAutom to group routers by that column when processing data. This is particularly useful if you have the same router along several rows in the DATA file.

If you want taskAutom not to group routers by the ip column, you should use the -so/--strictOrder=yes CLI parameter: this will process the routers' data in the order of the DATA file as is.

The next columns in the DATA file, are the variables that will be used in the configuration template.

Example: this is a CSV for two different routers, including the data to modify their interfaces.

ip,name,port,interName,ipAddress
10.0.0.1,router1,1/1/1,inter1,192.168.0.1/30
10.0.0.2,router2,1/3/5,inter7,192.168.2.1/30

Notes on the data file

There are cases where it is needed to send the complete dataFrame to the plugin. In those cases, you can do so by issuing the CLI parameter -pbr/--passByRow=no. When doing so, taskAutom will send the whole set of rows selected by the IP of the router, to the plugin. By deafult, -pbr/--passByRow=yes.

Plugin

The plugin is a Python code which is fed with each row of the DATA file at a time, in order to render a configuration script. It consists of a function called construir_cliLine() which accepts four arguments:

  • m which is a counter, representing the row_id of the data.
  • datos which is a Pandas object; the data itself.
  • lenData which is the length of the Pandas dataFrame; i.e.: the amount of rows inside the grouped data.
  • mop, a boolean.

m and lenData can be used to decide when some part of the code must be ran. mop is used when the configuration script needs to be verified before running; mop=True when the CLI parameter -j/--jobType is 0.

Example: use the previous data, to generate configuration scripts. The example is assuming no header has been defined in the DATA file, so column id is used to identify the proper variable.

def construir_cliLine(m, datos, lenData, mop=None):

    ipSystem   = datos.ip
    router     = datos.name
    port       = datos.port
    intName    = datos.interName
    address    = datos.ipAddress

    cfg        = ""

    if mop and m == 0:
        cfg = "\nHeading_2:Router: " + router + ", " + ipSystem + "\n"

    cfg = cfg + f'/configure router interface {intName} port {port}\n'
    cfg = cfg + f'/configure router interface {intName} address {address}\n'

    if m == lenData-1:
        cfg = cfg + f'/configure router interface {intName} no shutdown\n'

    return cfg

Notes on plugin

  1. When writing plugins, do not to use abbreviated commands. This will potentially led to errors. For example: /configure rout int system add 10.0.0.1/32 is discouraged. Better off use /configure router interface system address 10.0.0.1/32.

  2. Common practice: it is better to try to accommodate plugins so that they reflect they purpose. Then use the configuration parameter --pluginType=[show|config] to reflect the spirit of the plugin.

  3. In general, use --cmdVerify=yes. Only disable cmdVerify if facing problems.

Inventory

By default, taskAutom connects to each and every router that exists inside the DATA data file (identifying the routers by the ip column). Optionally, an inventory file can be provided, with per router connection parameters. If so, the default connection values are overridden by those inside the inventory file.

ip username password useSSHTunnel readTimeOut deviceType jumpHost
10.0.0.1 user1 pass1 yes 15 nokia_sros server1
10.0.0.2 user2 pass2 no 90 nokia_sros_telnet
10.0.0.3 user3 pass3 no 90 nokia_srl

If fieds in the inventory CSV file are left empty, default values are used.

MOP: Method of Procedure

When writing a plugin, is important to help taskAutom understand which string should be considered as a title if you intend to generate a Word document out of the combination of the data file and the plugin.

You do so be adding a prefix Heading_2 to the tiltle variable, under the if mop: statement. After this, a MOP is created with the intended information. There is also the possibility of using the prefix Heading_3.

Result

If taskAutom is invoked with option -j/--jobType 0, a text file with the rendered output, will be genereated.

$ taskAutom -d example/example.csv -py example/example.py -l test -j 0

Router: router1, 10.0.0.1
/configure router interface inter1 port 1/1/1
/configure router interface inter1 address 192.168.0.1

Router: router2, 10.0.0.2
/configure router interface inter7 port 1/3/5
/configure router interface inter7 address 192.168.2.1

Otherwise, if taskAutom is invoked with option -j/--jobType 2, it will connect to each and every router, and execute the commands. User and password must be provided in this case.


Bulk SCP/SFTP transfer to routers

There is also the possibility of bulk transfer of files to several routers. To do so you need to to the following:

  • use jobtype=3
  • prepare a dataFile with the following three column names: ip|ftpLocalFilename|ftpRemoteFilename.

Next, taskAutom will connect to each and every router, transfering the ftpLocalFilename and creating on the remote device a file with the name ftpRemoteFilename.

taskautom's People

Contributors

beatrizbonafe avatar laimaretto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

taskautom's Issues

manage through inventory different data or plugin

Today taskAutom assumes all end devices will use the same data file (or even excel sheet name) as input. Same happens with the plugin. The rendering produces diffente pluginScripts for each router.

But there might be a case where different routers should use different input data or plugin. Handling of these should be done via the inventory file.

fncUploadFile default to CF3:/

the function sendFiles(sftp,ftpFiles) by tdefault sends ftpRemoteFiles to CF3. Allow a user to define the remote location

update of `connInfo` inside the class: move out

The connInfo dictionary holds all the information related to a router's connection, such as sshTunnel, username, password, etc.

If there is any update to happen, because of an inventory file, today this update is taking place inside the class myConnection.__init__().

It's cleaner if the class would receive all the router's connection information at once. So this per-router update should happen before.

To do so, one possible idea is to build a dictionary inside the function fncRun() with an entry per each router, with all this information. This will be passed over to the class ...

MD-CLI

by default, taskAutom includes environment no more at the very begining. this provokes a minor error when using MD-CLI

send complete DATA file to the plugin

send the complete DATA file to the plugin. This is specially useful if the DATA file is an Excel file with several spread_sheets. This will allow for better handling of data.

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.