ops

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Configuration Datastores
	RunningCfg     = "running"
	CandidateCfg   = "candidate"
	StartupCfg     = "startup"
	IntendedCfg    = "intended"
	OperationalCfg = "operational"

	// Edit Config Error Options
	StopOnErrorErrOpt     = "stop-on-error"
	ContinueOnErrorErrOpt = "continue-on-error"
	RollbackOnErrorErrOpt = "rollback-on-error"

	// Edit Config Operation Types
	MergeOp   = "merge"
	ReplaceOp = "replace"
	NoneOp    = "none"

	// Edit Config Test Options
	TestThenSetOpt = "test-then-set"
	SetOpt         = "set"
	TestOnlyOpt    = "test-only"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CfgDsOpt

type CfgDsOpt func(*ConfigType)

CfgDsOpt

func DsName

func DsName(name string) CfgDsOpt

func DsURL added in v2.5.0

func DsURL(url string) CfgDsOpt

type CloseSessionReq

type CloseSessionReq struct {
	XMLName xml.Name `xml:"close-session"`
}

type Config

type Config struct {
	XMLName xml.Name `xml:"config"`
	*common.Union
}

type ConfigOption

type ConfigOption func(*EditConfigReq)

ConfigOption defines the configuration to be applied by an edit config operation

func Cfg

func Cfg(cfg interface{}) ConfigOption

func CfgURL added in v2.5.0

func CfgURL(url string) ConfigOption

type ConfigType

type ConfigType struct {
	Type string `xml:",innerxml"`
	URL  string `xml:"url,omitempty"`
}

type CopyConfigReq

type CopyConfigReq struct {
	XMLName xml.Name    `xml:"copy-config"`
	Target  *ConfigType `xml:"target"`
	Source  *ConfigType `xml:"source"`
}

type Data

type Data struct {
	XMLName xml.Name    `xml:"data"`
	Body    interface{} `xml:",any"`
	Content string      `xml:",innerxml"`
}

type DeleteConfigReq

type DeleteConfigReq struct {
	XMLName xml.Name    `xml:"delete-config"`
	Target  *ConfigType `xml:"target"`
}

type DiscardReq

type DiscardReq struct {
	XMLName xml.Name `xml:"discard-changes"`
}

type EditConfigReq

type EditConfigReq struct {
	XMLName          xml.Name    `xml:"edit-config"`
	Target           *ConfigType `xml:"target"`
	ErrorOption      string      `xml:"error-option,omitempty"`
	TestOption       string      `xml:"test-option,omitempty"`
	DefaultOperation string      `xml:"default-operation,omitempty"`
	Config           *Config
	ConfigURL        string `xml:"url,omitempty"`
}

type EditOption

type EditOption func(*EditConfigReq)

EditOption configures an edit config operation.

func DefaultOperation

func DefaultOperation(oper string) EditOption

func ErrorOption

func ErrorOption(opt string) EditOption

func TestOption

func TestOption(opt string) EditOption

type Filter

type Filter struct {
	XMLName xml.Name `xml:"filter"`
	Type    string   `xml:"type,attr"`
	Select  string   `xml:"select,attr,omitempty"`
	*common.Union
}

type GetConfigReq

type GetConfigReq struct {
	XMLName    xml.Name    `xml:"get-config"`
	Source     *ConfigType `xml:"source"`
	Filter     *Filter
	FilterBody string `xml:",innerxml"`
}

type GetReq

type GetReq struct {
	XMLName xml.Name `xml:"get"`
	Filter  *Filter
}

type GetSchema

type GetSchema struct {
	XMLName xml.Name `xml:"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring get-schema"`
	ID      string   `xml:"identifier"`
	Vsn     string   `xml:"version"`
	Fmt     string   `xml:"format"`
}

type KillSessionReq

type KillSessionReq struct {
	XMLName xml.Name `xml:"kill-session"`
	ID      uint64   `xml:"session-id"`
}

type LockReq

type LockReq struct {
	XMLName xml.Name    `xml:"lock"`
	Target  *ConfigType `xml:"target"`
}

type Namespace

type Namespace struct {
	ID   string
	Path string
}

type NetconfState

type NetconfState struct {
	XMLName xml.Name `xml:"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring netconf-state"`
	Xmlns   string   `xml:"xmlns,attr"`
	Schemas struct {
		Schema []Schema `xml:"schema"`
	} `xml:"schemas"`
	Capabilities struct {
		Text       string   `xml:",chardata"`
		Capability []string `xml:"capability"`
	} `xml:"capabilities"`
	Statistics struct {
		Text             string `xml:",chardata"`
		NetconfStartTime string `xml:"netconf-start-time"`
		InBadHellos      string `xml:"in-bad-hellos"`
		InSessions       string `xml:"in-sessions"`
		DroppedSessions  string `xml:"dropped-sessions"`
		InRpcs           string `xml:"in-rpcs"`
		InBadRpcs        string `xml:"in-bad-rpcs"`
		OutRPCErrors     string `xml:"out-rpc-errors"`
		OutNotifications string `xml:"out-notifications"`
	} `xml:"statistics"`
	Sessions struct {
		Text    string `xml:",chardata"`
		Session struct {
			Text             string `xml:",chardata"`
			SessionID        string `xml:"session-id"`
			Transport        string `xml:"transport"`
			Username         string `xml:"username"`
			SourceHost       string `xml:"source-host"`
			LoginTime        string `xml:"login-time"`
			InRpcs           string `xml:"in-rpcs"`
			InBadRpcs        string `xml:"in-bad-rpcs"`
			OutRPCErrors     string `xml:"out-rpc-errors"`
			OutNotifications string `xml:"out-notifications"`
		} `xml:"session"`
	} `xml:"sessions"`
}

