netconf

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: BSD-2-Clause-Views Imports: 6 Imported by: 0

README

netconf

This library is a simple NETCONF client based on RFC6241 and RFC6242 (although not fully compliant yet).

Features

  • Support for SSH transport using go.crypto/ssh. (Other transports are planned).
  • Built in RPC support (in progress).
  • Support for custom RPCs.
  • Independent of XML library. Free to choose encoding/xml or another third party library to parse the results.
  • Client struct in the vain of UpGuard's sftp fork (might need to refactor this slightly)

Install

go get github.com/cloudhousetech/go-netconf/netconf

Documentation

You can view full API documentation at GoDoc:

http://godoc.org/github.com/Juniper/go-netconf/netconf

License

(BSD 2)

Copyright © 2013, Juniper Networks

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

(1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

(2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Juniper Networks.

Authors and Contributors

Documentation

Index

Constants

View Source
const (
	SSHDefaultNetconfPort = 830
	SSHNetconfSubsystem   = "netconf"
)
View Source
const (
	CapabilityNetconfBase = "urn:ietf:params:xml:ns:netconf:base:1.0"
)
View Source
const (
	TransportMessageSeparator = "]]>]]>"
)

Variables

This section is empty.

Functions

func SSHConfigPassword

func SSHConfigPassword(username, password string) *ssh.ClientConfig

SSH config including authentication information

Types

type Capability

type Capability string

type Client

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

Client works quite a lot like SFTP, which is also a subsystem of SSH

func NewClient

func NewClient(conn *ssh.Client) (*Client, error)

NewClient is the constructor for Client. It creates a Client with stdin and stdout as the Reader and WriteCloser

func NewClientPipe

func NewClientPipe(sshClient *ssh.Client, sshSession *ssh.Session, r io.Reader, w io.WriteCloser) (*Client, error)

NewClientPipe creates a Client using the given Reader and WriteCloser

func (*Client) Close

func (c *Client) Close() error

Close closes the netconf session to which the Client is connected

func (*Client) GetConfig

func (c *Client) GetConfig(typ string) ([]byte, error)

GetConfig issues a request to netconf for configuration data.

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"`
}

an error returned over the course of RPC communication

func (*RPCError) Error

func (re *RPCError) Error() string

type RPCMessage

type RPCMessage struct {
	ID      string
	Methods []RPCMethod
}

a message to send to the remote

func NewRPCMessage

func NewRPCMessage(methods []RPCMethod) *RPCMessage

func (*RPCMessage) MarshalXML

func (m *RPCMessage) MarshalXML(e *xml.Encoder, start xml.StartElement) error

type RPCMethod

type RPCMethod interface {
	MarshalRPCMethod() string
}

func MethodGetConfig

func MethodGetConfig(source string) RPCMethod

func MethodUnlock

func MethodUnlock(target string) RPCMethod

func RPCMethodLock

func RPCMethodLock(target string) RPCMethod

type RPCMethodRaw

type RPCMethodRaw string

a raw RPC method is just a plain string

func (RPCMethodRaw) MarshalRPCMethod

func (m RPCMethodRaw) MarshalRPCMethod() string

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:"-"`
}

the remote's response to valid RPC messages

type Session

type Session struct {
	ID                 int
	ServerCapabilities []Capability
	Transport          Transport
	ErrOnWarnings      bool
}

func NewSession

func NewSession(t Transport) (*Session, error)

func (*Session) Close

func (s *Session) Close() error

func (*Session) Exec

func (s *Session) Exec(methods ...RPCMethod) (*RPCReply, error)

type Transport

type Transport interface {
	Send(data []byte) error
	Recieve() ([]byte, error)
	Close() error
	SendHello(*TransportHelloMessage) error
	ReceiveHello() (*TransportHelloMessage, error)
}

type TransportHelloMessage

type TransportHelloMessage struct {
	XMLName      xml.Name     `xml:"hello"`
	Capabilities []Capability `xml:"capabilities>capability"`
	SessionID    int          `xml:"session-id,omitempty"`
}

type TransportReadWriteCloser

type TransportReadWriteCloser struct {
	io.Reader
	io.WriteCloser
}

we implement ReadWriteCloser here so we can use the result of things like SSH dialing as io.ReadWriteCloser

func NewTransportReadWriteCloser

func NewTransportReadWriteCloser(r io.Reader, w io.WriteCloser) *TransportReadWriteCloser

type TransportSSH

type TransportSSH struct {
	SSHClient  *ssh.Client
	SSHSession *ssh.Session
	// contains filtered or unexported fields
}

func TransportSSHFromSSHClient

func TransportSSHFromSSHClient(client *ssh.Client, session *ssh.Session) *TransportSSH

func (*TransportSSH) Close

func (t *TransportSSH) Close() error

func (*TransportSSH) ReceiveHello

func (t *TransportSSH) ReceiveHello() (*TransportHelloMessage, error)

func (*TransportSSH) Recieve

func (t *TransportSSH) Recieve() ([]byte, error)

func (*TransportSSH) Send

func (t *TransportSSH) Send(data []byte) error

Send a well formatted RPC message, including framing delimiters where applicable

func (*TransportSSH) SendHello

func (t *TransportSSH) SendHello(msg *TransportHelloMessage) error

func (*TransportSSH) WaitForBytes

func (t *TransportSSH) WaitForBytes(b []byte) ([]byte, error)

wait for byte subsequence

func (*TransportSSH) WaitForFunc

func (t *TransportSSH) WaitForFunc(fn TransportWaitFunc) ([]byte, error)

func (*TransportSSH) WaitForString

func (t *TransportSSH) WaitForString(s string) (string, error)

wait for string -- extends wait for bytes

type TransportWaitFunc

type TransportWaitFunc func(buf []byte) (int, error)

a transport wait func allows us to control the way we read input using a lambda function

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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