use 'get_host_ip' on more places

This commit is contained in:
Jakub Trllo 2023-01-06 17:48:05 +01:00
parent cd2324f07e
commit e1edb76f73
4 changed files with 25 additions and 22 deletions

View file

@ -3,6 +3,7 @@ import socket
import getpass
from openpype_modules.ftrack.lib import BaseAction
from openpype_modules.ftrack.ftrack_server.lib import get_host_ip
class ActionWhereIRun(BaseAction):
@ -53,8 +54,7 @@ class ActionWhereIRun(BaseAction):
try:
host_name = socket.gethostname()
msgs["Hostname"] = host_name
host_ip = socket.gethostbyname(host_name)
msgs["IP"] = host_ip
msgs["IP"] = get_host_ip() or "N/A"
except Exception:
pass

View file

@ -26,6 +26,7 @@ from openpype_modules.ftrack import (
)
from openpype_modules.ftrack.lib import credentials
from openpype_modules.ftrack.ftrack_server import socket_thread
from openpype_modules.ftrack.ftrack_server.lib import get_host_ip
class MongoPermissionsError(Exception):
@ -169,22 +170,6 @@ def legacy_server(ftrack_url):
time.sleep(1)
def get_host_ip():
host_name = socket.gethostname()
try:
return socket.gethostbyname(host_name)
except Exception:
pass
try:
import ipaddress
return socket.gethostbyname(str(ipaddress.ip_address(8888)))
except Exception:
pass
return None
def main_loop(ftrack_url):
""" This is main loop of event handling.

View file

@ -9,8 +9,9 @@ import time
import queue
import collections
import appdirs
import pymongo
import socket
import pymongo
import requests
import ftrack_api
import ftrack_api.session
@ -32,6 +33,22 @@ TOPIC_STATUS_SERVER = "openpype.event.server.status"
TOPIC_STATUS_SERVER_RESULT = "openpype.event.server.status.result"
def get_host_ip():
host_name = socket.gethostname()
try:
return socket.gethostbyname(host_name)
except Exception:
pass
try:
import ipaddress
return socket.gethostbyname(str(ipaddress.ip_address(8888)))
except Exception:
pass
return None
class SocketBaseEventHub(ftrack_api.event.hub.EventHub):
hearbeat_msg = b"hearbeat"

View file

@ -15,7 +15,8 @@ from openpype_modules.ftrack.ftrack_server.lib import (
SocketSession,
StatusEventHub,
TOPIC_STATUS_SERVER,
TOPIC_STATUS_SERVER_RESULT
TOPIC_STATUS_SERVER_RESULT,
get_host_ip
)
from openpype.lib import (
Logger,
@ -29,10 +30,10 @@ log = Logger.get_logger("Event storer")
action_identifier = (
"event.server.status" + os.environ["FTRACK_EVENT_SUB_ID"]
)
host_ip = socket.gethostbyname(socket.gethostname())
host_ip = get_host_ip()
action_data = {
"label": "OpenPype Admin",
"variant": "- Event server Status ({})".format(host_ip),
"variant": "- Event server Status ({})".format(host_ip or "IP N/A"),
"description": "Get Infromation about event server",
"actionIdentifier": action_identifier
}