Skip to content

Commit

Permalink
Merge pull request #7458 from normal-wls/release_next_3.32
Browse files Browse the repository at this point in the history
feat: release V3.32.5 #ignore
  • Loading branch information
normal-wls authored May 16, 2024
2 parents a2c213e + 48a7b55 commit 458e7fc
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 39 deletions.
3 changes: 3 additions & 0 deletions api/collections/nodeman.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ def get_rsa_public_key(self, executor):

def install_channel(self):
return self._request(method="get", url=_get_nodeman_api_v2("install_channel"), data={})

def get_ipchooser_host_details(self, params: dict):
return self._request(method="post", url=_get_nodeman_api("core/api/ipchooser_host/details"), data=params)
2 changes: 1 addition & 1 deletion app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ is_use_celery: True
author: 蓝鲸智云
introduction: 标准运维是通过一套成熟稳定的任务调度引擎,把在多系统间的工作整合到一个流程,助力运维实现跨系统调度自动化的SaaS应用。
introduction_en: SOPS is a SaaS application that utilizes a set of mature and stable task scheduling engines to help realize cross-system scheduling automation, and integrates the work among multiple systems into a single process.
version: 3.32.4
version: 3.32.5
category: 运维工具
language_support: 中文
desktop:
Expand Down
2 changes: 1 addition & 1 deletion app_desc.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spec_version: 2
app_version: "3.32.4"
app_version: "3.32.5"
app:
region: default
bk_app_code: bk_sops
Expand Down
2 changes: 1 addition & 1 deletion config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
# mako模板中:<script src="/a.js?v=${ STATIC_VERSION }"></script>
# 如果静态资源修改了以后,上线前改这个版本号即可

STATIC_VERSION = "3.32.4"
STATIC_VERSION = "3.32.5"
DEPLOY_DATETIME = datetime.datetime.now().strftime("%Y%m%d%H%M%S")

STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
Expand Down
9 changes: 8 additions & 1 deletion frontend/desktop/builds/webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const webpackBaseConfig = require('./webpack.base.js')
const CopyPlugin = require('copy-webpack-plugin')

// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin

