Documentation ¶
Overview ¶
Package netconf provides support for a a simple NETCONF client based on RFC6241 and RFC6242 (although not fully compliant yet).
Index ¶
- Variables
- func SSHConfigPassword(user string, pass string) *ssh.ClientConfig
- func SSHConfigPubKeyAgent(user string) (*ssh.ClientConfig, error)
- func SSHConfigPubKeyFile(user string, file string, passphrase string) (*ssh.ClientConfig, error)
- type HelloMessage
- type RPCError
- type RPCMessage
- type RPCMethod
- type RPCReply
- type RawMethod
- func MethodEditConfig(database string, dataXml string) RawMethod
- func MethodGet(filterType string, dataXml string) RawMethod
- func MethodGetConfig(source string) RawMethod
- func MethodGetConfigFiltered(source string, filterType string, dataXml string) RawMethod
- func MethodLock(target string) RawMethod
- func MethodUnlock(target string) RawMethod
- type ReadWriteCloser
- type Session
- func DialJunos() (*Session, error)
- func DialSSH(target string, config *ssh.ClientConfig) (*Session, error)
- func DialSSHTimeout(target string, config *ssh.ClientConfig, timeout time.Duration) (*Session, error)
- func NewSSHSession(conn net.Conn, config *ssh.ClientConfig) (*Session, error)
- func NewSession(t Transport) *Session
- type Transport
- type TransportBasicIO
- func (t *TransportBasicIO) GetVersion() string
- func (t *TransportBasicIO) Receive() ([]byte, error)
- func (t *TransportBasicIO) ReceiveHello() (*HelloMessage, error)
- func (t *TransportBasicIO) Send(data []byte) error
- func (t *TransportBasicIO) SendHello(hello *HelloMessage) error
- func (t *TransportBasicIO) SetVersion(version string)
- func (t *TransportBasicIO) WaitForBytes(b []byte) ([]byte, error)
- func (t *TransportBasicIO) WaitForFunc(f func([]byte) (int, error)) ([]byte, error)
- func (t *TransportBasicIO) WaitForRegexp(re *regexp.Regexp) ([]byte, [][]byte, error)
- func (t *TransportBasicIO) WaitForString(s string) (string, error)
- func (t *TransportBasicIO) Writeln(b []byte) (int, error)
- type TransportJunos
- type TransportSSH
Constants ¶
This section is empty.
Variables ¶
var DefaultCapabilities = []string{
"urn:ietf:params:netconf:base:1.0",
"urn:ietf:params:netconf:base:1.1",
}
DefaultCapabilities sets the default capabilities of the client library
Functions ¶
func SSHConfigPassword ¶
func SSHConfigPassword(user string, pass string) *ssh.ClientConfig
SSHConfigPassword is a convenience function that takes a username and password and returns a new ssh.ClientConfig setup to pass that username and password. Convenience means that HostKey checks are disabled so it's probably less secure
func SSHConfigPubKeyAgent ¶
func SSHConfigPubKeyAgent(user string) (*ssh.ClientConfig, error)
SSHConfigPubKeyAgent is a convience function that takes a username and returns a new ssh.Clientconfig setup to pass credentials received from an ssh agent
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
Types ¶
type HelloMessage ¶
type HelloMessage struct { XMLName xml.Name `xml:"urn:ietf:params:xml:ns:netconf:base:1.0 hello"` Capabilities []string `xml:"capabilities>capability"` SessionID int `xml:"session-id,omitempty"` }
HelloMessage is used when bringing up a NETCONF session
type RPCError ¶
type RPCError struct { Type string `xml:"error-type"` Tag string `xml:"error-tag"` Severity string `xml:"error-severity"` Path string `xml:"error-path"` Message string `xml:"error-message"` Info string `xml:",innerxml"` }
RPCError defines an error reply to a RPC request
type RPCMessage ¶
RPCMessage represents an RPC Message to be sent.
func NewRPCMessage ¶
func NewRPCMessage(methods []RPCMethod) *RPCMessage
NewRPCMessage generates a new RPC Message structure with the provided methods
func (*RPCMessage) MarshalXML ¶
func (m *RPCMessage) MarshalXML(e *xml.Encoder, start xml.StartElement) error
MarshalXML marshals the NETCONF XML data
type RPCMethod ¶
type RPCMethod interface {
MarshalMethod() string
}
RPCMethod defines the interface for creating an RPC method.
type RPCReply ¶
type RPCReply struct { XMLName xml.Name `xml:"rpc-reply"` Errors []RPCError `xml:"rpc-error,omitempty"` Data string `xml:",innerxml"` Ok bool `xml:",omitempty"` RawReply string `xml:"-"` MessageID string `xml:"-"` }
RPCReply defines a reply to a RPC request
type RawMethod ¶
type RawMethod string
RawMethod defines how a raw text request will be responded to
func MethodEditConfig ¶ added in v0.4.0
MethodEditConfig files a NETCONF edit-config request with the remote host
func MethodGetConfig ¶
MethodGetConfig files a NETCONF get-config source request with the remote host
func MethodGetConfigFiltered ¶ added in v0.4.0
MethodGetConfigFiltered files a NETCONF get-config source request with the remote host with a filter
func MethodLock ¶
MethodLock files a NETCONF lock target request with the remote host
func MethodUnlock ¶
MethodUnlock files a NETCONF unlock target request with the remote host
func (RawMethod) MarshalMethod ¶
MarshalMethod converts the method's output into a string
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 Write Closer from the provided objects
type Session ¶
type Session struct { Transport Transport SessionID int ServerCapabilities []string ErrOnWarning bool }
Session defines the necessary components for a NETCONF session
func DialJunos ¶ added in v0.2.0
DialJunos creates a new NETCONF session via Junos local shell NETCONF interface (xml-mode netconf need-trailer).
func DialSSH ¶
func DialSSH(target string, config *ssh.ClientConfig) (*Session, error)
DialSSH creates a new NETCONF session using a 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 a SSH Transport with timeout. See TransportSSH.Dial for arguments. The timeout value is used for both connection establishment and Read/Write operations.
func NewSSHSession ¶
NewSSHSession creates a new NETCONF session using an existing net.Conn.
func NewSession ¶
NewSession creates a new NETCONF session using the provided transport layer.
type Transport ¶
type Transport interface { Send([]byte) error Receive() ([]byte, error) Close() error ReceiveHello() (*HelloMessage, error) SendHello(*HelloMessage) error SetVersion(version string) GetVersion() string }
Transport interface defines what characteristics make up a NETCONF transport layer object.
type TransportBasicIO ¶ added in v0.4.0
type TransportBasicIO struct { io.ReadWriteCloser // contains filtered or unexported fields }
func (*TransportBasicIO) GetVersion ¶ added in v0.5.3
func (t *TransportBasicIO) GetVersion() string
func (*TransportBasicIO) Receive ¶ added in v0.4.0
func (t *TransportBasicIO) Receive() ([]byte, error)
func (*TransportBasicIO) ReceiveHello ¶ added in v0.4.0
func (t *TransportBasicIO) ReceiveHello() (*HelloMessage, error)
func (*TransportBasicIO) Send ¶ added in v0.4.0
func (t *TransportBasicIO) Send(data []byte) error
Sends a well formated NETCONF rpc message as a slice of bytes adding on the nessisary framining messages.
func (*TransportBasicIO) SendHello ¶ added in v0.4.0
func (t *TransportBasicIO) SendHello(hello *HelloMessage) error
func (*TransportBasicIO) SetVersion ¶ added in v0.4.0
func (t *TransportBasicIO) SetVersion(version string)
func (*TransportBasicIO) WaitForBytes ¶ added in v0.4.0
func (t *TransportBasicIO) WaitForBytes(b []byte) ([]byte, error)
func (*TransportBasicIO) WaitForFunc ¶ added in v0.4.0
func (*TransportBasicIO) WaitForRegexp ¶ added in v0.4.0
func (*TransportBasicIO) WaitForString ¶ added in v0.4.0
func (t *TransportBasicIO) WaitForString(s string) (string, error)
type TransportJunos ¶ added in v0.2.0
type TransportJunos struct { TransportBasicIO // contains filtered or unexported fields }
TransportJunos maintains the information necessary to communicate with Junos via local shell NETCONF interface.
func (*TransportJunos) Close ¶ added in v0.2.0
func (t *TransportJunos) Close() error
Close closes an existing local NETCONF session.
func (*TransportJunos) Open ¶ added in v0.2.0
func (t *TransportJunos) Open() error
Open creates a new local NETCONF session.
type TransportSSH ¶
type TransportSSH struct { TransportBasicIO // 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 utlizes 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