netconf

package module
v2.0.0-...-459835f Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: BSD-2-Clause-Views Imports: 9 Imported by: 0

README

Go netconf client library

WARNING: This is currently pre-alpha quality. The API isn't solid yet and a lot of testing still needs to be done as well as additional feaures.

GoDoc Report Card

This library is used to create client applications for connecting to network devices via NETCONF.

Support

RFC Support
RFC6241 Network Configuration Protocol (NETCONF) 🚧 inprogress
RFC6242 Using the NETCONF Protocol over Secure Shell (SSH)
RFC7589 Using the NETCONF Protocol over Transport Layer Security (TLS)
RFC5277 NETCONF Event Notifications planned
RFC5717 Partial Lock Remote Procedure Call (RPC) for NETCONF planned
RFC6243 With-defaults Capability for NETCONF maybe
RFC4743 Using NETCONF over the Simple Object Access Protocol (SOAP) not planned
RFC4744 Using the NETCONF Protocol over the BEEP not planned

There are other RFC around YANG integration that will be looked at later.

See TODO.md for a list of what is left to implement these features.

Differences from github.com/juniper/go-netconf/netconf

  • Much cleaner, idomatic API, less dumb I, @nemith, was the original creator of the netconf package and it was my very first Go project and it shows. There are number of questionable API design, code, and a lot of odd un tested bugs. Really this rewrite was created to fix this.
  • No impled vendor ownership Moving the project out of the Juniper organization allowes better control over the project, less implied support (or lack there of), and hopefully more contributions.
  • Transports are implemented in their own packages. This means if you are not using SSH or TLS you don't need to bring in the underlying depdendencies into your binary.
  • Stream based transports. Should mean less memory usage and much less allocation bringing overall performance higher.

Differences from github.com/scrapli/scrapligo/driver/netconf

Scrapligo driver is quite good and way better than the original juniper project. However this new package concentrates more on RFC correctness and implementing some of the more advanced RFC features like call-home and event notifications. If there is a desire there could be some callaboration with scrapligo in the future.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCapabilities = []string{
	"urn:ietf:params:netconf:base:1.0",
	"urn:ietf:params:netconf:base:1.1",
}

DefaultCapabilties are the capabilties sent by the client during the hello exchange by the server.

Functions

func ExpandCapability

func ExpandCapability(s string) string

ExpandCapability will automatically add the standard capability prefix of `urn:ietf:params:netconf:capability` if not already present.

Types

type Capability

type Capability string

type ErrSeverity

type ErrSeverity string
const (
	SevError   ErrSeverity = "error"
	SevWarning ErrSeverity = "warning"
)

type ErrType

type ErrType string
const (
	ErrTypeTrans ErrType = "transport"
	ErrTypeRPC   ErrType = "rpc"
	ErrTypeProto ErrType = "protocol"
	ErrTypeApp   ErrType = "app"
)
const ErrTypeTransport ErrType = "transport"

type Filter

type Filter struct {
	XMLName xml.Name `xml:"filter"`
	Type    xml.Attr `xml:"type"`
}

type GetConfig

type GetConfig struct {
	XMLName xml.Name   `xml:"get-config"`
	Source  StringElem `xml:"source"`
	Filter  *Filter    `xml:"filter,omitempty"`
}

type GetConfigRPC

type GetConfigRPC struct {
	Source StringElem
	Filter Filter
}

XXX: RPC calls these either Methods or Operations depending on what you look at.

type GetConfigResp

type GetConfigResp struct {
}

type HelloMsg

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

helloMsg maps the xml value of the <hello> message in RFC6241

type NotificationMsg

type NotificationMsg struct {
	XMLName   xml.Name  `xml:"urn:ietf:params:xml:ns:netconf:notification:1.0 notification"`
	EventTime time.Time `xml:"eventTime"`
	Data      []byte    `xml:",innerxml"`
}

type OKResponse

type OKResponse struct {
	Ok SentinalBool `xml:"ok"`
}

type RPCError

type RPCError struct {
	Type     string      `xml:"error-type"`
	Tag      string      `xml:"error-tag"`
	Severity ErrSeverity `xml:"error-severity"`
	AppTag   string      `xml:"error-app-tag,omitempty"`
	Path     string      `xml:"error-path,omitempty"`
	Message  string      `xml:"error-message,omitempty"`
	Info     interface{} `xml:"error-info,omitempty"`
}

func (RPCError) Error

func (e RPCError) Error() string

type RPCMsg

type RPCMsg struct {
	XMLName   xml.Name    `xml:"urn:ietf:params:xml:ns:netconf:base:1.0 rpc"`
	MessageID uint64      `xml:"message-id,attr"`
	Operation interface{} `xml:",innerxml"`
}

rpcMsg maps the xml value of <rpc> in RFC6241

type RPCReplyMsg

type RPCReplyMsg struct {
	XMLName   xml.Name `xml:"urn:ietf:params:xml:ns:netconf:base:1.0 rpc-reply"`
	MessageID uint64   `xml:"message-id,attr"`

	Errors []RPCError `xml:"rpc-error,omitempty"`
	Data   []byte     `xml:",innerxml"`
}

rpcReplyMsg maps the xml value of <rpc-reply> in RFC6241

type SentinalBool

type SentinalBool bool

func (SentinalBool) MarshalXML

func (b SentinalBool) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*SentinalBool) UnmarshalXML

func (b *SentinalBool) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Session

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

Session is represents a netconf session to a one given device.

func Open

func Open(transport transport.Transport, opts ...SessionOption) (*Session, error)

Open will create a new Session with th=e given transport and open it with the nessesary hello messages.

func (*Session) Call

func (s *Session) Call(ctx context.Context, op interface{}, resp interface{}) error

Call issues a rpc call for the given NETCONF operation and unmashaling the respose into `resp`.

func (*Session) ClientCapabilities

func (s *Session) ClientCapabilities() []string

ClientCapabilties will return the capabilities initialized with the session.

func (*Session) Close

func (s *Session) Close(ctx context.Context) error

Close will gracefully close the sessions first by sending a `close-session` operation to the remote and then closing the underlying transport

func (*Session) Do

func (s *Session) Do(ctx context.Context, msg *RPCMsg) (*RPCReplyMsg, error)

Do issues a low level RPC call taking in a full RPCMsg and returning the full RPCReplyMsg. In most cases `Session.Call` will do what you want handling errors and marshaling/unmarshaling your data.`

func (*Session) GetConfig

func (s *Session) GetConfig(ctx context.Context, source string) ([]byte, error)

func (*Session) ServerCapabilities

func (s *Session) ServerCapabilities() []string

ServcerCapabilties will return the capabilities returned by the server in it's hello message.

func (*Session) SessionID

func (s *Session) SessionID() uint64

SessionID returns the current session ID exchanged in the hello messages. Will return 0 if there is no session ID.

type SessionOption

type SessionOption interface {
	// contains filtered or unexported methods
}

func WithCapability

func WithCapability(capabilities ...string) SessionOption

type StringElem

type StringElem string

func (StringElem) MarshalXML

func (s StringElem) MarshalXML(e *xml.Encoder, start xml.StartElement) error

Directories

Path Synopsis
examples
ssh
tls
ssh
tls

Jump to

Keyboard shortcuts

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