Skip to content

Commit

Permalink
feat: 上云环境针对0区域限制新增主机校验提到API层级 (closed TencentBlueKing#2501)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpyoung3 committed Dec 5, 2024
1 parent 515dfaa commit d5734de
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions apps/node_man/tools/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,23 +570,25 @@ def add_host_cloud_blacklist(cls) -> List[int]:
return add_host_cloud_blacklist or []

@classmethod
def check_limit_add_host(cls, hosts):
def check_limit_add_host(cls, hosts: List[Dict[str, Any]]):
host_infos_gby_addressing: Dict[str, List[Dict[str, Any]]] = defaultdict(list)
for host in hosts:
bk_addressing: str = host.get("bk_addressing", constants.CmdbAddressingType.STATIC.value)
host_infos_gby_addressing[bk_addressing].append(host)
for addressing, host_infos in host_infos_gby_addressing.items():
cmdb_hosts = JobTools.query_hosts_by_addressing(host_infos, addressing)
cmdb_host_ips_set = {
cmdb_host_ips = {
ip for host in cmdb_hosts for ip in [host.get("bk_host_innerip"), host.get("bk_host_innerip_v6")] if ip
}
host_ips = {
ip for host in host_infos for ip in [host.get("inner_ip"), host.get("inner_ipv6")] if ip is not None
}
ip_host_map = {host["inner_ip"]: host for host in host_infos if host.get("inner_ip") is not None}
ip_host_map.update({host["inner_ipv6"]: host for host in host_infos if host.get("inner_ipv6") is not None})
ip_host_map = {host.get("inner_ip"): host for host in host_infos if host.get("inner_ip") is not None}
ip_host_map.update(
{host.get("inner_ipv6"): host for host in host_infos if host.get("inner_ipv6") is not None}
)
for ip in host_ips:
if ip in cmdb_host_ips_set:
if ip in cmdb_host_ips:
continue
host = ip_host_map.get(ip)
if not host:
Expand Down

0 comments on commit d5734de

Please sign in to comment.