|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.0 KB
|
| Line | |
|---|
| 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 {}
|
|---|
| 16 | if (!result) {
|
|---|
| 17 | throw new Error("Unable to determine default gateway");
|
|---|
| 18 | }
|
|---|
| 19 | return result;
|
|---|
| 20 | };
|
|---|
| 21 |
|
|---|
| 22 | const promise = async family => {
|
|---|
| 23 | const {stdout} = await execa(db2util, [sql, "-p", family, "-o", "json"]);
|
|---|
| 24 | return parse(stdout);
|
|---|
| 25 | };
|
|---|
| 26 |
|
|---|
| 27 | const sync = family => {
|
|---|
| 28 | const {stdout} = execa.sync(db2util, [sql, "-p", family, "-o", "json"]);
|
|---|
| 29 | return parse(stdout);
|
|---|
| 30 | };
|
|---|
| 31 |
|
|---|
| 32 | module.exports.v4 = () => promise("IPV4");
|
|---|
| 33 | module.exports.v6 = () => promise("IPV6");
|
|---|
| 34 |
|
|---|
| 35 | module.exports.v4.sync = () => sync("IPV4");
|
|---|
| 36 | module.exports.v6.sync = () => sync("IPV6");
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.