type OpSession

type OpSession interface {
	client.Session

	// GetSubtree issues a GET request, with the supplied subtree filter and stores the response in the result, which
	// should be the address of either:
	// - a string, in which case it will hold the response body, or
	// - a struct with xml tags.
	GetSubtree(filter interface{}, result interface{}) error

	// GetXpath issues a GET request, with the supplied xpath filter and namespace list and stores the response in the result, which
	// should be the address of either:
	// - a string, in which case it will hold the response body, or
	// - a struct with xml tags.
	GetXpath(xpath string, nslist []Namespace, result interface{}) error

	// GetConfigSubtree issues a GET-CONFIG request, with the supplied subtree filter and source, and stores the
	// response in the result, which should be the address of either:
	// - a string, in which case it will hold the response body, or
	// - a struct with xml tags.
	GetConfigSubtree(filter interface{}, source string, result interface{}) error

	// GetConfigXpath issues a GET-CONFIG request, with the supplied xpath filter, source and namespace list and stores the
	// response in the result, which should be the address of either:
	// - a string, in which case it will hold the response body, or
	// - a struct with xml tags.
	GetConfigXpath(xpath string, nslist []Namespace, source string, result interface{}) error

	// GetSchemas returns an array of schemas supported by the device.
	GetSchemas() ([]Schema, error)

	// GetSchema returns the text of the schema identified by id and version, in the format defined by fmt.
	GetSchema(id, version, fmt string) (string, error)

	// EditConfig issues an edit-config request defined by config to be applied to the target configuration.
	// EditOptions can be added to qualify the operation.
	// config will be defined by a ConfigOption, which can be one of:
	// - Cfg(cfg), where cfg is
	//   o   an xml string, in which case it will be used verbatim as the content of the <config> element.
	//   o   a struct with xml tags that will be marshalled as the child of the <config> element.
	// - CfgURL(url), in which case the configuration is defined by a <url> element.
	EditConfig(target string, config ConfigOption, options ...EditOption) error

	// EditConfigCfg issues an edit-config request defined by config to be applied to the target configuration.
	// EditOptions can be added to qualify the operation.
	// Convenience method to avoid complications with function arguments when using EditConfig() with a mock object
	EditConfigCfg(target string, config interface{}, options ...EditOption) error

	// CopyConfig issues a copy-config request.
	// source and target are defined by a CfgDsOpt, which can be one of:
	// - DsName(name) where name defines the configuration data store name (Running, Candidate ...)
	// - DsURL(url) where url defines the url of the datastore
	CopyConfig(source, target CfgDsOpt) error

	// DeleteConfig issues a delete-config request.
	// target is defined by a CfgDsOpt, which can be one of:
	// - DsName(name) where name defines the configuration data store name (Running, Candidate ...)
	// - DsURL(url) where url defines the url of the datastore to be deleted
	DeleteConfig(target CfgDsOpt) error

	// Lock issues a lock request on the target configuration.
	Lock(target string) error

	// Unlock issues an unlock request on the target configuration.
	Unlock(target string) error

	// Discard issues a discard changes request.
	Discard() error

	// CloseSession issues a close session request.
	CloseSession() error

	// KillSession issues a kill session request for the specified session id.
	KillSession(id uint64) error
}

OpSession represents a Netconf Operations OpSession

func NewSession

func NewSession(ctx context.Context, sshcfg *ssh.ClientConfig, target string) (s OpSession, err error)

NewSession connects to the target using the ssh configuration, and establishes a netconf session with default configuration.

func NewSessionWithConfig

func NewSessionWithConfig(ctx context.Context, sshcfg *ssh.ClientConfig, target string, cfg *client.Config) (s OpSession, err error)

NewSessionWithConfig connects to the target using the ssh configuration, and establishes a netconf session with the client configuration.

type Schema

type Schema struct {
	Identifier string `xml:"identifier"`
	Version    string `xml:"version"`
	Format     string `xml:"format"`
	Namespace  string `xml:"namespace"`
	Location   string `xml:"location"`
}

type UnlockReq

type UnlockReq struct {
	XMLName xml.Name    `xml:"unlock"`
	Target  *ConfigType `xml:"target"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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