From c3471843aa9535f257cedcbe156998c419259b22 Mon Sep 17 00:00:00 2001 From: Leodinas Hao Date: Wed, 25 Sep 2019 09:14:57 +1000 Subject: [PATCH] Add types for netconf (#38287) * add types for netconf * refactor: set `strictNullChecks` to true * refactor: change to 'dt.json' from 'dtslint.json' * docs: add notes * docs: minor change --- types/netconf/index.d.ts | 57 ++++++++++++++++++++++++++++++++++ types/netconf/netconf-tests.ts | 21 +++++++++++++ types/netconf/tsconfig.json | 23 ++++++++++++++ types/netconf/tslint.json | 3 ++ 4 files changed, 104 insertions(+) create mode 100644 types/netconf/index.d.ts create mode 100644 types/netconf/netconf-tests.ts create mode 100644 types/netconf/tsconfig.json create mode 100644 types/netconf/tslint.json diff --git a/types/netconf/index.d.ts b/types/netconf/index.d.ts new file mode 100644 index 0000000000..26b47574de --- /dev/null +++ b/types/netconf/index.d.ts @@ -0,0 +1,57 @@ +// Type definitions for netconf 2.0 +// Project: https://github.com/darylturner/node-netconf +// Definitions by: Leodinas Hao +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export class Client { + /** + * Creates a new Client object by passing in the connection parameters. Both password and private key authentication methods are supported + */ + constructor(params: { + host: string, + username: string, + port?: number, + password?: string, + pkey?: string, + }) + + /** + * Opens a session + */ + open(callback: ((err: any) => void)): void; + + /** + * Sends requests. Requests are sent using the .rpc() method + */ + rpc(request: any, callback: ((err: any, reply: any) => void)): void; + + /** + * Closes the session + */ + close(callback?: (err: any) => void): void; + + /** + * Collects some useful information from several RPC calls and presents the results back + */ + facts(callback: ((err: any, facts: { hostname: string, version: string, module: string, uptime: string, serial: string }) => void)): void; + + /** + * Loads configuration data into candidate-config using NETCONF. Default options are equivalent to "load merge" and would expect configuration data in JunOS curly-brace format + */ + load(args: string | { config: any, action?: 'merge' | 'replace' | 'override' | 'update' | 'set', format?: 'text' | 'xml' }, callback: (err: any, reply: any) => void): void; + + /** + * Commits candidate configuration to device + */ + commit(callback: ((err: any, reply: any) => void)): void; + + /** + * Shows difference between running and candidate-config. Equivalent to "show | compare". + */ + compare(callback: ((err: any, diff: any) => void)): void; + + /** + * Discards candidate configuration on device + */ + rollback(callback: ((err: any, reply: any) => void)): void; +} diff --git a/types/netconf/netconf-tests.ts b/types/netconf/netconf-tests.ts new file mode 100644 index 0000000000..b67cf536a2 --- /dev/null +++ b/types/netconf/netconf-tests.ts @@ -0,0 +1,21 @@ +import * as netconf from 'netconf'; + +const router = new netconf.Client({ + host: '172.28.128.3', + username: 'vagrant', + password: 'password', +}); + +router.open((err) => { + if (err) { + throw err; + } + + router.rpc('get-arp-table-information', (err, reply) => { + router.close(); + if (err) { + throw err; + } + // console.log(reply); + }); +}); diff --git a/types/netconf/tsconfig.json b/types/netconf/tsconfig.json new file mode 100644 index 0000000000..57abc5af0e --- /dev/null +++ b/types/netconf/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "netconf-tests.ts" + ] +} \ No newline at end of file diff --git a/types/netconf/tslint.json b/types/netconf/tslint.json new file mode 100644 index 0000000000..30a1bdde2e --- /dev/null +++ b/types/netconf/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file