source: trip-planner-front/node_modules/default-gateway/ibmi.js@ 6a3a178

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
Line 
1"use strict";
2
3const execa = require("execa");
4
5const db2util = "/QOpenSys/pkgs/bin/db2util";
6const sql = "select NEXT_HOP, LOCAL_BINDING_INTERFACE from QSYS2.NETSTAT_ROUTE_INFO where ROUTE_TYPE='DFTROUTE' and NEXT_HOP!='*DIRECT' and CONNECTION_TYPE=?";
7
8const 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
22const promise = family => {
23 return execa.stdout(db2util, [sql, "-p", family, "-o", "json"]).then(stdout => parse(stdout));
24};
25
26const sync = family => {
27 const {stdout} = execa.sync(db2util, [sql, "-p", family, "-o", "json"]);
28 return parse(stdout);
29};
30
31module.exports.v4 = () => promise("IPV4");
32module.exports.v6 = () => promise("IPV6");
33
34module.exports.v4.sync = () => sync("IPV4");
35module.exports.v6.sync = () => sync("IPV6");
Note: See TracBrowser for help on using the repository browser.