提交 3bb78a2e 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!523 Fix startup console message to optionally print ssh server ip

Merge pull request !523 from LiHongzhang/show_all_ipaddrs
......@@ -16,7 +16,6 @@
import os
import re
import shlex
import socket
import stat
import subprocess
import time
......@@ -212,17 +211,20 @@ class GunicornLogger(Logger):
def _get_all_ip_addresses(host):
"""Get all the accessible IP address."""
localhost, hostname = '127.0.0.1', socket.gethostname()
_, _, ip_addresses = socket.gethostbyname_ex(hostname)
if localhost in ip_addresses:
ip_addresses.remove(localhost)
yield localhost
if host == localhost:
yield host
if host == '127.0.0.1':
return
if host not in ip_addresses:
yield from ip_addresses
else:
yield host
# The format of the environment variable SSH_CONNECTION is:
# '<client_ip> <client_port> <server_ip> <server_port>'
connection = os.getenv('SSH_CONNECTION', '')
if len(connection) > 128:
# The length should be less than 128 bytes, or the variable may be corruped.
# And 128 bytes should be enough to hold two IPs and two ports.
return
connection = connection.split()
if len(connection) == 4 and connection[2] != host:
# 'connection' should hold 4 components and '<server_ip>' should be in index 2.
yield connection[2]
def start():
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册