Skip to content

Commit

Permalink
feature: 全新部署根据 ENABLE_DHCP 选择初始化接入点版本 (closed #1623)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyyalt authored and ZhuoZhuoCrayon committed Jun 21, 2023
1 parent 76558e4 commit d4154c9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
from django.conf import settings
from django.db import migrations

from apps.node_man.constants import GSE_PORT_DEFAULT_VALUE
from apps.node_man.constants import GSE_PORT_DEFAULT_VALUE, GSE_V2_PORT_DEFAULT_VALUE


def init_gse_port_config(apps, schema_editor):
# 设置接入点端口信息
AccessPoint = apps.get_model("node_man", "AccessPoint")
AccessPoint.objects.update(port_config=GSE_PORT_DEFAULT_VALUE)
AccessPoint.objects.update(
port_config=GSE_V2_PORT_DEFAULT_VALUE if settings.BKAPP_ENABLE_DHCP else GSE_PORT_DEFAULT_VALUE
)


class Migration(migrations.Migration):
Expand Down
38 changes: 38 additions & 0 deletions apps/node_man/migrations/0071_update_ap_gse_version_to_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- 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 List

from django.db import migrations

from apps.node_man.constants import GSE_V2_PORT_DEFAULT_VALUE
from env.constants import GseVersion


def update_access_point_gse_version(apps, schema_editor):
# 全新部署更新gse_vserion
AccessPoint = apps.get_model("node_man", "AccessPoint")
access_points: List[AccessPoint] = list(AccessPoint.objects.all())
access_point: AccessPoint = access_points[0]
# 判断是否为全新部署
if len(access_points) == 1 and access_point.port_config == GSE_V2_PORT_DEFAULT_VALUE:
access_point.gse_version = GseVersion.V2.value
access_point.save()


class Migration(migrations.Migration):

dependencies = [
("node_man", "0070_auto_20230613_1055"),
]

operations = [
migrations.RunPython(update_access_point_gse_version),
]
17 changes: 16 additions & 1 deletion apps/node_man/serializers/ap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@
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 List

from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers

from apps.exceptions import ValidationError
from apps.node_man.constants import GSE_PORT_DEFAULT_VALUE, IamActionType
from apps.node_man.constants import (
GSE_PORT_DEFAULT_VALUE,
GSE_V2_PORT_DEFAULT_VALUE,
IamActionType,
)
from apps.node_man.handlers.iam import IamHandler
from apps.node_man.models import AccessPoint
from apps.utils import basic
from apps.utils.local import get_request_username
from env.constants import GseVersion


class ListSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -101,6 +108,14 @@ class ZKSerializer(serializers.Serializer):
outer_callback_url = serializers.CharField(label=_("节点管理外网回调地址"), required=False, allow_blank=True)
callback_url = serializers.CharField(label=_("节点管理内网回调地址"), required=False, allow_blank=True)

def validate(self, data):
gse_version_list: List[str] = list(set(AccessPoint.objects.values_list("gse_version", flat=True)))
# 存量接入点版本全部为V2新建/更新版本也为V2版本
if GseVersion.V1.value not in gse_version_list:
data["gse_version"] = GseVersion.V2.value
data["port_config"] = GSE_V2_PORT_DEFAULT_VALUE
return data

class Meta:
fields = "__all__"
model = AccessPoint

0 comments on commit d4154c9

Please sign in to comment.