GithubHelp home page GithubHelp logo

carlmontanari / srlinux-scrapli Goto Github PK

View Code? Open in Web Editor NEW

This project forked from srl-labs/srlinux-scrapli

1.0 1.0 0.0 16 KB

srlinux driver for scrapligo

License: BSD 3-Clause "New" or "Revised" License

Go 100.00%

srlinux-scrapli's Introduction

SR Linux driver for Scrapligo

This module adds Nokia SR Linux platform support for scrapligo project.

How to use?

In order to use SR Linux driver for scrapligo users need to import this module and create a new SR Linux driver. The following example demonstrates how this driver can be used:

package main

import (
	"fmt"

	"github.com/scrapli/scrapligo/driver/base"
	"github.com/scrapli/scrapligo/transport"
	"github.com/srl-labs/srlinux-scrapli"
)

func main() {
	d, err := srlinux.NewSRLinuxDriver(
		"clab-scrapli-srlinux",
		base.WithAuthStrictKey(false),
		base.WithAuthUsername("admin"),
		base.WithAuthPassword("admin"),
		base.WithTransportType(transport.StandardTransportName),
	)

    // uncomment to enable debug log
	// logging.SetDebugLogger(log.Print)

	if err != nil {
		fmt.Printf("failed to create driver; error: %+v\n", err)
		return
	}

	err = d.Open()
	if err != nil {
		fmt.Printf("failed to open driver; error: %+v\n", err)
		return
	}

	fmt.Println("Sending 'show version' command...")
	r, err := d.SendCommand("show version")
	if err != nil {
		fmt.Printf("failed to send commands; error: %+v\n", err)
		return
	}

	fmt.Println(r.Result)

	fmt.Println("Sending configuration commands...")
	configs := []string{
		"system information location scrapligo",
		"commit now",
	}

	_, err = d.SendConfigs(configs)
	if err != nil {
		fmt.Printf("failed to send configs; error: %+v\n", err)
		return
	}

	fmt.Println("Checking that configuration has been applied successfully...")

	r, err = d.SendCommand("info from running /system information location")
	if err != nil {
		fmt.Printf("failed to send commands; error: %+v\n", err)
		return
	}

	fmt.Println(r.Result)

	err = d.Close()
	fmt.Println("closing connection...")
	if err != nil {
		fmt.Printf("failed to close driver; error: %+v\n", err)
	}
}

Additional functions

In addition to providing a scrapligo driver for SR Linux, this package contains convenience functions with additional functionality.

AddSelfSignedServerTLSProfile

The AddSelfSignedServerTLSProfile function uses SR Linux ability to generate a self-signed certificate and key and uses those two artifacts to create a server TLS profile that is used for securing gNMI, HTTPS, etc.

The intent behind this function is to simplify TLS certificates provisioning in a lab setting, where self-signed certificates are norm. This function is usually called first thing after SR Linux boot process, to ensure that gNMI service can be enabled.

This function takes the following arguments:

  • *network.Driver - an initialized network driver, which is a result of srlinux.NewSRLinuxDriver()
  • profileName - a name of the server profile that will be created for the generated key/cert. If empty, the default name self-signed-tls-profile will be used.
  • authClient - a boolean value indicating if the server TLS profile should have authenticate-client option set to true or false.

Note, that the network.Driver that is passed as a first argument should not be opened prior to calling this function, as it will be opened with the specific PTY size inside the function.

Known issues and limitations

  1. scrapligo doesn't assume that a command in configuration context can switch the session to exec priv. level, although this is what SR Linux commands like commit save and commit now do.
    For that reason, if you send configs and up using one of the above mentioned commands, use d.AcquirePriv() function to get into the desired privilege level if it doesn't match the previously detected one.

Something doesn't work?

If the driver doesn't work, it is quite likely that the prompt has been changed. SR Linux driver relies on regular expressions defined in scrapli.go file for the relevant Privilege Levels. Check if those regular expressions match your prompt, and if not, create an issue or propose a change.

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.