Documentation
¶
Overview ¶
Package nxapi provides a JSON-RPC client for Cisco NX-OS devices via NX-API.
Use NewClient to create a client for a given deviceutil.Connection. The client supports both HTTP and HTTPS (selected automatically based on whether a TLS configuration is present) and authenticates with HTTP Basic Auth.
Commands are expressed as plain NX-OS CLI strings and grouped into a Request using NewRequest. A single HTTP POST is made per Request, which may contain one or more commands. Each command in a batch gets its own result in the returned slice.
Errors are surfaced as RPCErrors when NX-OS reports one or more command failures, or as HTTPError for non-2xx responses whose body cannot be parsed as JSON-RPC (for example, a 401 Authorization Required).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client sends JSON-RPC requests to a Cisco NX-OS device via NX-API. Use NewClient to construct one.
func NewClient ¶
func NewClient(c *deviceutil.Connection, timeout time.Duration) (*Client, error)
NewClient creates a new Client for the given connection. If the connection has a TLS configuration set, HTTPS is used; otherwise HTTP. The underlying HTTP client uses timeout for all requests; a value of 0 means no timeout.
func (*Client) Do ¶
Do sends a Request to the device and returns one json.RawMessage per command, in the same order as the request. If any command fails, Do returns an RPCErrors containing one RPCError per failed command; transport and HTTP errors are returned directly.
type ErrorAction ¶
type ErrorAction string
ErrorAction controls how NX-OS responds when an individual command fails.
const ( Stop ErrorAction = "stop-on-error" Continue ErrorAction = "continue-on-error" Rollback ErrorAction = "rollback-on-error" )
type HTTPError ¶
type HTTPError struct {
// Code is the HTTP status code.
Code int
// Body contains the raw response body.
Body []byte
}
HTTPError is returned when the NX-API endpoint responds with a non-2xx status and the body cannot be parsed as a JSON-RPC error.
type RPCError ¶
type RPCError struct {
// Code is the JSON-RPC error code.
Code int `json:"code"`
// Message is the human-readable error description.
Message string `json:"message"`
// Data contains additional error context as raw JSON, if present.
Data json.RawMessage `json:"data"`
}
RPCError represents a single JSON-RPC error returned by NX-OS.
type RPCErrors ¶
type RPCErrors []*RPCError
RPCErrors is a slice of RPCError values returned when one or more commands in a request fail. It implements the error interface.
type Request ¶
type Request []cmd
Request is an ordered list of commands to send in a single JSON-RPC batch.
func NewRequest ¶
NewRequest creates a Request from plain CLI command strings.
func (Request) WithRollback ¶
func (r Request) WithRollback(a ErrorAction) Request
WithRollback sets the error action on each command in the request, controlling what NX-OS does if that individual command fails.
type RoundTripFunc ¶
The RoundTripFunc type is an adapter to allow the use of ordinary functions as http.RoundTripper. If f is a function with the appropriate signature, RoundTripFunc(f) is a http.RoundTripper that calls f.