devcon

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: MIT Imports: 6 Imported by: 0

README

Devcon

A simple package to ssh into devices.

Overview

A client can only have 1 session at a time. Hence, we cannot include the session info in the factory function. Doing so would cause all subsequent calls to fail.

Usage

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/montybeatnik/devcon"
)

func main() {
	un := os.Getenv("SSH_USER")
	pw := os.Getenv("SSH_PASSWORD")
	ip := "10.0.0.60"
	client, err := devcon.NewClient(un, pw, ip)
	if err != nil {
		log.Println("client setup failed", err)
		os.Exit(42)
	}
	output, err := client.RunCommand("show version")
	if err != nil {
		log.Println("command failed", err)
		os.Exit(42)
	}
	fmt.Println(output)
}

TODO

  • Pull the client bits out of RunCommand and pull that logic into the Factory function

Profile

  • go test -v -run Run -cpuprofile cpu.prof -memprofile mem.prof -bench .

Testing

Unit tests
All tests

go test -v

A specific test

go test -v -run RunCommand

Specific tests matching a pattern

go test -v -run Run

Benchmarks

go test -run RunCommand -bench=.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SSHClient added in v0.2.1

type SSHClient struct {
	// contains filtered or unexported fields
}

SSHClient holds the elements to setup an SSH client

func NewClient

func NewClient(un, pw, ip string, args ...string) *SSHClient

NewClient is a factory function that takes in SSH parameters and returns a new client

func (*SSHClient) Run added in v0.3.0

func (c *SSHClient) Run(cmd string) (string, error)

Run takes in a command and attempts to establishe a remote session and run the command.

func (*SSHClient) RunAll added in v0.3.0

func (c *SSHClient) RunAll(cmds ...string) (string, error)

RunAll takes in one or more commands. It establishes a remote session with the target IP and attempts to run all of the commands supplied. You must remember to exit as this method does establish an interactive session.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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