Documentation ¶
Index ¶
- Variables
- func SSHConfigPubKeyFile(user string, file string, passphrase string) (*ssh.ClientConfig, error)
- func SplitChunked(endOfMessage func()) bufio.SplitFunc
- type Callback
- type Dispatcher
- type Event
- type EventType
- type ReadWriteCloser
- type Session
- func (session *Session) AsyncRPC(operation message.RPCMethod, callback Callback) error
- func (session *Session) Close() error
- func (session *Session) CreateNotificationStream(timeout int32, stopTime string, startTime string, stream string, ...) error
- func (session *Session) ReceiveHello() (*message.Hello, error)
- func (session *Session) SendHello(hello *message.Hello) error
- func (session *Session) SyncRPC(operation message.RPCMethod, timeout int32) (*message.RPCReply, error)
- type Transport
- type TransportSSH
- func (t *TransportSSH) Chunked(b []byte) ([]byte, error)
- func (t *TransportSSH) Close() error
- func (t *TransportSSH) Dial(target string, config *ssh.ClientConfig) error
- func (t *TransportSSH) Receive() ([]byte, error)
- func (t *TransportSSH) Send(data []byte) error
- func (t *TransportSSH) SetVersion(version string)
- func (t *TransportSSH) WaitForBytes(b []byte) ([]byte, error)
- func (t *TransportSSH) WaitForFunc(f func([]byte) (int, error)) ([]byte, error)
- func (t *TransportSSH) WaitForRegexp(re *regexp.Regexp) ([]byte, [][]byte, error)
- func (t *TransportSSH) WaitForString(s string) (string, error)
- func (t *TransportSSH) Writeln(b []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
var DefaultCapabilities = []string{ message.NetconfVersion10, message.NetconfVersion11, }
DefaultCapabilities sets the default capabilities of the client library
var ErrBadChunk = errors.New("bad chunk")
ErrBadChunk indicates a chunked framing protocol error occurred
Functions ¶
func SSHConfigPubKeyFile ¶
SSHConfigPubKeyFile is a convenience function that takes a username, private key and passphrase and returns a new ssh.ClientConfig setup to pass credentials to DialSSH
func SplitChunked ¶
SplitChunked returns a bufio.SplitFunc suitable for decoding "chunked framing" NETCONF transport streams.
endOfMessage will be called at the end of each NETCONF message, and must not be nil.
It must only be used with bufio.Scanner who have a buffer of at least 16 bytes (rarely is this a concern).
Types ¶
type Callback ¶ added in v1.2.0
type Callback func(Event)
Callback is a function that can receive events.
type Dispatcher ¶ added in v1.2.0
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher objects can register callbacks for specific events, then when those events occur, dispatch them its according callback functions.
func (*Dispatcher) Dispatch ¶ added in v1.2.0
func (d *Dispatcher) Dispatch(eventID string, eventType EventType, value interface{})
Dispatch an event by triggering its associated callback.
func (*Dispatcher) Register ¶ added in v1.2.0
func (d *Dispatcher) Register(eventID string, callback Callback)
Register a callback function for the specified eventID.
func (*Dispatcher) Remove ¶ added in v1.2.0
func (d *Dispatcher) Remove(eventID string)
Remove a callback function for the specified eventID.
func (*Dispatcher) WaitForMessages ¶ added in v1.2.0
func (d *Dispatcher) WaitForMessages()
WaitForMessages waits for all messages in the queue to be processed TODO support timeout
type Event ¶ added in v1.2.0
type Event interface { EventID() string Value() interface{} RPCReply() *message.RPCReply Notification() *message.Notification }
Event represents actions that occur during NETCONF exchange. Listeners can register callbacks with event handlers when creating a new RPC.
type EventType ¶ added in v1.2.0
type EventType uint16
EventType is an enumeration of the kind of events that can occur.
type ReadWriteCloser ¶
type ReadWriteCloser struct { io.Reader io.WriteCloser }
ReadWriteCloser represents a combined IO Reader and WriteCloser
func NewReadWriteCloser ¶
func NewReadWriteCloser(r io.Reader, w io.WriteCloser) *ReadWriteCloser
NewReadWriteCloser creates a new combined IO Reader and WriteCloser from the provided objects
type Session ¶
type Session struct { Transport Transport SessionID int Capabilities []string IsClosed bool Listener *Dispatcher IsNotificationStreamCreated bool }
Session represents a NETCONF sessions with a remote NETCONF server
func DialSSH ¶
func DialSSH(target string, config *ssh.ClientConfig) (*Session, error)
DialSSH creates a new NETCONF session using an SSH Transport. See TransportSSH.Dial for arguments.
func DialSSHTimeout ¶
func DialSSHTimeout(target string, config *ssh.ClientConfig, timeout time.Duration) (*Session, error)
DialSSHTimeout creates a new NETCONF session using an SSH Transport with timeout. See TransportSSH.Dial for arguments. The timeout value is used for both connection establishment and Read/Write operations.
func NewSession ¶
NewSession creates a new NETCONF session using the provided transport layer.
func (*Session) AsyncRPC ¶ added in v1.2.0
AsyncRPC is used to send an RPC method and receive the response asynchronously.
func (*Session) CreateNotificationStream ¶ added in v1.2.0
func (session *Session) CreateNotificationStream( timeout int32, stopTime string, startTime string, stream string, callback Callback, ) error
CreateNotificationStream is a convenient method to create a notification stream registration. TODO limitation - for now, we can only register one stream per session, because when a notification is received there is no way to attribute it to a specific stream
func (*Session) ReceiveHello ¶ added in v1.1.1
ReceiveHello is the first message received when connecting to a NETCONF server. It provides the supported capabilities of the server.
type Transport ¶
type Transport interface { Send([]byte) error Receive() ([]byte, error) Close() error SetVersion(version string) }
Transport interface defines what characteristics make up a NETCONF transport layer object.
type TransportSSH ¶
type TransportSSH struct {
// contains filtered or unexported fields
}
TransportSSH maintains the information necessary to communicate with the remote device over SSH
func (*TransportSSH) Close ¶
func (t *TransportSSH) Close() error
Close closes an existing SSH session and socket if they exist.
func (*TransportSSH) Dial ¶
func (t *TransportSSH) Dial(target string, config *ssh.ClientConfig) error
Dial connects and establishes SSH sessions
target can be an IP address (e.g.) 172.16.1.1 which utilizes the default NETCONF over SSH port of 830. Target can also specify a port with the following format <host>:<port (e.g. 172.16.1.1:22)
config takes a ssh.ClientConfig connection. See documentation for go.crypto/ssh for documentation. There is a helper function SSHConfigPassword thar returns a ssh.ClientConfig for simple username/password authentication
func (*TransportSSH) Send ¶
Send a well formatted NETCONF rpc message as a slice of bytes adding on the necessary framing messages.
func (*TransportSSH) SetVersion ¶
func (t *TransportSSH) SetVersion(version string)