perf: 修改 port

pull/10049/head
ibuler 2023-03-23 14:11:26 +08:00
parent 72b731629e
commit f12e6af86e
2 changed files with 11 additions and 11 deletions

View File

@ -2,11 +2,10 @@
#
from django.utils.translation import ugettext_lazy as _
from orgs.mixins.models import OrgManager
from assets.models.platform import Platform
from assets.const import GATEWAY_NAME
from assets.models.platform import Platform
from common.utils import get_logger, lazyproperty
from orgs.mixins.models import OrgManager
from .asset.host import Host
logger = get_logger(__file__)
@ -57,6 +56,14 @@ class Gateway(Host):
account = self.select_account
return account.password if account else None
@lazyproperty
def port(self):
protocol = self.protocols.filter(name='ssh').first()
if protocol:
return protocol.port
else:
return '22'
@lazyproperty
def private_key(self):
account = self.select_account

View File

@ -101,15 +101,8 @@ class JMSInventory:
@staticmethod
def get_primary_protocol(protocols):
primary_protocol = [p for p in protocols if p.primary]
if len(primary_protocol) >= 1:
primary = primary_protocol[0]
elif protocols:
if protocols:
primary = protocols[0]
else:
primary = None
if primary:
protocol = primary.name
port = primary.port
else: