netconf

package module
v0.0.0-...-c3addfb Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

README

FreeCONF

Add support or configuration, metrics, alerts and management functions to your application!

In this repository

Getting Started

Getting started docs here

Building Requirements

Requires Go version 1.20 or greater.

Getting the source

go get -u github.com/freeconf/netconf

Resources

Documentation

Index

Constants

View Source
const (
	Base_1_1 = "urn:ietf:params:netconf:base:1.1"
)

Variables

View Source
var ErrEOS = errors.New("end of session") // not really an error but linter wants "Err" prefix

ErrEOS signals the session should be closed gracefully.

View Source
var ErrInvalidLogin = errors.New("invalid login")

Functions

func Api

func Api(s *Server) node.Node

func NewChunkedRdr

func NewChunkedRdr(in io.Reader) <-chan io.Reader

NewChunkedRdr reads "chunked" xml messages according to RFC6242 so that individual xml messages can be sent over a ssh stream.

see https://datatracker.ietf.org/doc/html/rfc6242#section-4.1

Chunked message framing example where xxx is replaced with NETCONF messages:

  #4
  xxxx
  #12
  xxxxxxxxxxxx
  ##

This has 2 chunks of sizes 4 and 12 bytes.

func NewChunkedWtr

func NewChunkedWtr(w io.Writer) io.WriteCloser

NewChunkedWtr is the counterpart to NewMsgsRdr

func WriteResponse

func WriteResponse(response any, out io.Writer) error

func WriteResponseWithOptions

func WriteResponseWithOptions(response any, out io.Writer, includeMessageDelim bool, pretty bool) error

Types

type CreateSubscription

type CreateSubscription struct {
	StartTime *time.Time `xml:"startTime,omitempty"`
	StopTime  *time.Time `xml:"stopTime,omitempty"`
	Filter    *RpcFilter `xml:"filter,omitempty"`
	Stream    string     `xml:"stream,omitempty"`
}

type HelloMsg

type HelloMsg struct {
	XMLName      xml.Name `xml:"urn:ietf:params:xml:ns:netconf:base:1.0 hello"`
	Capabilities []*Msg   `xml:"capabilities>capability"`
	SessionId    string   `xml:"session-id,omitempty"`
}

type Msg

type Msg struct {
	XMLName xml.Name
	Attrs   []xml.Attr `xml:",any,attr"`
	Content string     `xml:",chardata"`
	Elems   []*Msg     `xml:",any"`
}

type MsgLeaf

type MsgLeaf struct {
	Attrs   []xml.Attr `xml:",any,attr"`
	Content string     `xml:",chardata"`
}

type NamedStreams

type NamedStreams struct {
	Predefined map[string]string
}

type Notification

type Notification struct {
	XMLName   xml.Name            `xml:"urn:ietf:params:xml:ns:netconf:notification:1.0 notification"`
	EventTime time.Time           `xml:"eventTime"`
	Elems     []*nodeutil.XMLWtr2 `xml:",any"`
}

type Request

type Request struct {
	Hello *HelloMsg
	Rpc   *RpcMsg
	Other *Msg
}

func DecodeRequest

func DecodeRequest(in io.Reader) (*Request, error)

func (Request) String

func (r Request) String() string

func (*Request) UnmarshalXML

func (m *Request) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type RpcCopy

type RpcCopy struct {
	Source *RpcSource `xml:"source,omitempty"`
	Target *Msg       `xml:"target,omitempty"`
}

type RpcData

type RpcData struct {
	Nodes []*nodeutil.XMLWtr2
}

type RpcEdit

type RpcEdit struct {
	Target *Msg `xml:"target,omitempty"`

	// allowed: merge(default), replace, create, delete, remove
	DefaultOperation string `xml:"default-operation,omitempty"`

	// allowed: test-then-set(default), set, test-only
	TestOperation *Msg `xml:"test-operation,omitempty"`

	// allowed: stop-on-error(default), continue-on-error, rollback-on-error
	ErrorOption *Msg `xml:"error-option,omitempty"`

	Config *nodeutil.XmlNode `xml:"config"`
	Elem   *Msg              `xml:",any"`
}

