-
Notifications
You must be signed in to change notification settings - Fork 403
feat: 配置平台(CMDB) 相关插件支持 云区域:IP #7432 #7454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
normal-wls
merged 10 commits into
TencentBlueKing:master
from
lTimej:release_3.32.2_by_master_7432
Aug 21, 2024
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c920103
feat: 配置平台(CMDB) 相关插件支持 云区域:IP #7432
lTimej bf4e0fa
feat: 配置平台(CMDB) 相关插件支持 云区域:IP #7432
lTimej 815bcb6
feat: 配置平台(CMDB) 相关插件支持 云区域:IP #7432
lTimej e0e65b8
feat: 配置平台(CMDB) 相关插件支持 云区域:IP #7432
lTimej 1d850f6
feat: 配置平台(CMDB) 相关插件支持 云区域:IP #7432
lTimej 58349d4
feat: 配置平台(CMDB) 相关插件支持 云区域:IP #7432
lTimej 0e52170
feat: 配置平台(CMDB) 相关插件支持 云区域:IP #7432
lTimej 84d956f
feat: 配置平台(CMDB) 相关插件支持 云区域:IP #7432
lTimej 5a74350
feat: 配置平台(CMDB) 相关插件支持 云区域:IP #7432
lTimej 06033eb
feat: 配置平台(CMDB) 相关插件支持 云区域:IP #7432
lTimej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
get_ip_by_regex_type, | ||
ip_pattern, | ||
ipv6_pattern, | ||
plat_ip_reg, | ||
) | ||
from pipeline_plugins.components.collections.sites.open.cc.ipv6_utils import ( | ||
get_hosts_by_hosts_ids, | ||
|
@@ -138,6 +139,70 @@ def cc_get_host_id_by_innerip(executor, bk_biz_id, ip_list, supplier_account): | |
return {"result": True, "data": [str(host["bk_host_id"]) for host in host_list]} | ||
|
||
|
||
def cc_get_host_id_by_str(executor, bk_biz_id, ip_str, supplier_account): | ||
""" | ||
:param executor: API 请求用户身份 | ||
:type executor: string | ||
:param bk_biz_id: 业务 CC ID | ||
:type bk_biz_id: int | ||
:param ip_str: 主机内网 IP | ||
:type ip_str: string | ||
:param supplier_account: 开发商账号 | ||
:type supplier_account: int | ||
:return: 主机 id 列表 | ||
@note: 需要兼容的ip_str格式有 | ||
1: IP,纯IP格式 | ||
2: 管控区域ID:IP | ||
:return: 主机 id 列表 | ||
:rtype: list | ||
["1", "2", "3", ...] | ||
""" | ||
ip_list = get_ip_by_regex(ip_str) | ||
# 格式2 管控区域ID:IP | ||
if plat_ip_reg.match(ip_str): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里如果部分带了部分没带,看上去有问题 |
||
host_list = cmdb.get_business_host( | ||
executor, | ||
bk_biz_id, | ||
supplier_account, | ||
["bk_host_id", "bk_host_innerip", "bk_cloud_id"], | ||
ip_list, | ||
) | ||
|
||
if not host_list: | ||
message = _(f"IP {ip_list} 在本业务下不存在: 请检查配置, 修复后重新执行 | cc_get_host_id_by_str") | ||
logger.error(message) | ||
return {"result": False, "message": message} | ||
|
||
if len(host_list) > len(ip_list): | ||
# find repeat innerip host | ||
hosts = [] | ||
c_hosts = [] | ||
for host in host_list: | ||
if {host["bk_host_innerip"]: host.get("bk_cloud_id", "")} in hosts: | ||
c_hosts.append(host["bk_host_innerip"]) | ||
else: | ||
hosts.append({host["bk_host_innerip"]: host.get("bk_cloud_id", "")}) | ||
if len(c_hosts) > 0: | ||
message = _(f"IP [{', '.join(c_hosts)}] 在本业务下重复: 请检查配置, 修复后重新执行 | cc_get_host_id_by_str") | ||
logger.error(message) | ||
return { | ||
"result": False, | ||
"message": message, | ||
} | ||
|
||
if len(host_list) < len(ip_list): | ||
return_innerip_set = {host["bk_host_innerip"] for host in host_list} | ||
absent_innerip = set(ip_list).difference(return_innerip_set) | ||
message = _(f"IP [{', '.join(absent_innerip)}] 在本业务下不存在: 请检查配置, 修复后重新执行 | cc_get_host_id_by_str") | ||
logger.error(message) | ||
return {"result": False, "message": message} | ||
|
||
return {"result": True, "data": [str(host["bk_host_id"]) for host in host_list]} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. host_list 看上去会有冗余,这里不合理。假如1.1.1.1的机器有两台,那么这里我填了0:1.1.1.1之后,会得到两个 host_id |
||
# 格式1 纯IP格式 | ||
else: | ||
return cc_get_host_id_by_innerip(executor, bk_biz_id, ip_list, supplier_account) | ||
|
||
|
||
def cc_get_host_by_innerip_with_ipv6( | ||
executor, bk_biz_id, ip_str, supplier_account, is_biz_set=False, host_id_detail=False | ||
): | ||
|
@@ -458,8 +523,7 @@ def get_host_list(self, executor, biz_cc_id, ip_str, supplier_account): | |
if not host_result["result"]: | ||
return host_result | ||
return {"result": True, "data": [str(host["bk_host_id"]) for host in host_result["data"]]} | ||
ip_list = get_ip_by_regex(ip_str) | ||
return cc_get_host_id_by_innerip(executor, biz_cc_id, ip_list, supplier_account) | ||
return cc_get_host_id_by_str(executor, biz_cc_id, ip_str, supplier_account) | ||
|
||
def get_ip_info_list(self, executor, biz_cc_id, ip_str, supplier_account): | ||
""" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看实现,这个函数只能识别不带云区域的字符串
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ip_list = ["0:1.1.1.1", "2.2.2.2"]
0:1:1.1.1.1 1:2:2.2.2.2
len(host_list) == len(ip_list)