Documentation ¶
Index ¶
- Variables
- func WithClientTrace(ctx context.Context, trace *ClientTrace) context.Context
- type ClientTrace
- type Config
- type RealDialer
- type SSHClientFactory
- type Session
- func NewRPCSession(ctx context.Context, sshcfg *ssh.ClientConfig, target string) (s Session, err error)
- func NewRPCSessionFromSSHClient(ctx context.Context, client *ssh.Client) (s Session, err error)
- func NewRPCSessionFromSSHClientWithConfig(ctx context.Context, client *ssh.Client, cfg *Config) (s Session, err error)
- func NewRPCSessionWithConfig(ctx context.Context, sshcfg *ssh.ClientConfig, target string, cfg *Config) (s Session, err error)
- func NewSession(ctx context.Context, t Transport, cfg *Config) (Session, error)
- type Transport
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = &Config{ SetupTimeoutSecs: 5, DisableChunkedCodec: false, }
var DefaultLoggingHooks = &ClientTrace{ Error: func(context, target string, err error) { log.Printf("NETCONF-Error context:%s target:%s err:%v\n", context, target, err) }, }
DefaultLoggingHooks provides a default logging hook to report errors.
var DiagnosticLoggingHooks = &ClientTrace{ ConnectStart: func(target string) { log.Printf("NETCONF-ConnectStart target:%s\n", target) }, ConnectDone: MetricLoggingHooks.ConnectDone, DialStart: func(clientConfig *ssh.ClientConfig, target string) { log.Printf("NETCONF-DialStart target:%s config:%v\n", target, clientConfig) }, DialDone: MetricLoggingHooks.DialDone, ConnectionClosed: func(target string, err error) { log.Printf("NETCONF-ConnectionClosed target:%s err:%v\n", target, err) }, ReadStart: func(p []byte) { log.Printf("NETCONF-ReadStart capacity:%d\n", len(p)) }, ReadDone: MetricLoggingHooks.ReadDone, WriteStart: func(p []byte) { log.Printf("NETCONF-WriteStart len:%d\n", len(p)) }, WriteDone: MetricLoggingHooks.WriteDone, Error: DefaultLoggingHooks.Error, NotificationReceived: func(n *common.Notification) { log.Printf("NETCONF-NotificationReceived %s\n", n.XMLName.Local) }, NotificationDropped: func(n *common.Notification) { log.Printf("NETCONF-NotificationDropped %s\n", n.XMLName.Local) }, ExecuteStart: func(req common.Request, async bool) { log.Printf("NETCONF-ExecuteStart async:%v req:%s\n", async, req) }, ExecuteDone: func(req common.Request, async bool, res *common.RPCReply, err error, d time.Duration) { log.Printf("NETCONF-ExecuteDone async:%v req:%s err:%v took:%dms\n", async, req, err, d.Milliseconds()) }, }
DiagnosticLoggingHooks provides a set of default diagnostic hooks
var MetricLoggingHooks = &ClientTrace{ ConnectDone: func(target string, err error, d time.Duration) { log.Printf("NETCONF-ConnectDone target:%s err:%v took:%dms\n", target, err, d.Milliseconds()) }, DialDone: func(clientConfig *ssh.ClientConfig, target string, err error, d time.Duration) { log.Printf("NETCONF-DialDone target:%s config:%v err:%v took:%dms\n", target, clientConfig, err, d.Milliseconds()) }, ReadDone: func(p []byte, c int, err error, d time.Duration) { log.Printf("NETCONF-ReadDone len:%d err:%v took:%dms\n", c, err, d.Milliseconds()) }, WriteDone: func(p []byte, c int, err error, d time.Duration) { log.Printf("NETCONF-WriteDone len:%d err:%v took:%dms\n", c, err, d.Milliseconds()) }, Error: DefaultLoggingHooks.Error, ExecuteDone: func(req common.Request, async bool, res *common.RPCReply, err error, d time.Duration) { log.Printf("NETCONF-ExecuteDone async:%v err:%v took:%dms\n", async, err, d.Milliseconds()) }, }
MetricLoggingHooks provides a set of hooks that will log network metrics.
var NoOpLoggingHooks = &ClientTrace{ ConnectStart: func(target string) {}, ConnectDone: func(target string, err error, d time.Duration) {}, DialStart: func(clientConfig *ssh.ClientConfig, target string) {}, DialDone: func(clientConfig *ssh.ClientConfig, target string, err error, d time.Duration) {}, ConnectionClosed: func(target string, err error) {}, HelloDone: func(msg *common.HelloMessage) {}, ReadStart: func(p []byte) {}, ReadDone: func(p []byte, c int, err error, d time.Duration) {}, WriteStart: func(p []byte) {}, WriteDone: func(p []byte, c int, err error, d time.Duration) {}, Error: func(context, target string, err error) {}, NotificationReceived: func(n *common.Notification) {}, NotificationDropped: func(n *common.Notification) {}, ExecuteStart: func(req common.Request, async bool) {}, ExecuteDone: func(req common.Request, async bool, res *common.RPCReply, err error, d time.Duration) {}, }
NoOpLoggingHooks provides set of hooks that do nothing.
Functions ¶
func WithClientTrace ¶
func WithClientTrace(ctx context.Context, trace *ClientTrace) context.Context
WithClientTrace returns a new context based on the provided parent ctx. Netconf client requests made with the returned context will use the provided trace hooks
Types ¶
type ClientTrace ¶
type ClientTrace struct { // ConnectStart is called when starting to create a netconf connection to a remote server. ConnectStart func(target string) // ConnectDone is called when the transport connection attempt completes, with err indicating // whether it was successful. ConnectDone func(target string, err error, d time.Duration) // DialStart is called when starting to dial a remote server. DialStart func(clientConfig *ssh.ClientConfig, target string) // DialDone is called when dial completes. DialDone func(clientConfig *ssh.ClientConfig, target string, err error, d time.Duration) // HelloDone is called when the hello message has been received from the server. HelloDone func(msg *common.HelloMessage) // ConnectionClosed is called after a transport connection has been closed, with // err indicating any error condition. ConnectionClosed func(target string, err error) // ReadStart is called before a read from the underlying transport. ReadStart func(buf []byte) // ReadDone is called after a read from the underlying transport. ReadDone func(buf []byte, c int, err error, d time.Duration) // WriteStart is called before a write to the underlying transport. WriteStart func(buf []byte) // WriteDone is called after a write to the underlying transport. WriteDone func(buf []byte, c int, err error, d time.Duration) // Error is called after an error condition has been detected. Error func(context, target string, err error) // NotificationReceived is called when a notification has been received. NotificationReceived func(m *common.Notification) // NotificationDropped is called when a notification is dropped because the reader is not ready. NotificationDropped func(m *common.Notification) // ExecuteStart is called before the execution of an rpc request. ExecuteStart func(req common.Request, async bool) // ExecuteDone is called after the execution of an rpc request. ExecuteDone func(req common.Request, async bool, res *common.RPCReply, err error, d time.Duration) }
func ContextClientTrace ¶
func ContextClientTrace(ctx context.Context) *ClientTrace
ContextClientTrace returns the Trace associated with the provided context. If none, it returns nil.
type Config ¶
type Config struct { // Defines the time in seconds that the client will wait to receive a hello message from the server. SetupTimeoutSecs int // Indicates that the client should not advertised chunked encoding capability. DisableChunkedCodec bool }
Config defines properties that configure netconf session behaviour.
type RealDialer ¶ added in v2.7.0
type RealDialer struct {
// contains filtered or unexported fields
}
func NewDialer ¶ added in v2.6.0
func NewDialer(target string, clientConfig *ssh.ClientConfig) *RealDialer
type SSHClientFactory ¶ added in v2.6.0
type SSHClientFactory interface { Dial(ctx context.Context) (*ssh.Client, error) // Close will close the client (assumed to have been returned by an earlier call to the Dial method), if // appropriate. Close(*ssh.Client) error }
SSHClientFactory defines a factory that provides an SSH client.
type Session ¶
type Session interface { // Execute executes an RPC request on the server and returns the reply. Execute(req common.Request) (*common.RPCReply, error) // ExecuteAsync submits an RPC request for execution on the server, arranging for the // reply to be sent to the supplied channel. ExecuteAsync(req common.Request, rchan chan *common.RPCReply) (err error) // Subscribe issues an RPC request and returns the reply. If successful, notifications will // be sent to the supplied channel. Subscribe(req common.Request, nchan chan *common.Notification) (reply *common.RPCReply, err error) // Close closes the session and releases any associated resources. // The channel will be automatically closed if the underlying network connection is closed, for // example if the remote server discoonects. // When the session is closed, any outstanding execute requests and reads from a notification // channel will return nil. Close() // ID delivers the server-allocated id of the session. ID() uint64 // Capabilities delivers the server-supplied capabilities. ServerCapabilities() []string }
Session represents a Netconf Session
func NewRPCSession ¶
func NewRPCSession(ctx context.Context, sshcfg *ssh.ClientConfig, target string) (s Session, err error)
NewRPCSession connects to the target using the ssh configuration, and establishes a netconf session with default configuration.
func NewRPCSessionFromSSHClient ¶ added in v2.6.0
NewRPCSessionFromSSHClient establishes a netconf session over the given ssh Client with default configuration.
func NewRPCSessionFromSSHClientWithConfig ¶ added in v2.6.0
func NewRPCSessionFromSSHClientWithConfig(ctx context.Context, client *ssh.Client, cfg *Config) (s Session, err error)
NewRPCSessionFromSSHClientWithConfig establishes a netconf session over the given ssh Client with the client configuration.
func NewRPCSessionWithConfig ¶
func NewRPCSessionWithConfig(ctx context.Context, sshcfg *ssh.ClientConfig, target string, cfg *Config) (s Session, err error)
NewRPCSessionWithConfig connects to the target using the ssh configuration, and establishes a netconf session with the client configuration.
type Transport ¶
type Transport interface { io.ReadWriteCloser }
Transport interface defines what characteristics make up a NETCONF transport layer object.
func NewSSHTransport ¶
func NewSSHTransport(ctx context.Context, dialer SSHClientFactory, target string) (rt Transport, err error)
NewSSHTransport creates a new SSH transport, connecting to the target with the supplied client configuration and requesting the specified subsystem.