From 37dcde04c9b5cc17057fa1cd9aced0697ee5f328 Mon Sep 17 00:00:00 2001 From: huangpixu Date: Mon, 9 Dec 2024 16:34:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ugettext=5Flazy=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BAgettext=5Flazy=20#7625?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/http.py | 85 ++++++-- api/utils/request.py | 2 +- config/default.py | 2 +- docs/develop/dev_plugins.md | 2 +- en_docs/develop/dev_plugins.md | 2 +- files/bartenders/upload_module.py | 8 +- files/bartenders/utils.py | 6 +- files/factory.py | 15 +- gcloud/analysis_statistics/models.py | 2 +- gcloud/common_template/models.py | 2 +- gcloud/conf/default_settings.py | 2 +- gcloud/constants.py | 2 +- .../contrib/admin/migration_api/app_maker.py | 2 +- .../admin/migration_api/resource_config.py | 8 +- .../admin/migration_api/staff_group.py | 9 +- .../admin/migration_api/template_category.py | 10 +- gcloud/contrib/appmaker/api.py | 6 +- gcloud/contrib/appmaker/models.py | 26 +-- gcloud/contrib/collection/models.py | 2 +- gcloud/contrib/develop/constants.py | 2 +- gcloud/contrib/function/api.py | 15 +- gcloud/contrib/function/models.py | 5 +- gcloud/contrib/operate_record/constants.py | 2 +- gcloud/contrib/operate_record/models.py | 4 +- gcloud/core/api.py | 2 +- gcloud/core/api_adapter/app_maker/v3.py | 21 +- .../core/apis/drf/serilaziers/collection.py | 3 +- .../apis/drf/serilaziers/common_template.py | 2 +- .../apis/drf/serilaziers/component_model.py | 9 +- .../apis/drf/serilaziers/periodic_task.py | 2 +- .../apis/drf/serilaziers/project_config.py | 2 +- .../apis/drf/serilaziers/task_template.py | 2 +- gcloud/core/apis/drf/viewsets/business.py | 9 +- gcloud/core/apis/drf/viewsets/collection.py | 2 +- .../core/apis/drf/viewsets/periodic_task.py | 14 +- .../core/apis/drf/viewsets/task_template.py | 2 +- gcloud/core/apis/drf/viewsets/taskflow.py | 2 +- gcloud/core/context_processors.py | 2 +- gcloud/core/footer/sites/open/footer.py | 2 +- .../commands/_template/plugin_py.txt | 2 +- gcloud/core/middlewares.py | 12 +- gcloud/core/models.py | 2 +- gcloud/core/roles.py | 31 ++- gcloud/core/roles/sites/open/roles.py | 39 ++-- gcloud/exceptions.py | 2 +- gcloud/external_plugins/models/base.py | 17 +- gcloud/external_plugins/models/cache.py | 18 +- gcloud/external_plugins/models/origin.py | 11 +- gcloud/external_plugins/models/sync.py | 23 +- gcloud/iam_auth/conf.py | 3 +- gcloud/iam_auth/resource_api/task.py | 6 +- gcloud/label/models.py | 6 +- gcloud/mako_template_helper/hub.py | 4 +- gcloud/periodictask/models.py | 2 +- gcloud/project_constants/models.py | 3 +- gcloud/taskflow3/apis/django/api.py | 18 +- .../taskflow3/apis/django/v4/node_callback.py | 13 +- gcloud/taskflow3/apis/django/v4/state.py | 6 +- .../apis/drf/viewsets/preview_task_tree.py | 19 +- gcloud/taskflow3/celery/tasks.py | 3 +- gcloud/taskflow3/domains/context.py | 2 +- gcloud/taskflow3/domains/dispatchers/base.py | 9 +- gcloud/taskflow3/domains/dispatchers/node.py | 2 +- gcloud/taskflow3/domains/dispatchers/task.py | 37 ++-- gcloud/taskflow3/domains/task_constants.py | 4 +- gcloud/taskflow3/models.py | 30 ++- gcloud/taskflow3/utils.py | 8 +- gcloud/tasktmpl3/apis/django/api.py | 7 +- gcloud/tasktmpl3/apis/django/validators.py | 9 +- .../drf/viewsets/batch_form_with_schemes.py | 6 +- .../apis/drf/viewsets/form_with_schemes.py | 24 +-- gcloud/tasktmpl3/models.py | 6 +- gcloud/template_base/apis/django/api.py | 16 +- .../apis/drf/viewsets/template_scheme.py | 18 +- gcloud/template_base/domains/importer.py | 9 +- .../template_base/domains/schema_converter.py | 17 +- .../template_base/domains/template_manager.py | 47 +++-- gcloud/template_base/models.py | 2 +- gcloud/template_base/utils.py | 2 +- .../external_plugins/models/test_sync_task.py | 16 +- gcloud/user_custom_config/constants.py | 3 +- gcloud/user_custom_config/models.py | 2 +- gcloud/utils/cmdb.py | 6 +- gcloud/utils/components.py | 10 +- gcloud/utils/forms.py | 20 +- gcloud/utils/handlers.py | 3 +- gcloud/utils/validate.py | 4 +- pipeline_plugins/base/query/cmdb.py | 3 +- pipeline_plugins/cmdb_ip_picker/query.py | 2 +- pipeline_plugins/cmdb_ip_picker/utils.py | 10 +- .../components/collections/common.py | 17 +- .../components/collections/controller.py | 2 +- .../collections/gse_kit/flush_process/v1_0.py | 2 +- .../collections/gse_kit/job_exec/v1_0.py | 38 +++- .../components/collections/http/v1_0.py | 27 ++- .../collections/remote_plugin/v1_0_0.py | 6 +- .../collections/sites/open/bk/__init__.py | 2 +- .../collections/sites/open/bk/approve/v1_0.py | 21 +- .../collections/sites/open/bk/display/v1_0.py | 10 +- .../sites/open/bk/notify/legacy.py | 198 +++++++++--------- .../collections/sites/open/bk/notify/v1_0.py | 33 +-- .../collections/sites/open/cc/__init__.py | 6 +- .../collections/sites/open/cc/base.py | 22 +- .../sites/open/cc/batch_delete_set/legacy.py | 66 +++--- .../sites/open/cc/batch_delete_set/v1_0.py | 31 +-- .../sites/open/cc/batch_module_update/v1_0.py | 20 +- .../cc/batch_transfer_host_module/v1_0.py | 27 ++- .../cc/batch_transfer_host_module/v1_1.py | 19 +- .../sites/open/cc/batch_update_host/v1_0.py | 14 +- .../sites/open/cc/batch_update_set/v1_0.py | 12 +- .../sites/open/cc/create_module/legacy.py | 39 ++-- .../sites/open/cc/create_set/legacy.py | 16 +- .../sites/open/cc/create_set/v1_0.py | 18 +- .../sites/open/cc/create_set/v2_0.py | 32 +-- .../open/cc/create_set_by_template/v1_0.py | 39 ++-- .../sites/open/cc/empty_set_hosts/legacy.py | 59 +++--- .../sites/open/cc/empty_set_hosts/v1_0.py | 31 +-- .../cc/host_custom_property_change/v1_0.py | 28 ++- .../open/cc/host_lock/add_host_lock/v1_0.py | 5 +- .../sites/open/cc/host_lock/base.py | 14 +- .../cc/host_lock/delete_host_lock/v1_0.py | 5 +- .../open/cc/replace_fault_machine/legacy.py | 18 +- .../open/cc/transfer_fault_host/legacy.py | 2 +- .../open/cc/transfer_host_module/legacy.py | 7 +- .../open/cc/transfer_host_module/v1_0.py | 10 +- .../open/cc/transfer_host_resource/legacy.py | 2 +- .../sites/open/cc/transfer_to_idle/legacy.py | 2 +- .../open/cc/transfer_to_recovery/v1_0.py | 3 +- .../sites/open/cc/update_host/legacy.py | 7 +- .../sites/open/cc/update_module/legacy.py | 18 +- .../sites/open/cc/update_module/v1_0.py | 28 +-- .../sites/open/cc/update_set/legacy.py | 6 +- .../sites/open/cc/update_set/v1_0.py | 12 +- .../cc/update_set_service_status/legacy.py | 76 +++---- .../open/cc/update_set_service_status/v1_0.py | 24 ++- .../open/cc/update_set_service_status/v1_1.py | 18 +- .../collections/sites/open/job/__init__.py | 10 +- .../all_biz_execute_job_plan/base_service.py | 6 +- .../open/job/all_biz_execute_job_plan/v1_0.py | 11 +- .../open/job/all_biz_execute_job_plan/v1_1.py | 2 +- .../base_service.py | 16 +- .../job/all_biz_fast_execute_script/v1_0.py | 10 +- .../job/all_biz_fast_execute_script/v1_1.py | 12 +- .../all_biz_fast_push_file/base_service.py | 20 +- .../open/job/all_biz_fast_push_file/v1_0.py | 5 +- .../open/job/all_biz_fast_push_file/v1_1.py | 7 +- .../collections/sites/open/job/base.py | 66 ++++-- .../sites/open/job/cron_task/legacy.py | 11 +- .../job/execute_task/execute_task_base.py | 6 +- .../sites/open/job/execute_task/legacy.py | 6 +- .../sites/open/job/execute_task/v1_0.py | 15 +- .../sites/open/job/execute_task/v1_1.py | 6 +- .../sites/open/job/execute_task/v1_2.py | 8 +- .../open/job/fast_execute_script/legacy.py | 23 +- .../open/job/fast_execute_script/v1_0.py | 21 +- .../open/job/fast_execute_script/v1_1.py | 21 +- .../open/job/fast_execute_script/v1_2.py | 6 +- .../sites/open/job/fast_push_file/legacy.py | 2 +- .../sites/open/job/fast_push_file/v1_0.py | 2 +- .../sites/open/job/fast_push_file/v2_0.py | 7 +- .../sites/open/job/fast_push_file/v2_1.py | 7 +- .../sites/open/job/fetch_task_log/v1_0.py | 13 +- .../job/local_content_upload/base_service.py | 6 +- .../open/job/local_content_upload/v1_0.py | 5 +- .../open/job/local_content_upload/v1_1.py | 4 +- .../open/job/push_local_files/base_service.py | 20 +- .../sites/open/job/push_local_files/v1_0_0.py | 6 +- .../sites/open/job/push_local_files/v2_0.py | 13 +- .../sites/open/job/push_local_files/v2_1.py | 5 +- .../sites/open/monitor/__init__.py | 4 +- .../sites/open/monitor/alarm_shield/base.py | 10 +- .../sites/open/monitor/alarm_shield/v1_0.py | 10 +- .../sites/open/monitor/alarm_shield/v1_1.py | 6 +- .../sites/open/monitor/alarm_shield/v1_2.py | 6 +- .../open/monitor/alarm_shield_disable/v1_0.py | 19 +- .../monitor/alarm_shield_strategy/v1_0.py | 8 +- .../monitor/alarm_shield_strategy/v1_1.py | 8 +- .../monitor/alarm_shield_strategy/v1_2.py | 8 +- .../collections/sites/open/monitor/base.py | 12 +- .../collections/sites/open/nodeman/base.py | 21 +- .../sites/open/nodeman/create_task/legacy.py | 38 +++- .../sites/open/nodeman/create_task/v2_0.py | 30 ++- .../sites/open/nodeman/create_task/v3_0.py | 11 +- .../sites/open/nodeman/create_task/v4_0.py | 17 +- .../sites/open/nodeman/create_task/v5_0.py | 2 +- .../sites/open/nodeman/create_task/v6_0.py | 2 +- .../sites/open/nodeman/plugin_operate/v1_0.py | 11 +- .../sites/open/nodeman/plugin_operate/v2_0.py | 11 +- .../wechat_work_send_message/v1_0.py | 16 +- .../wechat_work_send_message/v2_0.py | 2 +- .../collections/subprocess_plugin/v1_0_0.py | 2 +- .../components/query/sites/open/cc.py | 2 +- .../query/sites/open/file_upload.py | 2 +- .../components/query/sites/open/job.py | 2 +- .../components/query/sites/open/monitor.py | 2 +- .../components/query/sites/open/nodeman.py | 2 +- pipeline_plugins/components/utils/common.py | 6 +- .../components/utils/sites/open/utils.py | 24 ++- .../collections/bk_manage_user_selector.py | 5 +- .../variables/collections/common.py | 2 +- .../variables/collections/datatable.py | 2 +- .../variables/collections/sites/open/cc.py | 14 +- .../cmdb/var_cmdb_set_module_ip_selector.py | 6 +- .../open/cmdb/var_set_filter_selector.py | 6 +- .../sites/open/cmdb/var_set_group_selector.py | 8 +- .../open/cmdb/var_set_module_selector.py | 6 +- .../collections/sites/open/ip_filter_base.py | 2 +- .../variables/query/sites/open/query.py | 2 +- .../variables/query/sites/open/select.py | 2 +- pipeline_web/core/abstract.py | 18 +- pipeline_web/core/models.py | 4 +- pipeline_web/label/models.py | 4 +- pipeline_web/plugin_management/models.py | 2 +- weixin/core/accounts.py | 77 +++---- 214 files changed, 1646 insertions(+), 1149 deletions(-) diff --git a/api/http.py b/api/http.py index 101e1423e2..fcf4c3df8d 100644 --- a/api/http.py +++ b/api/http.py @@ -11,11 +11,11 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ import logging -import requests import curlify +import requests +from django.utils.translation import gettext_lazy as _ logger = logging.getLogger("component") @@ -28,7 +28,14 @@ def _gen_header(): def _http_request( - method, url, headers=None, data=None, verify=False, cert=None, timeout=None, cookies=None, + method, + url, + headers=None, + data=None, + verify=False, + cert=None, + timeout=None, + cookies=None, ): resp = requests.Response() request_id = None @@ -36,21 +43,52 @@ def _http_request( try: if method == "GET": resp = requests.get( - url=url, headers=headers, params=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies, + url=url, + headers=headers, + params=data, + verify=verify, + cert=cert, + timeout=timeout, + cookies=cookies, ) elif method == "HEAD": - resp = requests.head(url=url, headers=headers, verify=verify, cert=cert, timeout=timeout, cookies=cookies,) + resp = requests.head( + url=url, + headers=headers, + verify=verify, + cert=cert, + timeout=timeout, + cookies=cookies, + ) elif method == "POST": resp = requests.post( - url=url, headers=headers, json=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies, + url=url, + headers=headers, + json=data, + verify=verify, + cert=cert, + timeout=timeout, + cookies=cookies, ) elif method == "DELETE": resp = requests.delete( - url=url, headers=headers, json=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies, + url=url, + headers=headers, + json=data, + verify=verify, + cert=cert, + timeout=timeout, + cookies=cookies, ) elif method == "PUT": resp = requests.put( - url=url, headers=headers, json=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies, + url=url, + headers=headers, + json=data, + verify=verify, + cert=cert, + timeout=timeout, + cookies=cookies, ) else: message = _(f"非法请求: 请求不是合法的HTTP Method: {method} | api http") @@ -105,7 +143,9 @@ def _http_request( resp.request = requests.Request(method, url, headers=headers, data=data, cookies=cookies).prepare() logger.debug( - "the request_id: `%s`. curl: `%s`", request_id, curlify.to_curl(resp.request, verify=False), + "the request_id: `%s`. curl: `%s`", + request_id, + curlify.to_curl(resp.request, verify=False), ) @@ -113,7 +153,14 @@ def get(url, data, headers=None, verify=False, cert=None, timeout=None, cookies= if not headers: headers = _gen_header() return _http_request( - method="GET", url=url, headers=headers, data=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies, + method="GET", + url=url, + headers=headers, + data=data, + verify=verify, + cert=cert, + timeout=timeout, + cookies=cookies, ) @@ -121,7 +168,14 @@ def post(url, data, headers=None, verify=False, cert=None, timeout=None, cookies if not headers: headers = _gen_header() return _http_request( - method="POST", url=url, headers=headers, data=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies, + method="POST", + url=url, + headers=headers, + data=data, + verify=verify, + cert=cert, + timeout=timeout, + cookies=cookies, ) @@ -129,7 +183,14 @@ def put(url, data, headers=None, verify=False, cert=None, timeout=None, cookies= if not headers: headers = _gen_header() return _http_request( - method="PUT", url=url, headers=headers, data=data, verify=verify, cert=cert, timeout=timeout, cookies=cookies, + method="PUT", + url=url, + headers=headers, + data=data, + verify=verify, + cert=cert, + timeout=timeout, + cookies=cookies, ) diff --git a/api/utils/request.py b/api/utils/request.py index 2448c0973f..e5b63dd273 100644 --- a/api/utils/request.py +++ b/api/utils/request.py @@ -12,7 +12,7 @@ """ import logging -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from gcloud.conf import settings from gcloud.exceptions import ApiRequestError diff --git a/config/default.py b/config/default.py index 320894e16b..33d425e5ca 100644 --- a/config/default.py +++ b/config/default.py @@ -23,7 +23,7 @@ from blueapps.opentelemetry.utils import inject_logging_trace_info from django.db.backends.mysql.features import DatabaseFeatures from django.utils.functional import cached_property -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.celery.queues import ScalableQueues import env diff --git a/docs/develop/dev_plugins.md b/docs/develop/dev_plugins.md index 29c71ed054..f6e49e83f1 100644 --- a/docs/develop/dev_plugins.md +++ b/docs/develop/dev_plugins.md @@ -107,7 +107,7 @@ python manage.py create_new_plugin cc create_set v1.0 open pipeline_plugins site import logging -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.activity import Service from pipeline.component_framework.component import Component diff --git a/en_docs/develop/dev_plugins.md b/en_docs/develop/dev_plugins.md index dccb13be90..8ccdc742e0 100644 --- a/en_docs/develop/dev_plugins.md +++ b/en_docs/develop/dev_plugins.md @@ -107,7 +107,7 @@ Write plugin background logic in `plugin.py`. It mainly includes standard plugin import logging -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.activity import Service from pipeline.component_framework.component import Component diff --git a/files/bartenders/upload_module.py b/files/bartenders/upload_module.py index d93b0f290e..75cfd8bb07 100644 --- a/files/bartenders/upload_module.py +++ b/files/bartenders/upload_module.py @@ -10,11 +10,11 @@ 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 re import logging +import re import traceback -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .base import UploadRequestBartender @@ -52,7 +52,9 @@ def process_request(self, request, *args, **kwargs): try: file_tag = self.manager.save(name=file_name, content=None, source_ip=source_ip, file_path=file_path) except Exception as e: - message = _(f"文件上传失败: 文件归档失败请重试, 如持续失败可联系管理员处理, {traceback.format_exc()} | process_request") + message = _( + f"文件上传失败: 文件归档失败请重试, 如持续失败可联系管理员处理, {traceback.format_exc()} | process_request" + ) logger.error(message) return {"result": False, "message": message + f":{e}", "code": 500} diff --git a/files/bartenders/utils.py b/files/bartenders/utils.py index c1ece50e60..e093827f74 100644 --- a/files/bartenders/utils.py +++ b/files/bartenders/utils.py @@ -10,11 +10,11 @@ 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 re -import logging import hashlib +import logging +import re -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ logger = logging.getLogger("root") diff --git a/files/factory.py b/files/factory.py index ed024f3ad0..8bb7c59145 100644 --- a/files/factory.py +++ b/files/factory.py @@ -10,18 +10,19 @@ 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 _ +import logging + +from django.utils.translation import gettext_lazy as _ from . import env +from .bartenders.bk_repo import BKRepoBartender from .bartenders.job_repo import JobRepoBartender +from .bartenders.nfs import HostNFSBartender +from .bartenders.upload_module import UploadModuleBartender from .managers.bk_repo import BKRepoManager from .managers.job_repo import JobRepoManager from .managers.nfs import HostNFSManager from .managers.upload_module import UploadModuleManager -from .bartenders.nfs import HostNFSBartender -from .bartenders.upload_module import UploadModuleBartender -from .bartenders.bk_repo import BKRepoBartender -import logging logger = logging.getLogger("root") @@ -31,7 +32,9 @@ class ManagerFactory(object): def get_manager(cls, manager_type): creator = getattr(cls, "_create_{}_manager".format(manager_type), None) if not creator or not callable(creator): - message = _(f"文件上传失败: 无法找到对应的FileManager: {manager_type}, 请重试, 如持续失败可联系管理员处理 | get_manager") + message = _( + f"文件上传失败: 无法找到对应的FileManager: {manager_type}, 请重试, 如持续失败可联系管理员处理 | get_manager" + ) logger.error(message) raise LookupError(message) diff --git a/gcloud/analysis_statistics/models.py b/gcloud/analysis_statistics/models.py index 8aa0f84e44..160642f053 100644 --- a/gcloud/analysis_statistics/models.py +++ b/gcloud/analysis_statistics/models.py @@ -12,7 +12,7 @@ """ from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from gcloud.constants import TASK_CATEGORY, TASK_CREATE_METHOD, TaskCreateMethod diff --git a/gcloud/common_template/models.py b/gcloud/common_template/models.py index c8314ab7ea..656063f4ba 100644 --- a/gcloud/common_template/models.py +++ b/gcloud/common_template/models.py @@ -13,7 +13,7 @@ import logging -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from gcloud import err_code from gcloud.template_base.models import BaseTemplate, BaseTemplateManager diff --git a/gcloud/conf/default_settings.py b/gcloud/conf/default_settings.py index 1fb1736a05..ce94ace9fb 100644 --- a/gcloud/conf/default_settings.py +++ b/gcloud/conf/default_settings.py @@ -12,7 +12,7 @@ """ from django.conf import settings -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ import env from packages.blueking.component.shortcuts import get_client_by_request, get_client_by_user diff --git a/gcloud/constants.py b/gcloud/constants.py index 508ae6f96b..61d27ace09 100644 --- a/gcloud/constants.py +++ b/gcloud/constants.py @@ -13,7 +13,7 @@ from enum import Enum -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ PROJECT = "project" BUSINESS = "business" diff --git a/gcloud/contrib/admin/migration_api/app_maker.py b/gcloud/contrib/admin/migration_api/app_maker.py index b2172453cb..ccc9877443 100644 --- a/gcloud/contrib/admin/migration_api/app_maker.py +++ b/gcloud/contrib/admin/migration_api/app_maker.py @@ -17,7 +17,7 @@ from blueapps.account.decorators import login_exempt from django.http.response import JsonResponse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from pipeline.models import TemplateScheme diff --git a/gcloud/contrib/admin/migration_api/resource_config.py b/gcloud/contrib/admin/migration_api/resource_config.py index 30a4db895f..43f11919d6 100644 --- a/gcloud/contrib/admin/migration_api/resource_config.py +++ b/gcloud/contrib/admin/migration_api/resource_config.py @@ -12,19 +12,19 @@ """ import json +import logging import traceback from datetime import datetime +from blueapps.account.decorators import login_exempt from django.http.response import JsonResponse +from django.utils.translation import gettext_lazy as _ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST -from blueapps.account.decorators import login_exempt +from gcloud import err_code from gcloud.contrib.admin.migration_api.decorators import require_migrate_token from gcloud.core.models import Project, ResourceConfig -from gcloud import err_code -from django.utils.translation import ugettext_lazy as _ -import logging logger = logging.getLogger("root") diff --git a/gcloud/contrib/admin/migration_api/staff_group.py b/gcloud/contrib/admin/migration_api/staff_group.py index 80396a3678..3f93f4ec2a 100644 --- a/gcloud/contrib/admin/migration_api/staff_group.py +++ b/gcloud/contrib/admin/migration_api/staff_group.py @@ -11,17 +11,18 @@ specific language governing permissions and limitations under the License. """ -import logging import json +import logging +from blueapps.account.decorators import login_exempt from django.http.response import JsonResponse +from django.utils.translation import gettext_lazy as _ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST -from django.utils.translation import ugettext_lazy as _ -from blueapps.account.decorators import login_exempt -from gcloud.core.models import Project, StaffGroupSet from gcloud import err_code +from gcloud.core.models import Project, StaffGroupSet + from .decorators import require_migrate_token logger = logging.getLogger("root") diff --git a/gcloud/contrib/admin/migration_api/template_category.py b/gcloud/contrib/admin/migration_api/template_category.py index af2e402f54..99ad0c6776 100644 --- a/gcloud/contrib/admin/migration_api/template_category.py +++ b/gcloud/contrib/admin/migration_api/template_category.py @@ -12,20 +12,20 @@ """ import json +import logging import traceback +from blueapps.account.decorators import login_exempt from django.http.response import JsonResponse +from django.utils.translation import gettext_lazy as _ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST -from blueapps.account.decorators import login_exempt -from gcloud.contrib.admin.migration_api.decorators import require_migrate_token -from gcloud.constants import TASK_CATEGORY from gcloud import err_code +from gcloud.constants import TASK_CATEGORY +from gcloud.contrib.admin.migration_api.decorators import require_migrate_token from gcloud.label.models import Label, TemplateLabelRelation from gcloud.tasktmpl3.models import TaskTemplate -from django.utils.translation import ugettext_lazy as _ -import logging logger = logging.getLogger("root") diff --git a/gcloud/contrib/appmaker/api.py b/gcloud/contrib/appmaker/api.py index 435e0c5734..29b787fb43 100755 --- a/gcloud/contrib/appmaker/api.py +++ b/gcloud/contrib/appmaker/api.py @@ -16,7 +16,7 @@ import jsonschema import magic from django.http import JsonResponse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views.decorators.http import require_GET from gcloud.conf import settings @@ -61,7 +61,9 @@ def save(request, project_id): file_size = logo_obj.size # LOGO大小不能大于 100K if file_size > 100 * 1024: - message = _("轻应用保存失败: 非法的图片大小, 请使用不超过100KB 的 JPG / PNG 图片作为应用LOGO | appmaker save") + message = _( + "轻应用保存失败: 非法的图片大小, 请使用不超过100KB 的 JPG / PNG 图片作为应用LOGO | appmaker save" + ) logger.error(message) return JsonResponse({"result": False, "message": message}) logo_content = logo_obj.read() diff --git a/gcloud/contrib/appmaker/models.py b/gcloud/contrib/appmaker/models.py index 40484ee9d1..3df8ed18ea 100755 --- a/gcloud/contrib/appmaker/models.py +++ b/gcloud/contrib/appmaker/models.py @@ -16,31 +16,21 @@ from django.db import models from django.db.models import Count -from django.utils.translation import ugettext_lazy as _ - -from gcloud.utils import managermixins - -from iam import Subject, Action +from django.utils.translation import gettext_lazy as _ +from iam import Action, Subject from iam.shortcuts import allow_or_raise_auth_failed from gcloud.conf import settings -from gcloud.core.api_adapter import ( - create_maker_app, - edit_maker_app, - del_maker_app, - modify_app_logo, - get_app_logo_url, -) from gcloud.constants import AE, TASK_CATEGORY +from gcloud.core.api_adapter import create_maker_app, del_maker_app, edit_maker_app, get_app_logo_url, modify_app_logo from gcloud.core.models import Project +from gcloud.core.utils import convert_readable_username +from gcloud.iam_auth import IAMMeta, get_iam_client from gcloud.tasktmpl3.models import TaskTemplate +from gcloud.utils import managermixins from gcloud.utils.dates import time_now_str -from gcloud.core.utils import convert_readable_username from gcloud.utils.strings import standardize_name -from gcloud.iam_auth import IAMMeta -from gcloud.iam_auth import get_iam_client - logger = logging.getLogger("root") iam = get_iam_client() @@ -122,7 +112,9 @@ def save_app_maker(self, project_id, app_params, fake=False): app_params["desc"], ) if not app_create_result["result"]: - message = _(f"轻应用保存失败: 请重试, 如多次失败可联系管理员处理. {app_create_result['result']} | save_app_maker") + message = _( + f"轻应用保存失败: 请重试, 如多次失败可联系管理员处理. {app_create_result['result']} | save_app_maker" + ) logger.error(message) return False, message diff --git a/gcloud/contrib/collection/models.py b/gcloud/contrib/collection/models.py index a690a6086d..5a20036d1d 100644 --- a/gcloud/contrib/collection/models.py +++ b/gcloud/contrib/collection/models.py @@ -13,7 +13,7 @@ import json from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class CollectionManager(models.Manager): diff --git a/gcloud/contrib/develop/constants.py b/gcloud/contrib/develop/constants.py index 6f85e61e3a..12dd6eff87 100644 --- a/gcloud/contrib/develop/constants.py +++ b/gcloud/contrib/develop/constants.py @@ -16,7 +16,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.activity import Service from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema, ObjectItemSchema diff --git a/gcloud/contrib/function/api.py b/gcloud/contrib/function/api.py index f4ba51070e..8027a8598b 100644 --- a/gcloud/contrib/function/api.py +++ b/gcloud/contrib/function/api.py @@ -1,23 +1,28 @@ # -*- coding: utf-8 -*- +import logging + +from django.utils.translation import gettext_lazy as _ from drf_yasg.utils import swagger_auto_schema from rest_framework.decorators import action from rest_framework.response import Response from rest_framework.views import APIView from gcloud.contrib.function.models import FunctionTask -from gcloud.contrib.function.serializers import FunctionTaskClaimantTransferRequestSerializer, \ - FunctionTaskClaimantTransferResponse +from gcloud.contrib.function.serializers import ( + FunctionTaskClaimantTransferRequestSerializer, + FunctionTaskClaimantTransferResponse, +) from gcloud.core.api_adapter.user_role import is_user_role from gcloud.iam_auth import IAMMeta -from django.utils.translation import ugettext_lazy as _ -import logging logger = logging.getLogger("root") class FunctionTaskClaimantTransferView(APIView): @swagger_auto_schema( - method="POST", operation_summary="职能转交", request_body=FunctionTaskClaimantTransferRequestSerializer, + method="POST", + operation_summary="职能转交", + request_body=FunctionTaskClaimantTransferRequestSerializer, responses={200: FunctionTaskClaimantTransferResponse}, ) @action(methods=["POST"], detail=False) diff --git a/gcloud/contrib/function/models.py b/gcloud/contrib/function/models.py index d66c68c9a2..c4faafec80 100755 --- a/gcloud/contrib/function/models.py +++ b/gcloud/contrib/function/models.py @@ -11,13 +11,14 @@ specific language governing permissions and limitations under the License. """ +import logging + from django.db import models from django.utils import timezone -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from gcloud.core.utils import convert_readable_username from gcloud.taskflow3.models import TaskFlowInstance -import logging logger = logging.getLogger("root") diff --git a/gcloud/contrib/operate_record/constants.py b/gcloud/contrib/operate_record/constants.py index 52c4fcef77..038bc631dd 100644 --- a/gcloud/contrib/operate_record/constants.py +++ b/gcloud/contrib/operate_record/constants.py @@ -12,7 +12,7 @@ """ from enum import Enum -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class OperateType(Enum): diff --git a/gcloud/contrib/operate_record/models.py b/gcloud/contrib/operate_record/models.py index 43ee0f3075..9d5063877f 100644 --- a/gcloud/contrib/operate_record/models.py +++ b/gcloud/contrib/operate_record/models.py @@ -12,9 +12,9 @@ """ from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ -from .constants import OPERATE_TYPE, OPERATE_SOURCE +from .constants import OPERATE_SOURCE, OPERATE_TYPE class BaseOperateRecord(models.Model): diff --git a/gcloud/core/api.py b/gcloud/core/api.py index 814ef1d2d0..7f5368efa2 100644 --- a/gcloud/core/api.py +++ b/gcloud/core/api.py @@ -18,7 +18,7 @@ from blueapps.account.decorators import login_exempt from django.contrib.auth.models import Group from django.http import JsonResponse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views.decorators.http import require_GET, require_POST from drf_yasg.utils import swagger_auto_schema from mako.template import Template diff --git a/gcloud/core/api_adapter/app_maker/v3.py b/gcloud/core/api_adapter/app_maker/v3.py index cd546e9909..0370c06459 100644 --- a/gcloud/core/api_adapter/app_maker/v3.py +++ b/gcloud/core/api_adapter/app_maker/v3.py @@ -12,14 +12,14 @@ """ import logging -import requests +import requests import ujson as json +from django.utils.translation import gettext_lazy as _ import env from gcloud.conf import settings from gcloud.core.models import EnvironmentVariables -from django.utils.translation import ugettext_lazy as _ logger = logging.getLogger("component") ENV = "stag" if settings.IS_LOCAL else "prod" @@ -58,7 +58,9 @@ def _request_paasv3_light_app_api(url, method, params=None, data=None): try: response.raise_for_status() except requests.HTTPError as e: - message = _(f"轻应用请求Paas接口报错: 请求url: {response.request.url}, 报错内容: {e}, 响应内容: {response.text}") + message = _( + f"轻应用请求Paas接口报错: 请求url: {response.request.url}, 报错内容: {e}, 响应内容: {response.text}" + ) logger.error(message) return {"result": False, "message": message} @@ -83,14 +85,23 @@ def _request_paasv3_light_app_api(url, method, params=None, data=None): resp_data["message"] = resp_data.get("bk_error_msg") return resp_data except Exception as e: - message = _(f"轻应用请求PaaS接口报错: 请求url {response.request.url}, 接口响应json格式转换失败 {e},响应内容 {response.content}") + message = _( + f"轻应用请求PaaS接口报错: 请求url {response.request.url}, 接口响应json格式转换失败 {e},响应内容 {response.content}" + ) logger.error(message) return {"result": False, "message": message} def create_maker_app( - creator, app_name, app_url, developer="", app_tag="", introduction="", add_user="", company_code="", + creator, + app_name, + app_url, + developer="", + app_tag="", + introduction="", + add_user="", + company_code="", ): """ @summary: 创建 maker app diff --git a/gcloud/core/apis/drf/serilaziers/collection.py b/gcloud/core/apis/drf/serilaziers/collection.py index 46a983549d..63c7bb5bc1 100644 --- a/gcloud/core/apis/drf/serilaziers/collection.py +++ b/gcloud/core/apis/drf/serilaziers/collection.py @@ -12,8 +12,7 @@ """ import ujson as json - -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from rest_framework import serializers from gcloud.contrib.collection.models import Collection diff --git a/gcloud/core/apis/drf/serilaziers/common_template.py b/gcloud/core/apis/drf/serilaziers/common_template.py index 06fc03df5a..d627782684 100644 --- a/gcloud/core/apis/drf/serilaziers/common_template.py +++ b/gcloud/core/apis/drf/serilaziers/common_template.py @@ -12,7 +12,7 @@ """ import json -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from rest_framework import serializers from gcloud.common_template.models import CommonTemplate diff --git a/gcloud/core/apis/drf/serilaziers/component_model.py b/gcloud/core/apis/drf/serilaziers/component_model.py index 447f8c9587..b2c8f4e641 100644 --- a/gcloud/core/apis/drf/serilaziers/component_model.py +++ b/gcloud/core/apis/drf/serilaziers/component_model.py @@ -12,14 +12,13 @@ """ import re -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ +from pipeline.component_framework.library import ComponentLibrary +from pipeline.component_framework.models import ComponentModel +from pipeline.exceptions import ComponentNotExistException from rest_framework import serializers from rest_framework.exceptions import NotFound -from pipeline.exceptions import ComponentNotExistException -from pipeline.component_framework.models import ComponentModel -from pipeline.component_framework.library import ComponentLibrary - from pipeline_web.plugin_management.models import DeprecatedPlugin group_en_pattern = re.compile(r"(?:\()(.*)(?:\))") diff --git a/gcloud/core/apis/drf/serilaziers/periodic_task.py b/gcloud/core/apis/drf/serilaziers/periodic_task.py index c29b27b36c..9a68c1ff74 100644 --- a/gcloud/core/apis/drf/serilaziers/periodic_task.py +++ b/gcloud/core/apis/drf/serilaziers/periodic_task.py @@ -13,7 +13,7 @@ import logging import ujson as json -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django_celery_beat.models import CrontabSchedule as DjangoCeleryBeatCrontabSchedule from django_celery_beat.models import PeriodicTask as CeleryTask from pipeline.contrib.periodic_task.models import PeriodicTask as PipelinePeriodicTask diff --git a/gcloud/core/apis/drf/serilaziers/project_config.py b/gcloud/core/apis/drf/serilaziers/project_config.py index 6c9e27dd7a..794d18e346 100644 --- a/gcloud/core/apis/drf/serilaziers/project_config.py +++ b/gcloud/core/apis/drf/serilaziers/project_config.py @@ -11,7 +11,7 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from rest_framework import serializers from gcloud.core.models import ProjectConfig diff --git a/gcloud/core/apis/drf/serilaziers/task_template.py b/gcloud/core/apis/drf/serilaziers/task_template.py index 7afb08bf9b..4826c33ff5 100644 --- a/gcloud/core/apis/drf/serilaziers/task_template.py +++ b/gcloud/core/apis/drf/serilaziers/task_template.py @@ -12,7 +12,7 @@ """ import json -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from rest_framework import serializers from gcloud.constants import DATETIME_FORMAT, TASK_CATEGORY diff --git a/gcloud/core/apis/drf/viewsets/business.py b/gcloud/core/apis/drf/viewsets/business.py index 1cd812582a..d991830d3d 100644 --- a/gcloud/core/apis/drf/viewsets/business.py +++ b/gcloud/core/apis/drf/viewsets/business.py @@ -10,14 +10,13 @@ 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 gettext_lazy as _ from rest_framework import permissions -from django.utils.translation import ugettext_lazy as _ -from gcloud.core.models import Business - -from gcloud.core.apis.drf.viewsets.base import GcloudReadOnlyViewSet -from gcloud.core.apis.drf.filtersets import AllLookupSupportFilterSet, ALL_LOOKUP +from gcloud.core.apis.drf.filtersets import ALL_LOOKUP, AllLookupSupportFilterSet from gcloud.core.apis.drf.serilaziers import BusinessSerializer +from gcloud.core.apis.drf.viewsets.base import GcloudReadOnlyViewSet +from gcloud.core.models import Business class BusinessFilter(AllLookupSupportFilterSet): diff --git a/gcloud/core/apis/drf/viewsets/collection.py b/gcloud/core/apis/drf/viewsets/collection.py index b2f859d40a..631fed87a5 100644 --- a/gcloud/core/apis/drf/viewsets/collection.py +++ b/gcloud/core/apis/drf/viewsets/collection.py @@ -13,7 +13,7 @@ import logging -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from rest_framework import mixins, permissions, status from rest_framework.exceptions import ErrorDetail from rest_framework.response import Response diff --git a/gcloud/core/apis/drf/viewsets/periodic_task.py b/gcloud/core/apis/drf/viewsets/periodic_task.py index 658331065b..8fcabfc8e1 100644 --- a/gcloud/core/apis/drf/viewsets/periodic_task.py +++ b/gcloud/core/apis/drf/viewsets/periodic_task.py @@ -15,7 +15,7 @@ from django.db import transaction from django.db.models import BooleanField, ExpressionWrapper, Q -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.exceptions import PipelineException from rest_framework import permissions, status from rest_framework.exceptions import APIException @@ -141,20 +141,26 @@ def _handle_serializer(request, serializer): model_cls = CommonTemplate condition = {"id": template_id, "is_deleted": False} else: - message = _(f"周期任务创建失败: 周期任务关联的流程[ID: {template_source}]不存在, 请检查配置 | _handle_serializer") + message = _( + f"周期任务创建失败: 周期任务关联的流程[ID: {template_source}]不存在, 请检查配置 | _handle_serializer" + ) logger.error(message) raise APIException(detail=message, code=err_code.REQUEST_PARAM_INVALID.code) try: template = model_cls.objects.filter(**condition).first() except model_cls.DoesNotExist: - message = _(f"周期任务创建失败: 周期任务关联的公共流程[ID: {template_id}]不存在, 请检查配置 | _handle_serializer") + message = _( + f"周期任务创建失败: 周期任务关联的公共流程[ID: {template_id}]不存在, 请检查配置 | _handle_serializer" + ) logger.error(message) raise APIException(detail=message, code=err_code.REQUEST_PARAM_INVALID.code) try: replace_template_id(model_cls, pipeline_tree) except model_cls.DoesNotExist: - message = _(f"周期任务创建失败: 周期任务关联的流程[ID: {template_id}]中, 子流程节点存在异常, 请检查配置 | _handle_serializer") + message = _( + f"周期任务创建失败: 周期任务关联的流程[ID: {template_id}]中, 子流程节点存在异常, 请检查配置 | _handle_serializer" + ) logger.error(message) raise APIException(detail=message, code=err_code.REQUEST_PARAM_INVALID.code) diff --git a/gcloud/core/apis/drf/viewsets/task_template.py b/gcloud/core/apis/drf/viewsets/task_template.py index 5c3b45b095..b745242a2c 100644 --- a/gcloud/core/apis/drf/viewsets/task_template.py +++ b/gcloud/core/apis/drf/viewsets/task_template.py @@ -16,7 +16,7 @@ from django.contrib.auth import get_user_model from django.db import transaction from django.db.models import BooleanField, ExpressionWrapper, Q -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django_filters import CharFilter from drf_yasg.utils import swagger_auto_schema from pipeline.models import TemplateRelationship, TemplateScheme diff --git a/gcloud/core/apis/drf/viewsets/taskflow.py b/gcloud/core/apis/drf/viewsets/taskflow.py index 1be3bbb751..b3792b2330 100644 --- a/gcloud/core/apis/drf/viewsets/taskflow.py +++ b/gcloud/core/apis/drf/viewsets/taskflow.py @@ -19,7 +19,7 @@ from django.conf import settings from django.db import transaction from django.db.models import Q, QuerySet, Value -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django_filters import FilterSet from drf_yasg.utils import swagger_auto_schema from pipeline.eri.models import State diff --git a/gcloud/core/context_processors.py b/gcloud/core/context_processors.py index 232fc08963..a1db25d59f 100644 --- a/gcloud/core/context_processors.py +++ b/gcloud/core/context_processors.py @@ -18,7 +18,7 @@ import os from bkcrypto.asymmetric.configs import KeyConfig as AsymmetricKeyConfig -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ import env from gcloud.conf import settings diff --git a/gcloud/core/footer/sites/open/footer.py b/gcloud/core/footer/sites/open/footer.py index 77bd7ec4f5..365ad918d7 100644 --- a/gcloud/core/footer/sites/open/footer.py +++ b/gcloud/core/footer/sites/open/footer.py @@ -11,7 +11,7 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from gcloud.core.models import EnvironmentVariables diff --git a/gcloud/core/management/commands/_template/plugin_py.txt b/gcloud/core/management/commands/_template/plugin_py.txt index d4a047a61f..d429101511 100644 --- a/gcloud/core/management/commands/_template/plugin_py.txt +++ b/gcloud/core/management/commands/_template/plugin_py.txt @@ -12,7 +12,7 @@ specific language governing permissions and limitations under the License. """ import logging -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.activity import Service from pipeline.component_framework.component import Component diff --git a/gcloud/core/middlewares.py b/gcloud/core/middlewares.py index 46cefd31d9..abe31355a6 100644 --- a/gcloud/core/middlewares.py +++ b/gcloud/core/middlewares.py @@ -10,22 +10,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. """ -import os -import uuid import logging +import os import traceback +import uuid import pytz from django.conf import settings -from django.http import JsonResponse, HttpResponse, HttpResponseRedirect +from django.db.models import ObjectDoesNotExist +from django.http import HttpResponse, HttpResponseRedirect, JsonResponse from django.utils import timezone from django.utils.deprecation import MiddlewareMixin -from django.db.models import ObjectDoesNotExist +from django.utils.translation import gettext_lazy as _ from gcloud import err_code -from gcloud.core.models import Project from gcloud.core.logging import local -from django.utils.translation import ugettext_lazy as _ +from gcloud.core.models import Project logger = logging.getLogger("root") diff --git a/gcloud/core/models.py b/gcloud/core/models.py index d0b6f9f094..3f710cdd98 100644 --- a/gcloud/core/models.py +++ b/gcloud/core/models.py @@ -20,7 +20,7 @@ from django.db import models, transaction from django.db.models import Q from django.utils import timezone -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from gcloud.constants import TEMPLATE_SOURCE diff --git a/gcloud/core/roles.py b/gcloud/core/roles.py index ec8a10463a..e9234f87a7 100644 --- a/gcloud/core/roles.py +++ b/gcloud/core/roles.py @@ -11,18 +11,18 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ -MAINTAINERS = 'Maintainers' -PRODUCTPM = 'ProductPm' -DEVELOPER = 'Developer' -TESTER = 'Tester' -OWNER = 'Owner' -COOPERATION = 'Cooperation' -ADMIN = 'Admin' -FUNCTOR = 'Functor' # 职能化人员 -AUDITOR = 'Auditor' -NORMAL = 'Normal' +MAINTAINERS = "Maintainers" +PRODUCTPM = "ProductPm" +DEVELOPER = "Developer" +TESTER = "Tester" +OWNER = "Owner" +COOPERATION = "Cooperation" +ADMIN = "Admin" +FUNCTOR = "Functor" # 职能化人员 +AUDITOR = "Auditor" +NORMAL = "Normal" ROLES_DECS = { MAINTAINERS: _("运维人员"), @@ -34,7 +34,6 @@ TESTER: _("测试人员"), DEVELOPER: _("开发人员"), AUDITOR: _("审计人员"), - } ALL_ROLES = [ @@ -62,10 +61,6 @@ ] # 默认通知分组 -CC_PERSON_GROUP = [ - {"value": role, "text": ROLES_DECS[role]} for role in CC_ROLES -] +CC_PERSON_GROUP = [{"value": role, "text": ROLES_DECS[role]} for role in CC_ROLES] -DEFAULT_CC_NOTIFY_SET = ( - MAINTAINERS, -) +DEFAULT_CC_NOTIFY_SET = (MAINTAINERS,) diff --git a/gcloud/core/roles/sites/open/roles.py b/gcloud/core/roles/sites/open/roles.py index a69b201b02..92771eca3d 100644 --- a/gcloud/core/roles/sites/open/roles.py +++ b/gcloud/core/roles/sites/open/roles.py @@ -11,18 +11,18 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ -MAINTAINERS = 'Maintainers' -PRODUCTPM = 'ProductPm' -DEVELOPER = 'Developer' -TESTER = 'Tester' -OWNER = 'Owner' -COOPERATION = 'Cooperation' -ADMIN = 'Admin' -FUNCTOR = 'Functor' # 职能化人员 -AUDITOR = 'Auditor' -NORMAL = 'Normal' +MAINTAINERS = "Maintainers" +PRODUCTPM = "ProductPm" +DEVELOPER = "Developer" +TESTER = "Tester" +OWNER = "Owner" +COOPERATION = "Cooperation" +ADMIN = "Admin" +FUNCTOR = "Functor" # 职能化人员 +AUDITOR = "Auditor" +NORMAL = "Normal" ROLES_DECS = { MAINTAINERS: _("运维人员"), @@ -34,7 +34,6 @@ TESTER: _("测试人员"), DEVELOPER: _("开发人员"), AUDITOR: _("审计人员"), - } ALL_ROLES = [ @@ -61,17 +60,13 @@ ] # 默认通知分组 -CC_PERSON_GROUP = [ - {"value": role, "text": ROLES_DECS[role]} for role in CC_ROLES -] +CC_PERSON_GROUP = [{"value": role, "text": ROLES_DECS[role]} for role in CC_ROLES] -DEFAULT_CC_NOTIFY_SET = ( - MAINTAINERS, -) +DEFAULT_CC_NOTIFY_SET = (MAINTAINERS,) CC_V2_ROLE_MAP = { - MAINTAINERS: 'bk_biz_maintainer', - PRODUCTPM: 'bk_biz_productor', - DEVELOPER: 'bk_biz_developer', - TESTER: 'bk_biz_tester' + MAINTAINERS: "bk_biz_maintainer", + PRODUCTPM: "bk_biz_productor", + DEVELOPER: "bk_biz_developer", + TESTER: "bk_biz_tester", } diff --git a/gcloud/exceptions.py b/gcloud/exceptions.py index 9680079b18..7dbf3d60cb 100644 --- a/gcloud/exceptions.py +++ b/gcloud/exceptions.py @@ -11,7 +11,7 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class BkSopsError(Exception): diff --git a/gcloud/external_plugins/models/base.py b/gcloud/external_plugins/models/base.py index 3a58d6b690..0d46e2c663 100644 --- a/gcloud/external_plugins/models/base.py +++ b/gcloud/external_plugins/models/base.py @@ -12,8 +12,7 @@ """ from django.db import models, transaction -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ from pipeline.contrib.external_plugins.models import source_cls_factory as base_source_cls_factory source_cls_factory = {} @@ -79,7 +78,7 @@ class PackageSource(models.Model): type = models.CharField(_("包源类型"), max_length=64) base_source_id = models.IntegerField(_("包源模型 ID"), blank=True, null=True) - _base_source_attr = '_base_source' + _base_source_attr = "_base_source" class Meta: abstract = True @@ -114,19 +113,15 @@ def update_base_source(self, source_type, packages, **kwargs): if source_type != self.type: with transaction.atomic(): new_base_source_cls = base_source_cls_factory[source_type] - base_source = new_base_source_cls.objects.create_source(name=self.name, - packages=packages, - from_config=False, - **kwargs) + base_source = new_base_source_cls.objects.create_source( + name=self.name, packages=packages, from_config=False, **kwargs + ) self.type = source_type self.delete_base_source() self.base_source_id = base_source.id self.save() else: base_source_cls = base_source_cls_factory[self.type] - base_source_cls.objects.filter(id=self.base_source_id).update( - packages=packages, - **kwargs - ) + base_source_cls.objects.filter(id=self.base_source_id).update(packages=packages, **kwargs) if hasattr(self, self._base_source_attr): self.base_source.refresh_from_db() diff --git a/gcloud/external_plugins/models/cache.py b/gcloud/external_plugins/models/cache.py index 6885d54ab0..673f508a6d 100644 --- a/gcloud/external_plugins/models/cache.py +++ b/gcloud/external_plugins/models/cache.py @@ -12,23 +12,23 @@ """ from django.db import models, transaction -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ -from gcloud.external_plugins import exceptions, CACHE_TEMP_PATH +from gcloud.external_plugins import CACHE_TEMP_PATH, exceptions from gcloud.external_plugins.models.base import PackageSource, PackageSourceManager from gcloud.external_plugins.protocol.writers import writer_cls_factory -CACHE = 'cache' +CACHE = "cache" class CachePackageSourceManager(PackageSourceManager): @transaction.atomic() - def add_cache_source(self, name, source_type, packages, desc='', **kwargs): + def add_cache_source(self, name, source_type, packages, desc="", **kwargs): if source_type not in writer_cls_factory: - raise exceptions.CacheSourceTypeError('Source type[%s] does not support as cache source' % source_type) + raise exceptions.CacheSourceTypeError("Source type[%s] does not support as cache source" % source_type) if self.all().count() > 0: - raise exceptions.MultipleCacheSourceError('Can not add multiple cache source') + raise exceptions.MultipleCacheSourceError("Can not add multiple cache source") base_source = super(CachePackageSourceManager, self).add_base_source(name, source_type, packages, **kwargs) return self.create(type=source_type, base_source_id=base_source.id, desc=desc) @@ -36,7 +36,7 @@ def add_cache_source(self, name, source_type, packages, desc='', **kwargs): def get_base_source(self): count = self.all().count() if count > 1: - raise exceptions.MultipleCacheSourceError('Can not add multiple cache source') + raise exceptions.MultipleCacheSourceError("Can not add multiple cache source") if count == 0: return None return self.all().first().base_source @@ -50,7 +50,7 @@ class CachePackageSource(PackageSource): class Meta: verbose_name = _("远程包源缓存 CachePackageSource") verbose_name_plural = _("远程包源缓存 CachePackageSource") - ordering = ['-id'] + ordering = ["-id"] @property def category(self): @@ -70,6 +70,6 @@ def details(self): def write(self, sub_dir=None): if self.type not in writer_cls_factory: - raise exceptions.CacheSourceTypeError('Source type[%s] does not support as cache source' % self.type) + raise exceptions.CacheSourceTypeError("Source type[%s] does not support as cache source" % self.type) writer = writer_cls_factory[self.type](CACHE_TEMP_PATH, self.base_source) writer.write(sub_dir) diff --git a/gcloud/external_plugins/models/origin.py b/gcloud/external_plugins/models/origin.py index 556c673b3c..29f70fbfe9 100644 --- a/gcloud/external_plugins/models/origin.py +++ b/gcloud/external_plugins/models/origin.py @@ -16,16 +16,11 @@ from abc import abstractmethod from django.db import models, transaction -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ +from pipeline.contrib.external_plugins.models import FILE_SYSTEM, GIT, S3 from pipeline.contrib.external_plugins.models.fields import JSONTextField -from pipeline.contrib.external_plugins.models import ( - GIT, - S3, - FILE_SYSTEM, -) -from gcloud.external_plugins import exceptions, CACHE_TEMP_PATH +from gcloud.external_plugins import CACHE_TEMP_PATH, exceptions from gcloud.external_plugins.models.base import PackageSource, PackageSourceManager from gcloud.external_plugins.models.cache import CachePackageSource from gcloud.external_plugins.protocol.readers import reader_cls_factory diff --git a/gcloud/external_plugins/models/sync.py b/gcloud/external_plugins/models/sync.py index 59823573c3..777cc71806 100644 --- a/gcloud/external_plugins/models/sync.py +++ b/gcloud/external_plugins/models/sync.py @@ -12,30 +12,23 @@ """ from django.db import models -from django.utils.translation import ugettext_lazy as _ from django.utils import timezone +from django.utils.translation import gettext_lazy as _ from gcloud.core.utils import convert_readable_username -RUNNING = 'RUNNING' -SUCCEEDED = 'SUCCEEDED' -FAILED = 'FAILED' +RUNNING = "RUNNING" +SUCCEEDED = "SUCCEEDED" +FAILED = "FAILED" -SYNC_TASK_STATUS = [ - (RUNNING, _("执行中")), - (SUCCEEDED, _("成功")), - (FAILED, _("失败")) -] +SYNC_TASK_STATUS = [(RUNNING, _("执行中")), (SUCCEEDED, _("成功")), (FAILED, _("失败"))] -SYNC_TASK_CREATED = [ - ('manual', _("手动触发")), - ('auto', _("部署自动触发")) -] +SYNC_TASK_CREATED = [("manual", _("手动触发")), ("auto", _("部署自动触发"))] class SyncTask(models.Model): creator = models.CharField(_("执行者"), max_length=32, blank=True) - create_method = models.CharField(_("创建方式"), max_length=32, default='manual', choices=SYNC_TASK_CREATED) + create_method = models.CharField(_("创建方式"), max_length=32, default="manual", choices=SYNC_TASK_CREATED) start_time = models.DateTimeField(_("启动时间"), auto_now_add=True) finish_time = models.DateTimeField(_("结束时间"), null=True, blank=True) status = models.CharField(_("同步状态"), max_length=32, default=RUNNING, choices=SYNC_TASK_STATUS) @@ -44,7 +37,7 @@ class SyncTask(models.Model): class Meta: verbose_name = _("远程包源同步任务 SyncTask") verbose_name_plural = _("远程包源同步任务 SyncTask") - ordering = ['-id'] + ordering = ["-id"] @property def creator_name(self): diff --git a/gcloud/iam_auth/conf.py b/gcloud/iam_auth/conf.py index 05c2ce3154..b798a12ad8 100644 --- a/gcloud/iam_auth/conf.py +++ b/gcloud/iam_auth/conf.py @@ -12,8 +12,7 @@ """ from django.conf import settings -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ from iam import meta SYSTEM_ID = settings.BK_IAM_SYSTEM_ID diff --git a/gcloud/iam_auth/resource_api/task.py b/gcloud/iam_auth/resource_api/task.py index e3b4a8963c..957ea895dc 100644 --- a/gcloud/iam_auth/resource_api/task.py +++ b/gcloud/iam_auth/resource_api/task.py @@ -13,14 +13,14 @@ from django.contrib.auth import get_user_model from django.core.cache import cache from django.db.models import Q, Value -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ +from iam import PathEqDjangoQuerySetConverter +from iam.contrib.django.dispatcher import InvalidPageException from iam.resource.provider import ListResult, ResourceProvider from gcloud.core.models import Project from gcloud.iam_auth.conf import SEARCH_INSTANCE_CACHE_TIME from gcloud.taskflow3.models import TaskFlowInstance -from iam import PathEqDjangoQuerySetConverter -from iam.contrib.django.dispatcher import InvalidPageException attr_names = { "en": {"type": "Task type", "iam_resource_owner": "Resource owner"}, diff --git a/gcloud/label/models.py b/gcloud/label/models.py index 600b667c4d..f8eab0d650 100644 --- a/gcloud/label/models.py +++ b/gcloud/label/models.py @@ -17,7 +17,7 @@ from django.db import models from django.db.models import Count -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from gcloud.tasktmpl3.models import TaskTemplate @@ -34,7 +34,9 @@ def check_label_ids(self, label_ids): class Label(models.Model): name = models.CharField(_("标签名称"), max_length=255, db_index=True, help_text="标签名称") creator = models.CharField(_("创建者"), max_length=255, help_text="标签创建人") - project_id = models.IntegerField(_("项目 ID"), default=-1, help_text="标签对应project id") # 默认标签时project_id=-1 + project_id = models.IntegerField( + _("项目 ID"), default=-1, help_text="标签对应project id" + ) # 默认标签时project_id=-1 is_default = models.BooleanField(_("默认标签"), default=False, help_text="是否是默认标签") color = models.CharField(_("标签颜色"), max_length=7, default="#dcffe2", help_text="标签颜色值") description = models.CharField(_("标签描述"), max_length=255, blank=True, null=True, help_text="标签描述") diff --git a/gcloud/mako_template_helper/hub.py b/gcloud/mako_template_helper/hub.py index a5f72acc23..734c1daf36 100644 --- a/gcloud/mako_template_helper/hub.py +++ b/gcloud/mako_template_helper/hub.py @@ -10,11 +10,11 @@ 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 django.utils.translation import gettext_lazy as _ from gcloud.constants import Type -from .base import MakoTemplateOperation, MakoParam, MakoOperator +from .base import MakoOperator, MakoParam, MakoTemplateOperation OPERATIONS = [ MakoTemplateOperation( diff --git a/gcloud/periodictask/models.py b/gcloud/periodictask/models.py index 0018064eef..63e63b3153 100644 --- a/gcloud/periodictask/models.py +++ b/gcloud/periodictask/models.py @@ -16,7 +16,7 @@ import ujson as json from django.conf import settings from django.db import models, transaction -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.contrib.periodic_task.models import BAMBOO_ENGINE_TRIGGER_TASK from pipeline.contrib.periodic_task.models import PeriodicTask as PipelinePeriodicTask from pipeline.contrib.periodic_task.models import PeriodicTaskHistory as PipelinePeriodicTaskHistory diff --git a/gcloud/project_constants/models.py b/gcloud/project_constants/models.py index 43717e9c5a..f692776e8f 100644 --- a/gcloud/project_constants/models.py +++ b/gcloud/project_constants/models.py @@ -13,8 +13,7 @@ from django.db import models - -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class ProjectConstant(models.Model): diff --git a/gcloud/taskflow3/apis/django/api.py b/gcloud/taskflow3/apis/django/api.py index 62ed6328f8..f2aa8883e7 100644 --- a/gcloud/taskflow3/apis/django/api.py +++ b/gcloud/taskflow3/apis/django/api.py @@ -19,7 +19,7 @@ from cryptography.fernet import Fernet from django.db import transaction from django.http import JsonResponse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_GET, require_POST from drf_yasg.utils import swagger_auto_schema @@ -271,7 +271,9 @@ def get_job_instance_log(request, biz_cc_id): job_result = client.job.get_job_instance_log(log_kwargs) if not job_result["result"]: - message = _(f"执行历史请求失败: 请求[作业平台ID: {biz_cc_id}] 异常信息: {job_result['message']} | get_job_instance_log") + message = _( + f"执行历史请求失败: 请求[作业平台ID: {biz_cc_id}] 异常信息: {job_result['message']} | get_job_instance_log" + ) if job_result.get("code", 0) == HTTP_AUTH_FORBIDDEN_CODE: logger.warning(message) @@ -449,7 +451,9 @@ def preview_task_tree(request, project_id): try: data = preview_template_tree(project_id, template_source, template_id, version, exclude_task_nodes_id) except Exception as e: - message = _(f"任务数据请求失败: 请求任务数据发生异常: {e}. 请重试, 如多次失败可联系管理员处理 | preview_task_tree") + message = _( + f"任务数据请求失败: 请求任务数据发生异常: {e}. 请重试, 如多次失败可联系管理员处理 | preview_task_tree" + ) logger.exception(message) return JsonResponse({"result": False, "message": message}) @@ -502,7 +506,9 @@ def get_node_log(request, project_id, node_id): task = TaskFlowInstance.objects.get(pk=task_id, project_id=project_id) if not task.has_node(node_id): - message = _(f"节点状态请求失败: 任务[ID: {task.id}]中未找到节点[ID: {node_id}]. 请重试. 如持续失败可联系管理员处理 | get_node_log") + message = _( + f"节点状态请求失败: 任务[ID: {task.id}]中未找到节点[ID: {node_id}]. 请重试. 如持续失败可联系管理员处理 | get_node_log" + ) logger.error(message) return JsonResponse({"result": False, "data": None, "message": message}) @@ -537,7 +543,9 @@ def node_callback(request, token): try: callback_data = json.loads(request.body) except Exception: - message = _(f"节点回调失败: 无效的请求, 请重试. 如持续失败可联系管理员处理. {traceback.format_exc()} | api node_callback") + message = _( + f"节点回调失败: 无效的请求, 请重试. 如持续失败可联系管理员处理. {traceback.format_exc()} | api node_callback" + ) logger.error(message) return JsonResponse({"result": False, "message": message}, status=400) diff --git a/gcloud/taskflow3/apis/django/v4/node_callback.py b/gcloud/taskflow3/apis/django/v4/node_callback.py index 34e7beac17..420ed98730 100644 --- a/gcloud/taskflow3/apis/django/v4/node_callback.py +++ b/gcloud/taskflow3/apis/django/v4/node_callback.py @@ -15,18 +15,17 @@ import time import traceback +from blueapps.account.decorators import login_exempt +from cryptography.fernet import Fernet from django.conf import settings from django.http import JsonResponse -from cryptography.fernet import Fernet +from django.utils.translation import gettext_lazy as _ from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST -from blueapps.account.decorators import login_exempt - import env -from gcloud.taskflow3.models import TaskFlowInstance from gcloud.taskflow3.domains.dispatchers import NodeCommandDispatcher -from django.utils.translation import ugettext_lazy as _ +from gcloud.taskflow3.models import TaskFlowInstance logger = logging.getLogger("root") @@ -62,7 +61,9 @@ def node_callback(request, token): try: callback_data = json.loads(request.body) except Exception: - message = _(f"节点回调失败: 无效的请求, 请重试. 如持续失败可联系管理员处理. {traceback.format_exc()} | node_callback") + message = _( + f"节点回调失败: 无效的请求, 请重试. 如持续失败可联系管理员处理. {traceback.format_exc()} | node_callback" + ) logger.error(message) return JsonResponse({"result": False, "message": message}, status=400) diff --git a/gcloud/taskflow3/apis/django/v4/state.py b/gcloud/taskflow3/apis/django/v4/state.py index 5d984d812a..5cc02f326a 100644 --- a/gcloud/taskflow3/apis/django/v4/state.py +++ b/gcloud/taskflow3/apis/django/v4/state.py @@ -14,7 +14,7 @@ import logging from django.http.response import JsonResponse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views.decorators.http import require_GET from gcloud import err_code @@ -35,7 +35,9 @@ def root_state(request, project_id): try: task = TaskFlowInstance.objects.get(pk=instance_id, project_id=project_id, is_deleted=False) except Exception as e: - message = _(f"任务状态请求失败: 请求任务[ID: {instance_id}]的状态发生错误: {e}. 请重试, 如持续失败可联系管理员处理 | get_task_status") + message = _( + f"任务状态请求失败: 请求任务[ID: {instance_id}]的状态发生错误: {e}. 请重试, 如持续失败可联系管理员处理 | get_task_status" + ) logger.error(message) return { "result": False, diff --git a/gcloud/taskflow3/apis/drf/viewsets/preview_task_tree.py b/gcloud/taskflow3/apis/drf/viewsets/preview_task_tree.py index 222a172608..c4132fb48f 100644 --- a/gcloud/taskflow3/apis/drf/viewsets/preview_task_tree.py +++ b/gcloud/taskflow3/apis/drf/viewsets/preview_task_tree.py @@ -12,19 +12,18 @@ """ import logging -from rest_framework import serializers -from rest_framework.views import APIView + +from django.utils.translation import gettext_lazy as _ +from drf_yasg.utils import swagger_auto_schema +from rest_framework import permissions, serializers from rest_framework.decorators import action -from rest_framework import permissions from rest_framework.response import Response +from rest_framework.views import APIView from gcloud.common_template.models import CommonTemplate from gcloud.constants import PROJECT -from drf_yasg.utils import swagger_auto_schema - from gcloud.tasktmpl3.models import TaskTemplate from pipeline_web.preview import preview_template_tree_with_schemes -from django.utils.translation import ugettext_lazy as _ logger = logging.getLogger("root") @@ -75,7 +74,9 @@ def post(self, request): else: template = CommonTemplate.objects.get(pk=template_id, is_deleted=False) except TaskTemplate.DoesNotExist: - message = _(f"请求任务数据失败: 任务关联的流程[ID: {template_id}]已不存在, 项目[ID: {project_id}] 请检查 | preview_task_tree") + message = _( + f"请求任务数据失败: 任务关联的流程[ID: {template_id}]已不存在, 项目[ID: {project_id}] 请检查 | preview_task_tree" + ) logger.error(message) return Response({"result": False, "message": message, "data": {}}) except CommonTemplate.DoesNotExist: @@ -86,7 +87,9 @@ def post(self, request): try: data = preview_template_tree_with_schemes(template, version, scheme_id_list) except Exception as e: - message = _(f"任务数据请求失败: 获取带执行方案流程树数据失败, 错误信息: {e}, 请重试. 如多次失败可联系管理员处理 | preview_task_tree") + message = _( + f"任务数据请求失败: 获取带执行方案流程树数据失败, 错误信息: {e}, 请重试. 如多次失败可联系管理员处理 | preview_task_tree" + ) logger.exception(message) return Response({"result": False, "message": message, "data": {}}) diff --git a/gcloud/taskflow3/celery/tasks.py b/gcloud/taskflow3/celery/tasks.py index d5a92622e6..96fcd63a53 100644 --- a/gcloud/taskflow3/celery/tasks.py +++ b/gcloud/taskflow3/celery/tasks.py @@ -9,6 +9,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 json import logging import socket @@ -17,7 +18,7 @@ from celery import current_app from django.conf import settings from django.utils import timezone -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.engine.models import PipelineProcess from pipeline.eri.models import Process, State from pipeline.eri.runtime import BambooDjangoRuntime diff --git a/gcloud/taskflow3/domains/context.py b/gcloud/taskflow3/domains/context.py index 3a74c588cb..a079f7d692 100644 --- a/gcloud/taskflow3/domains/context.py +++ b/gcloud/taskflow3/domains/context.py @@ -16,7 +16,7 @@ import pytz from django.conf import settings from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from engine_pickle_obj.context import SystemObject from gcloud.core.models import Business, Project, ProjectConfig diff --git a/gcloud/taskflow3/domains/dispatchers/base.py b/gcloud/taskflow3/domains/dispatchers/base.py index 5970e3bf36..cf5d5fc593 100644 --- a/gcloud/taskflow3/domains/dispatchers/base.py +++ b/gcloud/taskflow3/domains/dispatchers/base.py @@ -12,16 +12,15 @@ """ import functools - +import logging from abc import ABCMeta +from bamboo_engine.api import EngineAPIResult +from django.utils.translation import gettext_lazy as _ + from gcloud import err_code from gcloud.core.models import EngineConfig -from bamboo_engine.api import EngineAPIResult -from django.utils.translation import ugettext_lazy as _ -import logging - logger = logging.getLogger("root") diff --git a/gcloud/taskflow3/domains/dispatchers/node.py b/gcloud/taskflow3/domains/dispatchers/node.py index ccec657b3f..fe3bde12b2 100644 --- a/gcloud/taskflow3/domains/dispatchers/node.py +++ b/gcloud/taskflow3/domains/dispatchers/node.py @@ -19,7 +19,7 @@ from bamboo_engine import exceptions as bamboo_exceptions from bamboo_engine import states as bamboo_engine_states from bamboo_engine.eri import ContextValueType -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from opentelemetry import trace from pipeline.component_framework.library import ComponentLibrary from pipeline.engine import api as pipeline_api diff --git a/gcloud/taskflow3/domains/dispatchers/task.py b/gcloud/taskflow3/domains/dispatchers/task.py index 66926a8576..3f2d9df8a6 100644 --- a/gcloud/taskflow3/domains/dispatchers/task.py +++ b/gcloud/taskflow3/domains/dispatchers/task.py @@ -27,7 +27,7 @@ from django.conf import settings from django.db import transaction from django.utils import timezone -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from opentelemetry import trace from pipeline.core.data.var import Variable from pipeline.engine import api as pipeline_api @@ -201,7 +201,9 @@ def start_v2(self, executor: str) -> dict: except Exception as e: logger.exception("run pipeline failed") PipelineInstance.objects.filter(instance_id=self.pipeline_instance.instance_id, is_started=True).update( - start_time=None, is_started=False, executor="", + start_time=None, + is_started=False, + executor="", ) message = _(f"任务启动失败: 引擎启动失败, 请重试. 如持续失败可联系管理员处理. {e} | start_v2") logger.error(message) @@ -213,7 +215,9 @@ def start_v2(self, executor: str) -> dict: if not result.result: PipelineInstance.objects.filter(instance_id=self.pipeline_instance.instance_id, is_started=True).update( - start_time=None, is_started=False, executor="", + start_time=None, + is_started=False, + executor="", ) logger.error("run_pipeline fail: {}, exception: {}".format(result.message, result.exc_trace)) else: @@ -407,7 +411,10 @@ def set_task_constants( f"update context values failed: pipeline instance state error, " f"tree state is {status_result}" ) - message = _(f"任务参数设置失败: 任务状态校验失败," f"任务状态为{status_result['data']['state']},不支持进行参数修改。") + message = _( + f"任务参数设置失败: 任务状态校验失败," + f"任务状态为{status_result['data']['state']},不支持进行参数修改。" + ) return {"result": False, "data": "", "message": message, "code": err_code.VALIDATION_ERROR.code} bamboo_runtime = BambooDjangoRuntime() @@ -418,7 +425,9 @@ def set_task_constants( ) if not update_res.result: logger.error("update context values failed: %s" % update_res.exc_trace) - message = _(f"任务参数设置失败: 更新引擎上下文发生异常: {update_res.message}. 请重试, 如持续失败可联系管理员处理 | set_task_constants") + message = _( + f"任务参数设置失败: 更新引擎上下文发生异常: {update_res.message}. 请重试, 如持续失败可联系管理员处理 | set_task_constants" + ) logger.error(message) return { "result": False, @@ -506,7 +515,9 @@ def get_task_status_v1(self, subprocess_id: Optional[str], with_ex_data: bool, * # do not raise error when subprocess not exist or has not been executed task_status = self.CREATED_STATUS except Exception: - message = _(f"获取任务状态树数据失败: subprocess[ID: {subprocess_id}]请重试, 如持续失败可联系管理员处理 | get_task_status_v1") + message = _( + f"获取任务状态树数据失败: subprocess[ID: {subprocess_id}]请重试, 如持续失败可联系管理员处理 | get_task_status_v1" + ) logger.exception(message) return { "result": False, @@ -585,10 +596,10 @@ def get_subprocess_status(task_status: dict, subprocess_id: str) -> dict: if with_new_status: # 遍历树,获取需要进行状态优化的节点,标记哪些节点具有独立子流程 # 遍历状态树,hit -> 状态优化,独立子流程 -> 递归 - node_infos_gby_code: typing.Dict[ - str, typing.List[typing.Dict[str, typing.Any]] - ] = find_nodes_from_pipeline_tree( - self.pipeline_instance.execution_data, codes=["pause_node", "bk_approve", "subprocess_plugin"] + node_infos_gby_code: typing.Dict[str, typing.List[typing.Dict[str, typing.Any]]] = ( + find_nodes_from_pipeline_tree( + self.pipeline_instance.execution_data, codes=["pause_node", "bk_approve", "subprocess_plugin"] + ) ) node_ids_gby_code: typing.Dict[str, typing.Set[str]] = {} @@ -601,9 +612,9 @@ def get_subprocess_status(task_status: dict, subprocess_id: str) -> dict: } status_tree, root_pipeline_id = task_status, task_status["id"] - node_id__auto_retry_info: typing.Dict[ - str, typing.Dict[str, typing.Any] - ] = fetch_node_id__auto_retry_info_map(root_pipeline_id, extract_nodes_by_statuses(status_tree)) + node_id__auto_retry_info: typing.Dict[str, typing.Dict[str, typing.Any]] = ( + fetch_node_id__auto_retry_info_map(root_pipeline_id, extract_nodes_by_statuses(status_tree)) + ) self.format_bamboo_engine_status( task_status, node_ids_gby_code, code__status_map, node_id__auto_retry_info, False, is_subquery diff --git a/gcloud/taskflow3/domains/task_constants.py b/gcloud/taskflow3/domains/task_constants.py index a4ca6e2221..02531f4ed5 100644 --- a/gcloud/taskflow3/domains/task_constants.py +++ b/gcloud/taskflow3/domains/task_constants.py @@ -10,9 +10,9 @@ 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 bamboo_engine.states import RUNNING, FINISHED +from bamboo_engine.states import FINISHED, RUNNING from bamboo_engine.template import Template +from django.utils.translation import gettext_lazy as _ from pipeline.eri.runtime import BambooDjangoRuntime from gcloud.core.models import EngineConfig diff --git a/gcloud/taskflow3/models.py b/gcloud/taskflow3/models.py index c65f71c8f3..316d8a3e7c 100644 --- a/gcloud/taskflow3/models.py +++ b/gcloud/taskflow3/models.py @@ -19,7 +19,7 @@ import ujson as json from django.db import connection, models, transaction from django.db.models import Count, Q -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.models import ComponentModel from pipeline.core.constants import PE from pipeline.engine import states @@ -723,7 +723,9 @@ class TaskFlowInstance(models.Model): template_id = models.CharField(_("创建任务所用的模板ID"), max_length=255, blank=True) template_source = models.CharField(_("流程模板来源"), max_length=32, choices=TEMPLATE_SOURCE, default=PROJECT) create_method = models.CharField(_("创建方式"), max_length=30, choices=TASK_CREATE_METHOD, default="app") - create_info = models.CharField(_("创建任务额外信息(App maker ID或APP CODE或周期任务ID)"), max_length=255, blank=True) + create_info = models.CharField( + _("创建任务额外信息(App maker ID或APP CODE或周期任务ID)"), max_length=255, blank=True + ) flow_type = models.CharField(_("任务流程类型"), max_length=255, choices=TASK_FLOW_TYPE, default="common") current_flow = models.CharField(_("当前任务流程阶段"), max_length=255) is_deleted = models.BooleanField(_("是否删除"), default=False) @@ -924,7 +926,9 @@ def task_url(cls, project_id, task_id): def get_node_data(self, node_id, username, component_code=None, subprocess_stack=None, loop=None): if not self.has_node(node_id): - message = _(f"节点状态请求失败: 任务[ID: {self.id}]中未找到节点[ID: {node_id}]. 请重试. 如持续失败可联系管理员处理 | get_node_data") + message = _( + f"节点状态请求失败: 任务[ID: {self.id}]中未找到节点[ID: {node_id}]. 请重试. 如持续失败可联系管理员处理 | get_node_data" + ) logger.error(message) return {"result": False, "message": message, "data": {}, "code": err_code.REQUEST_PARAM_INVALID.code} @@ -943,7 +947,9 @@ def get_node_detail( self, node_id, username, component_code=None, subprocess_stack=None, loop=None, include_data=True, **kwargs ): if not self.has_node(node_id): - message = _(f"节点状态请求失败: 任务[ID: {self.id}]中未找到节点[ID: {node_id}]. 请重试. 如持续失败可联系管理员处理 | get_node_detail") + message = _( + f"节点状态请求失败: 任务[ID: {self.id}]中未找到节点[ID: {node_id}]. 请重试. 如持续失败可联系管理员处理 | get_node_detail" + ) logger.error(message) return {"result": False, "message": message, "data": {}, "code": err_code.REQUEST_PARAM_INVALID.code} @@ -995,7 +1001,9 @@ def task_claim(self, username, constants, name): logger.error(message) return {"result": False, "message": message, "data": None} elif self.current_flow != "func_claim": - message = _(f"任务认领失败: 仅职能化任务才能认领, 当前任务类型: {self.current_flow}, 请检查任务类型 | task_claim") + message = _( + f"任务认领失败: 仅职能化任务才能认领, 当前任务类型: {self.current_flow}, 请检查任务类型 | task_claim" + ) logger.error(message) return { "result": False, @@ -1088,13 +1096,17 @@ def task_action(self, action, username): return dispatcher.dispatch(action, username) except Exception as e: logger.exception(traceback.format_exc()) - message = _(f"任务操作失败: 任务[ID: {self.id}]操作失败: {e}. 请重试, 持续失败可联系管理员处理 | task_action") + message = _( + f"任务操作失败: 任务[ID: {self.id}]操作失败: {e}. 请重试, 持续失败可联系管理员处理 | task_action" + ) logger.error(message) return {"result": False, "message": message, "code": err_code.UNKNOWN_ERROR.code} def nodes_action(self, action, node_id, username, **kwargs): if not self.has_node(node_id): - message = _(f"节点状态请求失败: 任务[ID: {self.id}]中未找到节点[ID: {node_id}]. 请重试. 如持续失败可联系管理员处理 | nodes_action") + message = _( + f"节点状态请求失败: 任务[ID: {self.id}]中未找到节点[ID: {node_id}]. 请重试. 如持续失败可联系管理员处理 | nodes_action" + ) logger.error(message) return {"result": False, "message": message, "code": err_code.REQUEST_PARAM_INVALID.code} @@ -1107,7 +1119,9 @@ def nodes_action(self, action, node_id, username, **kwargs): return dispatcher.dispatch(action, username, **kwargs) except Exception as e: logger.exception(traceback.format_exc()) - message = _(f"节点操作失败: 节点[ID: {node_id}], 任务[ID: {self.id}]操作失败: {e}, 请重试. 如持续失败可联系管理员处理 | nodes_action") + message = _( + f"节点操作失败: 节点[ID: {node_id}], 任务[ID: {self.id}]操作失败: {e}, 请重试. 如持续失败可联系管理员处理 | nodes_action" + ) logger.error(message) return {"result": False, "message": message, "code": err_code.UNKNOWN_ERROR.code} diff --git a/gcloud/taskflow3/utils.py b/gcloud/taskflow3/utils.py index 1ada64b2c3..899ea58779 100644 --- a/gcloud/taskflow3/utils.py +++ b/gcloud/taskflow3/utils.py @@ -17,7 +17,7 @@ from typing import Any, Dict, List, Optional from django.apps import apps -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core import constants as pipeline_constants from pipeline.engine import states as pipeline_states from pipeline.engine.utils import calculate_elapsed_time @@ -85,9 +85,9 @@ def find_nodes_from_pipeline_tree( for act_id, act in pipeline_tree[pipeline_constants.PE.activities].items(): if act["type"] == pipeline_constants.PE.SubProcess: # 非独立子流程继续递归查找 - child_node_infos_gby_code: typing.Dict[ - str, typing.List[typing.Dict[str, typing.Any]] - ] = find_nodes_from_pipeline_tree(act[pipeline_constants.PE.pipeline], codes) + child_node_infos_gby_code: typing.Dict[str, typing.List[typing.Dict[str, typing.Any]]] = ( + find_nodes_from_pipeline_tree(act[pipeline_constants.PE.pipeline], codes) + ) # 子树查找结果同父流程合并 for code in codes: node_infos_gby_code[code].extend(child_node_infos_gby_code.get(code) or []) diff --git a/gcloud/tasktmpl3/apis/django/api.py b/gcloud/tasktmpl3/apis/django/api.py index 3f13dbafe1..f87358c0d9 100644 --- a/gcloud/tasktmpl3/apis/django/api.py +++ b/gcloud/tasktmpl3/apis/django/api.py @@ -15,7 +15,7 @@ import ujson as json from django.http import HttpResponseForbidden, JsonResponse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views.decorators.http import require_GET, require_POST from drf_yasg.utils import swagger_auto_schema from rest_framework.decorators import api_view @@ -31,10 +31,7 @@ ParentsInterceptor, ) from gcloud.openapi.schema import AnnotationAutoSchema -from gcloud.tasktmpl3.domains.constants import ( - analysis_pipeline_constants_ref, - get_constant_values, -) +from gcloud.tasktmpl3.domains.constants import analysis_pipeline_constants_ref, get_constant_values from gcloud.tasktmpl3.models import TaskTemplate from gcloud.template_base.apis.django.api import ( base_batch_form, diff --git a/gcloud/tasktmpl3/apis/django/validators.py b/gcloud/tasktmpl3/apis/django/validators.py index ec42e97f60..9bf6beec35 100644 --- a/gcloud/tasktmpl3/apis/django/validators.py +++ b/gcloud/tasktmpl3/apis/django/validators.py @@ -11,14 +11,15 @@ specific language governing permissions and limitations under the License. """ +import logging + import ujson as json +from django.utils.translation import gettext_lazy as _ from gcloud.constants import TEMPLATE_EXPORTER_SOURCE_PROJECT -from gcloud.utils.validate import RequestValidator, ObjectJsonBodyValidator -from gcloud.utils.strings import check_and_rename_params from gcloud.template_base.utils import read_template_data_file -from django.utils.translation import ugettext_lazy as _ -import logging +from gcloud.utils.strings import check_and_rename_params +from gcloud.utils.validate import ObjectJsonBodyValidator, RequestValidator logger = logging.getLogger("root") diff --git a/gcloud/tasktmpl3/apis/drf/viewsets/batch_form_with_schemes.py b/gcloud/tasktmpl3/apis/drf/viewsets/batch_form_with_schemes.py index 073f7f5442..44b32f20b0 100644 --- a/gcloud/tasktmpl3/apis/drf/viewsets/batch_form_with_schemes.py +++ b/gcloud/tasktmpl3/apis/drf/viewsets/batch_form_with_schemes.py @@ -14,7 +14,7 @@ import itertools import logging -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from drf_yasg.utils import swagger_auto_schema from pipeline.models import TemplateScheme from rest_framework import permissions @@ -115,7 +115,9 @@ def post(self, request): try: preview_data = preview_template_tree_with_schemes(template, version, scheme_id_list) except Exception as e: - message = _(f"请求参数信息失败: 批量获取带执行方案的流程表单失败, 错误信息: {e}, 请重试. 如持续失败可联系管理员处理 | batch form with schemes") + message = _( + f"请求参数信息失败: 批量获取带执行方案的流程表单失败, 错误信息: {e}, 请重试. 如持续失败可联系管理员处理 | batch form with schemes" + ) logger.error(message) return Response({"result": False, "message": message, "data": {}}) data[template_id].append( diff --git a/gcloud/tasktmpl3/apis/drf/viewsets/form_with_schemes.py b/gcloud/tasktmpl3/apis/drf/viewsets/form_with_schemes.py index 4db0dedc86..77bf8aeb87 100644 --- a/gcloud/tasktmpl3/apis/drf/viewsets/form_with_schemes.py +++ b/gcloud/tasktmpl3/apis/drf/viewsets/form_with_schemes.py @@ -12,26 +12,24 @@ """ import logging -from rest_framework.views import APIView -from rest_framework.decorators import action + +from django.utils.translation import gettext_lazy as _ +from drf_yasg.utils import swagger_auto_schema from rest_framework import permissions +from rest_framework.decorators import action from rest_framework.response import Response +from rest_framework.views import APIView -from gcloud.constants import PROJECT -from gcloud.tasktmpl3.models import TaskTemplate from gcloud.common_template.models import CommonTemplate +from gcloud.constants import PROJECT +from gcloud.tasktmpl3.apis.drf.permissions import TemplateFormWithSchemesPermissions from gcloud.tasktmpl3.apis.drf.serilaziers.form_with_schemes import ( - TemplateFormWithSchemesSerializer, TemplateFormResponseSerializer, + TemplateFormWithSchemesSerializer, ) -from gcloud.tasktmpl3.apis.drf.permissions import TemplateFormWithSchemesPermissions - -from drf_yasg.utils import swagger_auto_schema - +from gcloud.tasktmpl3.models import TaskTemplate from pipeline_web.preview import preview_template_tree_with_schemes -from django.utils.translation import ugettext_lazy as _ - logger = logging.getLogger("root") @@ -74,7 +72,9 @@ def post(self, request): try: template_data = preview_template_tree_with_schemes(template, version, scheme_id_list) except Exception as e: - message = _(f"请求参数信息失败: 批量获取带执行方案的流程表单失败, 错误信息: {e}, 请重试. 如持续失败可联系管理员处理 | form_with_schemes") + message = _( + f"请求参数信息失败: 批量获取带执行方案的流程表单失败, 错误信息: {e}, 请重试. 如持续失败可联系管理员处理 | form_with_schemes" + ) logger.exception(message) return Response({"result": False, "message": message, "data": {}}) diff --git a/gcloud/tasktmpl3/models.py b/gcloud/tasktmpl3/models.py index 68ec11f162..bbbdef0eb8 100644 --- a/gcloud/tasktmpl3/models.py +++ b/gcloud/tasktmpl3/models.py @@ -18,7 +18,7 @@ from django.contrib.auth import get_user_model from django.db import models from django.db.models import Count -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.models import ComponentModel from pipeline.contrib.periodic_task.models import PeriodicTask from pipeline.models import PipelineInstance, PipelineTemplate, TemplateRelationship @@ -541,7 +541,9 @@ def get_templates_with_expired_subprocess(self, project_id): class TaskTemplate(BaseTemplate): project = models.ForeignKey(Project, verbose_name=_("所属项目"), null=True, blank=True, on_delete=models.SET_NULL) executor_proxy = models.CharField(_("任务执行人代理"), max_length=255, default="", blank=True) - default_flow_type = models.CharField(_("偏好任务流程类型"), max_length=255, choices=TASK_FLOW_TYPE, default="common") + default_flow_type = models.CharField( + _("偏好任务流程类型"), max_length=255, choices=TASK_FLOW_TYPE, default="common" + ) objects = TaskTemplateManager() diff --git a/gcloud/template_base/apis/django/api.py b/gcloud/template_base/apis/django/api.py index 938b3275df..af3380a34d 100644 --- a/gcloud/template_base/apis/django/api.py +++ b/gcloud/template_base/apis/django/api.py @@ -21,7 +21,7 @@ import yaml from django.db.models import Model from django.http import HttpResponse, JsonResponse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from drf_yasg.utils import swagger_auto_schema from pipeline.models import TemplateRelationship from rest_framework.decorators import api_view @@ -32,10 +32,7 @@ from gcloud.core.models import Project from gcloud.exceptions import FlowExportError from gcloud.iam_auth.intercept import iam_intercept -from gcloud.iam_auth.view_interceptors.base_template import ( - YamlExportInterceptor, - YamlImportInterceptor, -) +from gcloud.iam_auth.view_interceptors.base_template import YamlExportInterceptor, YamlImportInterceptor from gcloud.openapi.schema import AnnotationAutoSchema from gcloud.template_base.apis.django.validators import ( FileValidator, @@ -45,10 +42,7 @@ from gcloud.template_base.domains import TEMPLATE_TYPE_MODEL from gcloud.template_base.domains.converter_handler import YamlSchemaConverterHandler from gcloud.template_base.domains.importer import TemplateImporter -from gcloud.template_base.utils import ( - format_import_result_to_response_data, - read_template_data_file, -) +from gcloud.template_base.utils import format_import_result_to_response_data, read_template_data_file from gcloud.utils.dates import time_now_str from gcloud.utils.decorators import request_validate from gcloud.utils.strings import string_to_boolean @@ -425,7 +419,9 @@ def base_template_parents(request: Request, template_model_cls: object, filters: qs = template_model_cls.objects.filter(**filters).only("pipeline_template_id") if len(qs) != 1: - message = _(f"流程导入失败: 文件解析异常, 可能内容不合法. 请重试或联系管理员处理, 根据过滤条件: {filters}, 找到{len(qs)}条数据 | base_template_parents") + message = _( + f"流程导入失败: 文件解析异常, 可能内容不合法. 请重试或联系管理员处理, 根据过滤条件: {filters}, 找到{len(qs)}条数据 | base_template_parents" + ) logger.error(message) return JsonResponse( { diff --git a/gcloud/template_base/apis/drf/viewsets/template_scheme.py b/gcloud/template_base/apis/drf/viewsets/template_scheme.py index cdeb8b3dea..79228117e9 100644 --- a/gcloud/template_base/apis/drf/viewsets/template_scheme.py +++ b/gcloud/template_base/apis/drf/viewsets/template_scheme.py @@ -15,7 +15,7 @@ from collections import Counter from django.db import transaction -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django_filters.rest_framework import DjangoFilterBackend from drf_yasg.utils import swagger_auto_schema from pipeline.models import TemplateRelationship, TemplateScheme @@ -139,25 +139,33 @@ def validate_batch_delete_scheme(self, pipeline_template_template_id, template_i template_quote_scheme_ids_set = set(self.get_scheme_quote_count_dict(pipeline_template_template_id).keys()) if remove_scheme_ids_set & template_quote_scheme_ids_set: - message = _(f"执行方案删除失败: 待删除的[执行方案]已被引用[{template_quote_scheme_ids_set}], 请处理后重试 | batch_operate") + message = _( + f"执行方案删除失败: 待删除的[执行方案]已被引用[{template_quote_scheme_ids_set}], 请处理后重试 | batch_operate" + ) logger.error(message) return message app_maker_names = self.get_app_maker_names_scheme_quote(template_id, remove_scheme_ids_set) if app_maker_names: - message = _(f"执行方案删除失败: 待删除的[执行方案]已被这些轻应用所引用{app_maker_names}, 请处理后重试 | batch_operate") + message = _( + f"执行方案删除失败: 待删除的[执行方案]已被这些轻应用所引用{app_maker_names}, 请处理后重试 | batch_operate" + ) logger.error(message) return message periodic_names = self.get_periodic_task_names_scheme_quote(template_id, remove_scheme_ids_set) if periodic_names: - message = _(f"执行方案删除失败: 待删除的[执行方案]已被这些周期任务所引用{periodic_names}, 请处理后重试 | batch_operate") + message = _( + f"执行方案删除失败: 待删除的[执行方案]已被这些周期任务所引用{periodic_names}, 请处理后重试 | batch_operate" + ) logger.error(message) return message clocked_names = self.get_clocked_task_names_scheme_quote(template_id, remove_scheme_ids_set) if clocked_names: - message = _(f"执行方案删除失败: 待删除的[执行方案]已被这些计划任务所引用{clocked_names}, 请处理后重试 | batch_operate") + message = _( + f"执行方案删除失败: 待删除的[执行方案]已被这些计划任务所引用{clocked_names}, 请处理后重试 | batch_operate" + ) logger.error(message) return message diff --git a/gcloud/template_base/domains/importer.py b/gcloud/template_base/domains/importer.py index 54c03c8ab2..ff3db59242 100644 --- a/gcloud/template_base/domains/importer.py +++ b/gcloud/template_base/domains/importer.py @@ -10,14 +10,15 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific lan """ +import logging + from django.apps import apps from django.db import transaction +from django.utils.translation import gettext_lazy as _ -from .template_manager import TemplateManager -from ..utils import replace_biz_id_value from ...common_template.models import CommonTemplate -from django.utils.translation import ugettext_lazy as _ -import logging +from ..utils import replace_biz_id_value +from .template_manager import TemplateManager logger = logging.getLogger("root") diff --git a/gcloud/template_base/domains/schema_converter.py b/gcloud/template_base/domains/schema_converter.py index df359110e7..35d8553623 100644 --- a/gcloud/template_base/domains/schema_converter.py +++ b/gcloud/template_base/domains/schema_converter.py @@ -16,7 +16,7 @@ import jsonschema import yaml -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.data import library from pipeline.parser.utils import replace_all_id @@ -122,7 +122,9 @@ def validate_data(self, yaml_docs: list): template_id = yaml_doc["meta"].get("id") yaml_data[template_id] = yaml_doc except jsonschema.ValidationError as e: - message = _(f"Yaml数据格式校验失败: Yaml文件解析异常, 可能内容不合法. 请重试或联系管理员处理. {e} | validate_data") + message = _( + f"Yaml数据格式校验失败: Yaml文件解析异常, 可能内容不合法. 请重试或联系管理员处理. {e} | validate_data" + ) logger.error(message) return {"result": False, "data": yaml_data, "message": message} # 检查流程间是否有环引用的情况 @@ -387,7 +389,8 @@ def _reconvert_tree(self, template: dict, cur_templates: dict): if "constants" in template: for constant_key, constant_attrs in template["constants"].items(): reconverted_constant, is_create = self._reconvert_constant( - constant={**constant_attrs, "key": constant_key}, cur_constants=reconverted_tree["constants"], + constant={**constant_attrs, "key": constant_key}, + cur_constants=reconverted_tree["constants"], ) if is_create: reconverted_tree["constants"][constant_key] = reconverted_constant @@ -606,9 +609,11 @@ def _convert_node(self, node: dict, param_constants: dict): sorted_node = dict( sorted( converted_node.items(), - key=lambda pair: self.NODE_FIELD_ORDER.index(pair[0]) - if pair[0] in self.NODE_FIELD_ORDER - else len(self.NODE_FIELD_ORDER), + key=lambda pair: ( + self.NODE_FIELD_ORDER.index(pair[0]) + if pair[0] in self.NODE_FIELD_ORDER + else len(self.NODE_FIELD_ORDER) + ), ) ) return sorted_node diff --git a/gcloud/template_base/domains/template_manager.py b/gcloud/template_base/domains/template_manager.py index 7d9f6f6417..30853c40b1 100644 --- a/gcloud/template_base/domains/template_manager.py +++ b/gcloud/template_base/domains/template_manager.py @@ -10,20 +10,19 @@ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific lan """ +import logging import traceback +from django.utils.translation import gettext_lazy as _ from pipeline.exceptions import PipelineException +from pipeline.models import PipelineTemplate, TemplateRelationship from gcloud.constants import TEMPLATE_NODE_NAME_MAX_LENGTH from gcloud.template_base.utils import replace_template_id from gcloud.utils.strings import standardize_name, standardize_pipeline_node_name - -from pipeline.models import PipelineTemplate, TemplateRelationship from pipeline_web.core.models import NodeInTemplate -from pipeline_web.parser.validator import validate_web_pipeline_tree from pipeline_web.parser.clean import PipelineWebTreeCleaner -from django.utils.translation import ugettext_lazy as _ -import logging +from pipeline_web.parser.validator import validate_web_pipeline_tree logger = logging.getLogger("root") @@ -32,7 +31,13 @@ class TemplateManager: def __init__(self, template_model_cls): self.template_model_cls = template_model_cls - def create_pipeline(self, name: str, creator: str, pipeline_tree: dict, description: str = "",) -> dict: + def create_pipeline( + self, + name: str, + creator: str, + pipeline_tree: dict, + description: str = "", + ) -> dict: """ 创建 pipeline 层模板 @@ -59,7 +64,9 @@ def create_pipeline(self, name: str, creator: str, pipeline_tree: dict, descript "result": False, "data": None, "message": message, - "verbose_message": _(f"保存流程失败: 流程树合法性校验失败, 请检查流程. 失败原因: {traceback.format_exc()} | create_pipeline"), + "verbose_message": _( + f"保存流程失败: 流程树合法性校验失败, 请检查流程. 失败原因: {traceback.format_exc()} | create_pipeline" + ), } create_template_kwargs = { @@ -71,7 +78,9 @@ def create_pipeline(self, name: str, creator: str, pipeline_tree: dict, descript try: pipeline_template = self.template_model_cls.objects.create_pipeline_template(**create_template_kwargs) except Exception as e: - message = _(f"保存流程失败: 创建Pipeline流程失败, 请检查流程. 创建参数[{create_template_kwargs}], 失败原因: [{e}] | create_pipeline") + message = _( + f"保存流程失败: 创建Pipeline流程失败, 请检查流程. 创建参数[{create_template_kwargs}], 失败原因: [{e}] | create_pipeline" + ) logger.error(message) return { "result": False, @@ -86,7 +95,12 @@ def create_pipeline(self, name: str, creator: str, pipeline_tree: dict, descript return {"result": True, "data": pipeline_template, "message": "success", "verbose_message": "success"} def create( - self, name: str, creator: str, pipeline_tree: dict, template_kwargs: dict, description: str = "", + self, + name: str, + creator: str, + pipeline_tree: dict, + template_kwargs: dict, + description: str = "", ) -> dict: """ 创建 template 层模板 @@ -114,7 +128,9 @@ def create( try: template = self.template_model_cls.objects.create(**template_kwargs) except Exception as e: - message = _(f"保存流程失败: 创建模板失败, 请检查流程. 创建参数[{template_kwargs}], 失败原因: [{e}] | create") + message = _( + f"保存流程失败: 创建模板失败, 请检查流程. 创建参数[{template_kwargs}], 失败原因: [{e}] | create" + ) logger.error(message) return { "result": False, @@ -183,7 +199,9 @@ def update_pipeline( try: pipeline_template.update_template(**update_kwargs) except Exception as e: - message = _(f"更新流程失败: 更新Pipeline失败, 请检查流程. 更新参数: [{update_kwargs}], 失败原因: [{e}] | update_pipeline") + message = _( + f"更新流程失败: 更新Pipeline失败, 请检查流程. 更新参数: [{update_kwargs}], 失败原因: [{e}] | update_pipeline" + ) logger.error(message) return { "result": False, @@ -204,7 +222,12 @@ def update_pipeline( return {"result": True, "data": pipeline_template, "message": "success", "verbose_message": "success"} def update( - self, template: object, editor: str, name: str = "", pipeline_tree: str = None, description: str = "", + self, + template: object, + editor: str, + name: str = "", + pipeline_tree: str = None, + description: str = "", ) -> dict: """ 更新 template 层模板 diff --git a/gcloud/template_base/models.py b/gcloud/template_base/models.py index 85c775fc5a..4037df797b 100644 --- a/gcloud/template_base/models.py +++ b/gcloud/template_base/models.py @@ -16,7 +16,7 @@ from django.apps import apps from django.contrib.auth import get_user_model from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.exceptions import SubprocessExpiredError from pipeline.models import PipelineTemplate, TemplateCurrentVersion, TemplateRelationship diff --git a/gcloud/template_base/utils.py b/gcloud/template_base/utils.py index be54301b62..adc4fe1a5f 100644 --- a/gcloud/template_base/utils.py +++ b/gcloud/template_base/utils.py @@ -19,7 +19,7 @@ import ujson as json from django.apps import apps -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.constants import PE from gcloud import err_code diff --git a/gcloud/tests/external_plugins/models/test_sync_task.py b/gcloud/tests/external_plugins/models/test_sync_task.py index 9bf684c8ad..541bdc1790 100644 --- a/gcloud/tests/external_plugins/models/test_sync_task.py +++ b/gcloud/tests/external_plugins/models/test_sync_task.py @@ -12,32 +12,28 @@ """ from django.test import TestCase +from django.utils.translation import gettext_lazy as _ -from django.utils.translation import ugettext_lazy as _ - +from gcloud.external_plugins.models import FAILED, SyncTask from gcloud.tests.external_plugins.mock import * # noqa from gcloud.tests.external_plugins.mock_settings import * # noqa -from gcloud.external_plugins.models import SyncTask, FAILED class TestSyncTaskModel(TestCase): def setUp(self): with patch(GCLOUD_EXTERNAL_PLUGINS_SYNC_TASK_DELAY, MagicMock()): - self.sync_task = SyncTask.objects.create( - creator='user1', - create_method='manual' - ) + self.sync_task = SyncTask.objects.create(creator="user1", create_method="manual") def tearDown(self): SyncTask.objects.all().delete() def test_creator_name(self): - self.assertEqual(self.sync_task.creator_name, 'user1') + self.assertEqual(self.sync_task.creator_name, "user1") def test_status_display(self): self.assertEqual(self.sync_task.status_display, _("执行中")) def test_finish_task(self): - self.sync_task.finish_task(status=FAILED, details='error') + self.sync_task.finish_task(status=FAILED, details="error") self.assertEqual(self.sync_task.status, FAILED) - self.assertEqual(self.sync_task.details, 'error') + self.assertEqual(self.sync_task.details, "error") diff --git a/gcloud/user_custom_config/constants.py b/gcloud/user_custom_config/constants.py index a6f2a6a58d..a1fe29fb85 100644 --- a/gcloud/user_custom_config/constants.py +++ b/gcloud/user_custom_config/constants.py @@ -10,8 +10,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. """ -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ TASKTMPL_ORDERBY_OPTIONS = [ {"name": _("模板ID"), "value": "id"}, diff --git a/gcloud/user_custom_config/models.py b/gcloud/user_custom_config/models.py index 0bea3d1bfe..68399cb8b5 100644 --- a/gcloud/user_custom_config/models.py +++ b/gcloud/user_custom_config/models.py @@ -13,7 +13,7 @@ from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class UserConfManager(models.Manager): diff --git a/gcloud/utils/cmdb.py b/gcloud/utils/cmdb.py index 4d54bb2194..d135ad9e43 100644 --- a/gcloud/utils/cmdb.py +++ b/gcloud/utils/cmdb.py @@ -13,7 +13,7 @@ import logging -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from api.utils.request import batch_request from gcloud.conf import settings @@ -297,7 +297,9 @@ def get_notify_receivers(client, biz_cc_id, supplier_account, receiver_group, mo biz_count = cc_result["data"]["count"] if biz_count != 1: logger.error(handle_api_error("CMDB", "cc.search_business", kwargs, cc_result)) - message = _(f"业务人员信息查询失败: 从[配置平台]中查询业务[ID: {biz_cc_id}] 人员信息失败, 请检查业务存在以及拥有访问权限 | get_notify_receivers") + message = _( + f"业务人员信息查询失败: 从[配置平台]中查询业务[ID: {biz_cc_id}] 人员信息失败, 请检查业务存在以及拥有访问权限 | get_notify_receivers" + ) logger.error(message) result = { "result": False, diff --git a/gcloud/utils/components.py b/gcloud/utils/components.py index caf9bff928..4ae634169d 100644 --- a/gcloud/utils/components.py +++ b/gcloud/utils/components.py @@ -11,16 +11,14 @@ specific language governing permissions and limitations under the License. """ -from cachetools import cached, TTLCache +from cachetools import TTLCache, cached from cachetools.keys import hashkey - -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.models import ComponentModel -from plugin_service.plugin_client import PluginServiceApiClient -from plugin_service import env from gcloud.analysis_statistics.models import TemplateNodeStatistics +from plugin_service import env +from plugin_service.plugin_client import PluginServiceApiClient @cached(cache=TTLCache(maxsize=1024, ttl=60), key=hashkey) diff --git a/gcloud/utils/forms.py b/gcloud/utils/forms.py index c914224d99..e338f3c31c 100644 --- a/gcloud/utils/forms.py +++ b/gcloud/utils/forms.py @@ -14,12 +14,12 @@ import ujson as json from django import forms from django.core.exceptions import ValidationError -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class JsonField(forms.CharField): default_error_messages = { - 'invalid': _('invalid json string'), + "invalid": _("invalid json string"), } def validate(self, value): @@ -28,16 +28,14 @@ def validate(self, value): try: json.loads(value) except Exception: - raise ValidationError( - self.error_messages['invalid'], - code='invalid') + raise ValidationError(self.error_messages["invalid"], code="invalid") else: return value class JsonListField(JsonField): default_error_messages = { - 'invalid': _('json.loads result is not instance of list or tuple '), + "invalid": _("json.loads result is not instance of list or tuple "), } def validate(self, value): @@ -46,16 +44,14 @@ def validate(self, value): data = json.loads(value) if not isinstance(data, (list, tuple)): - raise ValidationError( - self.error_messages['invalid'], - code='invalid') + raise ValidationError(self.error_messages["invalid"], code="invalid") return value class JsonDictField(JsonField): default_error_messages = { - 'invalid': _('json.loads result is not list'), + "invalid": _("json.loads result is not list"), } def validate(self, value): @@ -64,8 +60,6 @@ def validate(self, value): data = json.loads(value) if not isinstance(data, dict): - raise ValidationError( - self.error_messages['invalid'], - code='invalid') + raise ValidationError(self.error_messages["invalid"], code="invalid") return value diff --git a/gcloud/utils/handlers.py b/gcloud/utils/handlers.py index a5804760ea..87bd9c628a 100644 --- a/gcloud/utils/handlers.py +++ b/gcloud/utils/handlers.py @@ -16,8 +16,7 @@ import ujson as json from django.conf import settings -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ from iam.contrib.http import HTTP_AUTH_FORBIDDEN_CODE from gcloud.iam_auth import get_iam_client diff --git a/gcloud/utils/validate.py b/gcloud/utils/validate.py index 768468deca..52e43d7fd6 100644 --- a/gcloud/utils/validate.py +++ b/gcloud/utils/validate.py @@ -11,11 +11,11 @@ specific language governing permissions and limitations under the License. """ +import logging from abc import ABCMeta, abstractmethod import ujson as json -from django.utils.translation import ugettext_lazy as _ -import logging +from django.utils.translation import gettext_lazy as _ logger = logging.getLogger("root") diff --git a/pipeline_plugins/base/query/cmdb.py b/pipeline_plugins/base/query/cmdb.py index 884f74dedc..078dc423db 100644 --- a/pipeline_plugins/base/query/cmdb.py +++ b/pipeline_plugins/base/query/cmdb.py @@ -15,10 +15,9 @@ import ujson as json from django.http import JsonResponse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from gcloud.conf import settings - from pipeline_plugins.base.utils.adapter import cc_format_module_hosts from pipeline_plugins.base.utils.inject import supplier_account_inject diff --git a/pipeline_plugins/cmdb_ip_picker/query.py b/pipeline_plugins/cmdb_ip_picker/query.py index a09275b650..1d01980092 100644 --- a/pipeline_plugins/cmdb_ip_picker/query.py +++ b/pipeline_plugins/cmdb_ip_picker/query.py @@ -15,7 +15,7 @@ import ujson as json from django.http import JsonResponse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from iam.contrib.http import HTTP_AUTH_FORBIDDEN_CODE from iam.exceptions import RawAuthFailedException diff --git a/pipeline_plugins/cmdb_ip_picker/utils.py b/pipeline_plugins/cmdb_ip_picker/utils.py index 33bbd463e7..efc9092586 100644 --- a/pipeline_plugins/cmdb_ip_picker/utils.py +++ b/pipeline_plugins/cmdb_ip_picker/utils.py @@ -14,7 +14,7 @@ import re import requests -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from api.utils.request import batch_request from gcloud.conf import settings @@ -85,7 +85,9 @@ def generate_ip_data(self): else: result = cc_get_ips_info_by_str(self.username, self.request_kwargs["bk_biz_id"], self.raw_data) if result["invalid_ip"]: - message = _(f"IP [{result['invalid_ip']}] 在本业务下不存在: 请检查配置, 修复后重新执行任务 | generate_ip_data") + message = _( + f"IP [{result['invalid_ip']}] 在本业务下不存在: 请检查配置, 修复后重新执行任务 | generate_ip_data" + ) logger.error(message) return {"result": False, "data": [], "message": message} ips = [ @@ -734,7 +736,9 @@ def send_request(agent_ids): resp = requests.post(url=get_agent_status_url, json=params) if resp.status_code != 200: - raise Exception("[get_gse_agent_status_ipv6] 查询agent状态错误,返回值非200, content = {}".format(resp.content)) + raise Exception( + "[get_gse_agent_status_ipv6] 查询agent状态错误,返回值非200, content = {}".format(resp.content) + ) try: resp_data = resp.json() except Exception as e: diff --git a/pipeline_plugins/components/collections/common.py b/pipeline_plugins/components/collections/common.py index bfaf65750c..b28ab1130c 100644 --- a/pipeline_plugins/components/collections/common.py +++ b/pipeline_plugins/components/collections/common.py @@ -17,11 +17,10 @@ import requests from django.conf import settings from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service, StaticIntervalGenerator -from pipeline.core.flow.io import StringItemSchema, IntItemSchema, ObjectItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service, StaticIntervalGenerator +from pipeline.core.flow.io import IntItemSchema, ObjectItemSchema, StringItemSchema __group_name__ = _("蓝鲸服务(BK)") logger = logging.getLogger(__name__) @@ -63,7 +62,10 @@ def outputs_format(self): schema=ObjectItemSchema(description=_("HTTP 请求响应内容,内部结构不固定"), property_schemas={}), ), self.OutputItem( - name=_("状态码"), key="status_code", type="int", schema=IntItemSchema(description=_("HTTP 请求响应状态码")) + name=_("状态码"), + key="status_code", + type="int", + schema=IntItemSchema(description=_("HTTP 请求响应状态码")), ), ] @@ -124,7 +126,10 @@ def __getstate__(self): class HttpComponent(Component): name = _("HTTP 请求") - desc = _("提示: 1.请求URL需要在当前网络下可以访问,否则会超时失败 " "2.响应状态码在200-300(不包括300)之间,并且响应内容是 JSON 格式才会执行成功") + desc = _( + "提示: 1.请求URL需要在当前网络下可以访问,否则会超时失败 " + "2.响应状态码在200-300(不包括300)之间,并且响应内容是 JSON 格式才会执行成功" + ) code = "bk_http_request" bound_service = HttpRequestService form = settings.STATIC_URL + "components/atoms/bk/http/legacy.js" diff --git a/pipeline_plugins/components/collections/controller.py b/pipeline_plugins/components/collections/controller.py index f602a08d99..2a7b903ca2 100644 --- a/pipeline_plugins/components/collections/controller.py +++ b/pipeline_plugins/components/collections/controller.py @@ -19,7 +19,7 @@ import pytz from django.conf import settings from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service, StaticIntervalGenerator from pipeline.core.flow.io import ObjectItemSchema, StringItemSchema diff --git a/pipeline_plugins/components/collections/gse_kit/flush_process/v1_0.py b/pipeline_plugins/components/collections/gse_kit/flush_process/v1_0.py index 13ccb333a0..194091bb6f 100644 --- a/pipeline_plugins/components/collections/gse_kit/flush_process/v1_0.py +++ b/pipeline_plugins/components/collections/gse_kit/flush_process/v1_0.py @@ -13,7 +13,7 @@ import logging -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service diff --git a/pipeline_plugins/components/collections/gse_kit/job_exec/v1_0.py b/pipeline_plugins/components/collections/gse_kit/job_exec/v1_0.py index 785a91ee4d..50f04edf7e 100644 --- a/pipeline_plugins/components/collections/gse_kit/job_exec/v1_0.py +++ b/pipeline_plugins/components/collections/gse_kit/job_exec/v1_0.py @@ -14,7 +14,7 @@ import logging from functools import partial -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service, StaticIntervalGenerator from pipeline.core.flow.io import StringItemSchema @@ -86,7 +86,10 @@ def schedule(self, data, parent_data, callback_data=None): def inputs_format(self): return [ self.InputItem( - name=_("环境类型"), key="gsekit_bk_env", type="string", schema=StringItemSchema(description=_("当前业务的环境类型")), + name=_("环境类型"), + key="gsekit_bk_env", + type="string", + schema=StringItemSchema(description=_("当前业务的环境类型")), ), self.InputItem( name=_("操作对象"), @@ -101,31 +104,50 @@ def inputs_format(self): schema=StringItemSchema(description=_("操作类型")), ), self.InputItem( - name=_("集群ID"), key="gsekit_set", type="string", schema=StringItemSchema(description=_("集群ID")), + name=_("集群ID"), + key="gsekit_set", + type="string", + schema=StringItemSchema(description=_("集群ID")), ), self.InputItem( - name=_("模块ID"), key="gsekit_module", type="string", schema=StringItemSchema(description=_("模块ID"),), + name=_("模块ID"), + key="gsekit_module", + type="string", + schema=StringItemSchema( + description=_("模块ID"), + ), ), self.InputItem( name=_("服务实例"), key="gsekit_service_id", type="string", - schema=StringItemSchema(description=_("服务实例ID"),), + schema=StringItemSchema( + description=_("服务实例ID"), + ), ), self.InputItem( - name=_("进程"), key="gsekit_process_name", type="string", schema=StringItemSchema(description=_("进程ID"),), + name=_("进程"), + key="gsekit_process_name", + type="string", + schema=StringItemSchema( + description=_("进程ID"), + ), ), self.InputItem( name=_("进程实例"), key="gsekit_process_id", type="string", - schema=StringItemSchema(description=_("进程实例ID"),), + schema=StringItemSchema( + description=_("进程实例ID"), + ), ), self.InputItem( name=_("配置文件模版"), key="gsekit_config_template", type="list", - schema=StringItemSchema(description=_("配置文件模版名"),), + schema=StringItemSchema( + description=_("配置文件模版名"), + ), ), ] diff --git a/pipeline_plugins/components/collections/http/v1_0.py b/pipeline_plugins/components/collections/http/v1_0.py index 1c6f908403..6b5880189c 100644 --- a/pipeline_plugins/components/collections/http/v1_0.py +++ b/pipeline_plugins/components/collections/http/v1_0.py @@ -12,19 +12,19 @@ """ from __future__ import absolute_import + import logging import traceback from copy import deepcopy -from requests import request from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ +from pipeline.component_framework.component import Component from pipeline.conf import settings -from pipeline.utils.boolrule import BoolRule from pipeline.core.flow.activity import Service, StaticIntervalGenerator -from pipeline.core.flow.io import StringItemSchema, IntItemSchema, ObjectItemSchema, ArrayItemSchema -from pipeline.component_framework.component import Component +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema +from pipeline.utils.boolrule import BoolRule +from requests import request __group_name__ = _("蓝鲸服务(BK)") logger = logging.getLogger(__name__) @@ -81,7 +81,10 @@ def inputs_format(self): key="bk_http_success_exp", type="string", schema=StringItemSchema( - description=_("根据返回的 JSON 的数据来控制节点的成功或失败, " "使用 resp 引用返回的 JSON 对象,例 resp.result==True") + description=_( + "根据返回的 JSON 的数据来控制节点的成功或失败, " + "使用 resp 引用返回的 JSON 对象,例 resp.result==True" + ) ), ), ] @@ -95,7 +98,10 @@ def outputs_format(self): schema=ObjectItemSchema(description=_("HTTP 请求响应内容,内部结构不固定"), property_schemas={}), ), self.OutputItem( - name=_("状态码"), key="status_code", type="int", schema=IntItemSchema(description=_("HTTP 请求响应状态码")) + name=_("状态码"), + key="status_code", + type="int", + schema=IntItemSchema(description=_("HTTP 请求响应状态码")), ), ] @@ -177,7 +183,10 @@ def __getstate__(self): class HttpComponent(Component): name = _("HTTP 请求") - desc = _("提示: 1.请求URL需要在当前网络下可以访问,否则会超时失败 " "2.响应状态码在200-300(不包括300)之间,并且响应内容是 JSON 格式才会执行成功") + desc = _( + "提示: 1.请求URL需要在当前网络下可以访问,否则会超时失败 " + "2.响应状态码在200-300(不包括300)之间,并且响应内容是 JSON 格式才会执行成功" + ) code = "bk_http_request" bound_service = HttpRequestService version = "v1.0" diff --git a/pipeline_plugins/components/collections/remote_plugin/v1_0_0.py b/pipeline_plugins/components/collections/remote_plugin/v1_0_0.py index af59b7abe3..73f7b1215e 100644 --- a/pipeline_plugins/components/collections/remote_plugin/v1_0_0.py +++ b/pipeline_plugins/components/collections/remote_plugin/v1_0_0.py @@ -16,7 +16,7 @@ from dateutil import tz from django.conf import settings -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow import AbstractIntervalGenerator, Service from pipeline.core.flow.io import StringItemSchema @@ -105,7 +105,9 @@ def execute(self, data, parent_data): ok, result_data = plugin_client.invoke(plugin_version, {"inputs": data.inputs, "context": plugin_context}) if not ok: - message = _(f"调用第三方插件invoke接口错误, 错误内容: {result_data['message']}, trace_id: {result_data.get('trace_id')}") + message = _( + f"调用第三方插件invoke接口错误, 错误内容: {result_data['message']}, trace_id: {result_data.get('trace_id')}" + ) logger.error(message) data.set_outputs("ex_data", message) return False diff --git a/pipeline_plugins/components/collections/sites/open/bk/__init__.py b/pipeline_plugins/components/collections/sites/open/bk/__init__.py index 8cd499bd73..133a398a4a 100644 --- a/pipeline_plugins/components/collections/sites/open/bk/__init__.py +++ b/pipeline_plugins/components/collections/sites/open/bk/__init__.py @@ -11,7 +11,7 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ __group_name__ = _("蓝鲸服务(BK)") diff --git a/pipeline_plugins/components/collections/sites/open/bk/approve/v1_0.py b/pipeline_plugins/components/collections/sites/open/bk/approve/v1_0.py index 6ae7039640..bf5b933b15 100644 --- a/pipeline_plugins/components/collections/sites/open/bk/approve/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/bk/approve/v1_0.py @@ -14,7 +14,7 @@ import logging import traceback -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service from pipeline.core.flow.io import StringItemSchema @@ -42,18 +42,29 @@ def inputs_format(self): schema=StringItemSchema(description=_("审核人,多个用英文逗号`,`分隔")), ), self.InputItem( - name=_("审核标题"), key="bk_approve_title", type="string", schema=StringItemSchema(description=_("审核标题")) + name=_("审核标题"), + key="bk_approve_title", + type="string", + schema=StringItemSchema(description=_("审核标题")), ), self.InputItem( - name=_("审核内容"), key="bk_approve_message", type="string", schema=StringItemSchema(description=_("通知的标题")) + name=_("审核内容"), + key="bk_approve_message", + type="string", + schema=StringItemSchema(description=_("通知的标题")), ), ] def outputs_format(self): return [ - self.OutputItem(name=_("单据sn"), key="sn", type="string", schema=StringItemSchema(description=_("单据sn"))), self.OutputItem( - name=_("审核结果"), key="approve_result", type="string", schema=StringItemSchema(description=_("审核结果")) + name=_("单据sn"), key="sn", type="string", schema=StringItemSchema(description=_("单据sn")) + ), + self.OutputItem( + name=_("审核结果"), + key="approve_result", + type="string", + schema=StringItemSchema(description=_("审核结果")), ), ] diff --git a/pipeline_plugins/components/collections/sites/open/bk/display/v1_0.py b/pipeline_plugins/components/collections/sites/open/bk/display/v1_0.py index 9c25845192..252049d872 100644 --- a/pipeline_plugins/components/collections/sites/open/bk/display/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/bk/display/v1_0.py @@ -12,11 +12,10 @@ """ -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ +from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service from pipeline.core.flow.io import StringItemSchema -from pipeline.component_framework.component import Component from gcloud.conf import settings @@ -27,7 +26,10 @@ class DisplayService(Service): def inputs_format(self): return [ self.InputItem( - name=_("展示内容"), key="bk_display_message", type="string", schema=StringItemSchema(description=_("展示内容")) + name=_("展示内容"), + key="bk_display_message", + type="string", + schema=StringItemSchema(description=_("展示内容")), ), ] diff --git a/pipeline_plugins/components/collections/sites/open/bk/notify/legacy.py b/pipeline_plugins/components/collections/sites/open/bk/notify/legacy.py index eb2ec1deba..770169c555 100644 --- a/pipeline_plugins/components/collections/sites/open/bk/notify/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/bk/notify/legacy.py @@ -14,16 +14,14 @@ import logging from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, StringItemSchema from gcloud.conf import settings -from gcloud.utils.cmdb import get_notify_receivers from gcloud.core.roles import CC_V2_ROLE_MAP - +from gcloud.utils.cmdb import get_notify_receivers from pipeline_plugins.base.utils.inject import supplier_account_for_business __group_name__ = _("蓝鲸服务(BK)") @@ -35,140 +33,144 @@ class NotifyService(Service): def inputs_format(self): return [ - self.InputItem(name=_('业务 ID'), - key='biz_cc_id', - type='string', - schema=StringItemSchema(description=_('通知人员所属的 CMDB 业务 ID'))), - self.InputItem(name=_('通知方式'), - key='bk_notify_type', - type='array', - schema=ArrayItemSchema(description=_('需要使用的通知方式'), - enum=['weixin', 'email', 'sms'], - item_schema=StringItemSchema(description=_('通知方式')))), - self.InputItem(name=_('通知分组'), - key='bk_receiver_group', - type='array', - required=False, - schema=ArrayItemSchema(description=_('需要进行通知的业务人员分组'), - enum=['Maintainers', 'ProductPm', 'Developer', 'Tester'], - item_schema=StringItemSchema(description=_('通知分组')))), - self.InputItem(name=_('额外通知人'), - key='bk_more_receiver', - type='string', - schema=StringItemSchema(description=_('除了通知分组外需要额外通知的人员'))), - self.InputItem(name=_('通知标题'), - key='bk_notify_title', - type='string', - schema=StringItemSchema(description=_('通知的标题'))), - self.InputItem(name=_('通知内容'), - key='bk_notify_content', - type='string', - schema=StringItemSchema(description=_('通知的内容')))] + self.InputItem( + name=_("业务 ID"), + key="biz_cc_id", + type="string", + schema=StringItemSchema(description=_("通知人员所属的 CMDB 业务 ID")), + ), + self.InputItem( + name=_("通知方式"), + key="bk_notify_type", + type="array", + schema=ArrayItemSchema( + description=_("需要使用的通知方式"), + enum=["weixin", "email", "sms"], + item_schema=StringItemSchema(description=_("通知方式")), + ), + ), + self.InputItem( + name=_("通知分组"), + key="bk_receiver_group", + type="array", + required=False, + schema=ArrayItemSchema( + description=_("需要进行通知的业务人员分组"), + enum=["Maintainers", "ProductPm", "Developer", "Tester"], + item_schema=StringItemSchema(description=_("通知分组")), + ), + ), + self.InputItem( + name=_("额外通知人"), + key="bk_more_receiver", + type="string", + schema=StringItemSchema(description=_("除了通知分组外需要额外通知的人员")), + ), + self.InputItem( + name=_("通知标题"), + key="bk_notify_title", + type="string", + schema=StringItemSchema(description=_("通知的标题")), + ), + self.InputItem( + name=_("通知内容"), + key="bk_notify_content", + type="string", + schema=StringItemSchema(description=_("通知的内容")), + ), + ] def outputs_format(self): return [ - self.OutputItem(name=_('返回码'), - key='code', - type='string', - schema=StringItemSchema(description=_('通知接口的返回码'))), - self.OutputItem(name=_('信息'), - key='message', - type='string', - schema=StringItemSchema(description=_('通知接口返回的信息')))] + self.OutputItem( + name=_("返回码"), key="code", type="string", schema=StringItemSchema(description=_("通知接口的返回码")) + ), + self.OutputItem( + name=_("信息"), + key="message", + type="string", + schema=StringItemSchema(description=_("通知接口返回的信息")), + ), + ] def execute(self, data, parent_data): - executor = parent_data.get_one_of_inputs('executor') + executor = parent_data.get_one_of_inputs("executor") client = get_client_by_user(executor) - if parent_data.get_one_of_inputs('language'): - translation.activate(parent_data.get_one_of_inputs('language')) + if parent_data.get_one_of_inputs("language"): + translation.activate(parent_data.get_one_of_inputs("language")) - biz_cc_id = data.get_one_of_inputs('biz_cc_id', parent_data.inputs.biz_cc_id) + biz_cc_id = data.get_one_of_inputs("biz_cc_id", parent_data.inputs.biz_cc_id) supplier_account = supplier_account_for_business(biz_cc_id) - notify_type = data.get_one_of_inputs('bk_notify_type') - receiver_info = data.get_one_of_inputs('bk_receiver_info') + notify_type = data.get_one_of_inputs("bk_notify_type") + receiver_info = data.get_one_of_inputs("bk_receiver_info") # 兼容原有数据格式 if receiver_info: - receiver_groups = receiver_info.get('bk_receiver_group') - more_receiver = receiver_info.get('bk_more_receiver') + receiver_groups = receiver_info.get("bk_receiver_group") + more_receiver = receiver_info.get("bk_more_receiver") # 转换为cc3.0字段 receiver_group = [CC_V2_ROLE_MAP[group] for group in receiver_groups] else: - receiver_group = data.get_one_of_inputs('bk_receiver_group') - more_receiver = data.get_one_of_inputs('bk_more_receiver') - title = data.get_one_of_inputs('bk_notify_title') - content = data.get_one_of_inputs('bk_notify_content') - - code = '' - message = '' - res = get_notify_receivers(client, - biz_cc_id, - supplier_account, - receiver_group, - more_receiver) + receiver_group = data.get_one_of_inputs("bk_receiver_group") + more_receiver = data.get_one_of_inputs("bk_more_receiver") + title = data.get_one_of_inputs("bk_notify_title") + content = data.get_one_of_inputs("bk_notify_content") + + code = "" + message = "" + res = get_notify_receivers(client, biz_cc_id, supplier_account, receiver_group, more_receiver) result, msg, receivers = res["result"], res["message"], res["data"] if not result: - data.set_outputs('ex_data', msg) + data.set_outputs("ex_data", msg) return False for t in notify_type: kwargs = self._args_gen[t](self, receivers, title, content) result = getattr(client.cmsi, self._send_func[t])(kwargs) - if not result['result']: - data.set_outputs('ex_data', result['message']) + if not result["result"]: + data.set_outputs("ex_data", result["message"]) return False - code = result['code'] - message = result['message'] + code = result["code"] + message = result["message"] - data.set_outputs('code', code) - data.set_outputs('message', message) + data.set_outputs("code", code) + data.set_outputs("message", message) return True def _email_args(self, receivers, title, content): return { - 'receiver__username': receivers, - 'title': title, + "receiver__username": receivers, + "title": title, # 保留通知内容中的换行和空格 - 'content': "
%s
" % content + "content": "
%s
" % content, } def _weixin_args(self, receivers, title, content): - return { - 'receiver__username': receivers, - 'data': { - 'heading': title, - 'message': content - } - } + return {"receiver__username": receivers, "data": {"heading": title, "message": content}} def _sms_args(self, receivers, title, content): - return { - 'receiver__username': receivers, - 'content': "%s\n%s" % (title, content) - } + return {"receiver__username": receivers, "content": "%s\n%s" % (title, content)} _send_func = { - 'weixin': 'send_weixin', - 'email': 'send_mail', - 'sms': 'send_sms', + "weixin": "send_weixin", + "email": "send_mail", + "sms": "send_sms", } - _args_gen = { - 'weixin': _weixin_args, - 'email': _email_args, - 'sms': _sms_args - } + _args_gen = {"weixin": _weixin_args, "email": _email_args, "sms": _sms_args} class NotifyComponent(Component): - name = _('发送通知') - code = 'bk_notify' + name = _("发送通知") + code = "bk_notify" bound_service = NotifyService - form = '%scomponents/atoms/bk/notify/legacy.js' % settings.STATIC_URL - desc = _("API 网关定义了这些消息通知组件的接口协议,但是,并没有完全实现组件内容,用户可根据接口协议,重写此部分组件。" - "API网关为降低实现消息通知组件的难度,提供了在线更新组件配置,不需编写组件代码的方案。详情请查阅PaaS->API网" - "关->使用指南。") + form = "%scomponents/atoms/bk/notify/legacy.js" % settings.STATIC_URL + desc = _( + "API 网关定义了这些消息通知组件的接口协议,但是,并没有完全实现组件内容,用户可根据接口协议,重写此部分组件。" + "API网关为降低实现消息通知组件的难度,提供了在线更新组件配置,不需编写组件代码的方案。详情请查阅PaaS->API网" + "关->使用指南。" + ) diff --git a/pipeline_plugins/components/collections/sites/open/bk/notify/v1_0.py b/pipeline_plugins/components/collections/sites/open/bk/notify/v1_0.py index 08dbf63c86..60d8a3111e 100644 --- a/pipeline_plugins/components/collections/sites/open/bk/notify/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/bk/notify/v1_0.py @@ -15,18 +15,16 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, BooleanItemSchema, IntItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, BooleanItemSchema, IntItemSchema, StringItemSchema from gcloud.conf import settings from gcloud.core.models import StaffGroupSet -from gcloud.utils.handlers import handle_api_error -from gcloud.utils.cmdb import get_notify_receivers from gcloud.core.roles import CC_V2_ROLE_MAP - +from gcloud.utils.cmdb import get_notify_receivers +from gcloud.utils.handlers import handle_api_error from pipeline_plugins.base.utils.inject import supplier_account_for_business __group_name__ = _("蓝鲸服务(BK)") @@ -49,7 +47,8 @@ def inputs_format(self): key="bk_notify_type", type="array", schema=ArrayItemSchema( - description=_("需要使用的通知方式,从 API 网关自动获取已实现的通知渠道"), item_schema=StringItemSchema(description=_("通知方式")) + description=_("需要使用的通知方式,从 API 网关自动获取已实现的通知渠道"), + item_schema=StringItemSchema(description=_("通知方式")), ), ), self.InputItem( @@ -69,7 +68,8 @@ def inputs_format(self): type="array", required=False, schema=ArrayItemSchema( - description=_("需要进行通知的项目人员分组ID列表"), item_schema=IntItemSchema(description=_("项目人员分组ID")) + description=_("需要进行通知的项目人员分组ID列表"), + item_schema=IntItemSchema(description=_("项目人员分组ID")), ), ), self.InputItem( @@ -79,13 +79,22 @@ def inputs_format(self): schema=StringItemSchema(description=_("除了通知分组外需要额外通知的人员,多个用英文逗号 `,` 分隔")), ), self.InputItem( - name=_("通知标题"), key="bk_notify_title", type="string", schema=StringItemSchema(description=_("通知的标题")) + name=_("通知标题"), + key="bk_notify_title", + type="string", + schema=StringItemSchema(description=_("通知的标题")), ), self.InputItem( - name=_("通知内容"), key="bk_notify_content", type="string", schema=StringItemSchema(description=_("通知的内容")) + name=_("通知内容"), + key="bk_notify_content", + type="string", + schema=StringItemSchema(description=_("通知的内容")), ), self.InputItem( - name=_("通知执行人"), key="notify", type="boolean", schema=BooleanItemSchema(description=_("通知执行人名字")) + name=_("通知执行人"), + key="notify", + type="boolean", + schema=BooleanItemSchema(description=_("通知执行人名字")), ), ] diff --git a/pipeline_plugins/components/collections/sites/open/cc/__init__.py b/pipeline_plugins/components/collections/sites/open/cc/__init__.py index 3f11b7b939..c439a9881f 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/__init__.py +++ b/pipeline_plugins/components/collections/sites/open/cc/__init__.py @@ -11,13 +11,15 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ __group_name__ = _("配置平台(CMDB)") from .batch_delete_set import * # noqa from .create_set import * # noqa from .empty_set_hosts import * # noqa +from .host_lock.add_host_lock import * # noqa +from .host_lock.delete_host_lock import * # noqa from .replace_fault_machine import * # noqa from .transfer_fault_host import * # noqa from .transfer_host_module import * # noqa @@ -27,5 +29,3 @@ from .update_module import * # noqa from .update_set import * # noqa from .update_set_service_status import * # noqa -from .host_lock.add_host_lock import * # noqa -from .host_lock.delete_host_lock import * # noqa diff --git a/pipeline_plugins/components/collections/sites/open/cc/base.py b/pipeline_plugins/components/collections/sites/open/cc/base.py index 16152c8edf..9498f42fe4 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/base.py +++ b/pipeline_plugins/components/collections/sites/open/cc/base.py @@ -18,7 +18,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.activity import Service from pipeline.core.flow.io import StringItemSchema @@ -121,7 +121,9 @@ def cc_get_host_id_by_innerip(executor, bk_biz_id, ip_list, supplier_account): # find repeat innerip host host_counter = Counter([host["bk_host_innerip"] for host in host_list]) mutiple_innerip_hosts = [innerip for innerip, count in host_counter.items() if count > 1] - message = _(f"IP [{', '.join(mutiple_innerip_hosts)}] 在本业务下重复: 请检查配置, 修复后重新执行 | cc_get_host_id_by_innerip") + message = _( + f"IP [{', '.join(mutiple_innerip_hosts)}] 在本业务下重复: 请检查配置, 修复后重新执行 | cc_get_host_id_by_innerip" + ) logger.error(message) return { "result": False, @@ -131,7 +133,9 @@ def cc_get_host_id_by_innerip(executor, bk_biz_id, ip_list, supplier_account): if len(host_list) < len(ip_list): return_innerip_set = {host["bk_host_innerip"] for host in host_list} absent_innerip = set(ip_list).difference(return_innerip_set) - message = _(f"IP [{', '.join(absent_innerip)}] 在本业务下不存在: 请检查配置, 修复后重新执行 | cc_get_host_id_by_innerip") + message = _( + f"IP [{', '.join(absent_innerip)}] 在本业务下不存在: 请检查配置, 修复后重新执行 | cc_get_host_id_by_innerip" + ) logger.error(message) return {"result": False, "message": message} @@ -199,9 +203,7 @@ def cc_get_host_id_by_innerip_and_cloudid(executor, bk_biz_id, ip_str, supplier_ else: return_innerip_set.add(host["bk_host_innerip"]) absent_innerip = set(ipv4s).difference(return_innerip_set) - message = ( - f"IP [{', '.join(absent_innerip)}] 在本业务下不存在: 请检查配置, 修复后重新执行 | cc_get_host_id_by_innerip_and_cloudid" - ) + message = f"IP[{', '.join(absent_innerip)}]在本业务下不存在: 请检查配置, 修复后重新执行|cc_get_host_id_by_innerip_and_cloudid" logger.error(message) return {"result": False, "message": message} hosts.extend(host_list) @@ -448,7 +450,9 @@ def cc_list_match_node_inst_id(executor, biz_cc_id, supplier_account, path_list) inst_id_list.append(match_node["bk_inst_id"]) topo_node_list = match_node["child"] else: - message = _(f"拓扑路径 [{'>'.join(path)}] 在本业务下不存在: 请检查配置, 修复后重新执行 | cc_list_match_node_inst_id") + message = _( + f"拓扑路径 [{'>'.join(path)}] 在本业务下不存在: 请检查配置, 修复后重新执行 | cc_list_match_node_inst_id" + ) logger.error(message) return {"result": False, "message": message} return {"result": True, "data": inst_id_list} @@ -478,7 +482,9 @@ def cc_list_select_node_inst_id( # 对输入的文本路径进行业务层级校验 if bk_obj_type.name not in BkObjType.__members__: - message = _(f"拓扑路径 [{bk_obj_type}] 在本业务下不存在: 请检查配置, 修复后重新执行任务 | cc_list_select_node_inst_id") + message = _( + f"拓扑路径 [{bk_obj_type}] 在本业务下不存在: 请检查配置, 修复后重新执行任务 | cc_list_select_node_inst_id" + ) logger.error(message) return {"result": False, "message": message} diff --git a/pipeline_plugins/components/collections/sites/open/cc/batch_delete_set/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/batch_delete_set/legacy.py index 99cdd60194..395ad4372c 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/batch_delete_set/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/batch_delete_set/legacy.py @@ -15,19 +15,17 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component - -from pipeline_plugins.base.utils.inject import supplier_account_for_business -from pipeline_plugins.components.collections.sites.open.cc.base import cc_format_tree_mode_id +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business +from pipeline_plugins.components.collections.sites.open.cc.base import cc_format_tree_mode_id -logger = logging.getLogger('celery') +logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER __group_name__ = _("配置平台(CMDB)") @@ -38,51 +36,55 @@ class CCBatchDeleteSetService(Service): def inputs_format(self): - return [self.InputItem(name=_('业务 ID'), - key='biz_cc_id', - type='string', - schema=StringItemSchema(description=_('当前操作所属的 CMDB 业务 ID'))), - self.InputItem(name=_('集群列表'), - key='cc_set_select', - type='array', - schema=ArrayItemSchema(description=_('需要清空的集群 ID 列表'), - item_schema=IntItemSchema(description=_('集群 ID')))) - ] + return [ + self.InputItem( + name=_("业务 ID"), + key="biz_cc_id", + type="string", + schema=StringItemSchema(description=_("当前操作所属的 CMDB 业务 ID")), + ), + self.InputItem( + name=_("集群列表"), + key="cc_set_select", + type="array", + schema=ArrayItemSchema( + description=_("需要清空的集群 ID 列表"), item_schema=IntItemSchema(description=_("集群 ID")) + ), + ), + ] def outputs_format(self): return [] def execute(self, data, parent_data): - executor = parent_data.get_one_of_inputs('executor') + executor = parent_data.get_one_of_inputs("executor") client = get_client_by_user(executor) - if parent_data.get_one_of_inputs('language'): - setattr(client, 'language', parent_data.get_one_of_inputs('language')) - translation.activate(parent_data.get_one_of_inputs('language')) + if parent_data.get_one_of_inputs("language"): + setattr(client, "language", parent_data.get_one_of_inputs("language")) + translation.activate(parent_data.get_one_of_inputs("language")) - biz_cc_id = data.get_one_of_inputs('biz_cc_id', parent_data.inputs.biz_cc_id) + biz_cc_id = data.get_one_of_inputs("biz_cc_id", parent_data.inputs.biz_cc_id) supplier_account = supplier_account_for_business(biz_cc_id) - cc_set_select = cc_format_tree_mode_id(data.get_one_of_inputs('cc_set_select')) + cc_set_select = cc_format_tree_mode_id(data.get_one_of_inputs("cc_set_select")) cc_kwargs = { "bk_biz_id": biz_cc_id, "bk_supplier_account": supplier_account, - "delete": { - "inst_ids": cc_set_select - } + "delete": {"inst_ids": cc_set_select}, } cc_result = client.cc.batch_delete_set(cc_kwargs) - if not cc_result['result']: - message = cc_handle_api_error('cc.batch_delete_set', cc_kwargs, cc_result) + if not cc_result["result"]: + message = cc_handle_api_error("cc.batch_delete_set", cc_kwargs, cc_result) self.logger.error(message) - data.set_outputs('ex_data', message) + data.set_outputs("ex_data", message) return False return True class CCBatchDeleteSetComponent(Component): name = _("删除集群") - code = 'cc_batch_delete_set' + code = "cc_batch_delete_set" bound_service = CCBatchDeleteSetService - form = '%scomponents/atoms/cc/cc_batch_delete_set.js' % settings.STATIC_URL + form = "%scomponents/atoms/cc/cc_batch_delete_set.js" % settings.STATIC_URL diff --git a/pipeline_plugins/components/collections/sites/open/cc/batch_delete_set/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/batch_delete_set/v1_0.py index 5f98275dda..90704d0c52 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/batch_delete_set/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/batch_delete_set/v1_0.py @@ -14,22 +14,20 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema +from gcloud.conf import settings +from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.cc.base import ( BkObjType, SelectMethod, cc_format_tree_mode_id, - cc_list_select_node_inst_id + cc_list_select_node_inst_id, ) -from pipeline_plugins.base.utils.inject import supplier_account_for_business - -from gcloud.conf import settings -from gcloud.utils.handlers import handle_api_error logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -53,7 +51,9 @@ def inputs_format(self): name=_("填参方式"), key="cc_set_select_method", type="string", - schema=StringItemSchema(description=_("集群填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"]), + schema=StringItemSchema( + description=_("集群填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"] + ), ), self.InputItem( name=_("拓扑-集群列表"), @@ -67,7 +67,11 @@ def inputs_format(self): name=_("文本路径-集群"), key="cc_set_select_text", type="string", - schema=StringItemSchema(description=_("集群文本路径,请输入完整路径,从业务拓扑开始,如`业务A>集群B`,多个目标集群用换行分隔")), + schema=StringItemSchema( + description=_( + "集群文本路径,请输入完整路径,从业务拓扑开始,如`业务A>集群B`,多个目标集群用换行分隔" + ) + ), ), ] @@ -122,6 +126,7 @@ class CCBatchDeleteSetComponent(Component): name = _("删除集群") code = "cc_batch_delete_set" bound_service = CCBatchDeleteSetService - form = '{static_url}components/atoms/cc/batch_delete_set/{ver}.js'.format(static_url=settings.STATIC_URL, - ver=VERSION.replace('.', '_')) + form = "{static_url}components/atoms/cc/batch_delete_set/{ver}.js".format( + static_url=settings.STATIC_URL, ver=VERSION.replace(".", "_") + ) version = VERSION diff --git a/pipeline_plugins/components/collections/sites/open/cc/batch_module_update/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/batch_module_update/v1_0.py index 77a7832ce7..727875dec6 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/batch_module_update/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/batch_module_update/v1_0.py @@ -12,20 +12,21 @@ """ from functools import partial -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ + from gcloud.conf import settings __group_name__ = _("配置平台(CMDB)") -from gcloud.utils.handlers import handle_api_error - from pipeline.component_framework.component import Component -from pipeline.core.flow.io import ArrayItemSchema, ObjectItemSchema, StringItemSchema from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, ObjectItemSchema, StringItemSchema + +from gcloud.utils.handlers import handle_api_error from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.cc.base import ( - cc_list_select_node_inst_id, BkObjType, + cc_list_select_node_inst_id, get_module_set_id, ) from pipeline_plugins.components.utils import chunk_table_data, convert_num_to_str @@ -41,7 +42,10 @@ class CCBatchModuleUpdateService(Service): def inputs_format(self): return [ self.InputItem( - name=_("填参方式"), key="cc_tag_method", type="string", schema=StringItemSchema(description=_("填参方式")), + name=_("填参方式"), + key="cc_tag_method", + type="string", + schema=StringItemSchema(description=_("填参方式")), ), self.InputItem( name=_("拓扑模块属性修改"), @@ -172,7 +176,9 @@ def execute(self, data, parent_data): self.logger.info("module 属性更新成功, item={}, data={}".format(update_item, kwargs)) success_update.append(update_item) else: - message = _(f"模块属性更新失败: 主机属性: {update_item}, 更新属性: {kwargs}, 错误消息: {update_result['message']}") + message = _( + f"模块属性更新失败: 主机属性: {update_item}, 更新属性: {kwargs}, 错误消息: {update_result['message']}" + ) self.logger.error(message) failed_update.append(message) diff --git a/pipeline_plugins/components/collections/sites/open/cc/batch_transfer_host_module/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/batch_transfer_host_module/v1_0.py index d0d4d984ce..59a34f44c9 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/batch_transfer_host_module/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/batch_transfer_host_module/v1_0.py @@ -13,22 +13,20 @@ import logging from functools import partial -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ +from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, BooleanItemSchema, ObjectItemSchema, StringItemSchema from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error - -from pipeline_plugins.components.utils import chunk_table_data, convert_num_to_str -from pipeline.component_framework.component import Component -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, ObjectItemSchema, BooleanItemSchema from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.cc.base import ( BkObjType, - cc_list_select_node_inst_id, CCPluginIPMixin, + cc_list_select_node_inst_id, ) - +from pipeline_plugins.components.utils import chunk_table_data, convert_num_to_str logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -64,7 +62,10 @@ def inputs_format(self): schema=StringItemSchema(description=_("在自动填参时使用的扩展分割符")), ), self.InputItem( - name=_("更新方式"), key="is_append", type="boolean", schema=BooleanItemSchema(description=_("更新方式")), + name=_("更新方式"), + key="is_append", + type="boolean", + schema=BooleanItemSchema(description=_("更新方式")), ), ] @@ -115,7 +116,9 @@ def execute(self, data, parent_data): # 获取主机id列表 host_result = self.get_host_list(executor, biz_cc_id, attr["cc_transfer_host_ip"], supplier_account) if not host_result["result"]: - message = _(f"主机转移模块失败: [配置平台]里未找到待转移的主机, 请检查配置. 主机属性:{attr}, 错误信息: {host_result['message']}") + message = _( + f"主机转移模块失败: [配置平台]里未找到待转移的主机, 请检查配置. 主机属性:{attr}, 错误信息: {host_result['message']}" + ) self.logger.info(message) failed_update.append(message) continue @@ -151,7 +154,9 @@ def execute(self, data, parent_data): self.logger.info("主机所属业务模块更新成功, data={}".format(cc_kwargs)) success_update.append(attr) else: - message = _(f"主机所属业务模块更新失败: 主机属性={attr}, kwargs: {cc_kwargs}, 错误信息: {update_result['message']}") + message = _( + f"主机所属业务模块更新失败: 主机属性={attr}, kwargs: {cc_kwargs}, 错误信息: {update_result['message']}" + ) self.logger.info(message) failed_update.append(message) diff --git a/pipeline_plugins/components/collections/sites/open/cc/batch_transfer_host_module/v1_1.py b/pipeline_plugins/components/collections/sites/open/cc/batch_transfer_host_module/v1_1.py index 1353c2d429..a06393fe90 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/batch_transfer_host_module/v1_1.py +++ b/pipeline_plugins/components/collections/sites/open/cc/batch_transfer_host_module/v1_1.py @@ -13,22 +13,21 @@ import logging from functools import partial -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ +from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, BooleanItemSchema, ObjectItemSchema from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error from gcloud.utils.ip import get_ip_by_regex - -from pipeline_plugins.components.utils import convert_num_to_str -from pipeline.component_framework.component import Component -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import ArrayItemSchema, ObjectItemSchema, BooleanItemSchema from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.cc.base import ( BkObjType, cc_get_host_id_by_innerip, cc_list_select_node_inst_id, ) +from pipeline_plugins.components.utils import convert_num_to_str logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -111,7 +110,9 @@ def execute(self, data, parent_data): # 获取主机id列表 host_result = cc_get_host_id_by_innerip(executor, biz_cc_id, cc_host_ip_list, supplier_account) if not host_result["result"]: - message = _(f"主机转移模块失败: [配置平台]里未找到待转移的主机, 请检查配置. 主机属性:{attr}, 错误信息: {host_result['message']}") + message = _( + f"主机转移模块失败: [配置平台]里未找到待转移的主机, 请检查配置. 主机属性:{attr}, 错误信息: {host_result['message']}" + ) self.logger.info(message) failed_update.append(message) continue @@ -122,7 +123,9 @@ def execute(self, data, parent_data): ) if not result: - message = _(f"主机转移模块失败: [配置平台]未找到目标模块, 请检查配置. 主机属性: {attr}, 错误信息: {message}") + message = _( + f"主机转移模块失败: [配置平台]未找到目标模块, 请检查配置. 主机属性: {attr}, 错误信息: {message}" + ) self.logger.info(message) failed_update.append(message) continue diff --git a/pipeline_plugins/components/collections/sites/open/cc/batch_update_host/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/batch_update_host/v1_0.py index fb4537019a..754525fcd0 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/batch_update_host/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/batch_update_host/v1_0.py @@ -14,7 +14,7 @@ from copy import deepcopy from functools import partial -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service from pipeline.core.flow.io import ArrayItemSchema, ObjectItemSchema, StringItemSchema @@ -82,7 +82,8 @@ def inputs_format(self): key="cc_host_property_custom", type="array", schema=ArrayItemSchema( - item_schema=ObjectItemSchema(description=_("主机属性修改"), property_schemas={}), description="主机属性列表" + item_schema=ObjectItemSchema(description=_("主机属性修改"), property_schemas={}), + description="主机属性列表", ), ), self.InputItem( @@ -110,7 +111,9 @@ def execute(self, data, parent_data): for column in host_property_custom: column_result = chunk_table_data(column, separator) if not column_result["result"]: - message = _(f"单行扩展失败: 请检查输入参数格式是否合法, 修复后重试. 错误内容: {column_result['message']}") + message = _( + f"单行扩展失败: 请检查输入参数格式是否合法, 修复后重试. 错误内容: {column_result['message']}" + ) data.outputs.ex_data = message self.logger.error(message) return False @@ -157,7 +160,10 @@ def execute(self, data, parent_data): def outputs_format(self): return [ self.OutputItem( - name=_("不合法的IP"), key="invalid_ip", type="string", schema=StringItemSchema(description=_("不合法的IP")) + name=_("不合法的IP"), + key="invalid_ip", + type="string", + schema=StringItemSchema(description=_("不合法的IP")), ), ] diff --git a/pipeline_plugins/components/collections/sites/open/cc/batch_update_set/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/batch_update_set/v1_0.py index e9873b49dd..b712a86830 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/batch_update_set/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/batch_update_set/v1_0.py @@ -13,11 +13,10 @@ import logging from functools import partial -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, ObjectItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, ObjectItemSchema, StringItemSchema from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error @@ -37,7 +36,10 @@ class CCBatchUpdateSetService(Service): def inputs_format(self): return [ self.InputItem( - name=_("填参方式"), key="cc_set_select_method", type="str", schema=StringItemSchema(description=_("填参方式")), + name=_("填参方式"), + key="cc_set_select_method", + type="str", + schema=StringItemSchema(description=_("填参方式")), ), self.InputItem( name=_("拓扑模块属性修改"), diff --git a/pipeline_plugins/components/collections/sites/open/cc/create_module/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/create_module/legacy.py index bbb7eb01d5..a49b37a92f 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/create_module/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/create_module/legacy.py @@ -10,30 +10,28 @@ 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 logging import copy +import logging from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema, ObjectItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema +from gcloud.conf import settings +from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.cc.base import ( BkObjType, - SelectMethod, ModuleCreateMethod, - cc_format_tree_mode_id, - cc_list_select_node_inst_id, + SelectMethod, cc_format_prop_data, + cc_format_tree_mode_id, cc_get_name_id_from_combine_value, + cc_list_select_node_inst_id, ) -from pipeline_plugins.base.utils.inject import supplier_account_for_business - -from gcloud.conf import settings -from gcloud.utils.handlers import handle_api_error logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -56,26 +54,35 @@ def inputs_format(self): name=_("填参方式"), key="cc_set_select_method", type="string", - schema=StringItemSchema(description=_("集群填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"]), + schema=StringItemSchema( + description=_("集群填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"] + ), ), self.InputItem( name=_("拓扑-集群列表"), key="cc_set_select_topo", type="array", - schema=ArrayItemSchema(description=_("所属集群 ID 列表"), item_schema=IntItemSchema(description=_("集群 ID"))), + schema=ArrayItemSchema( + description=_("所属集群 ID 列表"), item_schema=IntItemSchema(description=_("集群 ID")) + ), ), self.InputItem( name=_("文本路径-集群"), key="cc_set_select_text", type="string", - schema=StringItemSchema(description=_("集群文本路径,请输入完整路径,从业务拓扑开始,如`业务A>集群B`,多个目标集群用换行分隔")), + schema=StringItemSchema( + description=_( + "集群文本路径,请输入完整路径,从业务拓扑开始,如`业务A>集群B`,多个目标集群用换行分隔" + ) + ), ), self.InputItem( name=_("创建方式"), key="cc_create_method", type="string", schema=StringItemSchema( - description=_("按模板创建(template),直接创建-按服务分类创建(category)"), enum=["template", "category"] + description=_("按模板创建(template),直接创建-按服务分类创建(category)"), + enum=["template", "category"], ), ), self.InputItem( diff --git a/pipeline_plugins/components/collections/sites/open/cc/create_set/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/create_set/legacy.py index 6f4ff8ae67..ff607ef25a 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/create_set/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/create_set/legacy.py @@ -16,17 +16,15 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema, ObjectItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component - -from pipeline_plugins.base.utils.inject import supplier_account_for_business -from pipeline_plugins.components.collections.sites.open.cc.base import cc_format_tree_mode_id, cc_format_prop_data +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business +from pipeline_plugins.components.collections.sites.open.cc.base import cc_format_prop_data, cc_format_tree_mode_id logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -49,7 +47,9 @@ def inputs_format(self): name=_("父实例"), key="cc_set_parent_select", type="array", - schema=ArrayItemSchema(description=_("父实例 ID 列表"), item_schema=IntItemSchema(description=_("实例 ID"))), + schema=ArrayItemSchema( + description=_("父实例 ID 列表"), item_schema=IntItemSchema(description=_("实例 ID")) + ), ), self.InputItem( name=_("集群信息"), diff --git a/pipeline_plugins/components/collections/sites/open/cc/create_set/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/create_set/v1_0.py index fa33a12425..f712552764 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/create_set/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/create_set/v1_0.py @@ -13,21 +13,19 @@ import logging import traceback -from functools import partial from copy import deepcopy +from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema, ObjectItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component - -from pipeline_plugins.components.collections.sites.open.cc.base import cc_format_tree_mode_id, cc_format_prop_data -from pipeline_plugins.base.utils.inject import supplier_account_for_business +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business +from pipeline_plugins.components.collections.sites.open.cc.base import cc_format_prop_data, cc_format_tree_mode_id logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -91,7 +89,9 @@ def inputs_format(self): name=_("父实例"), key="cc_set_parent_select", type="array", - schema=ArrayItemSchema(description=_("父实例 ID 列表"), item_schema=IntItemSchema(description=_("实例 ID"))), + schema=ArrayItemSchema( + description=_("父实例 ID 列表"), item_schema=IntItemSchema(description=_("实例 ID")) + ), ), self.InputItem( name=_("集群信息"), diff --git a/pipeline_plugins/components/collections/sites/open/cc/create_set/v2_0.py b/pipeline_plugins/components/collections/sites/open/cc/create_set/v2_0.py index e0400a93a1..e7c684c39b 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/create_set/v2_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/create_set/v2_0.py @@ -13,27 +13,25 @@ import logging import traceback -from functools import partial from copy import deepcopy +from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema, ObjectItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema +from gcloud.conf import settings +from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.cc.base import ( BkObjType, SelectMethod, - cc_format_tree_mode_id, cc_format_prop_data, + cc_format_tree_mode_id, cc_list_select_node_inst_id, ) -from pipeline_plugins.base.utils.inject import supplier_account_for_business - -from gcloud.conf import settings -from gcloud.utils.handlers import handle_api_error logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -97,19 +95,27 @@ def inputs_format(self): name=_("填参方式"), key="cc_select_set_parent_method", type="string", - schema=StringItemSchema(description=_("父实例填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"]), + schema=StringItemSchema( + description=_("父实例填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"] + ), ), self.InputItem( name=_("拓扑-父实例"), key="cc_set_parent_select_topo", type="array", - schema=ArrayItemSchema(description=_("父实例 ID 列表"), item_schema=IntItemSchema(description=_("实例 ID"))), + schema=ArrayItemSchema( + description=_("父实例 ID 列表"), item_schema=IntItemSchema(description=_("实例 ID")) + ), ), self.InputItem( name=_("文本路径-父实例"), key="cc_set_parent_select_text", type="string", - schema=StringItemSchema(description=_("父实例文本路径,请输入完整路径,从业务拓扑开始,如`业务A>网络B`,多个父实例用换行分隔")), + schema=StringItemSchema( + description=_( + "父实例文本路径,请输入完整路径,从业务拓扑开始,如`业务A>网络B`,多个父实例用换行分隔" + ) + ), ), self.InputItem( name=_("集群信息"), diff --git a/pipeline_plugins/components/collections/sites/open/cc/create_set_by_template/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/create_set_by_template/v1_0.py index b760926b0f..e1d4b19118 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/create_set_by_template/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/create_set_by_template/v1_0.py @@ -13,22 +13,21 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema + +from gcloud.conf import settings +from gcloud.utils.handlers import handle_api_error from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.cc.base import ( - cc_format_tree_mode_id, - cc_list_select_node_inst_id, BkObjType, SelectMethod, + cc_format_tree_mode_id, + cc_list_select_node_inst_id, ) -from gcloud.conf import settings -from gcloud.utils.handlers import handle_api_error - get_client_by_user = settings.ESB_GET_CLIENT_BY_USER __group_name__ = _("配置平台(CMDB)") @@ -49,25 +48,39 @@ def inputs_format(self): name=_("填参方式"), key="cc_select_set_parent_method", type="string", - schema=StringItemSchema(description=_("父实例填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"]), + schema=StringItemSchema( + description=_("父实例填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"] + ), ), self.InputItem( name=_("拓扑-父实例"), key="cc_set_parent_select_topo", type="array", - schema=ArrayItemSchema(description=_("父实例 ID 列表"), item_schema=IntItemSchema(description=_("实例 ID"))), + schema=ArrayItemSchema( + description=_("父实例 ID 列表"), item_schema=IntItemSchema(description=_("实例 ID")) + ), ), self.InputItem( name=_("文本路径-父实例"), key="cc_set_parent_select_text", type="string", - schema=StringItemSchema(description=_("父实例文本路径,请输入完整路径,从业务拓扑开始,如`业务A>网络B`,多个父实例用换行分隔")), + schema=StringItemSchema( + description=_( + "父实例文本路径,请输入完整路径,从业务拓扑开始,如`业务A>网络B`,多个父实例用换行分隔" + ) + ), ), self.InputItem( - name=_("集群名称"), key="cc_set_name", type="string", schema=StringItemSchema(description=_("集群名称")), + name=_("集群名称"), + key="cc_set_name", + type="string", + schema=StringItemSchema(description=_("集群名称")), ), self.InputItem( - name=_("集群模板"), key="cc_set_template", type="string", schema=StringItemSchema(description=_("集群模板")), + name=_("集群模板"), + key="cc_set_template", + type="string", + schema=StringItemSchema(description=_("集群模板")), ), ] diff --git a/pipeline_plugins/components/collections/sites/open/cc/empty_set_hosts/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/empty_set_hosts/legacy.py index 6bd3a3888a..e5ae78fb03 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/empty_set_hosts/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/empty_set_hosts/legacy.py @@ -15,19 +15,17 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component - -from pipeline_plugins.base.utils.inject import supplier_account_for_business -from pipeline_plugins.components.collections.sites.open.cc.base import cc_format_tree_mode_id +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business +from pipeline_plugins.components.collections.sites.open.cc.base import cc_format_tree_mode_id -logger = logging.getLogger('celery') +logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER __group_name__ = _("配置平台(CMDB)") @@ -39,32 +37,37 @@ class CCEmptySetHostsService(Service): def inputs_format(self): return [ - self.InputItem(name=_('业务 ID'), - key='biz_cc_id', - type='string', - schema=StringItemSchema(description=_('当前操作所属的 CMDB 业务 ID'))), - self.InputItem(name=_('集群列表'), - key='cc_set_select', - type='array', - schema=ArrayItemSchema(description=_('需要清空的集群 ID 列表'), - item_schema=IntItemSchema(description=_('集群 ID')))) + self.InputItem( + name=_("业务 ID"), + key="biz_cc_id", + type="string", + schema=StringItemSchema(description=_("当前操作所属的 CMDB 业务 ID")), + ), + self.InputItem( + name=_("集群列表"), + key="cc_set_select", + type="array", + schema=ArrayItemSchema( + description=_("需要清空的集群 ID 列表"), item_schema=IntItemSchema(description=_("集群 ID")) + ), + ), ] def outputs_format(self): return [] def execute(self, data, parent_data): - executor = parent_data.get_one_of_inputs('executor') + executor = parent_data.get_one_of_inputs("executor") client = get_client_by_user(executor) - if parent_data.get_one_of_inputs('language'): - setattr(client, 'language', parent_data.get_one_of_inputs('language')) - translation.activate(parent_data.get_one_of_inputs('language')) + if parent_data.get_one_of_inputs("language"): + setattr(client, "language", parent_data.get_one_of_inputs("language")) + translation.activate(parent_data.get_one_of_inputs("language")) - biz_cc_id = data.get_one_of_inputs('biz_cc_id', parent_data.inputs.biz_cc_id) + biz_cc_id = data.get_one_of_inputs("biz_cc_id", parent_data.inputs.biz_cc_id) supplier_account = supplier_account_for_business(biz_cc_id) - cc_set_select = cc_format_tree_mode_id(data.get_one_of_inputs('cc_set_select')) + cc_set_select = cc_format_tree_mode_id(data.get_one_of_inputs("cc_set_select")) for set_id in cc_set_select: cc_kwargs = { "bk_biz_id": biz_cc_id, @@ -72,16 +75,16 @@ def execute(self, data, parent_data): "bk_set_id": set_id, } cc_result = client.cc.transfer_sethost_to_idle_module(cc_kwargs) - if not cc_result['result']: - message = cc_handle_api_error('cc.transfer_sethost_to_idle_module', cc_kwargs, cc_result) + if not cc_result["result"]: + message = cc_handle_api_error("cc.transfer_sethost_to_idle_module", cc_kwargs, cc_result) self.logger.error(message) - data.set_outputs('ex_data', message) + data.set_outputs("ex_data", message) return False return True class CCEmptySetHostsComponent(Component): name = _("清空集群中主机") - code = 'cc_empty_set_hosts' + code = "cc_empty_set_hosts" bound_service = CCEmptySetHostsService - form = '%scomponents/atoms/cc/cc_empty_set_hosts.js' % settings.STATIC_URL + form = "%scomponents/atoms/cc/cc_empty_set_hosts.js" % settings.STATIC_URL diff --git a/pipeline_plugins/components/collections/sites/open/cc/empty_set_hosts/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/empty_set_hosts/v1_0.py index 9b6018a6e1..022c56a1fa 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/empty_set_hosts/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/empty_set_hosts/v1_0.py @@ -14,22 +14,20 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema +from gcloud.conf import settings +from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.cc.base import ( BkObjType, SelectMethod, cc_format_tree_mode_id, - cc_list_select_node_inst_id + cc_list_select_node_inst_id, ) -from pipeline_plugins.base.utils.inject import supplier_account_for_business - -from gcloud.conf import settings -from gcloud.utils.handlers import handle_api_error logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -53,7 +51,9 @@ def inputs_format(self): name=_("填参方式"), key="cc_set_select_method", type="string", - schema=StringItemSchema(description=_("集群填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"]), + schema=StringItemSchema( + description=_("集群填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"] + ), ), self.InputItem( name=_("拓扑-集群列表"), @@ -67,7 +67,11 @@ def inputs_format(self): name=_("文本路径-集群"), key="cc_set_select_text", type="string", - schema=StringItemSchema(description=_("集群文本路径,请输入完整路径,从业务拓扑开始,如`业务A>集群B`,多个目标集群用换行分隔")), + schema=StringItemSchema( + description=_( + "集群文本路径,请输入完整路径,从业务拓扑开始,如`业务A>集群B`,多个目标集群用换行分隔" + ) + ), ), ] @@ -123,6 +127,7 @@ class CCEmptySetHostsComponent(Component): name = _("清空集群中主机") code = "cc_empty_set_hosts" bound_service = CCEmptySetHostsService - form = '{static_url}components/atoms/cc/empty_set_hosts/{ver}.js'.format(static_url=settings.STATIC_URL, - ver=VERSION.replace('.', '_')) + form = "{static_url}components/atoms/cc/empty_set_hosts/{ver}.js".format( + static_url=settings.STATIC_URL, ver=VERSION.replace(".", "_") + ) version = VERSION diff --git a/pipeline_plugins/components/collections/sites/open/cc/host_custom_property_change/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/host_custom_property_change/v1_0.py index 445f9ae006..0236da615d 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/host_custom_property_change/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/host_custom_property_change/v1_0.py @@ -13,11 +13,10 @@ import logging from functools import partial -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, ObjectItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, ObjectItemSchema, StringItemSchema from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error @@ -113,10 +112,18 @@ def execute(self, data, parent_data): supplier_account = supplier_account_for_business(biz_cc_id) ip_list = self.get_ip_info_list(operator, biz_cc_id, sa_ip_list, supplier_account) if not ip_list["result"] or not ip_list["ip_count"]: - data.outputs.ex_data = _("无法从配置平台(CMDB)查询到对应 IP,请确认输入的 IP 是否合法, ip_list = {}".format(ip_list["invalid_ip"])) + data.outputs.ex_data = _( + "无法从配置平台(CMDB)查询到对应 IP,请确认输入的 IP 是否合法, ip_list = {}".format( + ip_list["invalid_ip"] + ) + ) return False if ip_list["invalid_ip"]: - data.outputs.ex_data = _("无法从配置平台(CMDB)查询到对应 IP,请确认输入的 IP 是否合法, ip_list = {}".format(ip_list["invalid_ip"])) + data.outputs.ex_data = _( + "无法从配置平台(CMDB)查询到对应 IP,请确认输入的 IP 是否合法, ip_list = {}".format( + ip_list["invalid_ip"] + ) + ) data.outputs.invalid_ip = ",".join(ip_list["invalid_ip"]) return False @@ -168,7 +175,9 @@ def execute(self, data, parent_data): module_kwargs = {"bk_biz_id": biz_cc_id, "bk_ids": list(set(module_id_list)), "fields": module_rule_list} module_result = client.cc.find_module_batch(module_kwargs) if not module_result.get("result"): - error_message = handle_api_error("蓝鲸配置平台(CC)", "cc.find_module_batch", module_kwargs, module_result) + error_message = handle_api_error( + "蓝鲸配置平台(CC)", "cc.find_module_batch", module_kwargs, module_result + ) data.set_outputs("ex_data", error_message) self.logger.error(error_message) return False @@ -239,7 +248,10 @@ def execute(self, data, parent_data): def outputs_format(self): return [ self.OutputItem( - name=_("不合法的IP"), key="invalid_ip", type="string", schema=StringItemSchema(description=_("不合法的IP")) + name=_("不合法的IP"), + key="invalid_ip", + type="string", + schema=StringItemSchema(description=_("不合法的IP")), ), ] diff --git a/pipeline_plugins/components/collections/sites/open/cc/host_lock/add_host_lock/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/host_lock/add_host_lock/v1_0.py index 92f4a9f15e..895061b203 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/host_lock/add_host_lock/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/host_lock/add_host_lock/v1_0.py @@ -10,11 +10,10 @@ 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 django.utils.translation import gettext_lazy as _ +from pipeline.component_framework.component import Component from gcloud.conf import settings - -from pipeline.component_framework.component import Component from pipeline_plugins.components.collections.sites.open.cc.host_lock.base import ( CCHostLockBaseService, HostLockTypeService, diff --git a/pipeline_plugins/components/collections/sites/open/cc/host_lock/base.py b/pipeline_plugins/components/collections/sites/open/cc/host_lock/base.py index b2d1b05ede..2aa403869b 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/host_lock/base.py +++ b/pipeline_plugins/components/collections/sites/open/cc/host_lock/base.py @@ -10,19 +10,19 @@ 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 abc import ABCMeta, abstractmethod import logging +from abc import ABCMeta, abstractmethod from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.activity import Service from pipeline.core.flow.io import StringItemSchema -from pipeline_plugins.base.utils.inject import supplier_account_for_business -from pipeline_plugins.components.collections.sites.open.cc.base import CCPluginIPMixin + from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business +from pipeline_plugins.components.collections.sites.open.cc.base import CCPluginIPMixin logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -64,7 +64,9 @@ def execute(self, data, parent_data): if not host_list_result["result"]: data.outputs.ex_data = _( - "无法从配置平台(CMDB)查询到对应 IP,请确认输入的 IP 是否合法, message={}".format(host_list_result.get("message", "")) + "无法从配置平台(CMDB)查询到对应 IP,请确认输入的 IP 是否合法, message={}".format( + host_list_result.get("message", "") + ) ) return False diff --git a/pipeline_plugins/components/collections/sites/open/cc/host_lock/delete_host_lock/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/host_lock/delete_host_lock/v1_0.py index 4801417ce7..7bcc7bb055 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/host_lock/delete_host_lock/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/host_lock/delete_host_lock/v1_0.py @@ -10,11 +10,10 @@ 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 django.utils.translation import gettext_lazy as _ +from pipeline.component_framework.component import Component from gcloud.conf import settings - -from pipeline.component_framework.component import Component from pipeline_plugins.components.collections.sites.open.cc.host_lock.base import ( CCHostLockBaseService, HostLockTypeService, diff --git a/pipeline_plugins/components/collections/sites/open/cc/replace_fault_machine/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/replace_fault_machine/legacy.py index 4bcc274343..d16bf2c398 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/replace_fault_machine/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/replace_fault_machine/legacy.py @@ -15,16 +15,14 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, ObjectItemSchema, BooleanItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component - -from pipeline_plugins.base.utils.inject import supplier_account_for_business +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, BooleanItemSchema, ObjectItemSchema, StringItemSchema from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.cc.base import CCPluginIPMixin logger = logging.getLogger("celery") @@ -113,11 +111,15 @@ def execute(self, data, parent_data): # 如果不存在,或者查询到的值大于1 if not fault_host_list or len(fault_host_list) != 1: # 查询旧的主机出错 - data.outputs.ex_data = data.outputs.ex_data = _("无法查询到 %s 机器信息,请确认该机器是否在当前业务下") % fault_ip + data.outputs.ex_data = data.outputs.ex_data = ( + _("无法查询到 %s 机器信息,请确认该机器是否在当前业务下") % fault_ip + ) return False if not new_host_list or len(new_host_list) != 1: - data.outputs.ex_data = data.outputs.ex_data = _("无法查询到 %s 机器信息,请确认该机器是否在当前业务下") % fault_ip + data.outputs.ex_data = data.outputs.ex_data = ( + _("无法查询到 %s 机器信息,请确认该机器是否在当前业务下") % fault_ip + ) return False fault_host = fault_host_list[0] diff --git a/pipeline_plugins/components/collections/sites/open/cc/transfer_fault_host/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/transfer_fault_host/legacy.py index ace281d6dd..a748c279f8 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/transfer_fault_host/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/transfer_fault_host/legacy.py @@ -13,7 +13,7 @@ import logging -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from gcloud.conf import settings diff --git a/pipeline_plugins/components/collections/sites/open/cc/transfer_host_module/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/transfer_host_module/legacy.py index f46dd2bd81..b59bac06a7 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/transfer_host_module/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/transfer_host_module/legacy.py @@ -15,7 +15,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema @@ -111,4 +111,7 @@ class CCTransferHostModuleComponent(Component): code = "cc_transfer_host_module" bound_service = CCTransferHostModuleService form = "%scomponents/atoms/cc/cc_transfer_host_module.js" % settings.STATIC_URL - desc = _("注意:如果需要移动主机到空闲机池,请使用插件如下插件:\n" "转移主机至待回收模块, 转移主机至故障机模块, 转移主机至空闲机模块") + desc = _( + "注意:如果需要移动主机到空闲机池,请使用插件如下插件:\n" + "转移主机至待回收模块, 转移主机至故障机模块, 转移主机至空闲机模块" + ) diff --git a/pipeline_plugins/components/collections/sites/open/cc/transfer_host_module/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/transfer_host_module/v1_0.py index 84f4a36243..7e610e3e12 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/transfer_host_module/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/transfer_host_module/v1_0.py @@ -14,7 +14,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema @@ -52,7 +52,9 @@ def inputs_format(self): name=_("填参方式"), key="cc_module_select_method", type="string", - schema=StringItemSchema(description=_("模块填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"]), + schema=StringItemSchema( + description=_("模块填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"] + ), ), self.InputItem( name=_("主机内网 IP"), @@ -72,7 +74,9 @@ def inputs_format(self): name=_("文本路径-模块"), key="cc_module_select_text", type="string", - schema=StringItemSchema(description=_("请输入完整路径,从业务拓扑开始,如`业务A>集群B>模块C`,多个目标模块用换行分隔")), + schema=StringItemSchema( + description=_("请输入完整路径,从业务拓扑开始,如`业务A>集群B>模块C`,多个目标模块用换行分隔") + ), ), self.InputItem( name=_("转移方式"), diff --git a/pipeline_plugins/components/collections/sites/open/cc/transfer_host_resource/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/transfer_host_resource/legacy.py index 9fcce13763..d12175a9b7 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/transfer_host_resource/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/transfer_host_resource/legacy.py @@ -13,7 +13,7 @@ import logging -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from gcloud.conf import settings diff --git a/pipeline_plugins/components/collections/sites/open/cc/transfer_to_idle/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/transfer_to_idle/legacy.py index 1fe49481f1..d007c62bfb 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/transfer_to_idle/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/transfer_to_idle/legacy.py @@ -13,7 +13,7 @@ import logging -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from gcloud.conf import settings diff --git a/pipeline_plugins/components/collections/sites/open/cc/transfer_to_recovery/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/transfer_to_recovery/v1_0.py index ae84d0fe53..30714fc862 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/transfer_to_recovery/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/transfer_to_recovery/v1_0.py @@ -13,8 +13,7 @@ import logging -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from gcloud.conf import settings diff --git a/pipeline_plugins/components/collections/sites/open/cc/update_host/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/update_host/legacy.py index ba85e8ba4c..33260ea980 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/update_host/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/update_host/legacy.py @@ -15,7 +15,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service from pipeline.core.flow.io import StringItemSchema @@ -49,7 +49,10 @@ def inputs_format(self): schema=StringItemSchema(description=_("待转移的主机内网 IP,多个用英文逗号 `,` 分隔")), ), self.InputItem( - name=_("主机属性"), key="cc_host_property", type="string", schema=StringItemSchema(description=_("待修改主机属性")) + name=_("主机属性"), + key="cc_host_property", + type="string", + schema=StringItemSchema(description=_("待修改主机属性")), ), self.InputItem( name=_("主机属性值"), diff --git a/pipeline_plugins/components/collections/sites/open/cc/update_module/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/update_module/legacy.py index 7c1224a954..79a69e711c 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/update_module/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/update_module/legacy.py @@ -15,22 +15,20 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema +from gcloud.conf import settings +from gcloud.utils.handlers import handle_api_error from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.cc.base import ( - cc_format_tree_mode_id, cc_format_prop_data, + cc_format_tree_mode_id, get_module_set_id, ) -from gcloud.conf import settings -from gcloud.utils.handlers import handle_api_error - logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -52,7 +50,9 @@ def inputs_format(self): name=_("模块"), key="cc_module_select", type="array", - schema=ArrayItemSchema(description=_("模块 ID 列表"), item_schema=IntItemSchema(description=_("模块 ID"))), + schema=ArrayItemSchema( + description=_("模块 ID 列表"), item_schema=IntItemSchema(description=_("模块 ID")) + ), ), self.InputItem( name=_("模块属性"), diff --git a/pipeline_plugins/components/collections/sites/open/cc/update_module/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/update_module/v1_0.py index 52afa1f303..ce550f94b4 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/update_module/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/update_module/v1_0.py @@ -14,24 +14,22 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema +from gcloud.conf import settings +from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.cc.base import ( BkObjType, SelectMethod, - cc_format_tree_mode_id, cc_format_prop_data, - get_module_set_id, + cc_format_tree_mode_id, cc_list_select_node_inst_id, + get_module_set_id, ) -from pipeline_plugins.base.utils.inject import supplier_account_for_business - -from gcloud.conf import settings -from gcloud.utils.handlers import handle_api_error logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -55,7 +53,9 @@ def inputs_format(self): name=_("填参方式"), key="cc_module_select_method", type="string", - schema=StringItemSchema(description=_("模块填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"]), + schema=StringItemSchema( + description=_("模块填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"] + ), ), self.InputItem( name=_("拓扑-模块"), @@ -69,7 +69,11 @@ def inputs_format(self): name=_("文本路径-模块"), key="cc_module_select_text", type="string", - schema=StringItemSchema(description=_("模块文本路径,请输入完整路径,从业务拓扑开始,如`业务A>集群B>模块C`,多个目标模块用换行分隔")), + schema=StringItemSchema( + description=_( + "模块文本路径,请输入完整路径,从业务拓扑开始,如`业务A>集群B>模块C`,多个目标模块用换行分隔" + ) + ), ), self.InputItem( name=_("模块属性"), diff --git a/pipeline_plugins/components/collections/sites/open/cc/update_set/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/update_set/legacy.py index 4bbbbe5fd7..ad66361c1b 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/update_set/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/update_set/legacy.py @@ -16,7 +16,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema @@ -47,7 +47,9 @@ def inputs_format(self): name=_("集群列表"), key="cc_set_select", type="array", - schema=ArrayItemSchema(description=_("集群 ID 列表"), item_schema=IntItemSchema(description=_("集群 ID"))), + schema=ArrayItemSchema( + description=_("集群 ID 列表"), item_schema=IntItemSchema(description=_("集群 ID")) + ), ), self.InputItem( name=_("集群属性"), diff --git a/pipeline_plugins/components/collections/sites/open/cc/update_set/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/update_set/v1_0.py index 053e91c338..6833f517b8 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/update_set/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/update_set/v1_0.py @@ -15,7 +15,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema @@ -53,7 +53,9 @@ def inputs_format(self): name=_("填参方式"), key="cc_set_select_method", type="string", - schema=StringItemSchema(description=_("模块填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"]), + schema=StringItemSchema( + description=_("模块填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"] + ), ), self.InputItem( name=_("拓扑-集群列表"), @@ -67,7 +69,11 @@ def inputs_format(self): name=_("文本路径-集群"), key="cc_set_select_text", type="string", - schema=StringItemSchema(description=_("集群文本路径,请输入完整路径,从业务拓扑开始,如`业务A>集群B`,多个目标集群用换行分隔")), + schema=StringItemSchema( + description=_( + "集群文本路径,请输入完整路径,从业务拓扑开始,如`业务A>集群B`,多个目标集群用换行分隔" + ) + ), ), self.InputItem( name=_("集群属性"), diff --git a/pipeline_plugins/components/collections/sites/open/cc/update_set_service_status/legacy.py b/pipeline_plugins/components/collections/sites/open/cc/update_set_service_status/legacy.py index 8a55beaab6..01754e1d8e 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/update_set_service_status/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/cc/update_set_service_status/legacy.py @@ -15,19 +15,17 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component - -from pipeline_plugins.base.utils.inject import supplier_account_for_business -from pipeline_plugins.components.collections.sites.open.cc.base import cc_format_tree_mode_id +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business +from pipeline_plugins.components.collections.sites.open.cc.base import cc_format_tree_mode_id -logger = logging.getLogger('celery') +logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER __group_name__ = _("配置平台(CMDB)") @@ -38,56 +36,62 @@ class CCUpdateSetServiceStatusService(Service): def inputs_format(self): - return [self.InputItem(name=_('业务 ID'), - key='biz_cc_id', - type='string', - schema=StringItemSchema(description=_('当前操作所属的 CMDB 业务 ID'))), - self.InputItem(name=_('集群列表'), - key='cc_set_select', - type='array', - schema=ArrayItemSchema(description=_('需要清空的集群 ID 列表'), - item_schema=IntItemSchema(description=_('集群 ID')))), - self.InputItem(name=_('服务状态'), - key='cc_set_status', - type='string', - schema=StringItemSchema(description=_('集群服务器状态,开放(1)或关闭(2)'), - enum=['1', '2']))] + return [ + self.InputItem( + name=_("业务 ID"), + key="biz_cc_id", + type="string", + schema=StringItemSchema(description=_("当前操作所属的 CMDB 业务 ID")), + ), + self.InputItem( + name=_("集群列表"), + key="cc_set_select", + type="array", + schema=ArrayItemSchema( + description=_("需要清空的集群 ID 列表"), item_schema=IntItemSchema(description=_("集群 ID")) + ), + ), + self.InputItem( + name=_("服务状态"), + key="cc_set_status", + type="string", + schema=StringItemSchema(description=_("集群服务器状态,开放(1)或关闭(2)"), enum=["1", "2"]), + ), + ] def outputs_format(self): return [] def execute(self, data, parent_data): - executor = parent_data.get_one_of_inputs('executor') + executor = parent_data.get_one_of_inputs("executor") client = get_client_by_user(executor) - if parent_data.get_one_of_inputs('language'): - setattr(client, 'language', parent_data.get_one_of_inputs('language')) - translation.activate(parent_data.get_one_of_inputs('language')) + if parent_data.get_one_of_inputs("language"): + setattr(client, "language", parent_data.get_one_of_inputs("language")) + translation.activate(parent_data.get_one_of_inputs("language")) - biz_cc_id = data.get_one_of_inputs('biz_cc_id', parent_data.inputs.biz_cc_id) + biz_cc_id = data.get_one_of_inputs("biz_cc_id", parent_data.inputs.biz_cc_id) supplier_account = supplier_account_for_business(biz_cc_id) - cc_set_select = cc_format_tree_mode_id(data.get_one_of_inputs('cc_set_select')) + cc_set_select = cc_format_tree_mode_id(data.get_one_of_inputs("cc_set_select")) for set_id in cc_set_select: cc_kwargs = { "bk_biz_id": biz_cc_id, "bk_supplier_account": supplier_account, "bk_set_id": set_id, - "data": { - "bk_service_status": data.get_one_of_inputs('cc_set_status') - } + "data": {"bk_service_status": data.get_one_of_inputs("cc_set_status")}, } cc_result = client.cc.update_set(cc_kwargs) - if not cc_result['result']: - message = cc_handle_api_error('cc.update_set', cc_kwargs, cc_result) + if not cc_result["result"]: + message = cc_handle_api_error("cc.update_set", cc_kwargs, cc_result) self.logger.error(message) - data.set_outputs('ex_data', message) + data.set_outputs("ex_data", message) return False return True class CCUpdateSetServiceStatusComponent(Component): name = _("修改集群服务状态") - code = 'cc_update_set_service_status' + code = "cc_update_set_service_status" bound_service = CCUpdateSetServiceStatusService - form = '%scomponents/atoms/cc/cc_update_set_service_status.js' % settings.STATIC_URL + form = "%scomponents/atoms/cc/cc_update_set_service_status.js" % settings.STATIC_URL diff --git a/pipeline_plugins/components/collections/sites/open/cc/update_set_service_status/v1_0.py b/pipeline_plugins/components/collections/sites/open/cc/update_set_service_status/v1_0.py index 49d696f55a..e39604b6c0 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/update_set_service_status/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/cc/update_set_service_status/v1_0.py @@ -15,22 +15,20 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, IntItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, StringItemSchema +from gcloud.conf import settings +from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.cc.base import ( BkObjType, SelectMethod, cc_format_tree_mode_id, cc_list_select_node_inst_id, ) -from pipeline_plugins.base.utils.inject import supplier_account_for_business - -from gcloud.conf import settings -from gcloud.utils.handlers import handle_api_error logger = logging.getLogger("celery") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -54,7 +52,9 @@ def inputs_format(self): name=_("填参方式"), key="cc_set_select_method", type="string", - schema=StringItemSchema(description=_("模块填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"]), + schema=StringItemSchema( + description=_("模块填入方式,拓扑(topo),层级文本(text)"), enum=["topo", "text"] + ), ), self.InputItem( name=_("拓扑-集群列表"), @@ -68,7 +68,11 @@ def inputs_format(self): name=_("文本路径-集群"), key="cc_set_select_text", type="string", - schema=StringItemSchema(description=_("集群文本路径,请输入完整路径,从业务拓扑开始,如`业务A>集群B`,多个目标集群用换行分隔")), + schema=StringItemSchema( + description=_( + "集群文本路径,请输入完整路径,从业务拓扑开始,如`业务A>集群B`,多个目标集群用换行分隔" + ) + ), ), self.InputItem( name=_("服务状态"), diff --git a/pipeline_plugins/components/collections/sites/open/cc/update_set_service_status/v1_1.py b/pipeline_plugins/components/collections/sites/open/cc/update_set_service_status/v1_1.py index d7548b9259..784688b5d7 100644 --- a/pipeline_plugins/components/collections/sites/open/cc/update_set_service_status/v1_1.py +++ b/pipeline_plugins/components/collections/sites/open/cc/update_set_service_status/v1_1.py @@ -14,14 +14,14 @@ import logging from functools import partial -from django.utils.translation import ugettext_lazy as _ - -from gcloud.conf import settings -from api.utils.request import batch_request -from gcloud.utils.handlers import handle_api_error +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service from pipeline.core.flow.io import StringItemSchema + +from api.utils.request import batch_request +from gcloud.conf import settings +from gcloud.utils.handlers import handle_api_error from pipeline_plugins.base.utils.inject import supplier_account_for_business logger = logging.getLogger("celery") @@ -41,7 +41,8 @@ def inputs_format(self): key="set_select_method", type="string", schema=StringItemSchema( - description=_("集群填入方式,Set名称(name),Set ID(id),自定义(根据集群属性过滤)"), enum=["name", "id", "custom"] + description=_("集群填入方式,Set名称(name),Set ID(id),自定义(根据集群属性过滤)"), + enum=["name", "id", "custom"], ), ), self.InputItem( @@ -57,7 +58,10 @@ def inputs_format(self): schema=StringItemSchema(description=_("集群范围,多个集群使用英文','分割")), ), self.InputItem( - name=_("服务状态"), key="set_status", type="string", schema=StringItemSchema(description=_("实时拉取的服务状态")), + name=_("服务状态"), + key="set_status", + type="string", + schema=StringItemSchema(description=_("实时拉取的服务状态")), ), ] diff --git a/pipeline_plugins/components/collections/sites/open/job/__init__.py b/pipeline_plugins/components/collections/sites/open/job/__init__.py index 007a727865..72af036236 100644 --- a/pipeline_plugins/components/collections/sites/open/job/__init__.py +++ b/pipeline_plugins/components/collections/sites/open/job/__init__.py @@ -11,17 +11,17 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ __group_name__ = _("作业平台(JOB)") +from .all_biz_execute_job_plan import * # noqa +from .all_biz_fast_execute_script import * # noqa +from .all_biz_fast_push_file import * # noqa from .base import JobService, Jobv3Service # noqa from .cron_task import * # noqa from .execute_task import * # noqa from .fast_execute_script import * # noqa from .fast_push_file import * # noqa -from .push_local_files import * # noqa from .local_content_upload import * # noqa -from .all_biz_fast_push_file import * # noqa -from .all_biz_fast_execute_script import * # noqa -from .all_biz_execute_job_plan import * # noqa +from .push_local_files import * # noqa diff --git a/pipeline_plugins/components/collections/sites/open/job/all_biz_execute_job_plan/base_service.py b/pipeline_plugins/components/collections/sites/open/job/all_biz_execute_job_plan/base_service.py index ab7e9e262c..fd8dd0c7ec 100644 --- a/pipeline_plugins/components/collections/sites/open/job/all_biz_execute_job_plan/base_service.py +++ b/pipeline_plugins/components/collections/sites/open/job/all_biz_execute_job_plan/base_service.py @@ -4,7 +4,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema from gcloud.conf import settings @@ -68,7 +68,9 @@ def inputs_format(self): item_schema=ObjectItemSchema( description=_("全局变量"), property_schemas={ - "type": IntItemSchema(description=_("变量类型,字符串(1) 命名空间(2) IP(3) 密码(4) 数组(5)")), + "type": IntItemSchema( + description=_("变量类型,字符串(1) 命名空间(2) IP(3) 密码(4) 数组(5)") + ), "name": StringItemSchema(description=_("变量名")), "value": StringItemSchema(description=_("变量值")), }, diff --git a/pipeline_plugins/components/collections/sites/open/job/all_biz_execute_job_plan/v1_0.py b/pipeline_plugins/components/collections/sites/open/job/all_biz_execute_job_plan/v1_0.py index a7736652bb..5cb2b455b8 100644 --- a/pipeline_plugins/components/collections/sites/open/job/all_biz_execute_job_plan/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/job/all_biz_execute_job_plan/v1_0.py @@ -10,12 +10,9 @@ 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 django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component -from pipeline.core.flow.io import ( - BooleanItemSchema, - StringItemSchema, -) +from pipeline.core.flow.io import BooleanItemSchema, StringItemSchema from gcloud.conf import settings from pipeline_plugins.components.collections.sites.open.job.all_biz_execute_job_plan.base_service import ( @@ -33,7 +30,9 @@ def inputs_format(self): name=_("IP 存在性校验"), key="ip_is_exist", type="boolean", - schema=BooleanItemSchema(description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误")), + schema=BooleanItemSchema( + description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误") + ), ), self.InputItem( name=_("IP Tag 分组"), diff --git a/pipeline_plugins/components/collections/sites/open/job/all_biz_execute_job_plan/v1_1.py b/pipeline_plugins/components/collections/sites/open/job/all_biz_execute_job_plan/v1_1.py index ad4dc86e65..ab4952cdbb 100644 --- a/pipeline_plugins/components/collections/sites/open/job/all_biz_execute_job_plan/v1_1.py +++ b/pipeline_plugins/components/collections/sites/open/job/all_biz_execute_job_plan/v1_1.py @@ -10,7 +10,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. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import StringItemSchema diff --git a/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_execute_script/base_service.py b/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_execute_script/base_service.py index e5d170f78d..ea64a4e8bb 100644 --- a/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_execute_script/base_service.py +++ b/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_execute_script/base_service.py @@ -13,7 +13,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema from gcloud.conf import settings @@ -43,7 +43,9 @@ def inputs_format(self): key="job_script_type", type="string", schema=StringItemSchema( - description=_("待执行的脚本类型:shell(1) bat(2) perl(3) python(4) powershell(5)" ",仅在脚本来源为手动时生效"), + description=_( + "待执行的脚本类型:shell(1) bat(2) perl(3) python(4) powershell(5)" ",仅在脚本来源为手动时生效" + ), enum=["1", "2", "3", "4", "5"], ), ), @@ -66,10 +68,16 @@ def inputs_format(self): schema=StringItemSchema(description=_("执行脚本的目标机器账户")), ), self.InputItem( - name=_("脚本超时时间"), key="job_target_account", type="int", schema=IntItemSchema(description=_("脚本超时时间")), + name=_("脚本超时时间"), + key="job_target_account", + type="int", + schema=IntItemSchema(description=_("脚本超时时间")), ), self.InputItem( - name=_("脚本超时时间"), key="job_target_account", type="int", schema=IntItemSchema(description=_("脚本超时时间")), + name=_("脚本超时时间"), + key="job_target_account", + type="int", + schema=IntItemSchema(description=_("脚本超时时间")), ), self.InputItem( name=_("执行目标信息"), diff --git a/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_execute_script/v1_0.py b/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_execute_script/v1_0.py index de08322cbd..8257267c73 100644 --- a/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_execute_script/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_execute_script/v1_0.py @@ -30,12 +30,12 @@ import base64 -from django.utils.translation import ugettext_lazy as _ - -from gcloud.constants import JobBizScopeType -from pipeline.core.flow.io import BooleanItemSchema, StringItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.io import BooleanItemSchema, StringItemSchema +from gcloud.conf import settings +from gcloud.constants import JobBizScopeType from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.job.all_biz_fast_execute_script.base_service import ( BaseAllBizJobFastExecuteScriptService, @@ -43,8 +43,6 @@ from pipeline_plugins.components.collections.sites.open.job.ipv6_base import GetJobTargetServerMixin from pipeline_plugins.components.utils import get_node_callback_url -from gcloud.conf import settings - __group_name__ = _("作业平台(JOB)") diff --git a/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_execute_script/v1_1.py b/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_execute_script/v1_1.py index fee7007d6e..04df394698 100644 --- a/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_execute_script/v1_1.py +++ b/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_execute_script/v1_1.py @@ -30,22 +30,20 @@ import base64 -from django.utils.translation import ugettext_lazy as _ - -from gcloud.constants import JobBizScopeType -from pipeline.core.flow.io import StringItemSchema, BooleanItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.io import BooleanItemSchema, StringItemSchema +from gcloud.conf import settings +from gcloud.constants import JobBizScopeType from pipeline_plugins.base.utils.inject import supplier_account_for_business -from pipeline_plugins.components.collections.sites.open.job.ipv6_base import GetJobTargetServerMixin from pipeline_plugins.components.collections.sites.open.job.all_biz_fast_execute_script.base_service import ( BaseAllBizJobFastExecuteScriptService, ) from pipeline_plugins.components.collections.sites.open.job.base import get_job_tagged_ip_dict_complex +from pipeline_plugins.components.collections.sites.open.job.ipv6_base import GetJobTargetServerMixin from pipeline_plugins.components.utils import get_node_callback_url -from gcloud.conf import settings - __group_name__ = _("作业平台(JOB)") diff --git a/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_push_file/base_service.py b/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_push_file/base_service.py index cc05f0453b..7d8fd36966 100644 --- a/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_push_file/base_service.py +++ b/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_push_file/base_service.py @@ -13,7 +13,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.io import ArrayItemSchema, ObjectItemSchema, StringItemSchema from gcloud.conf import settings @@ -53,7 +53,10 @@ def inputs_format(self): ), ), self.InputItem( - name=_("上传限速"), key="upload_speed_limit", type="string", schema=StringItemSchema(description=_("MB/s")), + name=_("上传限速"), + key="upload_speed_limit", + type="string", + schema=StringItemSchema(description=_("MB/s")), ), self.InputItem( name=_("下载限速"), @@ -72,8 +75,12 @@ def inputs_format(self): property_schemas={ "bk_cloud_id": StringItemSchema(description=_("管控区域ID, 默认为0")), "job_ip_list": StringItemSchema(description=_("待分发机器 IP,多IP请使用;分隔")), - "job_target_path": StringItemSchema(description=_("分发目标绝对路径,(可用[FILESRCIP]代替源IP)")), - "job_target_account": StringItemSchema(description=_("执行账户,输入在蓝鲸作业平台上注册的账户名")), + "job_target_path": StringItemSchema( + description=_("分发目标绝对路径,(可用[FILESRCIP]代替源IP)") + ), + "job_target_account": StringItemSchema( + description=_("执行账户,输入在蓝鲸作业平台上注册的账户名") + ), }, ), ), @@ -174,7 +181,10 @@ def outputs_format(self): schema=StringItemSchema(description=_("分发请求成功数")), ), self.OutputItem( - name=_("分发成功数"), key="success_count", type="string", schema=StringItemSchema(description=_("上传成功数")) + name=_("分发成功数"), + key="success_count", + type="string", + schema=StringItemSchema(description=_("上传成功数")), ), self.OutputItem( name=_("任务id"), diff --git a/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_push_file/v1_0.py b/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_push_file/v1_0.py index c575fabf39..7cef21c7b9 100644 --- a/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_push_file/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_push_file/v1_0.py @@ -11,15 +11,14 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from gcloud.conf import settings from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.job.all_biz_fast_push_file.base_service import ( BaseAllBizJobFastPushFileService, ) -from gcloud.conf import settings __group_name__ = _("作业平台(JOB)") diff --git a/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_push_file/v1_1.py b/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_push_file/v1_1.py index 68b29e294b..039d75c061 100644 --- a/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_push_file/v1_1.py +++ b/pipeline_plugins/components/collections/sites/open/job/all_biz_fast_push_file/v1_1.py @@ -11,16 +11,15 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.io import StringItemSchema, BooleanItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.io import BooleanItemSchema, StringItemSchema +from gcloud.conf import settings from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.job.all_biz_fast_push_file.base_service import ( BaseAllBizJobFastPushFileService, ) -from gcloud.conf import settings __group_name__ = _("作业平台(JOB)") diff --git a/pipeline_plugins/components/collections/sites/open/job/base.py b/pipeline_plugins/components/collections/sites/open/job/base.py index c3d103b598..eea9b8d5a8 100644 --- a/pipeline_plugins/components/collections/sites/open/job/base.py +++ b/pipeline_plugins/components/collections/sites/open/job/base.py @@ -33,7 +33,7 @@ import traceback from functools import partial -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow import StaticIntervalGenerator from pipeline.core.flow.activity import Service from pipeline.core.flow.io import IntItemSchema, StringItemSchema @@ -232,7 +232,12 @@ def get_job_tagged_ip_dict( result = client.jobv3.get_job_instance_status(kwargs) if not result["result"]: - message = handle_api_error(__group_name__, "jobv3.get_job_instance_status", kwargs, result,) + message = handle_api_error( + __group_name__, + "jobv3.get_job_instance_status", + kwargs, + result, + ) service_logger.warning(message) return False, message @@ -332,7 +337,12 @@ def get_job_tagged_ip_dict_complex( result = client.jobv3.get_job_instance_status(kwargs) if not result["result"]: - message = handle_api_error(__group_name__, "jobv3.get_job_instance_status", kwargs, result,) + message = handle_api_error( + __group_name__, + "jobv3.get_job_instance_status", + kwargs, + result, + ) service_logger.warning(message) return False, message @@ -508,7 +518,9 @@ def schedule(self, data, parent_data, callback_data=None): if not global_var_result["result"]: message = job_handle_api_error( - "jobv3.get_job_instance_global_var_value", get_var_kwargs, global_var_result, + "jobv3.get_job_instance_global_var_value", + get_var_kwargs, + global_var_result, ) self.logger.error(message) data.outputs.ex_data = message @@ -557,9 +569,9 @@ def schedule(self, data, parent_data, callback_data=None): data.set_outputs( "ex_data", { - "exception_msg": _("任务执行失败,前往作业平台(JOB)查看详情").format( - job_inst_url=data.outputs.job_inst_url - ), + "exception_msg": _( + "任务执行失败,前往作业平台(JOB)查看详情" + ).format(job_inst_url=data.outputs.job_inst_url), "task_inst_id": job_instance_id, "show_ip_log": True, }, @@ -634,15 +646,17 @@ def schedule(self, data, parent_data, callback_data=None): elif job_status > 3: # 出于性能考虑,不拉取对应主机IP的日志,引导用户跳转JOB平台查看 failure_inst_url.append(job_detail_url) - data.outputs.ex_data += "任务执行失败,前往作业平台(JOB)查看详情\n".format( - job_detail_url + data.outputs.ex_data += ( + "任务执行失败,前往作业平台(JOB)查看详情\n".format( + job_detail_url + ) ) else: running_task_list.append(job_id_str) else: failure_inst_url.append(job_detail_url) - data.outputs.ex_data += "任务执行失败,前往作业平台(JOB)查看详情\n".format( - job_detail_url + data.outputs.ex_data += ( + "任务执行失败,前往作业平台(JOB)查看详情\n".format(job_detail_url) ) self.logger.error("请求job_id({}),结果为:{}".format(job_id_str, result.get("message"))) # 需要继续轮询的任务 @@ -748,7 +762,9 @@ def schedule(self, data, parent_data, callback_data=None): if not global_var_result["result"]: message = job_handle_api_error( - "jobv3.get_job_instance_global_var_value", get_var_kwargs, global_var_result, + "jobv3.get_job_instance_global_var_value", + get_var_kwargs, + global_var_result, ) self.logger.error(message) data.outputs.ex_data = message @@ -798,9 +814,9 @@ def schedule(self, data, parent_data, callback_data=None): data.set_outputs( "ex_data", { - "exception_msg": _("任务执行失败,前往作业平台(JOB)查看详情").format( - job_inst_url=data.outputs.job_inst_url - ), + "exception_msg": _( + "任务执行失败,前往作业平台(JOB)查看详情" + ).format(job_inst_url=data.outputs.job_inst_url), "task_inst_id": job_instance_id, "show_ip_log": True, }, @@ -874,8 +890,8 @@ def schedule(self, data, parent_data, callback_data=None): else: running_task_list.append(job_id_str) else: - data.outputs.ex_data += "任务执行失败,前往作业平台(JOB)查看详情\n".format( - job_detail_url + data.outputs.ex_data += ( + "任务执行失败,前往作业平台(JOB)查看详情\n".format(job_detail_url) ) # 需要继续轮询的任务 @@ -905,7 +921,12 @@ def get_job_history_result(self, data, parent_data): job_result = client.jobv3.get_job_instance_status(job_kwargs) if not job_result["result"]: - message = handle_api_error(__group_name__, "jobv3.get_job_instance_status", job_kwargs, job_result,) + message = handle_api_error( + __group_name__, + "jobv3.get_job_instance_status", + job_kwargs, + job_result, + ) self.logger.error(message) data.outputs.ex_data = message self.logger.info(data.outputs) @@ -913,7 +934,9 @@ def get_job_history_result(self, data, parent_data): # judge success status if job_result["data"]["job_instance"]["status"] not in JOB_SUCCESS: - message = _(f"执行历史请求失败: 任务实例[ID: {job_success_id}], 异常信息: {job_result['result']} | get_job_history_result") + message = _( + f"执行历史请求失败: 任务实例[ID: {job_success_id}], 异常信息: {job_result['result']} | get_job_history_result" + ) self.logger.error(message) data.outputs.ex_data = message self.logger.info(data.outputs) @@ -925,7 +948,10 @@ def get_job_history_result(self, data, parent_data): return True get_job_sops_var_dict_return = get_job_sops_var_dict( - client, self.logger, job_success_id, data.get_one_of_inputs("biz_cc_id", parent_data.inputs.biz_cc_id), + client, + self.logger, + job_success_id, + data.get_one_of_inputs("biz_cc_id", parent_data.inputs.biz_cc_id), ) if not get_job_sops_var_dict_return["result"]: self.logger.error( diff --git a/pipeline_plugins/components/collections/sites/open/job/cron_task/legacy.py b/pipeline_plugins/components/collections/sites/open/job/cron_task/legacy.py index 3b7125e280..d058379085 100644 --- a/pipeline_plugins/components/collections/sites/open/job/cron_task/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/job/cron_task/legacy.py @@ -14,14 +14,11 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import ( - StringItemSchema, - IntItemSchema, -) +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import IntItemSchema, StringItemSchema + from gcloud.conf import settings from gcloud.constants import JobBizScopeType from gcloud.utils.handlers import handle_api_error diff --git a/pipeline_plugins/components/collections/sites/open/job/execute_task/execute_task_base.py b/pipeline_plugins/components/collections/sites/open/job/execute_task/execute_task_base.py index 66f5874a3e..c9a805ca7e 100644 --- a/pipeline_plugins/components/collections/sites/open/job/execute_task/execute_task_base.py +++ b/pipeline_plugins/components/collections/sites/open/job/execute_task/execute_task_base.py @@ -15,7 +15,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema from gcloud.conf import settings @@ -179,7 +179,9 @@ def execute(self, data, parent_data): server = self.build_ip_list(biz_across, val, executor, biz_cc_id, data, ip_is_exist) self.logger.info("[job_execute_task_base] find a ip var, ip_list is {}".format(server)) if not server: - data.outputs.ex_data = _(f"无法从配置平台(CMDB)查询到对应 IP,请确认输入的 IP 是否合法。查询失败 IP: {val}") + data.outputs.ex_data = _( + f"无法从配置平台(CMDB)查询到对应 IP,请确认输入的 IP 是否合法。查询失败 IP: {val}" + ) return False global_vars.append({"name": _value["name"], "server": server}) # 密文变量在没有修改的情况下不加入全局变量,避免脱敏字符串作为正式值进行作业执行逻辑 diff --git a/pipeline_plugins/components/collections/sites/open/job/execute_task/legacy.py b/pipeline_plugins/components/collections/sites/open/job/execute_task/legacy.py index fbf15f5c44..43cd378146 100644 --- a/pipeline_plugins/components/collections/sites/open/job/execute_task/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/job/execute_task/legacy.py @@ -13,7 +13,7 @@ from functools import partial -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import BooleanItemSchema @@ -36,7 +36,9 @@ def inputs_format(self): name=_("IP 存在性校验"), key="ip_is_exist", type="boolean", - schema=BooleanItemSchema(description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误")), + schema=BooleanItemSchema( + description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误") + ), ), ] diff --git a/pipeline_plugins/components/collections/sites/open/job/execute_task/v1_0.py b/pipeline_plugins/components/collections/sites/open/job/execute_task/v1_0.py index 53060e96a9..1e5fe0a6f0 100644 --- a/pipeline_plugins/components/collections/sites/open/job/execute_task/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/job/execute_task/v1_0.py @@ -12,14 +12,16 @@ """ from functools import partial -from django.utils.translation import ugettext_lazy as _ -from .execute_task_base import JobExecuteTaskServiceBase -from pipeline.core.flow.io import BooleanItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from pipeline.core.flow.io import BooleanItemSchema + from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error +from .execute_task_base import JobExecuteTaskServiceBase + __group_name__ = _("作业平台(JOB)") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER @@ -34,7 +36,9 @@ def inputs_format(self): name=_("IP 存在性校验"), key="ip_is_exist", type="boolean", - schema=BooleanItemSchema(description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误")), + schema=BooleanItemSchema( + description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误") + ), ), ] @@ -47,5 +51,6 @@ class JobExecuteTaskComponent(Component): output_form = "%scomponents/atoms/job/job_execute_task_output.js" % settings.STATIC_URL version = "1.0" desc = _( - "在接收到用户编辑的全局变量后,v1.0版本会默认用英文双引号将默认变量值包裹起来,再将得到的字符串作为一个整体在调用API时进行传参。\n" "如果不需要双引号包裹,可以使用legacy版本插件,也可以手动在表格中去掉。" + "在接收到用户编辑的全局变量后,v1.0版本会默认用英文双引号将默认变量值包裹起来,再将得到的字符串作为一个整体在调用API时进行传参。\n" + "如果不需要双引号包裹,可以使用legacy版本插件,也可以手动在表格中去掉。" ) diff --git a/pipeline_plugins/components/collections/sites/open/job/execute_task/v1_1.py b/pipeline_plugins/components/collections/sites/open/job/execute_task/v1_1.py index 865df56cff..1edb82fd24 100644 --- a/pipeline_plugins/components/collections/sites/open/job/execute_task/v1_1.py +++ b/pipeline_plugins/components/collections/sites/open/job/execute_task/v1_1.py @@ -13,7 +13,7 @@ from functools import partial -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import BooleanItemSchema, StringItemSchema @@ -43,7 +43,9 @@ def inputs_format(self): name=_("IP 存在性校验"), key="ip_is_exist", type="boolean", - schema=BooleanItemSchema(description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误")), + schema=BooleanItemSchema( + description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误") + ), ), ] diff --git a/pipeline_plugins/components/collections/sites/open/job/execute_task/v1_2.py b/pipeline_plugins/components/collections/sites/open/job/execute_task/v1_2.py index bb9d113427..fa7227108e 100644 --- a/pipeline_plugins/components/collections/sites/open/job/execute_task/v1_2.py +++ b/pipeline_plugins/components/collections/sites/open/job/execute_task/v1_2.py @@ -13,15 +13,17 @@ """ from functools import partial -from django.utils.translation import ugettext_lazy as _ -from .execute_task_base import JobExecuteTaskServiceBase -from ..base import GetJobHistoryResultMixin, get_job_tagged_ip_dict_complex +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import StringItemSchema + from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error +from ..base import GetJobHistoryResultMixin, get_job_tagged_ip_dict_complex +from .execute_task_base import JobExecuteTaskServiceBase + __group_name__ = _("作业平台(JOB)") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER diff --git a/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/legacy.py b/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/legacy.py index 06be278b13..af56eedf0b 100644 --- a/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/legacy.py @@ -33,21 +33,16 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.io import ( - StringItemSchema, - ObjectItemSchema, - BooleanItemSchema, -) +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component -from pipeline_plugins.components.collections.sites.open.job import JobService -from pipeline_plugins.components.collections.sites.open.job.ipv6_base import GetJobTargetServerMixin -from pipeline_plugins.components.utils import get_job_instance_url, get_node_callback_url +from pipeline.core.flow.io import BooleanItemSchema, ObjectItemSchema, StringItemSchema from gcloud.conf import settings from gcloud.constants import JobBizScopeType from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.components.collections.sites.open.job import JobService +from pipeline_plugins.components.collections.sites.open.job.ipv6_base import GetJobTargetServerMixin +from pipeline_plugins.components.utils import get_job_instance_url, get_node_callback_url __group_name__ = _("作业平台(JOB)") @@ -81,7 +76,9 @@ def inputs_format(self): key="job_script_type", type="string", schema=StringItemSchema( - description=_("待执行的脚本类型:shell(1) bat(2) perl(3) python(4) powershell(5)" ",仅在脚本来源为手动时生效"), + description=_( + "待执行的脚本类型:shell(1) bat(2) perl(3) python(4) powershell(5)" ",仅在脚本来源为手动时生效" + ), enum=["1", "2", "3", "4", "5"], ), ), @@ -125,7 +122,9 @@ def inputs_format(self): name=_("IP 存在性校验"), key="ip_is_exist", type="boolean", - schema=BooleanItemSchema(description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误")), + schema=BooleanItemSchema( + description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误") + ), ), ] diff --git a/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/v1_0.py b/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/v1_0.py index 8e41e6f09d..44b2310321 100644 --- a/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/v1_0.py @@ -32,7 +32,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import BooleanItemSchema, ObjectItemSchema, StringItemSchema @@ -77,7 +77,9 @@ def inputs_format(self): key="job_script_type", type="string", schema=StringItemSchema( - description=_("待执行的脚本类型:shell(1) bat(2) perl(3) python(4) powershell(5)" ",仅在脚本来源为手动时生效"), + description=_( + "待执行的脚本类型:shell(1) bat(2) perl(3) python(4) powershell(5)" ",仅在脚本来源为手动时生效" + ), enum=["1", "2", "3", "4", "5"], ), ), @@ -109,7 +111,11 @@ def inputs_format(self): name=_("是否允许跨业务"), key="job_across_biz", type="bool", - schema=BooleanItemSchema(description=_("是否允许跨业务(跨业务需在作业平台添加白名单),允许时,源文件IP格式需为【管控区域ID:IP】")), + schema=BooleanItemSchema( + description=_( + "是否允许跨业务(跨业务需在作业平台添加白名单),允许时,源文件IP格式需为【管控区域ID:IP】" + ) + ), ), self.InputItem( name=_("目标 IP"), @@ -118,13 +124,18 @@ def inputs_format(self): schema=StringItemSchema(description=_("执行脚本的目标机器 IP,多个用英文逗号 `,` 分隔")), ), self.InputItem( - name=_("目标账户"), key="job_account", type="string", schema=StringItemSchema(description=_("执行脚本的目标机器账户")), + name=_("目标账户"), + key="job_account", + type="string", + schema=StringItemSchema(description=_("执行脚本的目标机器账户")), ), self.InputItem( name=_("IP 存在性校验"), key="ip_is_exist", type="boolean", - schema=BooleanItemSchema(description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误")), + schema=BooleanItemSchema( + description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误") + ), ), self.InputItem( name=_("自定义任务名"), diff --git a/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/v1_1.py b/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/v1_1.py index 858fb339f5..7bb0d638c7 100644 --- a/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/v1_1.py +++ b/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/v1_1.py @@ -32,7 +32,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import BooleanItemSchema, ObjectItemSchema, StringItemSchema @@ -79,7 +79,9 @@ def inputs_format(self): key="job_script_type", type="string", schema=StringItemSchema( - description=_("待执行的脚本类型:shell(1) bat(2) perl(3) python(4) powershell(5)" ",仅在脚本来源为手动时生效"), + description=_( + "待执行的脚本类型:shell(1) bat(2) perl(3) python(4) powershell(5)" ",仅在脚本来源为手动时生效" + ), enum=["1", "2", "3", "4", "5"], ), ), @@ -111,7 +113,11 @@ def inputs_format(self): name=_("是否允许跨业务"), key="job_across_biz", type="bool", - schema=BooleanItemSchema(description=_("是否允许跨业务(跨业务需在作业平台添加白名单),允许时,源文件IP格式需为【管控区域ID:IP】")), + schema=BooleanItemSchema( + description=_( + "是否允许跨业务(跨业务需在作业平台添加白名单),允许时,源文件IP格式需为【管控区域ID:IP】" + ) + ), ), self.InputItem( name=_("目标 IP"), @@ -120,13 +126,18 @@ def inputs_format(self): schema=StringItemSchema(description=_("执行脚本的目标机器 IP,多个用英文逗号 `,` 分隔")), ), self.InputItem( - name=_("目标账户"), key="job_account", type="string", schema=StringItemSchema(description=_("执行脚本的目标机器账户")), + name=_("目标账户"), + key="job_account", + type="string", + schema=StringItemSchema(description=_("执行脚本的目标机器账户")), ), self.InputItem( name=_("IP 存在性校验"), key="ip_is_exist", type="boolean", - schema=BooleanItemSchema(description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误")), + schema=BooleanItemSchema( + description=_("是否做 IP 存在性校验,如果ip校验开关打开,校验通过的ip数量若减少,即返回错误") + ), ), self.InputItem( name=_("IP Tag 分组"), diff --git a/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/v1_2.py b/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/v1_2.py index de45650e77..08eec678c1 100644 --- a/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/v1_2.py +++ b/pipeline_plugins/components/collections/sites/open/job/fast_execute_script/v1_2.py @@ -32,7 +32,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import BooleanItemSchema, ObjectItemSchema, StringItemSchema @@ -79,7 +79,9 @@ def inputs_format(self): key="job_script_type", type="string", schema=StringItemSchema( - description=_("待执行的脚本类型:shell(1) bat(2) perl(3) python(4) powershell(5)" ",仅在脚本来源为手动时生效"), + description=_( + "待执行的脚本类型:shell(1) bat(2) perl(3) python(4) powershell(5)" ",仅在脚本来源为手动时生效" + ), enum=["1", "2", "3", "4", "5"], ), ), diff --git a/pipeline_plugins/components/collections/sites/open/job/fast_push_file/legacy.py b/pipeline_plugins/components/collections/sites/open/job/fast_push_file/legacy.py index 3c1bf59d87..a17bcd03c8 100644 --- a/pipeline_plugins/components/collections/sites/open/job/fast_push_file/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/job/fast_push_file/legacy.py @@ -16,7 +16,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import ArrayItemSchema, ObjectItemSchema, StringItemSchema diff --git a/pipeline_plugins/components/collections/sites/open/job/fast_push_file/v1_0.py b/pipeline_plugins/components/collections/sites/open/job/fast_push_file/v1_0.py index 93fa1d52e4..44d961a088 100644 --- a/pipeline_plugins/components/collections/sites/open/job/fast_push_file/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/job/fast_push_file/v1_0.py @@ -15,7 +15,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import ArrayItemSchema, BooleanItemSchema, ObjectItemSchema, StringItemSchema diff --git a/pipeline_plugins/components/collections/sites/open/job/fast_push_file/v2_0.py b/pipeline_plugins/components/collections/sites/open/job/fast_push_file/v2_0.py index 9e728b1de1..5b1f92bf7e 100644 --- a/pipeline_plugins/components/collections/sites/open/job/fast_push_file/v2_0.py +++ b/pipeline_plugins/components/collections/sites/open/job/fast_push_file/v2_0.py @@ -15,7 +15,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import ArrayItemSchema, BooleanItemSchema, ObjectItemSchema, StringItemSchema @@ -219,7 +219,10 @@ def outputs_format(self): schema=StringItemSchema(description=_("分发请求成功数")), ), self.OutputItem( - name=_("分发成功数"), key="success_count", type="string", schema=StringItemSchema(description=_("上传成功数")) + name=_("分发成功数"), + key="success_count", + type="string", + schema=StringItemSchema(description=_("上传成功数")), ), self.OutputItem( name=_("任务id"), diff --git a/pipeline_plugins/components/collections/sites/open/job/fast_push_file/v2_1.py b/pipeline_plugins/components/collections/sites/open/job/fast_push_file/v2_1.py index 6bfe7a194d..26cd5beda3 100644 --- a/pipeline_plugins/components/collections/sites/open/job/fast_push_file/v2_1.py +++ b/pipeline_plugins/components/collections/sites/open/job/fast_push_file/v2_1.py @@ -15,7 +15,7 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import ArrayItemSchema, BooleanItemSchema, ObjectItemSchema, StringItemSchema @@ -240,7 +240,10 @@ def outputs_format(self): schema=StringItemSchema(description=_("分发请求成功数")), ), self.OutputItem( - name=_("分发成功数"), key="success_count", type="string", schema=StringItemSchema(description=_("上传成功数")) + name=_("分发成功数"), + key="success_count", + type="string", + schema=StringItemSchema(description=_("上传成功数")), ), self.OutputItem( name=_("任务id"), diff --git a/pipeline_plugins/components/collections/sites/open/job/fetch_task_log/v1_0.py b/pipeline_plugins/components/collections/sites/open/job/fetch_task_log/v1_0.py index 1de5ce47fe..c2438ab29f 100644 --- a/pipeline_plugins/components/collections/sites/open/job/fetch_task_log/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/job/fetch_task_log/v1_0.py @@ -14,14 +14,14 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ - -from pipeline.core.flow.io import StringItemSchema +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component -from pipeline_plugins.components.collections.sites.open.job.base import get_job_instance_log from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import StringItemSchema + from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.components.collections.sites.open.job.base import get_job_instance_log __group_name__ = _("作业平台(JOB)") @@ -50,7 +50,10 @@ def inputs_format(self): def outputs_format(self): return [ self.OutputItem( - name=_("任务日志"), key="job_task_log", type="string", schema=StringItemSchema(description=_("任务日志")) + name=_("任务日志"), + key="job_task_log", + type="string", + schema=StringItemSchema(description=_("任务日志")), ) ] diff --git a/pipeline_plugins/components/collections/sites/open/job/local_content_upload/base_service.py b/pipeline_plugins/components/collections/sites/open/job/local_content_upload/base_service.py index b30e9e96a1..f2d6b9d611 100644 --- a/pipeline_plugins/components/collections/sites/open/job/local_content_upload/base_service.py +++ b/pipeline_plugins/components/collections/sites/open/job/local_content_upload/base_service.py @@ -13,7 +13,7 @@ import base64 from functools import partial -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.activity import Service, StaticIntervalGenerator from pipeline.core.flow.io import BooleanItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema @@ -55,7 +55,9 @@ def inputs_format(self): key="job_ip_list", type="string", schema=StringItemSchema( - description=_("IP必须填写【管控区域ID:IP】或者【IP】格式之一,多个用换行分隔;【IP】格式需要保证所填写的内网IP在配置平台(CMDB)的该业务中是唯一的") + description=_( + "IP必须填写【管控区域ID:IP】或者【IP】格式之一,多个用换行分隔;【IP】格式需要保证所填写的内网IP在配置平台(CMDB)的该业务中是唯一的" + ) ), ), self.InputItem( diff --git a/pipeline_plugins/components/collections/sites/open/job/local_content_upload/v1_0.py b/pipeline_plugins/components/collections/sites/open/job/local_content_upload/v1_0.py index 5af1a41887..da151a00f3 100644 --- a/pipeline_plugins/components/collections/sites/open/job/local_content_upload/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/job/local_content_upload/v1_0.py @@ -10,14 +10,13 @@ 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 django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component +from gcloud.conf import settings from pipeline_plugins.components.collections.sites.open.job.local_content_upload.base_service import ( BaseJobLocalContentUploadService, ) -from gcloud.conf import settings __group_name__ = _("作业平台(JOB)") diff --git a/pipeline_plugins/components/collections/sites/open/job/local_content_upload/v1_1.py b/pipeline_plugins/components/collections/sites/open/job/local_content_upload/v1_1.py index 9b5d50ccd6..93e2f06a84 100644 --- a/pipeline_plugins/components/collections/sites/open/job/local_content_upload/v1_1.py +++ b/pipeline_plugins/components/collections/sites/open/job/local_content_upload/v1_1.py @@ -10,14 +10,14 @@ 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 django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import BooleanItemSchema, StringItemSchema +from gcloud.conf import settings from pipeline_plugins.components.collections.sites.open.job.local_content_upload.base_service import ( BaseJobLocalContentUploadService, ) -from gcloud.conf import settings __group_name__ = _("作业平台(JOB)") diff --git a/pipeline_plugins/components/collections/sites/open/job/push_local_files/base_service.py b/pipeline_plugins/components/collections/sites/open/job/push_local_files/base_service.py index ead941edbd..73772a8e5f 100644 --- a/pipeline_plugins/components/collections/sites/open/job/push_local_files/base_service.py +++ b/pipeline_plugins/components/collections/sites/open/job/push_local_files/base_service.py @@ -14,7 +14,7 @@ import traceback from functools import partial -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.activity import StaticIntervalGenerator from pipeline.core.flow.io import ArrayItemSchema, ObjectItemSchema, StringItemSchema @@ -41,10 +41,16 @@ class BaseJobPushLocalFilesService(JobScheduleService, GetJobTargetServerMixin): def inputs_format(self): return [ self.InputItem( - name=_("目标IP"), key="job_target_ip_list", type="string", schema=StringItemSchema(description=_("目标IP")) + name=_("目标IP"), + key="job_target_ip_list", + type="string", + schema=StringItemSchema(description=_("目标IP")), ), self.InputItem( - name=_("执行账号"), key="job_target_account", type="string", schema=StringItemSchema(description=_("执行账号")) + name=_("执行账号"), + key="job_target_account", + type="string", + schema=StringItemSchema(description=_("执行账号")), ), self.InputItem( name=_("本地文件信息"), @@ -67,7 +73,8 @@ def inputs_format(self): description=_("tag"), property_schemas={ "type": StringItemSchema( - description=_("文件类型"), enum=["upload_module", "host_nfs"] + description=_("文件类型"), + enum=["upload_module", "host_nfs"], ), "tags": ObjectItemSchema( description=_( @@ -110,7 +117,10 @@ def outputs_format(self): schema=StringItemSchema(description=_("上传请求成功数")), ), self.OutputItem( - name=_("上传成功数"), key="success_count", type="string", schema=StringItemSchema(description=_("上传成功数")) + name=_("上传成功数"), + key="success_count", + type="string", + schema=StringItemSchema(description=_("上传成功数")), ), self.OutputItem( name=_("任务id"), diff --git a/pipeline_plugins/components/collections/sites/open/job/push_local_files/v1_0_0.py b/pipeline_plugins/components/collections/sites/open/job/push_local_files/v1_0_0.py index 4a502756db..cbb26f2a38 100644 --- a/pipeline_plugins/components/collections/sites/open/job/push_local_files/v1_0_0.py +++ b/pipeline_plugins/components/collections/sites/open/job/push_local_files/v1_0_0.py @@ -14,7 +14,7 @@ import traceback from functools import partial -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from files.factory import ManagerFactory @@ -107,4 +107,6 @@ class JobPushLocalFilesComponent(Component): bound_service = JobPushLocalFilesService form = "%scomponents/atoms/job/job_push_local_files/v1_0_0.js" % settings.STATIC_URL version = "1.0.0" - desc = _("本地上传的文件不保证长期保存并可用于多次分发,推荐勾选上传变量并在创建任务时进行上传操作。如果希望多次分发相同文件,请使用快速分发文件插件。") + desc = _( + "本地上传的文件不保证长期保存并可用于多次分发,推荐勾选上传变量并在创建任务时进行上传操作。如果希望多次分发相同文件,请使用快速分发文件插件。" + ) diff --git a/pipeline_plugins/components/collections/sites/open/job/push_local_files/v2_0.py b/pipeline_plugins/components/collections/sites/open/job/push_local_files/v2_0.py index 2303f1442b..a1401dd0c9 100644 --- a/pipeline_plugins/components/collections/sites/open/job/push_local_files/v2_0.py +++ b/pipeline_plugins/components/collections/sites/open/job/push_local_files/v2_0.py @@ -13,15 +13,14 @@ from functools import partial -from django.utils.translation import ugettext_lazy as _ - +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component -from pipeline_plugins.components.collections.sites.open.job.push_local_files.base_service import ( - BaseJobPushLocalFilesService, -) from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error +from pipeline_plugins.components.collections.sites.open.job.push_local_files.base_service import ( + BaseJobPushLocalFilesService, +) __group_name__ = _("作业平台(JOB)") @@ -40,4 +39,6 @@ class JobPushLocalFilesComponent(Component): bound_service = JobPushLocalFilesService form = "%scomponents/atoms/job/job_push_local_files/v2_0.js" % settings.STATIC_URL version = "2.0" - desc = _("本地上传的文件不保证长期保存并可用于多次分发,推荐勾选上传变量并在创建任务时进行上传操作。如果希望多次分发相同文件,请使用快速分发文件插件。") + desc = _( + "本地上传的文件不保证长期保存并可用于多次分发,推荐勾选上传变量并在创建任务时进行上传操作。如果希望多次分发相同文件,请使用快速分发文件插件。" + ) diff --git a/pipeline_plugins/components/collections/sites/open/job/push_local_files/v2_1.py b/pipeline_plugins/components/collections/sites/open/job/push_local_files/v2_1.py index 879f702faf..8eacd37e59 100644 --- a/pipeline_plugins/components/collections/sites/open/job/push_local_files/v2_1.py +++ b/pipeline_plugins/components/collections/sites/open/job/push_local_files/v2_1.py @@ -11,7 +11,7 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import BooleanItemSchema, StringItemSchema @@ -94,5 +94,6 @@ class JobPushLocalFilesComponent(Component): form = "%scomponents/atoms/job/job_push_local_files/v2_1.js" % settings.STATIC_URL version = "v2.1" desc = _( - "本地上传的文件不保证长期保存并可用于多次分发,推荐勾选上传变量并在创建任务时进行上传操作。如果希望多次分发相同文件,请使用快速分发文件插件。" "注:插件版本v2.1中滚动执行要求作业平台版本>=V3.6.0.0。\n" + "本地上传的文件不保证长期保存并可用于多次分发,推荐勾选上传变量并在创建任务时进行上传操作。如果希望多次分发相同文件,请使用快速分发文件插件。" + "注:插件版本v2.1中滚动执行要求作业平台版本>=V3.6.0.0。\n" ) diff --git a/pipeline_plugins/components/collections/sites/open/monitor/__init__.py b/pipeline_plugins/components/collections/sites/open/monitor/__init__.py index 788c301fe0..e16072a109 100644 --- a/pipeline_plugins/components/collections/sites/open/monitor/__init__.py +++ b/pipeline_plugins/components/collections/sites/open/monitor/__init__.py @@ -11,10 +11,10 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ __group_name__ = _("监控平台(Monitor)") -from .alarm_shield_disable import * # noqa from .alarm_shield import * # noqa +from .alarm_shield_disable import * # noqa from .base import * # noqa diff --git a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/base.py b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/base.py index 747432a656..5c5b9b8e02 100644 --- a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/base.py +++ b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/base.py @@ -1,17 +1,13 @@ # -*- coding: utf-8 -*- from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.io import ObjectItemSchema, StringItemSchema from api.collections.monitor import BKMonitorClient from pipeline_plugins.base.utils.inject import supplier_account_for_business -from pipeline_plugins.components.collections.sites.open.monitor.base import ( - MonitorBaseService, -) +from pipeline_plugins.components.collections.sites.open.monitor.base import MonitorBaseService from pipeline_plugins.components.utils.sites.open.choose_time_tools import choose_time -from pipeline_plugins.components.utils.sites.open.utils import ( - get_module_id_list_by_name, -) +from pipeline_plugins.components.utils.sites.open.utils import get_module_id_list_by_name from pipeline_plugins.variables.utils import ( get_list_by_selected_names, get_service_template_list, diff --git a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/v1_0.py b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/v1_0.py index 71638aee1a..8be398b67f 100644 --- a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/v1_0.py @@ -12,20 +12,20 @@ """ from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ +from pipeline.component_framework.component import Component +from pipeline.core.flow.io import ObjectItemSchema, StringItemSchema from api import BKMonitorClient from gcloud.conf import settings -from pipeline.core.flow.io import StringItemSchema, ObjectItemSchema -from pipeline.component_framework.component import Component from pipeline_plugins.base.utils.inject import supplier_account_for_business from pipeline_plugins.components.collections.sites.open.monitor.base import MonitorBaseService from pipeline_plugins.components.utils.sites.open.utils import get_module_id_list_by_name from pipeline_plugins.variables.utils import ( - get_set_list, get_list_by_selected_names, get_service_template_list, get_service_template_list_by_names, + get_set_list, ) SCOPE = {"business": "bk_alarm_shield_business", "IP": "bk_alarm_shield_IP", "node": "bk_alarm_shield_node"} @@ -42,7 +42,7 @@ def inputs_format(self): name=_("屏蔽范围类型"), key="bk_alarm_shield_info", type="object", - schema=ObjectItemSchema(description=_(u"屏蔽范围类型"), property_schemas={}), + schema=ObjectItemSchema(description=_("屏蔽范围类型"), property_schemas={}), ), self.InputItem( name=_("策略 ID"), diff --git a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/v1_1.py b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/v1_1.py index 69ffe5e4f5..92db806143 100644 --- a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/v1_1.py +++ b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/v1_1.py @@ -10,13 +10,11 @@ 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 django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from gcloud.conf import settings -from pipeline_plugins.components.collections.sites.open.monitor.alarm_shield.base import ( - MonitorAlarmShieldServiceBase, -) +from pipeline_plugins.components.collections.sites.open.monitor.alarm_shield.base import MonitorAlarmShieldServiceBase __group_name__ = _("监控平台(Monitor)") diff --git a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/v1_2.py b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/v1_2.py index 7c63cd01d4..9d6f235a08 100644 --- a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/v1_2.py +++ b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield/v1_2.py @@ -10,7 +10,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. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from gcloud.conf import settings @@ -36,4 +36,6 @@ class MonitorAlarmShieldComponent(Component): bound_service = MonitorAlarmShieldService form = "{static_url}components/atoms/monitor/alarm_shield/v1_2.js".format(static_url=settings.STATIC_URL) version = "1.2" - desc = _("注意: 1.屏蔽方案选择自定义监控时,屏蔽范围CC大区和集群必须选择all, 2.当按业务屏蔽时,使用当前项目选择的业务值") + desc = _( + "注意: 1.屏蔽方案选择自定义监控时,屏蔽范围CC大区和集群必须选择all, 2.当按业务屏蔽时,使用当前项目选择的业务值" + ) diff --git a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_disable/v1_0.py b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_disable/v1_0.py index 65249ab508..138b3060db 100644 --- a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_disable/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_disable/v1_0.py @@ -13,16 +13,15 @@ from functools import partial from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ +from pipeline.component_framework.component import Component +from pipeline.core.flow.activity import Service +from pipeline.core.flow.io import IntItemSchema, StringItemSchema from api import BKMonitorClient from gcloud.conf import settings from gcloud.utils.handlers import handle_api_error -from pipeline.core.flow.activity import Service -from pipeline.core.flow.io import StringItemSchema, IntItemSchema -from pipeline.component_framework.component import Component - __group_name__ = _("监控平台(Monitor)") monitor_handle_api_error = partial(handle_api_error, __group_name__) @@ -65,10 +64,16 @@ def execute(self, data, parent_data): def outputs_format(self): return [ self.OutputItem( - name=_("响应内容"), key="data", type="string", schema=StringItemSchema(description=_("解除告警屏蔽的响应内容")) + name=_("响应内容"), + key="data", + type="string", + schema=StringItemSchema(description=_("解除告警屏蔽的响应内容")), ), self.OutputItem( - name=_("状态码"), key="status_code", type="int", schema=IntItemSchema(description=_("解除告警屏蔽的响应状态码")) + name=_("状态码"), + key="status_code", + type="int", + schema=IntItemSchema(description=_("解除告警屏蔽的响应状态码")), ), ] diff --git a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_strategy/v1_0.py b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_strategy/v1_0.py index 08bfcd5fc6..1db6a547a2 100644 --- a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_strategy/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_strategy/v1_0.py @@ -12,14 +12,12 @@ """ from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ +from pipeline.component_framework.component import Component +from pipeline.core.flow.io import StringItemSchema from api import BKMonitorClient from gcloud.conf import settings - -from pipeline.core.flow.io import StringItemSchema -from pipeline.component_framework.component import Component - from pipeline_plugins.components.collections.sites.open.monitor.base import MonitorBaseService __group_name__ = _("监控平台(Monitor)") diff --git a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_strategy/v1_1.py b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_strategy/v1_1.py index a400f0fb5b..f75640a09e 100644 --- a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_strategy/v1_1.py +++ b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_strategy/v1_1.py @@ -14,14 +14,12 @@ import time from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ +from pipeline.component_framework.component import Component +from pipeline.core.flow.io import StringItemSchema from api.collections.monitor import BKMonitorClient from gcloud.conf import settings - -from pipeline.core.flow.io import StringItemSchema -from pipeline.component_framework.component import Component - from pipeline_plugins.components.collections.sites.open.monitor.base import MonitorBaseService __group_name__ = _("监控平台(Monitor)") diff --git a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_strategy/v1_2.py b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_strategy/v1_2.py index d89bc6b747..fee25c3c64 100644 --- a/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_strategy/v1_2.py +++ b/pipeline_plugins/components/collections/sites/open/monitor/alarm_shield_strategy/v1_2.py @@ -14,14 +14,12 @@ import time from django.utils import translation -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ +from pipeline.component_framework.component import Component +from pipeline.core.flow.io import ArrayItemSchema, ObjectItemSchema, StringItemSchema from api.collections.monitor import BKMonitorClient from gcloud.conf import settings - -from pipeline.core.flow.io import StringItemSchema, ArrayItemSchema, ObjectItemSchema -from pipeline.component_framework.component import Component - from pipeline_plugins.components.collections.sites.open.monitor import MonitorBaseService __group_name__ = _("监控平台(Monitor)") diff --git a/pipeline_plugins/components/collections/sites/open/monitor/base.py b/pipeline_plugins/components/collections/sites/open/monitor/base.py index aa06985350..2f88844cb7 100644 --- a/pipeline_plugins/components/collections/sites/open/monitor/base.py +++ b/pipeline_plugins/components/collections/sites/open/monitor/base.py @@ -3,7 +3,7 @@ from functools import partial from django.conf import settings -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.activity import Service from pipeline.core.flow.io import StringItemSchema @@ -114,9 +114,15 @@ def send_request(self, request_body, data, client): def outputs_format(self): return [ self.OutputItem( - name=_("屏蔽Id"), key="shield_id", type="string", schema=StringItemSchema(description=_("创建的告警屏蔽 ID")) + name=_("屏蔽Id"), + key="shield_id", + type="string", + schema=StringItemSchema(description=_("创建的告警屏蔽 ID")), ), self.OutputItem( - name=_("详情"), key="message", type="string", schema=StringItemSchema(description=_("创建的告警屏蔽详情")) + name=_("详情"), + key="message", + type="string", + schema=StringItemSchema(description=_("创建的告警屏蔽详情")), ), ] diff --git a/pipeline_plugins/components/collections/sites/open/nodeman/base.py b/pipeline_plugins/components/collections/sites/open/nodeman/base.py index 82b8059561..ffcd5fb5db 100644 --- a/pipeline_plugins/components/collections/sites/open/nodeman/base.py +++ b/pipeline_plugins/components/collections/sites/open/nodeman/base.py @@ -17,7 +17,7 @@ from bkcrypto.asymmetric.interceptors import BaseAsymmetricInterceptor from bkcrypto.constants import AsymmetricCipherType from bkcrypto.contrib.django.ciphers import get_asymmetric_cipher -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.flow.activity import Service, StaticIntervalGenerator from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema @@ -346,7 +346,8 @@ def inputs_format(self): "nodeman_ap_id": StringItemSchema(description=_("接入点 ID")), "nodeman_op_type": StringItemSchema( description=_( - "任务操作类型,可以是 INSTALL(安装)、 REINSTALL(重装)、" " UNINSTALL (卸载)、 REMOVE (移除)或 UPGRADE (升级)" + "任务操作类型,可以是 INSTALL(安装)、 REINSTALL(重装)、" + " UNINSTALL (卸载)、 REMOVE (移除)或 UPGRADE (升级)" ) ), "nodeman_hosts": ArrayItemSchema( @@ -357,14 +358,22 @@ def inputs_format(self): "nodeman_bk_cloud_id": StringItemSchema(description=_("管控区域ID")), "nodeman_ap_id": StringItemSchema(description=_("接入点")), "inner_ip": StringItemSchema(description=_("内网 IP")), - "login_ip": StringItemSchema(description=_("主机登录 IP,可以为空,适配复杂网络时填写")), - "data_ip": StringItemSchema(description=_("主机数据 IP,可以为空,适配复杂网络时填写")), + "login_ip": StringItemSchema( + description=_("主机登录 IP,可以为空,适配复杂网络时填写") + ), + "data_ip": StringItemSchema( + description=_("主机数据 IP,可以为空,适配复杂网络时填写") + ), "outer_ip": StringItemSchema(description=_("外网 IP, 可以为空")), - "os_type": StringItemSchema(description=_("操作系统类型,可以是 LINUX, WINDOWS, 或 AIX")), + "os_type": StringItemSchema( + description=_("操作系统类型,可以是 LINUX, WINDOWS, 或 AIX") + ), "port": StringItemSchema(description=_("端口号")), "account": StringItemSchema(description=_("登录帐号")), "auth_type": StringItemSchema(description=_("认证方式,可以是 PASSWORD 或 KEY")), - "auth_key": StringItemSchema(description=_("认证密钥,根据认证方式,是登录密码或者登陆密钥")), + "auth_key": StringItemSchema( + description=_("认证密钥,根据认证方式,是登录密码或者登陆密钥") + ), }, ), ), diff --git a/pipeline_plugins/components/collections/sites/open/nodeman/create_task/legacy.py b/pipeline_plugins/components/collections/sites/open/nodeman/create_task/legacy.py index 503aa4cc4d..91237ae7ab 100644 --- a/pipeline_plugins/components/collections/sites/open/nodeman/create_task/legacy.py +++ b/pipeline_plugins/components/collections/sites/open/nodeman/create_task/legacy.py @@ -14,7 +14,7 @@ import base64 import rsa -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.activity import Service, StaticIntervalGenerator from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema @@ -189,20 +189,32 @@ def schedule(self, data, parent_data, callback_data=None): def outputs_format(self): return [ self.OutputItem( - name=_("任务 ID"), key="job_id", type="int", schema=IntItemSchema(description=_("提交的任务的 job_id")), + name=_("任务 ID"), + key="job_id", + type="int", + schema=IntItemSchema(description=_("提交的任务的 job_id")), ), self.OutputItem( - name=_("安装成功个数"), key="success_num", type="int", schema=IntItemSchema(description=_("任务中安装成功的机器个数")), + name=_("安装成功个数"), + key="success_num", + type="int", + schema=IntItemSchema(description=_("任务中安装成功的机器个数")), ), self.OutputItem( - name=_("安装失败个数"), key="fail_num", type="int", schema=IntItemSchema(description=_("任务中安装失败的机器个数")), + name=_("安装失败个数"), + key="fail_num", + type="int", + schema=IntItemSchema(description=_("任务中安装失败的机器个数")), ), ] def inputs_format(self): return [ self.InputItem( - name=_("业务 ID"), key="biz_cc_id", type="int", schema=IntItemSchema(description=_("当前操作所属的 CMDB 业务 ID")), + name=_("业务 ID"), + key="biz_cc_id", + type="int", + schema=IntItemSchema(description=_("当前操作所属的 CMDB 业务 ID")), ), self.InputItem( name=_("管控区域 ID"), @@ -215,7 +227,10 @@ def inputs_format(self): key="nodeman_node_type", type="string", schema=StringItemSchema( - description=_("节点类型,可以是 AGENT(表示直连区域安装 Agent)、 " "PROXY(表示安装 Proxy) 或 PAGENT(表示直连区域安装 Agent)") + description=_( + "节点类型,可以是 AGENT(表示直连区域安装 Agent)、 " + "PROXY(表示安装 Proxy) 或 PAGENT(表示直连区域安装 Agent)" + ) ), ), self.InputItem( @@ -224,7 +239,8 @@ def inputs_format(self): type="string", schema=StringItemSchema( description=_( - "任务操作类型,可以是 INSTALL(安装)、 REINSTALL(重装)、" " UNINSTALL (卸载)、 REMOVE (移除)或 UPGRADE (升级)" + "任务操作类型,可以是 INSTALL(安装)、 REINSTALL(重装)、" + " UNINSTALL (卸载)、 REMOVE (移除)或 UPGRADE (升级)" ) ), ), @@ -243,12 +259,16 @@ def inputs_format(self): "cascade_ip": StringItemSchema(description=_("级联 IP, 可以为空,安装 PROXY 时必填")), "os_type": StringItemSchema(description=_("操作系统类型,可以是 LINUX, WINDOWS, 或 AIX")), "has_cygwin": StringItemSchema( - description=_("是否安装了 cygwin,True:表示已安装," "False:表示未安装, windows 操作系统时选填") + description=_( + "是否安装了 cygwin,True:表示已安装," "False:表示未安装, windows 操作系统时选填" + ) ), "port": StringItemSchema(description=_("端口号")), "account": StringItemSchema(description=_("登录帐号")), "auth_type": StringItemSchema(description=_("认证方式,可以是 PASSWORD 或 KEY")), - "auth_key": StringItemSchema(description=_("认证密钥,根据认证方式,是登录密码或者登陆密钥")), + "auth_key": StringItemSchema( + description=_("认证密钥,根据认证方式,是登录密码或者登陆密钥") + ), }, ), ), diff --git a/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v2_0.py b/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v2_0.py index b4aac307aa..e591e41135 100644 --- a/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v2_0.py +++ b/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v2_0.py @@ -12,7 +12,7 @@ """ import itertools -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema @@ -152,7 +152,9 @@ def execute(self, data, parent_data): try: one["bk_host_id"] = bk_host_id_dict[inner_ip] except KeyError: - data.set_outputs("ex_data", _("获取bk_host_id失败:{},请确认管控区域是否正确".format(inner_ip))) + data.set_outputs( + "ex_data", _("获取bk_host_id失败:{},请确认管控区域是否正确".format(inner_ip)) + ) return False # 组装其它可选参数, ip数量需要与inner_ip一一对应 @@ -165,7 +167,10 @@ def execute(self, data, parent_data): if len(others_ip_list) == len(inner_ip_list): one[ip_type] = others_ip_list[index] else: - data.set_outputs("ex_data", _("获取{}的{}失败,请确认是否与inner_ip一一对应".format(inner_ip, ip_type))) + data.set_outputs( + "ex_data", + _("获取{}的{}失败,请确认是否与inner_ip一一对应".format(inner_ip, ip_type)), + ) return False one.update(base_params) @@ -216,7 +221,8 @@ def inputs_format(self): "nodeman_ap_id": StringItemSchema(description=_("接入点 ID")), "nodeman_op_type": StringItemSchema( description=_( - "任务操作类型,可以是 INSTALL(安装)、 REINSTALL(重装)、" " UNINSTALL (卸载)、 REMOVE (移除)或 UPGRADE (升级)" + "任务操作类型,可以是 INSTALL(安装)、 REINSTALL(重装)、" + " UNINSTALL (卸载)、 REMOVE (移除)或 UPGRADE (升级)" ) ), "nodeman_ip_str": StringItemSchema(description=_("IP(升级,卸载,移除时需要)")), @@ -226,14 +232,22 @@ def inputs_format(self): description=_("主机相关信息"), property_schemas={ "inner_ip": StringItemSchema(description=_("内网 IP")), - "login_ip": StringItemSchema(description=_("主机登录 IP,可以为空,适配复杂网络时填写")), - "data_ip": StringItemSchema(description=_("主机数据 IP,可以为空,适配复杂网络时填写")), + "login_ip": StringItemSchema( + description=_("主机登录 IP,可以为空,适配复杂网络时填写") + ), + "data_ip": StringItemSchema( + description=_("主机数据 IP,可以为空,适配复杂网络时填写") + ), "outer_ip": StringItemSchema(description=_("外网 IP, 可以为空")), - "os_type": StringItemSchema(description=_("操作系统类型,可以是 LINUX, WINDOWS, 或 AIX")), + "os_type": StringItemSchema( + description=_("操作系统类型,可以是 LINUX, WINDOWS, 或 AIX") + ), "port": StringItemSchema(description=_("端口号")), "account": StringItemSchema(description=_("登录帐号")), "auth_type": StringItemSchema(description=_("认证方式,可以是 PASSWORD 或 KEY")), - "auth_key": StringItemSchema(description=_("认证密钥,根据认证方式,是登录密码或者登陆密钥")), + "auth_key": StringItemSchema( + description=_("认证密钥,根据认证方式,是登录密码或者登陆密钥") + ), }, ), ), diff --git a/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v3_0.py b/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v3_0.py index 518ed9ff03..d01498d1a3 100644 --- a/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v3_0.py +++ b/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v3_0.py @@ -12,7 +12,7 @@ """ import itertools -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from api.collections.nodeman import BKNodeManClient @@ -155,7 +155,9 @@ def execute(self, data, parent_data): try: one["bk_host_id"] = bk_host_id_dict[inner_ip] except KeyError: - data.set_outputs("ex_data", _("获取bk_host_id失败:{},请确认管控区域是否正确".format(inner_ip))) + data.set_outputs( + "ex_data", _("获取bk_host_id失败:{},请确认管控区域是否正确".format(inner_ip)) + ) return False # 组装其它可选参数, ip数量需要与inner_ip一一对应 @@ -168,7 +170,10 @@ def execute(self, data, parent_data): if len(others_ip_list) == len(inner_ip_list): one[ip_type] = others_ip_list[index] else: - data.set_outputs("ex_data", _("获取{}的{}失败,请确认是否与inner_ip一一对应".format(inner_ip, ip_type))) + data.set_outputs( + "ex_data", + _("获取{}的{}失败,请确认是否与inner_ip一一对应".format(inner_ip, ip_type)), + ) return False one.update(base_params) row_host_params_list.append(one) diff --git a/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v4_0.py b/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v4_0.py index a8a67c8fa9..800197433c 100644 --- a/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v4_0.py +++ b/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v4_0.py @@ -12,7 +12,7 @@ """ from copy import deepcopy -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from api.collections.nodeman import BKNodeManClient @@ -174,7 +174,9 @@ def execute(self, data, parent_data): try: row_host_info["bk_host_id"] = bk_host_id_dict[inner_ip] except KeyError: - data.set_outputs("ex_data", _("获取bk_host_id失败:{},请确认管控区域是否正确".format(inner_ip))) + data.set_outputs( + "ex_data", _("获取bk_host_id失败:{},请确认管控区域是否正确".format(inner_ip)) + ) return False # 组装其它可选参数, ip数量需要与inner_ip一一对应 @@ -187,7 +189,10 @@ def execute(self, data, parent_data): if len(others_ip_list) == len(inner_ip_list): row_host_info[ip_type] = others_ip_list[index] else: - data.set_outputs("ex_data", _("获取{}的{}失败,请确认是否与inner_ip一一对应".format(inner_ip, ip_type))) + data.set_outputs( + "ex_data", + _("获取{}的{}失败,请确认是否与inner_ip一一对应".format(inner_ip, ip_type)), + ) return False row_host_params_list.append(row_host_info) @@ -215,4 +220,8 @@ class NodemanCreateTaskComponent(Component): bound_service = NodemanCreateTaskService form = "%scomponents/atoms/nodeman/create_task/v4_0.js" % settings.STATIC_URL version = VERSION - desc = _("v4.0版本 安装/重装操作新增表单项是否安装最新版本插件 \n" "卸载AGENT操作参数和重装AGENT保持一致 \n" "移除操作下线") + desc = _( + "v4.0版本 安装/重装操作新增表单项是否安装最新版本插件 \n" + "卸载AGENT操作参数和重装AGENT保持一致 \n" + "移除操作下线" + ) diff --git a/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v5_0.py b/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v5_0.py index ad8d448e0e..0d9ddc725a 100644 --- a/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v5_0.py +++ b/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v5_0.py @@ -12,7 +12,7 @@ """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from gcloud.conf import settings diff --git a/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v6_0.py b/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v6_0.py index 61a91a2220..28f22451ff 100644 --- a/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v6_0.py +++ b/pipeline_plugins/components/collections/sites/open/nodeman/create_task/v6_0.py @@ -12,7 +12,7 @@ """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from gcloud.conf import settings diff --git a/pipeline_plugins/components/collections/sites/open/nodeman/plugin_operate/v1_0.py b/pipeline_plugins/components/collections/sites/open/nodeman/plugin_operate/v1_0.py index 6c21b31aa9..8e25692ca6 100644 --- a/pipeline_plugins/components/collections/sites/open/nodeman/plugin_operate/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/nodeman/plugin_operate/v1_0.py @@ -10,7 +10,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. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema @@ -29,7 +29,10 @@ class NodemanPluginOperateService(NodeManBaseService, NodemanPluginIPMixin): def inputs_format(self): return [ self.InputItem( - name=_("业务 ID"), key="bk_biz_id", type="int", schema=IntItemSchema(description=_("当前操作所属的 CMDB 业务 ID")), + name=_("业务 ID"), + key="bk_biz_id", + type="int", + schema=IntItemSchema(description=_("当前操作所属的 CMDB 业务 ID")), ), self.InputItem( name=_("插件操作信息"), @@ -92,7 +95,9 @@ def execute(self, data, parent_data): ip_str = host_info.get("nodeman_host_ip", "") host_result = self.get_host_list(executor, self.logger, bk_biz_id, ip_str, bk_cloud_id) if not host_result["result"]: - data.set_outputs("ex_data", _("获取bk_host_id失败:{},请确认管控区域是否正确".format(host_result["message"]))) + data.set_outputs( + "ex_data", _("获取bk_host_id失败:{},请确认管控区域是否正确".format(host_result["message"])) + ) return False host = [int(host_id) for host_id in host_result["data"]] else: diff --git a/pipeline_plugins/components/collections/sites/open/nodeman/plugin_operate/v2_0.py b/pipeline_plugins/components/collections/sites/open/nodeman/plugin_operate/v2_0.py index 92648cd31e..2e1131ab94 100644 --- a/pipeline_plugins/components/collections/sites/open/nodeman/plugin_operate/v2_0.py +++ b/pipeline_plugins/components/collections/sites/open/nodeman/plugin_operate/v2_0.py @@ -10,7 +10,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. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow.io import ArrayItemSchema, IntItemSchema, ObjectItemSchema, StringItemSchema @@ -29,7 +29,10 @@ class NodemanPluginOperateService(NodeManBaseService, NodemanPluginIPMixin): def inputs_format(self): return [ self.InputItem( - name=_("业务 ID"), key="bk_biz_id", type="int", schema=IntItemSchema(description=_("当前操作所属的 CMDB 业务 ID")), + name=_("业务 ID"), + key="bk_biz_id", + type="int", + schema=IntItemSchema(description=_("当前操作所属的 CMDB 业务 ID")), ), self.InputItem( name=_("插件操作信息"), @@ -82,7 +85,9 @@ def execute(self, data, parent_data): ip_str = data.inputs.nodeman_host_ip host_result = self.get_host_list(executor, self.logger, bk_biz_id, ip_str, bk_cloud_id) if not host_result["result"]: - data.set_outputs("ex_data", _("获取bk_host_id失败:{},请确认管控区域是否正确".format(host_result["message"]))) + data.set_outputs( + "ex_data", _("获取bk_host_id失败:{},请确认管控区域是否正确".format(host_result["message"])) + ) return False host = [int(host_id) for host_id in host_result["data"]] diff --git a/pipeline_plugins/components/collections/sites/open/wechat_work/wechat_work_send_message/v1_0.py b/pipeline_plugins/components/collections/sites/open/wechat_work/wechat_work_send_message/v1_0.py index 3800a64e01..2866e08bb4 100644 --- a/pipeline_plugins/components/collections/sites/open/wechat_work/wechat_work_send_message/v1_0.py +++ b/pipeline_plugins/components/collections/sites/open/wechat_work/wechat_work_send_message/v1_0.py @@ -14,7 +14,7 @@ import traceback import requests -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.conf import settings from pipeline.core.flow.activity import Service @@ -38,13 +38,18 @@ def inputs_format(self): schema=StringItemSchema(description=_("通过在群里@企业微信机器人获取,多个用换行分隔")), ), self.InputItem( - name=_("消息内容"), key="message_content", type="string", schema=StringItemSchema(description=_("消息内容")), + name=_("消息内容"), + key="message_content", + type="string", + schema=StringItemSchema(description=_("消息内容")), ), self.InputItem( name=_("提醒人"), key="wechat_work_mentioned_members", type="string", - schema=StringItemSchema(description=_("提醒群指定成员(@某个成员),多个成员用 `,` 分隔,@all表示提醒所有人")), + schema=StringItemSchema( + description=_("提醒群指定成员(@某个成员),多个成员用 `,` 分隔,@all表示提醒所有人") + ), ), self.InputItem( name=_("消息格式"), @@ -137,4 +142,7 @@ class WechatWorkSendMessageComponent(Component): form = "%scomponents/atoms/wechat_work/wechat_work_send_message/v1_0.js" % settings.STATIC_URL version = "1.0" is_default_version = True - desc = _("1.部署环境与企业微信服务器网络必须联通 " "2.通过企业微信机器人获取会话 ID,可参考https://open.work.weixin.qq.com/api/doc/90000/90136/91770") + desc = _( + "1.部署环境与企业微信服务器网络必须联通 " + "2.通过企业微信机器人获取会话 ID,可参考https://open.work.weixin.qq.com/api/doc/90000/90136/91770" + ) diff --git a/pipeline_plugins/components/collections/sites/open/wechat_work/wechat_work_send_message/v2_0.py b/pipeline_plugins/components/collections/sites/open/wechat_work/wechat_work_send_message/v2_0.py index 07cb444d55..9385f3708e 100644 --- a/pipeline_plugins/components/collections/sites/open/wechat_work/wechat_work_send_message/v2_0.py +++ b/pipeline_plugins/components/collections/sites/open/wechat_work/wechat_work_send_message/v2_0.py @@ -11,7 +11,7 @@ specific language governing permissions and limitations under the License. """ -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.conf import settings diff --git a/pipeline_plugins/components/collections/subprocess_plugin/v1_0_0.py b/pipeline_plugins/components/collections/subprocess_plugin/v1_0_0.py index d9ce575e04..f21f36000a 100644 --- a/pipeline_plugins/components/collections/subprocess_plugin/v1_0_0.py +++ b/pipeline_plugins/components/collections/subprocess_plugin/v1_0_0.py @@ -20,7 +20,7 @@ from bamboo_engine.template import Template from django.conf import settings from django.db import transaction -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.component_framework.component import Component from pipeline.core.flow import Service from pipeline.core.flow.io import IntItemSchema, StringItemSchema diff --git a/pipeline_plugins/components/query/sites/open/cc.py b/pipeline_plugins/components/query/sites/open/cc.py index 518027ea9b..faea7b74b9 100644 --- a/pipeline_plugins/components/query/sites/open/cc.py +++ b/pipeline_plugins/components/query/sites/open/cc.py @@ -16,7 +16,7 @@ from django.http import JsonResponse from django.urls import path, re_path -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from iam.contrib.http import HTTP_AUTH_FORBIDDEN_CODE from iam.exceptions import RawAuthFailedException diff --git a/pipeline_plugins/components/query/sites/open/file_upload.py b/pipeline_plugins/components/query/sites/open/file_upload.py index bb3b843ae5..d32bb9cbb5 100644 --- a/pipeline_plugins/components/query/sites/open/file_upload.py +++ b/pipeline_plugins/components/query/sites/open/file_upload.py @@ -15,7 +15,7 @@ from django.http import JsonResponse from django.urls import re_path -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from iam import Action, Subject from iam.shortcuts import allow_or_raise_auth_failed diff --git a/pipeline_plugins/components/query/sites/open/job.py b/pipeline_plugins/components/query/sites/open/job.py index 6318acf851..ea210f9d12 100644 --- a/pipeline_plugins/components/query/sites/open/job.py +++ b/pipeline_plugins/components/query/sites/open/job.py @@ -16,7 +16,7 @@ from django.http import JsonResponse from django.urls import re_path -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from api.utils.request import batch_request from gcloud.conf import settings diff --git a/pipeline_plugins/components/query/sites/open/monitor.py b/pipeline_plugins/components/query/sites/open/monitor.py index 7b403d4cff..2bab82c4ab 100644 --- a/pipeline_plugins/components/query/sites/open/monitor.py +++ b/pipeline_plugins/components/query/sites/open/monitor.py @@ -4,7 +4,7 @@ from django.http import JsonResponse from django.urls import re_path -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from api import BKMonitorClient from gcloud.iam_auth.utils import check_and_raise_raw_auth_fail_exception diff --git a/pipeline_plugins/components/query/sites/open/nodeman.py b/pipeline_plugins/components/query/sites/open/nodeman.py index f96838acd0..f07ea5bb66 100644 --- a/pipeline_plugins/components/query/sites/open/nodeman.py +++ b/pipeline_plugins/components/query/sites/open/nodeman.py @@ -15,7 +15,7 @@ from django.http import JsonResponse from django.urls import re_path -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from api.collections.nodeman import BKNodeManClient from gcloud.iam_auth.utils import check_and_raise_raw_auth_fail_exception diff --git a/pipeline_plugins/components/utils/common.py b/pipeline_plugins/components/utils/common.py index b585e65fa5..241b9652cf 100644 --- a/pipeline_plugins/components/utils/common.py +++ b/pipeline_plugins/components/utils/common.py @@ -17,7 +17,7 @@ import typing from copy import deepcopy -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from api.utils.thread import ThreadPool @@ -70,7 +70,9 @@ def chunk_table_data(column_dict, break_line): multiple_keys.append(key) value = value.split(break_line) if len(value) != count and count != 1: - message = _(f"非法请求: [单行自动扩展]中, [{value}] 按分隔符分割后的行数不一致, 请修复后重试 | chunk_table_data") + message = _( + f"非法请求: [单行自动扩展]中, [{value}] 按分隔符分割后的行数不一致, 请修复后重试 | chunk_table_data" + ) logger.error(message) return {"result": False, "message": message, "data": []} count = len(value) diff --git a/pipeline_plugins/components/utils/sites/open/utils.py b/pipeline_plugins/components/utils/sites/open/utils.py index cd190b1473..99a9a55a3f 100644 --- a/pipeline_plugins/components/utils/sites/open/utils.py +++ b/pipeline_plugins/components/utils/sites/open/utils.py @@ -16,7 +16,7 @@ from collections import Counter from cryptography.fernet import Fernet -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ import env from gcloud.conf import settings @@ -126,7 +126,9 @@ def get_ipv4_info_list(username, biz_cc_id, supplier_account, ipv4_list): for ip_info in ipv4_info_list: ip_result.append( { - "InnerIP": ip_info["host"]["bk_host_innerip"], # 即使多个host命中,也都是同一个主机id,这里以第一个合法host为标识 + "InnerIP": ip_info["host"][ + "bk_host_innerip" + ], # 即使多个host命中,也都是同一个主机id,这里以第一个合法host为标识 "HostID": ip_info["host"]["bk_host_id"], "Source": ip_info["host"].get("bk_cloud_id", -1), "Sets": ip_info["set"], @@ -168,7 +170,9 @@ def get_ipv4_info_list_with_cloud_id(username, biz_cc_id, supplier_account, ipv4 for item in ipv4_info_with_cloud_valid: ip_result.append( { - "InnerIP": item["host"]["bk_host_innerip"], # 即使多个host命中,也都是同一个主机id,这里以第一个合法host为标识 + "InnerIP": item["host"][ + "bk_host_innerip" + ], # 即使多个host命中,也都是同一个主机id,这里以第一个合法host为标识 "HostID": item["host"]["bk_host_id"], "Source": item["host"].get("bk_cloud_id", -1), "Sets": item["set"], @@ -225,7 +229,9 @@ def get_ipv6_info_list_with_cloud_id(username, biz_cc_id, supplier_account, ipv6 for item in ipv6_info_with_cloud_valid: ip_result.append( { - "InnerIP": item["host"]["bk_host_innerip_v6"], # 即使多个host命中,也都是同一个主机id,这里以第一个合法host为标识 + "InnerIP": item["host"][ + "bk_host_innerip_v6" + ], # 即使多个host命中,也都是同一个主机id,这里以第一个合法host为标识 "HostID": item["host"]["bk_host_id"], "Source": item["host"].get("bk_cloud_id", -1), "Sets": item["set"], @@ -536,7 +542,11 @@ def get_repeat_ip(ip_list): repeat_ip_detail.setdefault(ip_info["ip"], []).append(ip_info["bk_cloud_id"]) return ",".join( - ["ip: {} 管控区域{}".format(repeat_ip, value) for repeat_ip, value in repeat_ip_detail.items() if len(value) > 0] + [ + "ip: {} 管控区域{}".format(repeat_ip, value) + for repeat_ip, value in repeat_ip_detail.items() + if len(value) > 0 + ] ) @@ -594,7 +604,9 @@ def get_biz_ip_from_frontend_hybrid(executor, ip_str, biz_cc_id, data, ignore_ex # 这种情况应该是存在一个ip下有多个管控区域的情况 if not ignore_ex_data: repeat_err_msg = get_repeat_ip(ip_list) - data.outputs.ex_data = "IP在多个管控区域下重复,建议输入管控区域:ip确定目标主机,详情: {}".format(repeat_err_msg) + data.outputs.ex_data = "IP在多个管控区域下重复,建议输入管控区域:ip确定目标主机,详情: {}".format( + repeat_err_msg + ) return False, [] if not ip_list: if not ignore_ex_data: diff --git a/pipeline_plugins/variables/collections/bk_manage_user_selector.py b/pipeline_plugins/variables/collections/bk_manage_user_selector.py index a484ed3e7d..0881476fc0 100644 --- a/pipeline_plugins/variables/collections/bk_manage_user_selector.py +++ b/pipeline_plugins/variables/collections/bk_manage_user_selector.py @@ -14,13 +14,12 @@ import logging from typing import List -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.conf import settings from pipeline.core.data.var import LazyVariable from gcloud.constants import Type -from pipeline_plugins.variables.base import SelfExplainVariable, FieldExplain - +from pipeline_plugins.variables.base import FieldExplain, SelfExplainVariable logger = logging.getLogger("root") diff --git a/pipeline_plugins/variables/collections/common.py b/pipeline_plugins/variables/collections/common.py index 71d2447f8a..7b1764a2d6 100644 --- a/pipeline_plugins/variables/collections/common.py +++ b/pipeline_plugins/variables/collections/common.py @@ -18,7 +18,7 @@ import pytz from django.conf import settings -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.data.var import LazyVariable, RegisterVariableMeta, SpliceVariable from pipeline.core.flow.io import IntItemSchema, StringItemSchema diff --git a/pipeline_plugins/variables/collections/datatable.py b/pipeline_plugins/variables/collections/datatable.py index c68c7a9a11..0f14ad8793 100644 --- a/pipeline_plugins/variables/collections/datatable.py +++ b/pipeline_plugins/variables/collections/datatable.py @@ -14,7 +14,7 @@ import logging from django.conf import settings -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.data.var import LazyVariable from pipeline.core.flow.io import StringItemSchema diff --git a/pipeline_plugins/variables/collections/sites/open/cc.py b/pipeline_plugins/variables/collections/sites/open/cc.py index b7c5f8ee09..d2b890778a 100644 --- a/pipeline_plugins/variables/collections/sites/open/cc.py +++ b/pipeline_plugins/variables/collections/sites/open/cc.py @@ -17,7 +17,7 @@ from django.conf import settings from django.contrib.admin.utils import flatten -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.data.var import LazyVariable from gcloud.conf import settings as gcloud_settings @@ -222,8 +222,16 @@ def _self_explain(cls, **kwargs) -> List[FieldExplain]: fields = [ FieldExplain(key="${KEY}", type=Type.OBJECT, description="集群资源筛选结果对象"), FieldExplain(key="${KEY.set_count}", type=Type.INT, description="新增集群数量"), - FieldExplain(key="${KEY._module}", type=Type.LIST, description="集群下的模块信息列表,元素类型为字典,键为模块名,值为模块下的主机列"), - FieldExplain(key="${KEY.flat__ip_list}", type=Type.STRING, description="本次操作创建的所有集群下的主机(去重后),用 ',' 连接"), + FieldExplain( + key="${KEY._module}", + type=Type.LIST, + description="集群下的模块信息列表,元素类型为字典,键为模块名,值为模块下的主机列", + ), + FieldExplain( + key="${KEY.flat__ip_list}", + type=Type.STRING, + description="本次操作创建的所有集群下的主机(去重后),用 ',' 连接", + ), FieldExplain( key="${KEY.flat__verbose_ip_list}", type=Type.STRING, diff --git a/pipeline_plugins/variables/collections/sites/open/cmdb/var_cmdb_set_module_ip_selector.py b/pipeline_plugins/variables/collections/sites/open/cmdb/var_cmdb_set_module_ip_selector.py index 3df33d7d70..4bb345d424 100644 --- a/pipeline_plugins/variables/collections/sites/open/cmdb/var_cmdb_set_module_ip_selector.py +++ b/pipeline_plugins/variables/collections/sites/open/cmdb/var_cmdb_set_module_ip_selector.py @@ -13,7 +13,7 @@ import logging from typing import List -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.data.var import LazyVariable from gcloud.conf import settings @@ -45,7 +45,9 @@ class SetModuleIpSelector(LazyVariable, SelfExplainVariable): type = "dynamic" tag = "set_module_ip_selector.ip_selector" form = "%svariables/cmdb/var_set_module_ip_selector.js" % settings.STATIC_URL - desc = _("集群模块IP选择器只能拉取使用服务模板创建的模块,不适用于自定义拓扑的场景,自定义拓扑请使用IP选择器,输出为选择IP以 ',' 分隔的字符串") + desc = _( + "集群模块IP选择器只能拉取使用服务模板创建的模块,不适用于自定义拓扑的场景,自定义拓扑请使用IP选择器,输出为选择IP以 ',' 分隔的字符串" + ) @classmethod def _self_explain(cls, **kwargs) -> List[FieldExplain]: diff --git a/pipeline_plugins/variables/collections/sites/open/cmdb/var_set_filter_selector.py b/pipeline_plugins/variables/collections/sites/open/cmdb/var_set_filter_selector.py index e35abc62c5..4a3f758a88 100644 --- a/pipeline_plugins/variables/collections/sites/open/cmdb/var_set_filter_selector.py +++ b/pipeline_plugins/variables/collections/sites/open/cmdb/var_set_filter_selector.py @@ -15,13 +15,13 @@ from functools import reduce from typing import List -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ +from pipeline.core.data.var import LazyVariable from gcloud.conf import settings from gcloud.constants import Type from gcloud.exceptions import ApiRequestError -from pipeline.core.data.var import LazyVariable -from pipeline_plugins.variables.base import SelfExplainVariable, FieldExplain +from pipeline_plugins.variables.base import FieldExplain, SelfExplainVariable logger = logging.getLogger("root") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER diff --git a/pipeline_plugins/variables/collections/sites/open/cmdb/var_set_group_selector.py b/pipeline_plugins/variables/collections/sites/open/cmdb/var_set_group_selector.py index 1e7e9e05c4..f88dcf5fce 100644 --- a/pipeline_plugins/variables/collections/sites/open/cmdb/var_set_group_selector.py +++ b/pipeline_plugins/variables/collections/sites/open/cmdb/var_set_group_selector.py @@ -14,15 +14,15 @@ import logging from typing import List -from gcloud.conf import settings -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ +from pipeline.core.data.var import LazyVariable from api.utils.request import batch_request +from gcloud.conf import settings from gcloud.constants import Type from gcloud.exceptions import ApiRequestError from gcloud.utils.handlers import handle_api_error -from pipeline.core.data.var import LazyVariable -from pipeline_plugins.variables.base import SelfExplainVariable, FieldExplain +from pipeline_plugins.variables.base import FieldExplain, SelfExplainVariable logger = logging.getLogger("root") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER diff --git a/pipeline_plugins/variables/collections/sites/open/cmdb/var_set_module_selector.py b/pipeline_plugins/variables/collections/sites/open/cmdb/var_set_module_selector.py index f801f7bc45..793ab12dfa 100644 --- a/pipeline_plugins/variables/collections/sites/open/cmdb/var_set_module_selector.py +++ b/pipeline_plugins/variables/collections/sites/open/cmdb/var_set_module_selector.py @@ -14,15 +14,15 @@ import logging from typing import List -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline.core.data.var import LazyVariable from api.utils.request import batch_request from gcloud.conf import settings -from gcloud.exceptions import ApiRequestError from gcloud.constants import Type +from gcloud.exceptions import ApiRequestError from gcloud.utils.handlers import handle_api_error -from pipeline_plugins.variables.base import SelfExplainVariable, FieldExplain +from pipeline_plugins.variables.base import FieldExplain, SelfExplainVariable logger = logging.getLogger("root") get_client_by_user = settings.ESB_GET_CLIENT_BY_USER diff --git a/pipeline_plugins/variables/collections/sites/open/ip_filter_base.py b/pipeline_plugins/variables/collections/sites/open/ip_filter_base.py index d1d954b3fd..8c195a0330 100644 --- a/pipeline_plugins/variables/collections/sites/open/ip_filter_base.py +++ b/pipeline_plugins/variables/collections/sites/open/ip_filter_base.py @@ -14,7 +14,7 @@ from abc import ABCMeta, abstractmethod from django.conf import settings -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from api.collections.nodeman import BKNodeManClient from gcloud.conf import settings as gcloud_settings diff --git a/pipeline_plugins/variables/query/sites/open/query.py b/pipeline_plugins/variables/query/sites/open/query.py index 2ef5ad2bff..843b481110 100644 --- a/pipeline_plugins/variables/query/sites/open/query.py +++ b/pipeline_plugins/variables/query/sites/open/query.py @@ -14,7 +14,7 @@ from django.http import JsonResponse from django.urls import re_path -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from api.utils.request import batch_request from gcloud.conf import settings diff --git a/pipeline_plugins/variables/query/sites/open/select.py b/pipeline_plugins/variables/query/sites/open/select.py index c18ee6cd05..48bf88216c 100644 --- a/pipeline_plugins/variables/query/sites/open/select.py +++ b/pipeline_plugins/variables/query/sites/open/select.py @@ -17,7 +17,7 @@ from django.conf import settings from django.http import JsonResponse from django.urls import re_path -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ logger = logging.getLogger("root") diff --git a/pipeline_web/core/abstract.py b/pipeline_web/core/abstract.py index 5af9e01c17..697c6eb7d6 100644 --- a/pipeline_web/core/abstract.py +++ b/pipeline_web/core/abstract.py @@ -12,19 +12,19 @@ """ from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class Node(models.Model): - node_id = models.CharField(_('节点ID'), max_length=32) - node_type = models.CharField(_('节点类型'), max_length=100) - create_time = models.DateTimeField(_('创建时间'), auto_now_add=True) - edit_time = models.DateTimeField(_('修改时间'), auto_now=True) + node_id = models.CharField(_("节点ID"), max_length=32) + node_type = models.CharField(_("节点类型"), max_length=100) + create_time = models.DateTimeField(_("创建时间"), auto_now_add=True) + edit_time = models.DateTimeField(_("修改时间"), auto_now=True) class Meta: # abstract would not be inherited automatically abstract = True - ordering = ['-id'] + ordering = ["-id"] class NodeAttr(object): @@ -44,10 +44,10 @@ def register_instance_attr(cls, attr_model): @classmethod def get_nodes_attr(cls, nodes, model_type): - node_attr_lib = cls.node_in_template_attr if model_type == 'template' else cls.node_in_instance_attr + node_attr_lib = cls.node_in_template_attr if model_type == "template" else cls.node_in_instance_attr for node in nodes: - if not hasattr(node, 'attrs'): - setattr(node, 'attrs', {}) + if not hasattr(node, "attrs"): + setattr(node, "attrs", {}) for attr, attr_model in node_attr_lib.items(): attr_model.objects.batch_update_nodes_attr(nodes, attr) diff --git a/pipeline_web/core/models.py b/pipeline_web/core/models.py index b65b8bc71c..a8f504de6c 100644 --- a/pipeline_web/core/models.py +++ b/pipeline_web/core/models.py @@ -13,11 +13,11 @@ from django.db import models, transaction from django.utils.timezone import now -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from pipeline_web.constants import PWE from pipeline_web.core.abstract import Node -from pipeline_web.core.signals import node_in_template_post_save, node_in_template_delete, node_in_instance_post_save +from pipeline_web.core.signals import node_in_instance_post_save, node_in_template_delete, node_in_template_post_save from pipeline_web.parser.format import get_all_nodes diff --git a/pipeline_web/label/models.py b/pipeline_web/label/models.py index 2804d41bfb..cc06321531 100644 --- a/pipeline_web/label/models.py +++ b/pipeline_web/label/models.py @@ -12,10 +12,10 @@ """ from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ -from pipeline_web.core.models import NodeInTemplateAttr, NodeInInstanceAttr from pipeline_web.core.abstract import NodeAttr +from pipeline_web.core.models import NodeInInstanceAttr, NodeInTemplateAttr class LabelGroup(models.Model): diff --git a/pipeline_web/plugin_management/models.py b/pipeline_web/plugin_management/models.py index ab8dd7a422..d6d14b7d00 100644 --- a/pipeline_web/plugin_management/models.py +++ b/pipeline_web/plugin_management/models.py @@ -13,7 +13,7 @@ from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class DeprecatedPluginManager(models.Manager): diff --git a/weixin/core/accounts.py b/weixin/core/accounts.py index d326322fa5..38ccfbb2b5 100644 --- a/weixin/core/accounts.py +++ b/weixin/core/accounts.py @@ -13,28 +13,29 @@ 微信账号体系相关的Account """ -import time +import logging import random -import urllib.request -import urllib.parse +import time import urllib.error -import logging +import urllib.parse +import urllib.request -from django.http import HttpResponseRedirect, HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.middleware.csrf import rotate_token -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from . import settings as weixin_settings -from .api import WeiXinApi, QyWeiXinApi +from .api import QyWeiXinApi, WeiXinApi from .models import BkWeixinUser -logger = logging.getLogger('root') +logger = logging.getLogger("root") class WeixinAccountSingleton(object): """ 单例基类 """ + _instance = None def __new__(cls, *args, **kwargs): @@ -48,8 +49,9 @@ class WeixinAccount(WeixinAccountSingleton): 微信账号体系相关的基类Account 提供通用的账号功能 """ + # 跳转到微信重定向链接 - WEIXIN_OAUTH_URL = 'https://open.weixin.qq.com/connect/oauth2/authorize' + WEIXIN_OAUTH_URL = "https://open.weixin.qq.com/connect/oauth2/authorize" def __init__(self): if weixin_settings.IS_QY_WEIXIN: @@ -62,8 +64,11 @@ def is_weixin_visit(request): """ 是否来自微信访问 """ - if weixin_settings.USE_WEIXIN and request.path.startswith(weixin_settings.WEIXIN_SITE_URL) and \ - request.get_host() == weixin_settings.WEIXIN_APP_EXTERNAL_HOST: + if ( + weixin_settings.USE_WEIXIN + and request.path.startswith(weixin_settings.WEIXIN_SITE_URL) + and request.get_host() == weixin_settings.WEIXIN_APP_EXTERNAL_HOST + ): return True return False @@ -71,25 +76,25 @@ def set_weixin_oauth_state(self, request, length=32): """ 生成随机的state,并存储到session中 """ - allowed_chars = 'abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ0123456789' - state = ''.join(random.choice(allowed_chars) for _ in range(length)) - request.session['WEIXIN_OAUTH_STATE'] = state - request.session['WEIXIN_OAUTH_STATE_TIMESTAMP'] = time.time() + allowed_chars = "abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ0123456789" + state = "".join(random.choice(allowed_chars) for _ in range(length)) + request.session["WEIXIN_OAUTH_STATE"] = state + request.session["WEIXIN_OAUTH_STATE_TIMESTAMP"] = time.time() return state - def get_oauth_redirect_url(self, callback_url, state='authenticated'): + def get_oauth_redirect_url(self, callback_url, state="authenticated"): """ 获取oauth访问链接 """ params = { - 'appid': weixin_settings.WEIXIN_APP_ID, - 'redirect_uri': callback_url, - 'response_type': 'code', - 'scope': weixin_settings.WEIXIN_SCOPE, - 'state': state + "appid": weixin_settings.WEIXIN_APP_ID, + "redirect_uri": callback_url, + "response_type": "code", + "scope": weixin_settings.WEIXIN_SCOPE, + "state": state, } params = urllib.parse.urlencode(params) - redirect_uri = '%s?%s#wechat_redirect' % (self.WEIXIN_OAUTH_URL, params) + redirect_uri = "%s?%s#wechat_redirect" % (self.WEIXIN_OAUTH_URL, params) return redirect_uri def redirect_weixin_login(self, request): @@ -98,7 +103,7 @@ def redirect_weixin_login(self, request): """ url = urllib.parse.urlparse(request.build_absolute_uri()) path = weixin_settings.WEIXIN_LOGIN_URL - query = urllib.parse.urlencode({'c_url': request.get_full_path()}) + query = urllib.parse.urlencode({"c_url": request.get_full_path()}) callback_url = urllib.parse.urlunsplit((url.scheme, url.netloc, path, query, url.fragment)) state = self.set_weixin_oauth_state(request) redirect_uri = self.get_oauth_redirect_url(callback_url, state) @@ -109,9 +114,9 @@ def verify_weixin_oauth_state(self, request, expires_in=60): 验证state是否正确,防止csrf攻击 """ try: - state = request.GET.get('state') - raw_state = request.session.get('WEIXIN_OAUTH_STATE') - raw_timestamp = request.session.get('WEIXIN_OAUTH_STATE_TIMESTAMP') + state = request.GET.get("state") + raw_state = request.session.get("WEIXIN_OAUTH_STATE") + raw_timestamp = request.session.get("WEIXIN_OAUTH_STATE_TIMESTAMP") # 验证state if not raw_state or raw_state != state: return False @@ -119,8 +124,8 @@ def verify_weixin_oauth_state(self, request, expires_in=60): if not raw_timestamp or time.time() - raw_timestamp > expires_in: return False # 验证成功后清空session - request.session['WEIXIN_OAUTH_STATE'] = None - request.session['WEIXIN_OAUTH_STATE_TIMESTAMP'] = None + request.session["WEIXIN_OAUTH_STATE"] = None + request.session["WEIXIN_OAUTH_STATE_TIMESTAMP"] = None return True except Exception as e: logger.exception(_("验证请求weixin code的 state参数出错: %s") % e) @@ -130,7 +135,7 @@ def verfiy_weixin_oauth_code(self, request): """ 验证Code有效性 """ - code = request.GET.get('code') + code = request.GET.get("code") is_ok, data = self.weixin_api.check_login_code(code) return is_ok, data @@ -138,8 +143,8 @@ def get_user_info(self, base_data): """ 根据access_token, userid获取用户信息 """ - userid = base_data.get('userid') - access_token = base_data.get('access_token') + userid = base_data.get("userid") + access_token = base_data.get("access_token") userinfo = self.weixin_api.get_user_info_for_account(access_token, userid) return userinfo @@ -147,7 +152,7 @@ def get_callback_url(self, request): """ 获取实际访问的URL """ - callback_url = request.GET.get('c_url') or weixin_settings.WEIXIN_SITE_URL + callback_url = request.GET.get("c_url") or weixin_settings.WEIXIN_SITE_URL return callback_url def login(self, request): @@ -169,12 +174,12 @@ def login(self, request): # 获取用户信息并设置用户 userinfo = self.get_user_info(base_data) - logger.info('get_user_info kwargs: %s, result: %s' % (base_data, userinfo)) - userid = userinfo.pop('userid') + logger.info("get_user_info kwargs: %s, result: %s" % (base_data, userinfo)) + userid = userinfo.pop("userid") user = BkWeixinUser.objects.get_update_or_create_user(userid, **userinfo) # 设置session - request.session['weixin_user_id'] = user.id - setattr(request, 'weixin_user', user) + request.session["weixin_user_id"] = user.id + setattr(request, "weixin_user", user) # need csrftoken rotate_token(request)