"git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "b031c76ce0e1494b130d8b244278ab570a44c828"
Unverified Commit 51c6afde authored by liuzhe-lz's avatar liuzhe-lz Committed by GitHub
Browse files

change ipv4 detection method (#3860)


Co-authored-by: default avatarliuzhe <zhe.liu@microsoft.com>
parent 27e123df
astor astor
hyperopt == 0.1.2 hyperopt == 0.1.2
json_tricks json_tricks
netifaces
psutil psutil
pyyaml pyyaml
requests requests
......
...@@ -5,7 +5,6 @@ import json ...@@ -5,7 +5,6 @@ import json
import logging import logging
import os import os
import netifaces
from schema import And, Optional, Or, Regex, Schema, SchemaError from schema import And, Optional, Or, Regex, Schema, SchemaError
from nni.tools.package_utils import ( from nni.tools.package_utils import (
create_validator_instance, create_validator_instance,
...@@ -493,7 +492,6 @@ class NNIConfigSchema: ...@@ -493,7 +492,6 @@ class NNIConfigSchema:
self.validate_tuner_adivosr_assessor(experiment_config) self.validate_tuner_adivosr_assessor(experiment_config)
self.validate_pai_trial_conifg(experiment_config) self.validate_pai_trial_conifg(experiment_config)
self.validate_kubeflow_operators(experiment_config) self.validate_kubeflow_operators(experiment_config)
self.validate_eth0_device(experiment_config)
self.validate_hybrid_platforms(experiment_config) self.validate_hybrid_platforms(experiment_config)
self.validate_frameworkcontroller_trial_config(experiment_config) self.validate_frameworkcontroller_trial_config(experiment_config)
...@@ -599,13 +597,6 @@ class NNIConfigSchema: ...@@ -599,13 +597,6 @@ class NNIConfigSchema:
print_warning(warning_information.format('outputDir')) print_warning(warning_information.format('outputDir'))
self.validate_pai_config_path(experiment_config) self.validate_pai_config_path(experiment_config)
def validate_eth0_device(self, experiment_config):
'''validate whether the machine has eth0 device'''
if experiment_config.get('trainingServicePlatform') not in ['local'] \
and not experiment_config.get('nniManagerIp') \
and 'eth0' not in netifaces.interfaces():
raise SchemaError('This machine does not contain eth0 network device, please set nniManagerIp in config file!')
def validate_hybrid_platforms(self, experiment_config): def validate_hybrid_platforms(self, experiment_config):
required_config_name_map = { required_config_name_map = {
'remote': 'machineList', 'remote': 'machineList',
......
...@@ -8,6 +8,7 @@ import { randomBytes } from 'crypto'; ...@@ -8,6 +8,7 @@ import { randomBytes } from 'crypto';
import * as cpp from 'child-process-promise'; import * as cpp from 'child-process-promise';
import * as cp from 'child_process'; import * as cp from 'child_process';
import { ChildProcess, spawn, StdioOptions } from 'child_process'; import { ChildProcess, spawn, StdioOptions } from 'child_process';
import * as dgram from 'dgram';
import * as fs from 'fs'; import * as fs from 'fs';
import * as net from 'net'; import * as net from 'net';
import * as os from 'os'; import * as os from 'os';
...@@ -217,28 +218,24 @@ function cleanupUnitTest(): void { ...@@ -217,28 +218,24 @@ function cleanupUnitTest(): void {
setExperimentStartupInfo(true, 'unittest', 8080, 'unittest', undefined, logLevel); setExperimentStartupInfo(true, 'unittest', 8080, 'unittest', undefined, logLevel);
} }
let cachedipv4Address: string = ''; let cachedIpv4Address: string | null = null;
/** /**
* Get IPv4 address of current machine * Get IPv4 address of current machine.
*/ */
function getIPV4Address(): string { function getIPV4Address(): string {
if (cachedipv4Address && cachedipv4Address.length > 0) { if (cachedIpv4Address !== null) {
return cachedipv4Address; return cachedIpv4Address;
} }
const networkInterfaces = os.networkInterfaces(); // creates "udp connection" to a non-exist target, and get local address of the connection.
if (networkInterfaces.eth0) { // since udp is connectionless, this does not send actual packets.
for (const item of networkInterfaces.eth0) { const socket = dgram.createSocket('udp4');
if (item.family === 'IPv4') { socket.connect(1, '192.0.2.0');
cachedipv4Address = item.address; cachedIpv4Address = socket.address().address;
return cachedipv4Address; socket.close();
}
}
} else {
throw Error(`getIPV4Address() failed because os.networkInterfaces().eth0 is undefined. Please specify NNI manager IP in config.`);
}
throw Error('getIPV4Address() failed because no valid IPv4 address found.') return cachedIpv4Address;
} }
/** /**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment