Documentation
¶
Overview ¶
Package restconf is a RESTCONF (RFC 8040) client library for Go.
Index ¶
- Constants
- Variables
- func BackoffDelayFactor(x float64) func(*Client)
- func BackoffMaxDelay(x int) func(*Client)
- func BackoffMinDelay(x int) func(*Client)
- func MaxRetries(x int) func(*Client)
- func Query(k, v string) func(req *Req)
- func RequestTimeout(x time.Duration) func(*Client)
- func SkipDiscovery(restconfEndpoint string, yangPatchCapability bool) func(*Client)
- func Wait(req *Req)
- type Body
- type CapabilitiesModel
- type CapabilitiesRootModel
- type Client
- func (client *Client) Backoff(attempts int) bool
- func (client *Client) DeleteData(path string, mods ...func(*Req)) (Res, error)
- func (client *Client) Discovery(mods ...func(*Req)) error
- func (client *Client) Do(req Req) (Res, error)
- func (client *Client) GetData(path string, mods ...func(*Req)) (Res, error)
- func (client *Client) NewReq(method, uri string, body io.Reader, mods ...func(*Req)) Req
- func (client *Client) PatchData(path, data string, mods ...func(*Req)) (Res, error)
- func (client *Client) PostData(path, data string, mods ...func(*Req)) (Res, error)
- func (client *Client) PutData(path, data string, mods ...func(*Req)) (Res, error)
- func (client *Client) YangPatchData(path, patchId, comment string, edits []YangPatchEdit, mods ...func(*Req)) (Res, error)
- type DatastoreModel
- type DatastoreStatusRootModel
- type ErrorModel
- type ErrorsModel
- type ErrorsRootModel
- type ErrorsRootNamespaceModel
- type LocksModel
- type PartialLockModel
- type Req
- type Res
- type TransientError
- type YangPatchEdit
- type YangPatchEditModel
- type YangPatchModel
- type YangPatchRootModel
- type YangPatchStatusEditStatusEditModel
- type YangPatchStatusEditStatusModel
- type YangPatchStatusGlobalStatusModel
- type YangPatchStatusModel
- type YangPatchStatusRootModel
Constants ¶
Variables ¶
var TransientErrors = [...]TransientError{
{
StatusCode: 400,
ErrorTag: "invalid-value",
ErrorMessage: "inconsistent value: Device refused one or more commands",
},
{
ErrorTag: "lock-denied",
},
{
ErrorTag: "in-use",
},
{
StatusCode: 500,
},
{
StatusCode: 501,
},
{
StatusCode: 502,
},
{
StatusCode: 503,
},
{
StatusCode: 504,
},
}
Functions ¶
func BackoffDelayFactor ¶
BackoffDelayFactor modifies the backoff delay factor from the default of 3.
func BackoffMaxDelay ¶
BackoffMaxDelay modifies the maximum delay between two retries from the default of 60.
func BackoffMinDelay ¶
BackoffMinDelay modifies the minimum delay between two retries from the default of 4.
func MaxRetries ¶
MaxRetries modifies the maximum number of retries from the default of 2.
func Query ¶
Query sets an HTTP query parameter.
client.GetData("Cisco-IOS-XE-native:native", restconf.Query("content", "config"))
Or set multiple parameters:
client.GetData("Cisco-IOS-XE-native:native",
restconf.Query("content", "config"),
restconf.Query("depth", "1"))
func RequestTimeout ¶
RequestTimeout modifies the HTTP request timeout from the default of 60 seconds.
func SkipDiscovery ¶ added in v0.1.8
SkipDiscovery provides the otherwise dynamically discovered capabilities
Types ¶
type Body ¶
type Body struct {
Str string
}
Body wraps SJSON for building JSON body strings. Usage example:
Body{}.Set(Cisco-IOS-XE-native:native.hostname", "ROUTER-1").Str
type CapabilitiesModel ¶ added in v0.1.4
type CapabilitiesModel struct {
Capability []string `json:"capability"`
}
type CapabilitiesRootModel ¶ added in v0.1.4
type CapabilitiesRootModel struct {
Capabilities CapabilitiesModel `json:"ietf-restconf-monitoring:capabilities"`
}
type Client ¶
type Client struct {
// HttpClient is the *http.Client used for API requests.
HttpClient *http.Client
// Url is the device url.
Url string
// Usr is the device username.
Usr string
// Pwd is the device password.
Pwd string
// Insecure determines if insecure https connections are allowed.
Insecure bool
// Maximum number of retries
MaxRetries int
// Minimum delay between two retries
BackoffMinDelay int
// Maximum delay between two retries
BackoffMaxDelay int
// Backoff delay factor
BackoffDelayFactor float64
// True if discovery (RESTCONF API endpoint and capabilities) is complete
DiscoveryComplete bool
// Discovered RESTCONF API endpoint
RestconfEndpoint string
// RESTCONF capabilities
Capabilities []string
// RESTCONF YANG-Patch capability
YangPatchCapability bool
// contains filtered or unexported fields
}
Client is an HTTP RESTCONF client. Use restconf.NewClient to initiate a client. This will ensure proper cookie handling and processing of modifiers.
func NewClient ¶
NewClient creates a new RESTCONF HTTP client. Pass modifiers in to modify the behavior of the client, e.g.
client, _ := NewClient("https://10.0.0.1", "user", "password", true, RequestTimeout(120))
func (*Client) DeleteData ¶
DeleteData makes a DELETE request and returns a GJSON result.
func (*Client) Do ¶
Do makes a request. Requests for Do are built outside of the client, e.g.
req := client.NewReq("GET", "Cisco-IOS-XE-native:native/hostname", nil)
res, _ := client.Do(req)
func (*Client) PatchData ¶
PatchData makes a PATCH request and returns a GJSON result. Hint: Use the Body struct to easily create PATCH body data.
func (*Client) PostData ¶
PostData makes a POST request and returns a GJSON result. Hint: Use the Body struct to easily create POST body data.
func (*Client) PutData ¶
PutData makes a PUT request and returns a GJSON result. Hint: Use the Body struct to easily create PUT body data.
func (*Client) YangPatchData ¶ added in v0.1.4
func (client *Client) YangPatchData(path, patchId, comment string, edits []YangPatchEdit, mods ...func(*Req)) (Res, error)
YangPatchData makes a YANG-PATCH (RFC 8072) request and returns a GJSON result.
type DatastoreModel ¶ added in v0.1.11
type DatastoreModel struct {
Name string `json:"name"`
Locks LocksModel `json:"locks"`
TransactionId string `json:"tailf-netconf-monitoring:transaction-id"`
Status string `json:"tailf-netconf-monitoring:status"`
}
type DatastoreStatusRootModel ¶ added in v0.1.11
type DatastoreStatusRootModel struct {
Datastores []DatastoreModel `json:"ietf-netconf-monitoring:datastore"`
}
type ErrorModel ¶ added in v0.1.4
type ErrorsModel ¶ added in v0.1.4
type ErrorsModel struct {
Error []ErrorModel `json:"error"`
}
type ErrorsRootModel ¶ added in v0.1.4
type ErrorsRootModel struct {
Errors ErrorsModel `json:"errors"`
}
type ErrorsRootNamespaceModel ¶ added in v0.1.7
type ErrorsRootNamespaceModel struct {
Errors ErrorsModel `json:"ietf-restconf:errors"`
}
type LocksModel ¶ added in v0.1.11
type LocksModel struct {
PartialLock []PartialLockModel `json:"partial-lock"`
}
type PartialLockModel ¶ added in v0.1.11
type PartialLockModel struct {
LockId int `json:"lock-id"`
}
type Req ¶
type Req struct {
// HttpReq is the *http.Request object.
HttpReq *http.Request
// Wait until write operation is complete.
Wait bool
}
Req wraps http.Request for API requests.
type Res ¶
type Res struct {
Res gjson.Result
// HTTP response status code
StatusCode int
Errors ErrorsModel
YangPatchStatus YangPatchStatusModel
}
Res is an API response returned by client requests. Res.Res is a GJSON result, which offers advanced and safe parsing capabilities. https://github.com/tidwall/gjson
type TransientError ¶ added in v0.1.2
type YangPatchEdit ¶ added in v0.1.4
func NewYangPatchEdit ¶ added in v0.1.4
func NewYangPatchEdit(operation, target string, value Body) YangPatchEdit
Create new YangPathEdit for YangPatchData()
type YangPatchEditModel ¶ added in v0.1.4
type YangPatchModel ¶ added in v0.1.4
type YangPatchModel struct {
PatchId string `json:"patch-id"`
Comment string `json:"comment,omitempty"`
Edit []YangPatchEditModel `json:"edit"`
}
type YangPatchRootModel ¶ added in v0.1.4
type YangPatchRootModel struct {
YangPatch YangPatchModel `json:"ietf-yang-patch:yang-patch"`
}
type YangPatchStatusEditStatusEditModel ¶ added in v0.1.4
type YangPatchStatusEditStatusEditModel struct {
EditId string `json:"edit-id"`
Ok bool `json:"ok"`
Errors ErrorsModel `json:"errors"`
}
type YangPatchStatusEditStatusModel ¶ added in v0.1.4
type YangPatchStatusEditStatusModel struct {
Edit []YangPatchStatusEditStatusEditModel `json:"edit"`
}
type YangPatchStatusGlobalStatusModel ¶ added in v0.1.4
type YangPatchStatusGlobalStatusModel struct {
Ok bool `json:"ok"`
Errors ErrorsModel `json:"errors"`
}
type YangPatchStatusModel ¶ added in v0.1.4
type YangPatchStatusModel struct {
PatchId string `json:"patch-id"`
GlobalStatus YangPatchStatusGlobalStatusModel `json:"global-status,omitempty"`
EditStatus YangPatchStatusEditStatusModel `json:"edit-status,omitempty"`
Errors ErrorsModel `json:"errors,omitempty"`
}
type YangPatchStatusRootModel ¶ added in v0.1.4
type YangPatchStatusRootModel struct {
YangPatchStatus YangPatchStatusModel `json:"ietf-yang-patch:yang-patch-status"`
}