Documentation ¶
Index ¶
- type CLIParams
- type CLIRequest
- type CallBackConfirm
- type ClientOption
- type Command
- type CommandOption
- type CommandValue
- type JSONRPCClient
- func (c *JSONRPCClient) BulkDiff(delete []PV, replace []PV, update []PV, ym yms.EnumYmType) (*Response, error)
- func (c *JSONRPCClient) BulkSet(delete []PV, replace []PV, update []PV, ym yms.EnumYmType, ct int) (*Response, error)
- func (c *JSONRPCClient) BulkSetCallBack(delete []PV, replace []PV, update []PV, ym yms.EnumYmType, ct int, cbt int, ...) (*Response, error)
- func (c *JSONRPCClient) CLI(cmds []string, of formats.EnumOutputFormats) (*Response, error)
- func (c *JSONRPCClient) Delete(ct int, paths ...string) (*Response, error)
- func (c *JSONRPCClient) DiffCandidate(action actions.EnumActions, ym yms.EnumYmType, pvs ...PV) (*Response, error)
- func (c *JSONRPCClient) Do(r Requester) (*Response, error)
- func (c *JSONRPCClient) Get(paths ...string) (*Response, error)
- func (c *JSONRPCClient) GetHostname() string
- func (c *JSONRPCClient) GetSysVer() string
- func (c *JSONRPCClient) Replace(ct int, pvs ...PV) (*Response, error)
- func (c *JSONRPCClient) State(paths ...string) (*Response, error)
- func (c *JSONRPCClient) Tools(pvs ...PV) (*Response, error)
- func (c *JSONRPCClient) Update(ct int, pvs ...PV) (*Response, error)
- func (c *JSONRPCClient) Validate(action actions.EnumActions, pvs ...PV) (*Response, error)
- type JSONRPCTarget
- type PV
- type Params
- type Request
- func NewDiffRequest(delete []PV, replace []PV, update []PV, ym yms.EnumYmType, ...) (*Request, error)
- func NewGetRequest(paths []string, recursion bool, defaults bool, of formats.EnumOutputFormats, ...) (*Request, error)
- func NewRequest(m methods.EnumMethods, cmds []*Command, opts ...RequestOption) (*Request, error)
- func NewSetRequest(delete []PV, replace []PV, update []PV, ym yms.EnumYmType, ...) (*Request, error)
- func NewValidateRequest(delete []PV, replace []PV, update []PV, ym yms.EnumYmType, ...) (*Request, error)
- type RequestOption
- type Requester
- type Response
- type RpcError
- type TLSAttr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CLIParams ¶
type CLIParams struct { Commands []string `json:"commands"` *formats.OutputFormat }
CLIParams defines a container for CLI commands and optional OutputFormat object.
type CLIRequest ¶
type CLIRequest struct { JSONRpcVersion string `json:"jsonrpc"` ID int `json:"id"` *methods.Method Params *CLIParams `json:"params"` }
JSONRpcVersion is mandatory. Version, which must be ‟2.0”. No other JSON RPC versions are currently supported.
ID is mandatory. Client-provided integer. The JSON RPC responds with the same ID, which allows the client to match requests to responses when there are concurrent requests. Implementation uses random numbers and verifies Response ID is the same as Request ID. Embeds Method (set to CLI by NewCLIRequest) and CLIParams.
func NewCLIRequest ¶
func NewCLIRequest(cmds []string, of formats.EnumOutputFormats) (*CLIRequest, error)
Creates a new CLIRequest object using the provided list of commands executed one by one and output format. Each command should have a response under JSON RPC response message - Response under "result" field with respective command index.
func (*CLIRequest) Marshal ¶
func (r *CLIRequest) Marshal() ([]byte, error)
Marshalling CLIRequest into JSON.
func (*CLIRequest) SetOutputFormat ¶
func (r *CLIRequest) SetOutputFormat(of formats.EnumOutputFormats) error
Sets the output format of the request.
type CallBackConfirm ¶ added in v0.9.7
CallBackConfirm type to represent a callback function to confirm a request. In case of confirm commit must return true, otherwise false.
type ClientOption ¶
type ClientOption func(*JSONRPCClient) error
ClientOption is a function type that applies options to a JSONRPCClient object.
func WithOptCredentials ¶
func WithOptCredentials(u, p *string) ClientOption
ClientOption to specify credentials.
func WithOptTLS ¶
func WithOptTLS(t *TLSAttr) ClientOption
ClientOption to specify TLS configuration. Setting the TLS configuration will override the default skipVerify option and will enforce the verification of the server certificate. Assumes minimum TLS version 1.2.
func WithOptTimeout ¶
func WithOptTimeout(t time.Duration) ClientOption
ClientOption to set connection timeout.
type Command ¶
type Command struct { Path string `json:"path"` Value string `json:"value,omitempty"` PathKeywords json.RawMessage `json:"path-keywords,omitempty"` Recursive *bool `json:"recursive,omitempty"` IncludeFieldDefaults *bool `json:"include-field-defaults,omitempty"` *actions.Action *datastores.Datastore }
Command is mandatory. List of commands used to execute against the called method. Multiple commands can be executed with a single request. Number of CommandOptions could be used to influence command behavior. Embeds Action and Datastore objects.
func NewCommand ¶
func NewCommand(action actions.EnumActions, path string, value CommandValue, opts ...CommandOption) (*Command, error)
Constructor for a new Command object with mandatory action, path and value fields, and optional command options to influence command behavior.
type CommandOption ¶ added in v0.9.2
CommandOption type to represent a function that configures a Command.
func WithAddPathKeywords ¶
func WithAddPathKeywords(kw json.RawMessage) CommandOption
CommandOptions to add path keywords to the command to substitute named parameters with the path field.
func WithDatastore ¶
func WithDatastore(d datastores.EnumDatastores) CommandOption
CommandOptions to set datastore for the command.
func WithDefaults ¶
func WithDefaults() CommandOption
CommandOptions to enable inclusion of default values in returned JSON RPC response for the command.
func WithoutRecursion ¶
func WithoutRecursion() CommandOption
Provides CommandOptions to disable recursion for the command.
type JSONRPCClient ¶
type JSONRPCClient struct {
// contains filtered or unexported fields
}
JSONRPCClient type to represent a JSON RPC client: HTTP client, NE(target) and related info.
func NewJSONRPCClient ¶
func NewJSONRPCClient(host *string, opts ...ClientOption) (*JSONRPCClient, error)
Creates a new JSON RPC client and applies options in order of appearance.
func (*JSONRPCClient) BulkDiff ¶ added in v0.9.7
func (c *JSONRPCClient) BulkDiff(delete []PV, replace []PV, update []PV, ym yms.EnumYmType) (*Response, error)
Bulk CRUD method of JSONRPCClient. Executes a DIFF method with REPLACE/UPDATE/DELETE action request against CANDIDATE datastore. delete/replace/update are path-value pairs. yang model type is mandatory for diff to specify: SRL or OC.
func (*JSONRPCClient) BulkSet ¶ added in v0.9.7
func (c *JSONRPCClient) BulkSet(delete []PV, replace []PV, update []PV, ym yms.EnumYmType, ct int) (*Response, error)
Bulk CRUD method of JSONRPCClient. Executes a SET method with REPLACE/UPDATE/DELETE action request against CANDIDATE datastore. ct is the timeout in seconds for the confirm operation, set to 0 to disable. delete/replace/update are path-value pairs. All the PVs are applied immediately in the same order as they are provided. yang model type is mandatory for diff to specify: SRL or OC.
func (*JSONRPCClient) BulkSetCallBack ¶ added in v0.9.7
func (c *JSONRPCClient) BulkSetCallBack(delete []PV, replace []PV, update []PV, ym yms.EnumYmType, ct int, cbt int, cbf CallBackConfirm) (*Response, error)
Bulk CRUD method of JSONRPCClient w/ CallBackConfirm callback and mandatory confirm timeout. Executes a SET method with REPLACE/UPDATE/DELETE action request against CANDIDATE datastore. All the PVs are applied immediately in the same order as they are provided. yang model type is mandatory for diff to specify: SRL or OC. JSON RPC Response is not nil if the callback function returns true. if callback function returns false, the both response&error are nil to indicate changes rolled back and NE back to previous state.
func (*JSONRPCClient) CLI ¶
func (c *JSONRPCClient) CLI(cmds []string, of formats.EnumOutputFormats) (*Response, error)
Executes CLI commands against the target device (NE).
func (*JSONRPCClient) Delete ¶
func (c *JSONRPCClient) Delete(ct int, paths ...string) (*Response, error)
SetDelete method of JSONRPCClient. Executes a SET/DELETE action request against CANDIDATE datastore. t is the timeout in seconds for the confirm operation, set to 0 to disable. paths is the list of path to delete. Yang model type is default(SRL).
func (*JSONRPCClient) DiffCandidate ¶ added in v0.9.2
func (c *JSONRPCClient) DiffCandidate(action actions.EnumActions, ym yms.EnumYmType, pvs ...PV) (*Response, error)
DiffCandidate method of JSONRPCClient. Executes a DIFF/<action> action request against CANDIDATE datastore. Yang model type is default(SRL). pvs are path-value pairs. The action parameter must be one of DELETE, REPLACE, or UPDATE.
func (*JSONRPCClient) Do ¶
func (c *JSONRPCClient) Do(r Requester) (*Response, error)
Calls the JSON RPC server and returns the response.
func (*JSONRPCClient) Get ¶
func (c *JSONRPCClient) Get(paths ...string) (*Response, error)
Get method of JSONRPCClient. Executes a GET request against RUNNING datastore.
func (*JSONRPCClient) GetHostname ¶
func (c *JSONRPCClient) GetHostname() string
GetHostname returns the hostname of the target after verification.
func (*JSONRPCClient) GetSysVer ¶
func (c *JSONRPCClient) GetSysVer() string
GetSysVer returns the system version of the target after verification.
func (*JSONRPCClient) Replace ¶
func (c *JSONRPCClient) Replace(ct int, pvs ...PV) (*Response, error)
SetReplace method of JSONRPCClient. Executes a SET/REPLACE action request against CANDIDATE datastore. ct is the timeout in seconds for the confirm operation, set to 0 to disable. pvs is the list of path-value pairs. Yang model type is default(SRL).
func (*JSONRPCClient) State ¶
func (c *JSONRPCClient) State(paths ...string) (*Response, error)
Get state method of JSONRPCClient. Executes a GET request against STATE datastore.
func (*JSONRPCClient) Tools ¶
func (c *JSONRPCClient) Tools(pvs ...PV) (*Response, error)
Tools() action of the method SET. Executes a SET/UPDATE action request against TOOLS datastore. Yang model type is default(SRL).
func (*JSONRPCClient) Update ¶
func (c *JSONRPCClient) Update(ct int, pvs ...PV) (*Response, error)
SetUpdate method of JSONRPCClient executing a SET/UPDATE action request against CANDIDATE datastore. ct is the timeout in seconds for the confirm operation, set to 0 to disable. pvs is the list of path-value pairs. Yang model type is default(SRL).
func (*JSONRPCClient) Validate ¶
func (c *JSONRPCClient) Validate(action actions.EnumActions, pvs ...PV) (*Response, error)
Validate() action of the method SET. Executes a SET/VALIDATE specified action request against CANDIDATE datastore. Yang model type is default(SRL).
type JSONRPCTarget ¶
type JSONRPCTarget struct {
// contains filtered or unexported fields
}
JSONRPCTarget type to represent a JSON RPC target: NE(target), TLS attributes, credentials.
type PV ¶
type PV struct { Path string `json:"path"` Value CommandValue `json:"value"` }
PV type to represent a path-value pair.
type Params ¶
type Params struct { Commands []Command `json:"commands"` *formats.OutputFormat *datastores.Datastore *yms.YmType *ctimeout.ConfirmTimeout }
Params defines a container for Commands and optional OutputFormat and Datastore objects. Params embeds: OutputFormat, Datastore objects and ConfirmTimeout (used for confirmed commits).
type Request ¶
type Request struct { JSONRpcVersion string `json:"jsonrpc"` ID int `json:"id"` *methods.Method Params *Params `json:"params"` }
JSON RPC Request for get / set / validate methods.
JSONRpcVersion is mandatory. Version, which must be ‟2.0”. No other JSON RPC versions are currently supported. ID is mandatory. Client-provided integer. The JSON RPC responds with the same ID, which allows the client to match requests to responses when there are concurrent requests. Implementation uses random numbers and verifies Response ID is the same as Request ID. Embeds Method and Params.
func NewDiffRequest ¶ added in v0.9.2
func NewDiffRequest(delete []PV, replace []PV, update []PV, ym yms.EnumYmType, of formats.EnumOutputFormats, ds datastores.EnumDatastores) (*Request, error)
NewDiffRequest provides a new Request with the DIFF method and the given commands, which more advanced version of JRPCClient.Diff().
func NewGetRequest ¶ added in v0.9.2
func NewGetRequest(paths []string, recursion bool, defaults bool, of formats.EnumOutputFormats, ds datastores.EnumDatastores) (*Request, error)
NewGetRequest provides a new Request with the GET method and the given paths, which more advanced version of JRPCClient.Get().
func NewRequest ¶
func NewRequest(m methods.EnumMethods, cmds []*Command, opts ...RequestOption) (*Request, error)
NewRequest provides a new Request with the given method, commands and options. Sequence of functions is applied to the Request in the order of appearance.
func NewSetRequest ¶ added in v0.9.2
func NewSetRequest(delete []PV, replace []PV, update []PV, ym yms.EnumYmType, of formats.EnumOutputFormats, ds datastores.EnumDatastores, ct int) (*Request, error)
NewSetRequest provides a new Request with the SET method and the given commands, which more advanced version of JRPCClient.Set().
func NewValidateRequest ¶ added in v0.9.2
func NewValidateRequest(delete []PV, replace []PV, update []PV, ym yms.EnumYmType, of formats.EnumOutputFormats, ds datastores.EnumDatastores) (*Request, error)
NewValidateRequest provides a new Request with the VALIDATE method and the given commands, which more advanced version of JRPCClient.Validate().
func (*Request) SetConfirmTimeout ¶ added in v0.9.7
Setting confirm timeout for the Request.
func (*Request) SetOutputFormat ¶
func (r *Request) SetOutputFormat(of formats.EnumOutputFormats) error
Set output format for the request via embedded Params.
type RequestOption ¶
RequestOption is a function type that applies options to a Request. Each RequestOption has validation logic implemented to check correctness of the option application and return non nil apierr.MessageError if the option is not correct.
func WithConfirmTimeout ¶ added in v0.9.7
func WithConfirmTimeout(t int) RequestOption
Defines confirm timeout RequestOption.
func WithOutputFormat ¶
func WithOutputFormat(of formats.EnumOutputFormats) RequestOption
Defines output format RequestOption.
func WithRequestDatastore ¶
func WithRequestDatastore(ds datastores.EnumDatastores) RequestOption
RequestOption that sets the datastore for the request in Params level. Overrides the datastore in Command level! Implemented logic in this option is to check if datastore is valid for the selected method and perform necessary checks on the commands.
func WithYmType ¶ added in v0.9.2
func WithYmType(ym yms.EnumYmType) RequestOption
Defines yang models RequestOption.
type Requester ¶
type Requester interface { Marshal() ([]byte, error) GetMethod() (methods.EnumMethods, error) MethodName() string GetID() int SetOutputFormat(of formats.EnumOutputFormats) error }
Requester is an interface used by the JSON RPC client to send a request to the server.
type Response ¶
type Response struct { JSONRpcVersion string `json:"jsonrpc"` ID int `json:"id"` Result json.RawMessage `json:"result,omitempty"` Error *RpcError `json:"error,omitempty"` }
JSON RPC response message. When a rpc call is made, the Server MUST reply with a Response, except for in the case of Notifications. The Response is expressed as a single JSON Object. Result and error are mutually exclusive, so only one of them can be expected. Error is represented as a pointer to RpcError, so it can be nil.
JSONRpcVersion is mandatory. Version, which must be ‟2.0”. No other JSON RPC versions are currently supported. ID is mandatory. Client-provided integer. The JSON RPC responds with the same ID, which allows the client to match requests to responses when there are concurrent requests. Result is REQUIRED on success (jsonRawMessage). This member MUST NOT exist if there was an error invoking the method. The value of this member is determined by the method invoked on the Server. Error is REQUIRED on error. This member MUST NOT exist if there was no error triggered during invocation. The value for this member MUST be an RpcError object.
type RpcError ¶
type RpcError struct { ID int `json:"id"` Message string `json:"message"` Data string `json:"data,omitempty"` }
RpcError is generic JSON RPC error object. When a rpc call is made, the Server MUST reply with a Response, except for in the case of Notifications. The Response is expressed as a single JSON Object.
ID should be set to client provided ID. Message is a string providing a short description of the error. The message SHOULD be limited to a concise single sentence." Data is a primitive or structured value that contains additional information about the error. This may be omitted. The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.).
type TLSAttr ¶
type TLSAttr struct { CAFile *string `json:"ca_file,omitempty"` // CA certificate file in PEM format. CertFile *string `json:"cert_file,omitempty"` // Client certificate file in PEM format. KeyFile *string `json:"key_file,omitempty"` // Client private key file. SkipVerify *bool `json:"skip_verify,omitempty"` // Disable certificate validation during TLS session ramp-up. }
TLSAttr type to represent TLS attributes