Use loopback address for local host (fixes issue with locked down networks) (#65)

This commit is contained in:
2023-11-21 03:16:26 -06:00
committed by GitHub
parent e9f9521924
commit 32afcf945d

View File

@@ -20,6 +20,7 @@ categories = [RenderStatus.RUNNING, RenderStatus.WAITING_FOR_SUBJOBS, RenderStat
logger = logging.getLogger() logger = logging.getLogger()
OFFLINE_MAX = 2 OFFLINE_MAX = 2
LOOPBACK = '127.0.0.1'
class RenderServerProxy: class RenderServerProxy:
@@ -34,6 +35,7 @@ class RenderServerProxy:
self.__background_thread = None self.__background_thread = None
self.__offline_flags = 0 self.__offline_flags = 0
self.update_cadence = 5 self.update_cadence = 5
self.is_localhost = is_localhost(hostname)
# Cache some basic server info # Cache some basic server info
self.system_cpu = None self.system_cpu = None
@@ -75,7 +77,8 @@ class RenderServerProxy:
return None return None
def request(self, payload, timeout=5): def request(self, payload, timeout=5):
return requests.get(f'http://{self.hostname}:{self.port}/api/{payload}', timeout=timeout) hostname = LOOPBACK if self.is_localhost else self.hostname
return requests.get(f'http://{hostname}:{self.port}/api/{payload}', timeout=timeout)
def start_background_update(self): def start_background_update(self):
if self.__update_in_background: if self.__update_in_background:
@@ -140,15 +143,16 @@ class RenderServerProxy:
return self.request_data('all_engines') return self.request_data('all_engines')
def notify_parent_of_status_change(self, parent_id, subjob): def notify_parent_of_status_change(self, parent_id, subjob):
return requests.post(f'http://{self.hostname}:{self.port}/api/job/{parent_id}/notify_parent_of_status_change', hostname = LOOPBACK if self.is_localhost else self.hostname
return requests.post(f'http://{hostname}:{self.port}/api/job/{parent_id}/notify_parent_of_status_change',
json=subjob.json()) json=subjob.json())
def post_job_to_server(self, file_path, job_list, callback=None): def post_job_to_server(self, file_path, job_list, callback=None):
# bypass uploading file if posting to localhost # bypass uploading file if posting to localhost
if is_localhost(self.hostname): if self.is_localhost:
jobs_with_path = [{**item, "local_path": file_path} for item in job_list] jobs_with_path = [{**item, "local_path": file_path} for item in job_list]
return requests.post(f'http://{self.hostname}:{self.port}/api/add_job', data=json.dumps(jobs_with_path), return requests.post(f'http://{LOOPBACK}:{self.port}/api/add_job', data=json.dumps(jobs_with_path),
headers={'Content-Type': 'application/json'}) headers={'Content-Type': 'application/json'})
# Prepare the form data # Prepare the form data
@@ -168,7 +172,8 @@ class RenderServerProxy:
return requests.post(f'http://{self.hostname}:{self.port}/api/add_job', data=monitor, headers=headers) return requests.post(f'http://{self.hostname}:{self.port}/api/add_job', data=monitor, headers=headers)
def get_job_files(self, job_id, save_path): def get_job_files(self, job_id, save_path):
url = f"http://{self.hostname}:{self.port}/api/job/{job_id}/download_all" hostname = LOOPBACK if self.is_localhost else self.hostname
url = f"http://{hostname}:{self.port}/api/job/{job_id}/download_all"
return self.download_file(url, filename=save_path) return self.download_file(url, filename=save_path)
@staticmethod @staticmethod
@@ -188,4 +193,5 @@ class RenderServerProxy:
def delete_engine(self, engine, version, system_cpu=None): def delete_engine(self, engine, version, system_cpu=None):
form_data = {'engine': engine, 'version': version, 'system_cpu': system_cpu} form_data = {'engine': engine, 'version': version, 'system_cpu': system_cpu}
return requests.post(f'http://{self.hostname}:{self.port}/api/delete_engine', json=form_data) hostname = LOOPBACK if self.is_localhost else self.hostname
return requests.post(f'http://{hostname}:{self.port}/api/delete_engine', json=form_data)