-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: 提供 Agent 包管理后台接口 (closed #1683)
- Loading branch information
Showing
13 changed files
with
932 additions
and
0 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
97 changes: 97 additions & 0 deletions
97
apps/node_man/migrations/0081_gsepackagedesc_gsepackages.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,97 @@ | ||
# -*- 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 django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("node_man", "0080_auto_20231122_1552"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="GsePackageDesc", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("created_time", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")), | ||
("created_by", models.CharField(default="", max_length=32, verbose_name="创建者")), | ||
("updated_time", models.DateTimeField(auto_now=True, null=True, verbose_name="更新时间")), | ||
("updated_by", models.CharField(blank=True, default="", max_length=32, verbose_name="修改者")), | ||
("project", models.CharField(db_index=True, max_length=32, unique=True, verbose_name="工程名")), | ||
("description", models.TextField(verbose_name="安装包描述")), | ||
("description_en", models.TextField(blank=True, null=True, verbose_name="英文插件描述")), | ||
( | ||
"category", | ||
models.CharField( | ||
choices=[("official", "official"), ("external", "external"), ("scripts", "scripts")], | ||
max_length=32, | ||
verbose_name="所属范围", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Gse包描述(GsePackageDesc)", | ||
"verbose_name_plural": "Gse包描述(GsePackageDesc)", | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="GsePackages", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("created_time", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")), | ||
("created_by", models.CharField(default="", max_length=32, verbose_name="创建者")), | ||
("updated_time", models.DateTimeField(auto_now=True, null=True, verbose_name="更新时间")), | ||
("updated_by", models.CharField(blank=True, default="", max_length=32, verbose_name="修改者")), | ||
("pkg_name", models.CharField(max_length=128, verbose_name="压缩包名")), | ||
("version", models.CharField(max_length=128, verbose_name="版本号")), | ||
("project", models.CharField(db_index=True, max_length=32, verbose_name="工程名")), | ||
("pkg_size", models.IntegerField(verbose_name="包大小")), | ||
("pkg_path", models.CharField(max_length=128, verbose_name="包路径")), | ||
("md5", models.CharField(max_length=32, verbose_name="md5值")), | ||
("location", models.CharField(max_length=512, verbose_name="安装包链接")), | ||
( | ||
"os", | ||
models.CharField( | ||
choices=[("windows", "windows"), ("linux", "linux"), ("aix", "aix"), ("solaris", "solaris")], | ||
db_index=True, | ||
default="linux", | ||
max_length=32, | ||
verbose_name="系统类型", | ||
), | ||
), | ||
( | ||
"cpu_arch", | ||
models.CharField( | ||
choices=[ | ||
("x86", "x86"), | ||
("x86_64", "x86_64"), | ||
("powerpc", "powerpc"), | ||
("aarch64", "aarch64"), | ||
("sparc", "sparc"), | ||
], | ||
db_index=True, | ||
default="x86_64", | ||
max_length=32, | ||
verbose_name="CPU类型", | ||
), | ||
), | ||
("is_ready", models.BooleanField(default=True, verbose_name="插件是否可用")), | ||
("version_log", models.TextField(blank=True, null=True, verbose_name="版本日志")), | ||
("version_log_en", models.TextField(blank=True, null=True, verbose_name="英文版本日志")), | ||
], | ||
options={ | ||
"verbose_name": "Gse包(GsePackages)", | ||
"verbose_name_plural": "Gse包(GsePackages)", | ||
}, | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- 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. | ||
""" |
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,27 @@ | ||
# -*- 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 django.utils.translation import ugettext_lazy as _ | ||
from rest_framework import permissions | ||
|
||
from apps.node_man.handlers.iam import IamHandler | ||
from apps.utils.local import get_request_username | ||
|
||
|
||
class PackageManagePermission(permissions.BasePermission): | ||
message = _("您没有该操作的权限") | ||
|
||
def has_permission(self, request, view): | ||
|
||
if IamHandler().is_superuser(get_request_username()): | ||
return True | ||
|
||
return False |
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,121 @@ | ||
# -*- 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 django.utils.translation import ugettext_lazy as _ | ||
from rest_framework import serializers | ||
|
||
from apps.exceptions import ValidationError | ||
from apps.node_man.constants import GsePackageCode | ||
|
||
|
||
class TagsSerializer(serializers.Serializer): | ||
id = serializers.CharField() | ||
name = serializers.CharField() | ||
children = serializers.ListField() | ||
|
||
|
||
class ConditionsSerializer(serializers.Serializer): | ||
key = serializers.ChoiceField(choices=["version", "os_cpu_arch", "tags", "is_ready"]) | ||
values = serializers.ListField() | ||
|
||
|
||
class PackageSerializer(serializers.Serializer): | ||
id = serializers.IntegerField() | ||
pkg_name = serializers.CharField() | ||
version = serializers.CharField() | ||
os = serializers.CharField() | ||
cpu_arch = serializers.CharField() | ||
tags = TagsSerializer(many=True) | ||
creator = serializers.CharField() | ||
pkg_ctime = serializers.DateTimeField() | ||
is_ready = serializers.BooleanField() | ||
|
||
|
||
class PackageDescSerializer(serializers.Serializer): | ||
id = serializers.IntegerField() | ||
version = serializers.CharField() | ||
tags = TagsSerializer(many=True) | ||
packages = PackageSerializer(many=True) | ||
is_ready = serializers.BooleanField() | ||
|
||
|
||
class ListResponseSerializer(serializers.Serializer): | ||
total = serializers.IntegerField() | ||
list = PackageSerializer(many=True) | ||
|
||
|
||
class PackageDescResponseSerialiaer(serializers.Serializer): | ||
total = serializers.IntegerField() | ||
list = PackageDescSerializer(many=True) | ||
|
||
|
||
class OperateSerializer(serializers.Serializer): | ||
is_ready = serializers.BooleanField() | ||
|
||
|
||
class QuickSearchSerializer(serializers.Serializer): | ||
project = serializers.ChoiceField(choices=GsePackageCode.list_choices()) | ||
|
||
|
||
# TODO 与plugin相同可抽取公共Serializer | ||
class UploadSerializer(serializers.Serializer): | ||
class PkgFileField(serializers.FileField): | ||
def to_internal_value(self, data): | ||
data = super().to_internal_value(data) | ||
file_name = data.name | ||
if not (file_name.endswith(".tgz") or file_name.endswith(".tar.gz")): | ||
raise ValidationError(_("仅支持'tgz', 'tar.gz'拓展名的文件")) | ||
return data | ||
|
||
module = serializers.ChoiceField(choices=["gse_agent", "gse_proxy"], required=False, default="gse_agent") | ||
package_file = PkgFileField() | ||
|
||
|
||
class UploadResponseSerializer(serializers.Serializer): | ||
id = serializers.IntegerField() | ||
name = serializers.CharField() | ||
pkg_size = serializers.IntegerField() | ||
|
||
|
||
class ParseSerializer(serializers.Serializer): | ||
file_name = serializers.CharField() | ||
|
||
|
||
class ParseResponseSerializer(serializers.Serializer): | ||
class ParsePackageSerializer(serializers.Serializer): | ||
module = serializers.ChoiceField(choices=["agent", "proxy"]) | ||
pkg_name = serializers.CharField() | ||
pkg_abs_path = serializers.CharField() | ||
version = serializers.CharField() | ||
os = serializers.CharField() | ||
cpu_arch = serializers.CharField() | ||
config_templates = serializers.ListField() | ||
|
||
description = serializers.CharField() | ||
packages = ParsePackageSerializer(many=True) | ||
|
||
|
||
class AgentRegisterSerializer(serializers.Serializer): | ||
class RegisterPackageSerializer(serializers.Serializer): | ||
pkg_abs_path = serializers.CharField() | ||
tags = serializers.ListField() | ||
|
||
is_release = serializers.BooleanField() | ||
packages = RegisterPackageSerializer(many=True) | ||
|
||
|
||
class AgentRegisterTaskSerializer(serializers.Serializer): | ||
job_id = serializers.IntegerField() | ||
|
||
|
||
class AgentRegisterTaskResponseSerializer(serializers.Serializer): | ||
is_finish = serializers.BooleanField() | ||
status = serializers.ChoiceField(choices=["SUCCESS", "FAILED", "RUNNING"]) | ||
message = serializers.CharField() |
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
Oops, something went wrong.