diff --git a/apps/assets/models/gateway.py b/apps/assets/models/gateway.py index d9d4d891b..0fc6626df 100644 --- a/apps/assets/models/gateway.py +++ b/apps/assets/models/gateway.py @@ -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 diff --git a/apps/ops/ansible/inventory.py b/apps/ops/ansible/inventory.py index fb143cda5..6abf6d18e 100644 --- a/apps/ops/ansible/inventory.py +++ b/apps/ops/ansible/inventory.py @@ -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: