Last change
on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | const execa = require("execa");
|
---|
| 4 |
|
---|
| 5 | const db2util = "/QOpenSys/pkgs/bin/db2util";
|
---|
| 6 | const sql = "select NEXT_HOP, LOCAL_BINDING_INTERFACE from QSYS2.NETSTAT_ROUTE_INFO where ROUTE_TYPE='DFTROUTE' and NEXT_HOP!='*DIRECT' and CONNECTION_TYPE=?";
|
---|
| 7 |
|
---|
| 8 | const parse = stdout => {
|
---|
| 9 | let result;
|
---|
| 10 | try {
|
---|
| 11 | const resultObj = JSON.parse(stdout);
|
---|
| 12 | const gateway = resultObj.records[0].NEXT_HOP;
|
---|
| 13 | const iface = resultObj.records[0].LOCAL_BINDING_INTERFACE;
|
---|
| 14 | result = {gateway, iface};
|
---|
| 15 | } catch (err) {}
|
---|
| 16 | if (!result) {
|
---|
| 17 | throw new Error("Unable to determine default gateway");
|
---|
| 18 | }
|
---|
| 19 | return result;
|
---|
| 20 | };
|
---|
| 21 |
|
---|
| 22 | const promise = family => {
|
---|
| 23 | return execa.stdout(db2util, [sql, "-p", family, "-o", "json"]).then(stdout => parse(stdout));
|
---|
| 24 | };
|
---|
| 25 |
|
---|
| 26 | const sync = family => {
|
---|
| 27 | const {stdout} = execa.sync(db2util, [sql, "-p", family, "-o", "json"]);
|
---|
| 28 | return parse(stdout);
|
---|
| 29 | };
|
---|
| 30 |
|
---|
| 31 | module.exports.v4 = () => promise("IPV4");
|
---|
| 32 | module.exports.v6 = () => promise("IPV6");
|
---|
| 33 |
|
---|
| 34 | module.exports.v4.sync = () => sync("IPV4");
|
---|
| 35 | module.exports.v6.sync = () => sync("IPV6");
|
---|
Note:
See
TracBrowser
for help on using the repository browser.