perf: 优化 HUAWEI 设备判断逻辑

pull/13092/head
Bai 2024-04-22 11:27:48 +08:00 committed by Bryan
parent 1ecf8534f6
commit ad0bc82539
2 changed files with 11 additions and 3 deletions

View File

@ -1,8 +1,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from assets.const import AllTypes
from assets.const import Protocol
from assets.const import AllTypes, Category, Protocol
from common.db.fields import JsonDictTextField
from common.db.models import JMSBaseModel
@ -119,6 +118,15 @@ class Platform(LabeledMixin, JMSBaseModel):
)
return linux.id
def is_huawei(self):
if self.category != Category.DEVICE:
return False
if 'huawei' in self.name.lower():
return True
if '华为' in self.name:
return True
return False
def __str__(self):
return self.name

View File

@ -125,7 +125,7 @@ class JMSInventory:
else:
host.update(self.make_account_ansible_vars(account, path_dir))
if "huawei" in platform.name.lower() and platform.category == Category.DEVICE.value:
if platform.is_huawei():
host['ansible_connection'] = 'network_cli'
host['ansible_network_os'] = 'asa'