type RpcFilter

type RpcFilter struct {
	Type string `xml:"type,attr"`

	// when Type is "xpath"
	Select string `xml:"select,omitempty"`

	Elems []*Msg `xml:",any"`
	// contains filtered or unexported fields
}

func (*RpcFilter) CompileXPath

func (f *RpcFilter) CompileXPath(d device.Device) (*node.Selection, error)

func (*RpcFilter) UnmarshalXML

func (rf *RpcFilter) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type RpcGet

type RpcGet struct {
	Source *Msg       `xml:"source,omitempty"`
	Filter *RpcFilter `xml:"filter,omitempty"`
}

type RpcMsg

type RpcMsg struct {
	XMLName            xml.Name            `xml:"urn:ietf:params:xml:ns:netconf:base:1.0 rpc"`
	MessageId          string              `xml:"message-id,attr"`
	Attrs              []xml.Attr          `xml:",any,attr"`
	GetConfig          *RpcGet             `xml:"get-config,omitempty"`
	Get                *RpcGet             `xml:"get,omitempty"`
	EditConfig         *RpcEdit            `xml:"edit-config,omitempty"`
	Copy               *RpcCopy            `xml:"copy-config,omitempty"`
	Delete             *RpcEdit            `xml:"delete-config,omitempty"`
	Close              *Msg                `xml:"close-session,omitempty"`
	Kill               *Msg                `xml:"kill-session,omitempty"`
	CreateSubscription *CreateSubscription `xml:"create-subscription,omitempty"`
	Action             *nodeutil.XmlNode   `xml:",any"`
}

type RpcReply

type RpcReply struct {
	XMLName   xml.Name            `xml:"urn:ietf:params:xml:ns:netconf:base:1.0 rpc-reply"`
	MessageId string              `xml:"message-id,attr"`
	OK        *Msg                `xml:"ok,omitempty"`
	Data      *RpcData            `xml:"data,omitempty"`
	Out       []*nodeutil.XMLWtr2 `xml:",any"`
}

type RpcSource

type RpcSource struct {
	Url     *MsgLeaf `xml:"url,omitempty"`
	Content string   `xml:",innerxml"`
}

type Server

type Server struct {
	Ver string
	// contains filtered or unexported fields
}

func NewServer

func NewServer(d *device.Local, streams *estream.Service) *Server

func (*Server) HandleErr

func (s *Server) HandleErr(err error)

func (*Server) NextSessionId

func (s *Server) NextSessionId() int64

func (*Server) StreamService

func (s *Server) StreamService() *estream.Service

type Session

type Session struct {
	Id int64
	// contains filtered or unexported fields
}

func NewSession

func NewSession(mgr SessionManager, user string, dev device.Device, in io.Reader, out io.Writer) *Session

func (*Session) Hello

func (ses *Session) Hello() *HelloMsg

func (*Session) User

func (ses *Session) User() string

type SessionManager

type SessionManager interface {
	NextSessionId() int64
	StreamService() *estream.Service
	HandleErr(err error)
}

type SshHandler

type SshHandler struct {
	Auth secure.Auth
	// contains filtered or unexported fields
}

func NewSshHandler

func NewSshHandler(h SessionManager, dev device.Device) *SshHandler

func (*SshHandler) Apply

func (s *SshHandler) Apply(opts SshOptions) error

func (*SshHandler) Options

func (s *SshHandler) Options() SshOptions

func (*SshHandler) Status

func (s *SshHandler) Status() SshStatus

type SshOptions

type SshOptions struct {
	Port          string
	HostKeyFile   string
	AdminUsername string
	AdminPassword string
	AdminKey      string
}

type SshStatus

type SshStatus struct {
	Running bool
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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