新增get_jingrow_firewall_rules端点,前端防火墙列表改为使用get_jingrow_firewall_rules获取本地数据
This commit is contained in:
parent
bf658c478b
commit
45036ff400
@ -291,10 +291,11 @@ export default {
|
||||
resources: {
|
||||
firewallRules() {
|
||||
return {
|
||||
url: 'jcloud.api.aliyun_server_light.get_aliyun_firewall_rules',
|
||||
url: 'jcloud.api.aliyun_server_light.get_jingrow_firewall_rules',
|
||||
params: {
|
||||
instance_id: this.$jsiteServer.pg?.instance_id,
|
||||
region_id: this.$jsiteServer.pg?.region
|
||||
limit: this.pagination.limit,
|
||||
pageno: this.pagination.pageno
|
||||
},
|
||||
auto: true,
|
||||
onSuccess: (response) => {
|
||||
@ -311,22 +312,13 @@ export default {
|
||||
isNew: false
|
||||
}));
|
||||
|
||||
// 简单分页处理
|
||||
const total = this.firewallRules.length;
|
||||
const limit = this.pagination.limit;
|
||||
const pageno = this.pagination.pageno;
|
||||
const start = (pageno - 1) * limit;
|
||||
const end = start + limit;
|
||||
|
||||
// 使用API返回的分页信息
|
||||
this.pagination = {
|
||||
pageno: pageno,
|
||||
limit: limit,
|
||||
total: total,
|
||||
pagecount: Math.ceil(total / limit)
|
||||
pageno: response.data.pageno,
|
||||
limit: response.data.limit,
|
||||
total: response.data.total,
|
||||
pagecount: response.data.pagecount
|
||||
};
|
||||
|
||||
// 对当前页的数据进行切片
|
||||
this.firewallRules = this.firewallRules.slice(start, end);
|
||||
} else {
|
||||
this.error = response.message || '获取防火墙规则失败';
|
||||
}
|
||||
|
||||
@ -1781,4 +1781,73 @@ def sync_firewall_rules(instance_id):
|
||||
|
||||
except Exception as e:
|
||||
jingrow.log_error("同步防火墙规则失败", f"同步实例 {instance_id} 防火墙规则时发生错误: {str(e)}")
|
||||
return {"success": False, "error": str(e), "message": "同步防火墙规则失败"}
|
||||
return {"success": False, "error": str(e), "message": "同步防火墙规则失败"}
|
||||
|
||||
@jingrow.whitelist()
|
||||
def get_jingrow_firewall_rules(**data):
|
||||
"""获取防火墙规则(从本地数据库获取,支持分页)"""
|
||||
try:
|
||||
instance_id = data.get('instance_id')
|
||||
limit = data.get('limit', 20)
|
||||
pageno = data.get('pageno', 1)
|
||||
|
||||
if not instance_id:
|
||||
return {"success": False, "message": "缺少实例ID参数"}
|
||||
|
||||
# 查找对应的Jsite Server记录
|
||||
server_records = jingrow.get_all(
|
||||
"Jsite Server",
|
||||
{"instance_id": instance_id},
|
||||
["name"]
|
||||
)
|
||||
|
||||
if not server_records:
|
||||
return {"success": False, "message": "未找到指定的服务器记录"}
|
||||
|
||||
server_record = server_records[0]
|
||||
|
||||
# 获取该服务器的所有防火墙规则
|
||||
firewall_rules = jingrow.get_all(
|
||||
"Firewall Rules",
|
||||
{"parent": server_record.name},
|
||||
["name", "rule_id", "rule_protocol", "port", "source_cidr_ip", "remark"]
|
||||
)
|
||||
|
||||
# 转换为API格式的数据结构
|
||||
all_items = []
|
||||
for rule in firewall_rules:
|
||||
item = {
|
||||
"rule_id": rule.rule_id or rule.name,
|
||||
"rule_protocol": rule.rule_protocol or "",
|
||||
"port": rule.port or "",
|
||||
"source_cidr_ip": rule.source_cidr_ip or "0.0.0.0/0",
|
||||
"remark": rule.remark or ""
|
||||
}
|
||||
all_items.append(item)
|
||||
|
||||
# 对所有记录按协议排序
|
||||
sorted_items = sorted(all_items, key=lambda x: x.get('rule_protocol', ''))
|
||||
|
||||
# 计算分页
|
||||
total = len(sorted_items)
|
||||
pagecount = (total + limit - 1) // limit
|
||||
start_index = (pageno - 1) * limit
|
||||
end_index = start_index + limit
|
||||
|
||||
# 返回当前页的记录
|
||||
current_page_items = sorted_items[start_index:end_index]
|
||||
|
||||
# 返回格式化的防火墙规则信息
|
||||
return {
|
||||
"success": True,
|
||||
"data": {
|
||||
"pageno": pageno,
|
||||
"limit": limit,
|
||||
"total": total,
|
||||
"pagecount": pagecount,
|
||||
"firewall_rules": current_page_items
|
||||
}
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {"success": False, "message": f"防火墙规则查询失败: {str(e)}"}
|
||||
Loading…
x
Reference in New Issue
Block a user