Skip to content

Commit

Permalink
feature: 2.0 Proxy 支持配置临时文件传输路径 (closed #1757)
Browse files Browse the repository at this point in the history
  • Loading branch information
CohleRustW committed Sep 6, 2023
1 parent 98bda8e commit 4b0578e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
12 changes: 12 additions & 0 deletions apps/backend/subscription/steps/agent_adapter/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.
"""
import os
import typing
from dataclasses import dataclass

Expand Down Expand Up @@ -35,3 +36,14 @@ class AgentSetupInfo:
# extra setup info
# 是否强制更新 AgentID,True:注册 AgentID 前会先
force_update_agent_id: bool = False


class AgentSetupTools:
@staticmethod
def generate_gse_file_cache_dir(path: str, is_legacy: bool) -> str:
gse_file_cache_prefix: str = "/data"
if is_legacy:
file_cache_dir: str = os.path.join(gse_file_cache_prefix, os.path.basename(path))
else:
file_cache_dir: str = os.path.join(gse_file_cache_prefix, os.path.basename(path), "file_cache")
return file_cache_dir
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from apps.backend.agent import tools
from apps.backend.agent.solution_maker import ExecutionSolutionTools
from apps.backend.subscription.steps.agent_adapter.base import AgentSetupTools
from apps.backend.utils.data_renderer import nested_render_data
from apps.node_man import constants, models

Expand Down Expand Up @@ -212,7 +213,11 @@ def __post_init__(self):
tls_cli_cert_file=proxy_tls_cli_cert_file,
tls_cli_key_file=proxy_tls_cli_key_file,
),
context_dataclass.FileCacheConfigContext(),
context_dataclass.FileCacheConfigContext(
dirs=self.host.extra_data.get(
"data_path", AgentSetupTools.generate_gse_file_cache_dir(path=setup_path, is_legacy=False)
),
),
context_dataclass.FileMetricConfigContext(
exporter_bind_port=self.ap.port_config.get(
"file_metric_bind_port", constants.GSE_PORT_DEFAULT_VALUE["file_metric_bind_port"]
Expand Down
9 changes: 7 additions & 2 deletions apps/backend/subscription/steps/agent_adapter/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
from django.conf import settings

from apps.backend.agent.tools import fetch_gse_servers_info
from apps.backend.subscription.steps.agent_adapter.base import AgentSetupInfo
from apps.backend.subscription.steps.agent_adapter.base import (
AgentSetupInfo,
AgentSetupTools,
)
from apps.backend.utils.data_renderer import nested_render_data
from apps.backend.utils.encrypted import GseEncrypted
from apps.node_man import constants, models
Expand Down Expand Up @@ -470,7 +473,9 @@ def generate_gse_config(
setup_path = agent_config["setup_path"]
log_path = agent_config["log_path"]
# 如果没有自定义则使用接入点默认配置
data_path = host.extra_data.get("data_path") or agent_config["data_path"]
data_path = host.extra_data.get("data_path") or AgentSetupTools.generate_gse_file_cache_dir(
path=setup_path, is_legacy=True
)

gse_servers_info: Dict[str, Any] = fetch_gse_servers_info(
AgentSetupInfo(is_legacy=True), host, ap, proxies, install_channel
Expand Down
10 changes: 10 additions & 0 deletions apps/node_man/serializers/ap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers

from apps.backend.subscription.steps.agent_adapter.base import AgentSetupTools
from apps.exceptions import ValidationError
from apps.node_man.constants import (
GSE_PORT_DEFAULT_VALUE,
GSE_V2_PORT_DEFAULT_VALUE,
IamActionType,
OsType,
)
from apps.node_man.handlers.iam import IamHandler
from apps.node_man.models import AccessPoint
Expand Down Expand Up @@ -49,6 +51,7 @@ class ListSerializer(serializers.ModelSerializer):
is_enabled = serializers.BooleanField(label=_("是否启用"))
is_default = serializers.BooleanField(label=_("是否默认接入点,不可删除"))
proxy_package = serializers.JSONField(label=_("Proxy上的安装包"))
file_cache_dirs = serializers.SerializerMethodField(label=_("文件缓存目录"))

def to_representation(self, instance):
ret = super(ListSerializer, self).to_representation(instance)
Expand All @@ -63,6 +66,13 @@ def to_representation(self, instance):
}
return ret

def get_file_cache_dirs(self, instance):
is_legacy: bool = instance.gse_version == GseVersion.V1.value
data_path: str = AgentSetupTools.generate_gse_file_cache_dir(
path=instance.agent_config[OsType.LINUX.lower()]["setup_path"], is_legacy=is_legacy
)
return data_path

class Meta:
model = AccessPoint
exclude = ("zk_password",)
Expand Down

0 comments on commit 4b0578e

Please sign in to comment.