scrapligocfg

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: MIT Imports: 13 Imported by: 8

README

Go Report


Source Code: https://github.com/scrapli/scrapligocfg


scrapligocfg makes merging or replacing device configurations over Telnet or SSH easy, all while giving you the scrapli behaviour you know and love.

Please check out the Python version README/docs here for more info about the behavior of scrapligocfg (hint: It's pretty much the same as the Python version!).

Documentation

Index

Constants

View Source
const (
	// CiscoIOSXE is the Cisco IOS-XE scrapligocfg platform type.
	CiscoIOSXE = "cisco_iosxe"
	// CiscoNXOS is the Cisco NX-OS scrapligocfg platform type.
	CiscoNXOS = "cisco_nxos"
	// CiscoIOSXR is the Cisco IOS-XR scrapligocfg platform type.
	CiscoIOSXR = "cisco_iosxr"
	// AristaEOS is the Arista EOS scrapligocfg platform type.
	AristaEOS = "arista_eos"
	// JuniperJUNOS is the Juniper JunOS scrapligocfg platform type.
	JuniperJUNOS = "juniper_junos"
)
View Source
const (
	// GetVersion is the name of the get version operation.
	GetVersion = "GetVersion"
	// GetConfig is the name of the get config operation.
	GetConfig = "GetConfig"
	// LoadConfig is the name of the load config operation.
	LoadConfig = "LoadConfig"
	// CommitConfig is the name of the commit config operation.
	CommitConfig = "CommitConfig"
	// AbortConfig is the name of the abort config operation.
	AbortConfig = "AbortConfig"
)

Variables

This section is empty.

Functions

func SupportedPlatforms

func SupportedPlatforms() []string

SupportedPlatforms returns a slice of all available supported "cfg" platforms.

func WithCandidateName

func WithCandidateName(s string) util.Option

WithCandidateName sets a preferred candidate configuration name.

func WithCandidateTimestamp

func WithCandidateTimestamp() util.Option

WithCandidateTimestamp enables appending a unix timestamp to the candidate configuration name.

func WithDedicated

func WithDedicated() util.Option

WithDedicated sets the Dedicated option -- this options means that scrapligocfg can safely assume that the scrapligo connection is "dedicated" to the scrapligocfg object, and it can be opened and closed (rather than left open for subsequent use).

func WithDefaultLogger

func WithDefaultLogger() util.Option

WithDefaultLogger applies the default logging setup to a driver object. This means log.Print for the logger function, and "info" for the log level.

func WithDiffColorize

func WithDiffColorize() util.Option

WithDiffColorize sets the diff colorization to true.

func WithDiffSideBySideW

func WithDiffSideBySideW(i int) util.Option

WithDiffSideBySideW sets the character width for each column in side-by-side diffs.

func WithFilesystem

func WithFilesystem(s string) util.Option

WithFilesystem sets the filesystem to write candidate configurations to for those platforms that implement WriteToFSPlatform.

func WithFilesystemSpaceAvailBuffPerc

func WithFilesystemSpaceAvailBuffPerc(f float32) util.Option

WithFilesystemSpaceAvailBuffPerc sets the filesystem space buffer percent -- or the amount of "wiggle room" to leave in a filesystem when determining available space. This is only applicable for platforms that satisfy WriteToFSPlatform.

func WithLogger

func WithLogger(l *logging.Instance) util.Option

WithLogger accepts a logging.Instance and applies it to the driver object.

func WithOnPrepare

func WithOnPrepare(f func(*network.Driver) error) util.Option

WithOnPrepare sets an "OnPrepare" function that will be executed during the "prepare" phase.

Types

type Cfg

type Cfg struct {
	Logger *logging.Instance

	Impl Platform
	Conn *network.Driver

	OnPrepare func(*network.Driver) error

	Dedicated bool

	Candidate          string
	CandidateName      string
	CandidateTimestamp bool
	// contains filtered or unexported fields
}

Cfg is the primary point of interaction for scrapligocfg users -- this struct wraps the target Platform implementation and provides a consistent look and feel for users regardless of the underlying device type.

func NewCfg

func NewCfg(conn *network.Driver, platform string, opts ...util.Option) (*Cfg, error)

NewCfg returns an instance of Cfg for the provided platform type.

func (*Cfg) AbortConfig

func (c *Cfg) AbortConfig() (*response.Response, error)

AbortConfig aborts a loaded candidate configuration.

func (*Cfg) Cleanup

func (c *Cfg) Cleanup() error

Cleanup executes the Platform implementations Cleanup method and closes the scrapligo Conn.

func (*Cfg) CommitConfig

func (c *Cfg) CommitConfig() (*response.Response, error)

CommitConfig commits a loaded candidate configuration.

func (*Cfg) DiffConfig

func (c *Cfg) DiffConfig(source string, opts ...util.Option) (*response.DiffResponse, error)

DiffConfig diffs the requested `source` config with the candidate config. Supports `WithDiff` options to modify the DiffResponse behavior.

func (*Cfg) GetConfig

func (c *Cfg) GetConfig(source string) (*response.Response, error)

GetConfig fetches the source configuration from the target device -- the source is usually one of 'running', 'startup', or 'candidate', but valid options may vary from platform to platform.

func (*Cfg) GetVersion

func (c *Cfg) GetVersion() (*response.Response, error)

GetVersion captures target device version information and stores it in the response.Response.

func (*Cfg) LoadConfig

func (c *Cfg) LoadConfig(
	config string,
	replace bool,
	opts ...util.Option,
) (*response.Response, error)

LoadConfig loads a candidate configuration 'config' onto the target device. The replace argument is required -- when set to 'true' this means that scrapligocfg will load the provided candidate config in "replace" mode, which, when "committed" will fully replace the devices target config. If replace is false, the configuration will be loaded as a "merge" mode.

func (*Cfg) LoadConfigFromFile

func (c *Cfg) LoadConfigFromFile(
	f string,
	replace bool,
	opts ...util.Option,
) (*response.Response, error)

LoadConfigFromFile is a convenience method wrapping LoadConfig -- this method accepts a filepath which will be read and passed to LoadConfig.

func (*Cfg) Prepare

func (c *Cfg) Prepare() error

Prepare opens the scrapligo Conn object and executes the optional OnPrepare function.

type Platform

type Platform interface {
	GetVersion() (*response.PlatformResponse, error)
	GetConfig(source string) (*response.PlatformResponse, error)
	LoadConfig(
		f, config string,
		replace bool,
		options *util.OperationOptions,
	) (*response.PlatformResponse, error)
	AbortConfig() (*response.PlatformResponse, error)
	CommitConfig() (*response.PlatformResponse, error)
	GetDeviceDiff(source string) (*response.PlatformResponse, error)
	NormalizeConfig(config string) string
	Cleanup() error
}

Platform defines the required methods that a scrapligocfg "platform" needs to implement.

type WriteToFSPlatform

type WriteToFSPlatform interface {
	Platform
	SetFilesystem(s string)
	SetSpaceAvailBuffPerc(f float32)
}

WriteToFSPlatform defines additional Platform methods for those platforms that have candidate configurations written to the filesystem.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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