Expand Down Expand Up @@ -59,7 +60,13 @@ module.exports = merge(webpackBaseConfig, {
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /zh-cn/),
new MiniCssExtractPlugin({
filename: 'css/[name].[contenthash:10].css'
})
}),
new CopyPlugin([
{
from: path.resolve(__dirname, '../src/assets/html/login_success.html'),
to: path.resolve(__dirname, '../static/')
}
])
// new BundleAnalyzerPlugin()
],
optimization: {
Expand Down
3 changes: 2 additions & 1 deletion frontend/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@blueking/bkcharts": "^2.0.11-alpha.5",
"@blueking/bkui-form": "0.0.41-beta.1",
"@blueking/crypto-js-sdk": "0.0.5",
"@blueking/login-modal": "^1.0.1",
"@blueking/notice-component-vue2": "^2.0.1",
"@blueking/user-selector": "^1.0.5-beta.2",
"@vue/babel-preset-jsx": "^1.3.0",
Expand Down Expand Up @@ -70,7 +71,7 @@
"case-sensitive-paths-webpack-plugin": "^2.3.0",
"chokidar": "^3.2.2",
"clean-webpack-plugin": "^0.1.19",
"copy-webpack-plugin": "^4.5.1",
"copy-webpack-plugin": "^4.6.0",
"core-js": "^3.10.2",
"cross-env": "^5.1.6",
"css-loader": "^6.10.0",
Expand Down
16 changes: 7 additions & 9 deletions frontend/desktop/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import axios from 'axios'
import bus from '@/utils/bus.js'
import { setJqueryAjaxConfig } from '@/config/setting.js'
import { generateTraceId } from '@/utils/uuid.js'
import { showLoginModal } from '@blueking/login-modal'

axios.defaults.baseURL = window.SITE_URL
axios.defaults.xsrfCookieName = window.APP_CODE + '_csrftoken'
Expand Down Expand Up @@ -83,15 +84,12 @@ axios.interceptors.response.use(
if (isMatch) {
bus.$emit('createSnapshot', true) // 创建模板快照
}
const { login_url: src, width, height } = data
const { availHeight, availWidth } = window.screen
const left = (availWidth - width) / 2
const top = (availHeight - height) / 2
window.loginWindow = window.open(src, '_blank', `
width=` + width + `,
height=` + height + `,
left=` + left + `,
top=` + top + `,`)

const successUrl = `${window.location.origin}${window.SITE_URL}static/bk_sops/login_success.html`
let [loginUrl] = data.login_url.split('?')
loginUrl = `${loginUrl}?c_url=${encodeURIComponent(successUrl)}`

showLoginModal({ loginUrl })
}
break
case 499:
Expand Down
13 changes: 13 additions & 0 deletions frontend/desktop/src/assets/html/login_success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login Success</title>
</head>
<script>
window.opener && window.opener.location.reload()
window.close()
</script>
<body>
</body>
</html>
22 changes: 15 additions & 7 deletions pipeline_plugins/cmdb_ip_picker/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from iam.contrib.http import HTTP_AUTH_FORBIDDEN_CODE
from iam.exceptions import RawAuthFailedException

from api.collections.nodeman import BKNodeManClient
from api.utils.request import batch_request
from gcloud.conf import settings
from gcloud.utils import cmdb
Expand All @@ -27,6 +28,7 @@

from .constants import ERROR_CODES, NO_ERROR
from .utils import (
format_agent_data,
get_cmdb_topo_tree,
get_gse_agent_status_ipv6,
get_modules_id,
Expand Down Expand Up @@ -159,22 +161,28 @@ def cmdb_search_host(request, bk_biz_id, bk_supplier_account="", bk_supplier_id=
bk_agent_id = "{}:{}".format(host["bk_cloud_id"], host["bk_host_innerip"])
host["agent"] = agent_id_status_map.get(bk_agent_id, -1)
else:
client = BKNodeManClient(username=request.user.username)
agent_kwargs = {
"bk_biz_id": bk_biz_id,
"bk_supplier_id": bk_supplier_id,
"hosts": [
{"bk_cloud_id": host["bk_cloud_id"], "ip": host["bk_host_innerip"]}
"all_scope": True,
"host_list": [
{
"cloud_id": host["bk_cloud_id"],
"ip": host["bk_host_innerip"],
"meta": {"bk_biz_id": bk_biz_id, "scope_type": "biz", "scope_id": bk_biz_id},
}
for host in data
if host["bk_host_innerip"] != ""
],
}
agent_result = client.gse.get_agent_status(agent_kwargs)
agent_result = client.get_ipchooser_host_details(agent_kwargs)
if not agent_result["result"]:
message = handle_api_error(_("管控平台(GSE)"), "gse.get_agent_status", agent_kwargs, agent_result)
message = handle_api_error(
_("节点管理(nodeman)"), "nodeman.get_ipchooser_host_details", agent_kwargs, agent_result
)
result = {"result": False, "code": ERROR_CODES.API_GSE_ERROR, "message": message}
return JsonResponse(result)

agent_data = agent_result["data"]
agent_data = format_agent_data(agent_result["data"])
for host in data:
# agent在线状态,0为不在线,1为在线,-1为未知
agent_info = agent_data.get(
Expand Down
15 changes: 14 additions & 1 deletion pipeline_plugins/cmdb_ip_picker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,11 @@ def fetch_host_ip_with_property_filter(self):
fields.append("bk_host_innerip_v6")

host_info = cmdb.get_business_host_topo(
self.username, self.bk_biz_id, self.bk_supplier_account, fields, property_filters=self.property_filters,
self.username,
self.bk_biz_id,
self.bk_supplier_account,
fields,
property_filters=self.property_filters,
)
logger.info("[fetch_host_info] cmdb.get_business_host_topo return: {host_info}".format(host_info=host_info))

Expand Down Expand Up @@ -761,3 +765,12 @@ def send_request(agent_ids):
agent_id_status_map[item["bk_agent_id"]] = status_code

return agent_id_status_map


def format_agent_data(agents):
agent_data = {}
for agent in agents:
key = f"{agent['cloud_area']['id']}:{agent['ip']}"
val = {"ip": agent["ip"], "bk_cloud_id": agent["cloud_area"]["id"], "bk_agent_alive": agent["alive"]}
agent_data[key] = val
return agent_data
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def setUp(self):
get_agent_status_result = {
"result": True,
"code": 0,
"data": {
"0:1.1.1.1": {"ip": "1.1.1.1", "bk_cloud_id": 0, "bk_agent_alive": 1},
"0:2.2.2.2": {"ip": "2.2.2.2", "bk_cloud_id": 0, "bk_agent_alive": 0},
"1:3.3.3.3": {"ip": "3.3.3.3", "bk_cloud_id": 1, "bk_agent_alive": 1},
"2:4.4.4.4": {"ip": "4.4.4.4", "bk_cloud_id": 2, "bk_agent_alive": 0},
},
"data": [
{"ip": "1.1.1.1", "alive": 1, "cloud_area": {"id": 0, "ip": "1.1.1.1"}},
{"ip": "2.2.2.2", "alive": 0, "cloud_area": {"id": 0, "ip": "2.2.2.2"}},
{"ip": "3.3.3.3", "alive": 1, "cloud_area": {"id": 1, "ip": "3.3.3.3"}},
{"ip": "4.4.4.4", "alive": 0, "cloud_area": {"id": 2, "ip": "3.3.3.3"}},
],
}
mock_project_obj = MagicMock()
mock_project_obj.from_cmdb = True
Expand All @@ -43,7 +43,7 @@ def setUp(self):
mock_project.objects.get = MagicMock(return_value=mock_project_obj)

client = MagicMock()
client.gse.get_agent_status = MagicMock(return_value=get_agent_status_result)
client.get_ipchooser_host_details = MagicMock(return_value=get_agent_status_result)

self.supplier_account_for_project_patcher = patch(
"pipeline_plugins.variables.collections.sites.open.ip_filter_base.supplier_id_for_project",
Expand All @@ -53,7 +53,7 @@ def setUp(self):
"pipeline_plugins.variables.collections.sites.open.ip_filter_base.Project", mock_project
)
self.client = patch(
"pipeline_plugins.variables.collections.sites.open.ip_filter_base.get_client_by_user",
"pipeline_plugins.variables.collections.sites.open.ip_filter_base.get_nodeman_client_by_user",
MagicMock(return_value=client),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from api.collections.nodeman import BKNodeManClient
from gcloud.conf import settings as gcloud_settings
from gcloud.constants import GseAgentStatus
from gcloud.core.models import Project
Expand All @@ -24,11 +25,12 @@
from gcloud.utils.handlers import handle_api_error
from gcloud.utils.ip import IpRegexType, extract_ip_from_ip_str, get_ip_by_regex_type
from pipeline_plugins.base.utils.inject import supplier_account_for_business, supplier_id_for_project
from pipeline_plugins.cmdb_ip_picker.utils import get_gse_agent_status_ipv6
from pipeline_plugins.cmdb_ip_picker.utils import format_agent_data, get_gse_agent_status_ipv6
from pipeline_plugins.components.collections.sites.open.cc.base import cc_get_host_by_innerip_with_ipv6

logger = logging.getLogger("root")
get_client_by_user = gcloud_settings.ESB_GET_CLIENT_BY_USER
get_nodeman_client_by_user = BKNodeManClient


class IpFilterBase(metaclass=ABCMeta):
Expand Down Expand Up @@ -95,18 +97,27 @@ def match_ges_v2(self, gse_agent_status, username, bk_biz_id, bk_supplier_id, or
def match_gse_v1(self, gse_agent_status, username, bk_biz_id, bk_supplier_id, origin_ip_list):
match_ip = origin_ip_list
if gse_agent_status in [GseAgentStatus.ONlINE.value, GseAgentStatus.OFFLINE.value]:
client = get_client_by_user(username)
client = get_nodeman_client_by_user(username=username)
agent_kwargs = {
"bk_biz_id": bk_biz_id,
"bk_supplier_id": bk_supplier_id,
"hosts": origin_ip_list,
"all_scope": True,
"host_list": [
{
"cloud_id": host["bk_cloud_id"],
"ip": host["ip"],
"meta": {"bk_biz_id": bk_biz_id, "scope_type": "biz", "scope_id": bk_biz_id},
}
for host in origin_ip_list
if host["ip"] != ""
],
}
agent_result = client.gse.get_agent_status(agent_kwargs)
agent_result = client.get_ipchooser_host_details(agent_kwargs)

if not agent_result["result"]:
message = handle_api_error(_("管控平台(GSE)"), "gse.get_agent_status", agent_kwargs, agent_result)
message = handle_api_error(
_("节点管理(nodeman)"), "nodeman.get_ipchooser_host_details", agent_kwargs, agent_result
)
raise ApiRequestError(f"ERROR:{message}")

agent_data = agent_result["data"]
agent_data = format_agent_data(agent_result["data"])
agent_online_ip_list = []
agent_offline_ip_list = []
for plat_ip, info in agent_data.items():
Expand Down

0 comments on commit 458e7fc

Please sign in to comment.