From 03560a978b076e0a8855771f775523bfc0c41858 Mon Sep 17 00:00:00 2001 From: caleb Date: Fri, 30 Aug 2024 12:32:37 -0400 Subject: [PATCH] stop calling websocket_local_ip --- .../middlewared/plugins/apps/crud.py | 10 +++++++++- .../middlewared/plugins/vm/vm_display_info.py | 19 ++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/middlewared/middlewared/plugins/apps/crud.py b/src/middlewared/middlewared/plugins/apps/crud.py index 56f7e96288fca..8450dc8493716 100644 --- a/src/middlewared/middlewared/plugins/apps/crud.py +++ b/src/middlewared/middlewared/plugins/apps/crud.py @@ -93,9 +93,17 @@ def query(self, app, filters, options): return filter_list([], filters, options) extra = options.get('extra', {}) + host_ip = extra.get('host_ip') + if not host_ip: + try: + if app.origin.is_tcp_ip_family: + host_ip = app.origin.loc_addr + except AttributeError: + pass + retrieve_app_schema = extra.get('include_app_schema', False) kwargs = { - 'host_ip': extra.get('host_ip') or self.middleware.call_sync('interface.websocket_local_ip', app=app), + 'host_ip': host_ip, 'retrieve_config': extra.get('retrieve_config', False), 'image_update_cache': self.middleware.call_sync('app.image.op.get_update_cache', True), } diff --git a/src/middlewared/middlewared/plugins/vm/vm_display_info.py b/src/middlewared/middlewared/plugins/vm/vm_display_info.py index 1d5cdf0c03412..2e69513e5fd08 100644 --- a/src/middlewared/middlewared/plugins/vm/vm_display_info.py +++ b/src/middlewared/middlewared/plugins/vm/vm_display_info.py @@ -1,6 +1,6 @@ -import ipaddress +from socket import AF_INET6 -from middlewared.schema import accepts, Dict, Int, List, Ref, returns, Str +from middlewared.schema import accepts, Dict, Int, List, returns, Str from middlewared.service import pass_app, private, Service from .devices import DISPLAY @@ -94,13 +94,14 @@ async def get_display_web_uri(self, app, id_, host, options): """ uri_data = {'error': None, 'uri': None} protocol = options['protocol'].lower() - host = host or await self.middleware.call('interface.websocket_local_ip', app=app) - try: - ipaddress.IPv6Address(host) - except ipaddress.AddressValueError: - pass - else: - host = f'[{host}]' + if not host: + try: + if app.origin.is_tcp_ip_family and (_h := app.origin.loc_addr): + host = _h + if app.origin.family == AF_INET6: + host = f'[{_h}]' + except AttributeError: + pass if display_devices := await self.get_display_devices(id_): for device in map(lambda d: DISPLAY(d, middleware=self.middleware), display_devices):