From 4a6be1b1c3defc56210fc947d543fb79df0f4aa9 Mon Sep 17 00:00:00 2001 From: chalice-1831 <844589474@qq.com> Date: Wed, 17 Apr 2024 19:29:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20pagent=E8=8E=B7=E5=8F=96=E4=B8=8A?= =?UTF-8?q?=E6=B8=B8=E8=8A=82=E7=82=B9ip=E6=97=B6=E6=A0=B9=E6=8D=AEpagent?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E7=9A=84ip=E7=B1=BB=E5=9E=8B=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=AF=B9=E5=BA=94=E8=8A=82=E7=82=B9(closed=20#2032)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/backend/agent/tools.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/backend/agent/tools.py b/apps/backend/agent/tools.py index 2ba78491c..6887b1776 100644 --- a/apps/backend/agent/tools.py +++ b/apps/backend/agent/tools.py @@ -15,6 +15,7 @@ from django.conf import settings from apps.adapters.api.gse import get_gse_api_helper +from apps.backend.exceptions import GenCommandsError from apps.backend.subscription.steps.agent_adapter.base import AgentSetupInfo from apps.core.script_manage.base import ScriptHook from apps.core.script_manage.handlers import ScriptManageHandler @@ -81,6 +82,19 @@ def gen_nginx_download_url(nginx_ip: str) -> str: return f"http://{nginx_ip}:{settings.BK_NODEMAN_NGINX_DOWNLOAD_PORT}/" +def gen_pagent_upstream_ips(host: models.Host, proxies: List[models.Host]) -> List[str]: + proxy_ips: List[str] = [] + if host.inner_ipv6 and not host.inner_ip: + proxy_ips = list(set([proxy.inner_ipv6 for proxy in proxies])) + if not proxy_ips: + raise GenCommandsError(context=("Proxy IPv6地址获取失败,请检查Proxy是否存在IPv6地址")) + else: + proxy_ips = list(set([proxy.inner_ip or proxy.inner_ipv6 for proxy in proxies])) + if not proxy_ips: + raise GenCommandsError(context=("Proxy IP地址获取失败,请检查Proxy是否存在IPv4或IPv6地址")) + return proxy_ips + + def fetch_gse_servers_info( agent_setup_info: AgentSetupInfo, host: models.Host, @@ -118,7 +132,7 @@ def fetch_gse_servers_info( callback_url = host_ap.outer_callback_url or settings.BKAPP_NODEMAN_OUTER_CALLBACK_URL else: # PAGENT的场景 - proxy_ips = list(set([proxy.inner_ip or proxy.inner_ipv6 for proxy in proxies])) + proxy_ips: list = gen_pagent_upstream_ips(host, proxies) bt_file_server_hosts = proxy_ips data_server_hosts = proxy_ips task_server_hosts = proxy_ips