pssh

package module
v1.61.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

Usage example:

package main

import (
	"fmt"
	"log"

	"github.com/naseriax/pssh"
)

func main() {

	nodeIP := "172.16.0.1"
	log.Printf("connecting to %v", nodeIP)

	// create the node.
	node := pssh.Endpoint{
		Ip:       nodeIP,
		UserName: "admin",
		Password: "admin",
		Port:     "22",
		Kind:     "GMRE", //Accepted values: BASH, PSS, OSE, PSD, GMRE
	}


    // initiate the ssh connection.
	if err := node.Connect(); err != nil {
		log.Println(err)
		return
	}

	// set the logout clause.
	defer func(node pssh.Endpoint) { node.Disconnect(); log.Printf("Closed ssh session for %v", node.Ip) }(node)

    //res is a map[string]string which contains commands as key and their results as value.
	res, err := node.Run(
		"show lsp",
		"show node",
	)

	if err != nil {
		fmt.Println(err)
	}

	//Print the result.
	fmt.Println(node.Ip, res)
}

Features:

It supports connecting to 1830PSS cli (Kind = PSS),1830PSS ose (Kind = OSE), 1830PSS gmre (Kind = GMRE), Linux shell (Kind = BASH) and 1830PSD cli (Kind = PSD).
1830 PSS 23.6 cli login support has been added.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Endpoint added in v1.0.15

type Endpoint struct {
	ViaTunnel bool
	Ip        string
	Name      string
	UserName  string
	Password  string
	Vars      map[string][]string
	Port      string
	SshOut    io.Reader
	SshIn     io.WriteCloser
	Timeout   int
	Client    *ssh.Client
	Session   *ssh.Session
	Kind      string //Accepted values: BASH, PSS, OSE, PSD,...
}

func (*Endpoint) Connect added in v1.0.15

func (s *Endpoint) Connect() error

Connect connects to the specified server and opens a session (Filling the Client and Session fields in SshAgent struct).

func (*Endpoint) Disconnect added in v1.0.15

func (s *Endpoint) Disconnect()

Disconnect closes the ssh sessoin and connection.

func (*Endpoint) Run added in v1.0.15

func (s *Endpoint) Run(args ...string) (map[string]string, error)

Run executes the given cli command on the opened session.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL