Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Add ip address cached to resolve network issue #220

Merged
merged 12 commits into from
Oct 16, 2018
19 changes: 14 additions & 5 deletions src/nni_manager/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,27 @@ function cleanupUnitTest(): void {
Container.restore(ExperimentStartupInfo);
}

let cachedipv4Address : string = '';
/**
* Get IPv4 address of current machine
*/
function getIPV4Address(): string {
let ipv4Address : string = '';
if (cachedipv4Address && cachedipv4Address.length > 0) {
return cachedipv4Address;
}

for(const item of os.networkInterfaces().eth0) {
if(item.family === 'IPv4') {
ipv4Address = item.address;
if(os.networkInterfaces().eth0) {
for(const item of os.networkInterfaces().eth0) {
if(item.family === 'IPv4') {
cachedipv4Address = item.address;
return cachedipv4Address;
}
}
} else {
throw Error('getIPV4Address() failed because os.networkInterfaces().eth0 is undefined.');
}
return ipv4Address;

throw Error('getIPV4Address() failed because no valid IPv4 address found.')
}

export { generateParamFileName, getMsgDispatcherCommand, getLogDir, getExperimentRootDir,
Expand Down