Skip to content

Commit 57a75d3

Browse files
ThePrezsilverwind
authored andcommitted
WIP: initial pure js impl for IBM i AIX variant (#11)
* initial pure js impl for IBM i AIX variant * Fix style errors * minor bugfix with unassigned const * fix style errors #2 * remove silly plus sign
1 parent 50c5137 commit 57a75d3

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

aix.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use strict";
2+
3+
const execa = require("execa");
4+
5+
const sql = "select NEXT_HOP, LOCAL_BINDING_INTERFACE from QSYS2.NETSTAT_ROUTE_INFO where ROUTE_TYPE='DFTROUTE' and NEXT_HOP!='*DIRECT' and CONNECTION_TYPE=?";
6+
7+
const checkVariant = () => {if (require("os").type() !== "OS400") throw new Error("Unsupported AIX variant"); };
8+
9+
const parse = stdout => {
10+
let result;
11+
try {
12+
const resultObj = JSON.parse(stdout);
13+
const gateway = resultObj.records[0].NEXT_HOP;
14+
const iface = resultObj.records[0].LOCAL_BINDING_INTERFACE;
15+
result = {gateway, iface};
16+
} catch {}
17+
if (!result) {
18+
throw new Error("Unable to determine default gateway");
19+
}
20+
return result;
21+
};
22+
23+
const promise = family => {
24+
checkVariant();
25+
return execa.stdout("/QOpenSys/pkgs/bin/db2util", [sql, "-p", family, "-o", "json"]).then(stdout => {
26+
return parse(stdout);
27+
});
28+
};
29+
30+
const sync = family => {
31+
checkVariant();
32+
const result = execa.sync("/QOpenSys/pkgs/bin/db2util", [sql, "-p", family, "-o", "json"]);
33+
return parse(result.stdout);
34+
};
35+
36+
module.exports.v4 = () => promise("IPV4");
37+
module.exports.v6 = () => promise("IPV6");
38+
39+
module.exports.v4.sync = () => sync("IPV4");
40+
module.exports.v6.sync = () => sync("IPV6");

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ if ([
1010
"openbsd",
1111
"sunos",
1212
"win32",
13+
"aix",
1314
].indexOf(platform) !== -1) {
1415
const families = require(`./${platform}`);
1516
module.exports.v4 = () => families.v4();

0 commit comments

Comments
 (0)