forked from TencentBlueKing/bk-nodeman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Proxy Nginx 配置 v6 支持 (closed TencentBlueKing#1289)
- Loading branch information
1 parent
0368384
commit d18f649
Showing
8 changed files
with
195 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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 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
47 changes: 47 additions & 0 deletions
47
apps/backend/components/collections/agent_new/start_nginx.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-节点管理(BlueKing-BK-NODEMAN) available. | ||
Copyright (C) 2017-2022 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
from typing import Dict, Union | ||
|
||
from django.conf import settings | ||
from jinja2 import Template | ||
|
||
from apps.backend.components.collections.agent_new.base import ( | ||
AgentCommonData, | ||
AgentExecuteScriptService, | ||
) | ||
from apps.backend.components.collections.common.script_content import ( | ||
START_NGINX_TEMPLATE, | ||
) | ||
from apps.backend.subscription.errors import ScriptRenderFailed | ||
from apps.node_man import models | ||
from apps.utils import basic | ||
|
||
|
||
class StartNginxService(AgentExecuteScriptService): | ||
@property | ||
def script_name(self): | ||
return "start_nginx" | ||
|
||
def get_script_content(self, data, common_data: AgentCommonData, host: models.Host) -> str: | ||
template = Template(START_NGINX_TEMPLATE) | ||
script_variable_map: Dict[str, Union[str, bool]] = { | ||
"nginx_path": settings.DOWNLOAD_PATH, | ||
"bk_nodeman_nginx_download_port": settings.BK_NODEMAN_NGINX_DOWNLOAD_PORT, | ||
"bk_nodeman_nginx_proxy_pass_port": settings.BK_NODEMAN_NGINX_PROXY_PASS_PORT, | ||
"is_v6_host": basic.is_v6(host.inner_ipv6), | ||
"inner_ipv6": host.inner_ipv6, | ||
} | ||
try: | ||
content: str = template.render(script_variable_map) | ||
except Exception as e: | ||
raise ScriptRenderFailed({"name": self.script_name, "msg": e}) | ||
|
||
return content |
This file contains 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 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
40 changes: 40 additions & 0 deletions
40
apps/backend/tests/components/collections/agent_new/test_start_nginx.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-节点管理(BlueKing-BK-NODEMAN) available. | ||
Copyright (C) 2017-2022 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
from apps.backend.components.collections.agent_new import components | ||
from apps.node_man import constants, models | ||
|
||
from . import base | ||
|
||
|
||
class StartIpv4ProxyNginxTestCase(base.JobBaseTestCase): | ||
@classmethod | ||
def get_default_case_name(cls) -> str: | ||
return "启动 Ipv4 Proxy Nginx 成功" | ||
|
||
def component_cls(self): | ||
return components.StartNginxComponent | ||
|
||
|
||
class StartIpv6ProxyNginxTestCase(base.JobBaseTestCase): | ||
@classmethod | ||
def get_default_case_name(cls) -> str: | ||
return "启动 Ipv6 Proxy Nginx 成功" | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
super().setUpTestData() | ||
models.Host.objects.all().update(node_type=constants.NodeType.PROXY, inner_ipv6="2001:db8:85a3::8a2e:370:7334") | ||
|
||
def component_cls(self): | ||
return components.StartNginxComponent |
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
feature: | ||
- "Proxy Nginx 配置 v6 支持 (closed #1289)" |
This file was deleted.
Oops, something went wrong.