netconf-client
Version:
144 lines • 7.23 kB
TypeScript
import { Observable, Subject } from 'rxjs';
import { NetconfClient } from './netconf-client.ts';
import { EditConfigResult, GetDataResult, GetDataResultType, NetconfParams, NetconfPrimitiveType, NetconfType, NotificationResult, RpcReplyType, RpcResult, SubscriptionOption } from './netconf-types.ts';
/**
* Netconf client
*/
export declare class Netconf extends NetconfClient {
/**
* Class constructor
*
* @param {NetconfParams} params - Netconf client parameters
*/
constructor(params: NetconfParams);
/**
* Execute a custom RPC operation. Example:
*
* ```typescript
* const netconf = new Netconf({
* host: '127.0.0.1',
* port: 2022,
* user: 'admin',
* pass: 'admin',
* namespace: 'urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring',
* });
* netconf.rpc('/get-schema', { identifier: 'ietf-netconf' }).subscribe({
* next: (data) => {
* console.log(data);
* },
* error: (error) => {
* console.error(error);
* },
* });
* ```
*
* @param {string} xpath - RPC command formatted as XPath
* @param {NetconfType} values - Object of key-value pairs to be sent with the RPC request. The object may have
* nested objects and arrays.
* @returns {Observable<RpcResult>} Observable of the result
*/
rpc(xpath: string, values: NetconfType): Observable<RpcResult>;
/**
* Get items from the Netconf server using `get-data` or `get` RPC
*
* @param {string} xpath - XPath filter of the configuration object,
* for example, //aaa//user[name="admin"]
* @param {GetDataResultType} resultType Result type (config filter)
* - If 'config', only the configuration is returned
* - If 'state', only the state data is returned
* - If 'schema', only the shallow subtree for the XPath is returned (object with keys only), no descendants
* - If undefined, both config and state data are returned
* @returns {Observable<GetDataResult>} Observable of the result
*/
getData(xpath: string, resultType?: GetDataResultType): Observable<GetDataResult>;
/**
* Edit the configuration using `edit-config` RPC and merge operation
*
* @param {string} xpath XPath filter of the configuration object,
* for example, `/aaa/authentication/users/user[name="admin"]`
* @param {NetconfType} values New config object - a key-value pair object that can have
* nested objects, for example `{homedir: '/home/admin'}`
* @returns {Observable<EditConfigResult>} Observable of the result
*/
editConfigMerge(xpath: string, values: NetconfType): Observable<EditConfigResult>;
/**
* Creates a leaf in the configuration specified by XPath filter.
* Default operation is 'create', so if an item exists, confd will return error.
* If beforeKey is specified, the item will be inserted before the specified item.
*
* @param {string} xpath XPath filter of the leaf where the item needs to be inserted
* for example, /aaa/authentication/users/user
* @param {NetconfType} values New item config, for example {name: 'admin', homedir: '/home/admin'}
* @param {string} beforeKey If specified, the item will be inserted before the item specified by this key
* for example, '[name="oper"]'
* @returns {Observable<EditConfigResult>} Observable of the result
*/
editConfigCreate(xpath: string, values: NetconfType, beforeKey?: string): Observable<EditConfigResult>;
/**
* Creates a list item in the configuration.
*
* @param {string} xpath XPath filter of the object where the item needs to be created
* @param {NetconfPrimitiveType[]} listItems List of items to create
* @returns {Observable<EditConfigResult>} Observable of the result
*/
editConfigCreateListItems(xpath: string, listItems: NetconfPrimitiveType[]): Observable<EditConfigResult>;
/**
* Deletes a leaf in the configuration. Leaf is specified by XPath filter.
*
* @param {string} xpath XPath filter of the leaf where the item needs to be deleted
* for example, `/aaa/authentication/users/user`
* @param {NetconfType} values object containing the leaf key, for example `{name: 'admin'}`
* @returns {Observable<EditConfigResult>} Observable of the result
*/
editConfigDelete(xpath: string, values: NetconfType): Observable<EditConfigResult>;
/**
* Deletes a list item in the configuration.
*
* @param {string} xpath XPath filter of the object where the item needs to be deleted
* @param {NetconfPrimitiveType[]} listItems List of items to delete
* @returns {Observable<EditConfigResult>} Observable of the result
*/
editConfigDeleteListItems(xpath: string, listItems: NetconfPrimitiveType[]): Observable<EditConfigResult>;
/**
* Replaces a leaf in the configuration. Leaf is specified by XPath filter.
*
* @param {string} xpath XPath filter of the leaf where the item needs to be replaced
* for example, `/aaa/authentication/users/user`
* @param {NetconfType} values object containing the leaf key, for example `{name: 'admin'}`
* @returns {Observable<EditConfigResult>} Observable of the result
*/
editConfigReplace(xpath: string, values: NetconfType): Observable<EditConfigResult>;
/**
* Replaces a list item in the configuration.
*
* @param {string} xpath XPath filter of the object where the item needs to be replaced
* @param {NetconfPrimitiveType[]} listItems List of items to replace
* @returns {Observable<EditConfigResult>} Observable of the result
*/
editConfigReplaceListItems(xpath: string, listItems: NetconfPrimitiveType[]): Observable<EditConfigResult>;
/**
* Creates a subscription to the Netconf server and returns an observable that emits notifications as they arrive.
* See README for an example.
*
* @param {SubscriptionOption} option Subscription option - either xpath filter or stream name
* @param {Subject<void>} stop$ A subject that should emit a value to stop the subscription
* @returns {Observable<NotificationResult | RpcResult | undefined>} Observable of the result. Observable emits
* the following items in order:
* - `RpcResult` with the server's RPC response when the subscription is created
* - `NotificationResult` when a notification is received
* - `undefined` when the subscription is stopped
*/
subscription(option: SubscriptionOption, stop$?: Subject<void>): Observable<NotificationResult | RpcResult | undefined>;
protected fetchSchema(xpath: string): Observable<RpcReplyType>;
protected guessNamespace(xpath: string): Observable<string | undefined>;
private editConfig;
private checkMultipleEdit;
/**
* Given an object and one of its children, recursively traverse the object to find the parent of the given child
* @param root - The root object
* @param obj - The child object
* @returns The child's parent object
*/
private findParent;
}
//# sourceMappingURL=netconf.d.ts.map