From cd866532daa10265be1e5742dd4d1a26ece6c317 Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 13 Feb 2023 15:04:45 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E5=8F=AF=E8=BF=9E=E6=8E=A5=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/api/node.py | 16 ++++++++-------- apps/assets/tasks/ping.py | 2 +- apps/ops/ansible/inventory.py | 5 ++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/assets/api/node.py b/apps/assets/api/node.py index bb81a3b45..e690b8ebf 100644 --- a/apps/assets/api/node.py +++ b/apps/assets/api/node.py @@ -1,24 +1,24 @@ # ~*~ coding: utf-8 ~*~ -from functools import partial from collections import namedtuple, defaultdict +from functools import partial from django.db.models.signals import m2m_changed from django.utils.translation import ugettext_lazy as _ from rest_framework import status -from rest_framework.response import Response from rest_framework.decorators import action from rest_framework.generics import get_object_or_404 +from rest_framework.response import Response from rest_framework.serializers import ValidationError from assets.models import Asset -from common.const.http import POST -from common.utils import get_logger from common.api import SuggestionMixin -from common.exceptions import SomeoneIsDoingThis +from common.const.http import POST from common.const.signals import PRE_REMOVE, POST_REMOVE +from common.exceptions import SomeoneIsDoingThis +from common.utils import get_logger from orgs.mixins import generics -from orgs.utils import current_org from orgs.mixins.api import OrgBulkModelViewSet +from orgs.utils import current_org from .. import serializers from ..models import Node from ..tasks import ( @@ -210,7 +210,7 @@ class NodeTaskCreateApi(generics.CreateAPIView): return if action == "refresh": - task = update_node_assets_hardware_info_manual.delay(node.id) + task = update_node_assets_hardware_info_manual(node.id) else: - task = test_node_assets_connectivity_manual.delay(node.id) + task = test_node_assets_connectivity_manual(node.id) self.set_serializer_data(serializer, task) diff --git a/apps/assets/tasks/ping.py b/apps/assets/tasks/ping.py index 882f5e5ef..973085db3 100644 --- a/apps/assets/tasks/ping.py +++ b/apps/assets/tasks/ping.py @@ -40,4 +40,4 @@ def test_node_assets_connectivity_manual(node_id): node = Node.objects.get(id=node_id) task_name = gettext_noop("Test if the assets under the node are connectable ") assets = node.get_all_assets() - return test_assets_connectivity_task.delay(*assets, task_name) + return test_assets_connectivity_task.delay(assets, task_name) diff --git a/apps/ops/ansible/inventory.py b/apps/ops/ansible/inventory.py index e83f50c41..da9e8b599 100644 --- a/apps/ops/ansible/inventory.py +++ b/apps/ops/ansible/inventory.py @@ -117,7 +117,10 @@ class JMSInventory: if host['jms_account'] and asset.platform.type == 'oracle': host['jms_account']['mode'] = 'sysdba' if account.privileged else None - ansible_config = dict(automation.ansible_config) + try: + ansible_config = dict(automation.ansible_config) + except Exception as e: + ansible_config = {} ansible_connection = ansible_config.get('ansible_connection', 'ssh') host.update(ansible_config)