mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 04:10:44 -03:30
Refactored get_conn_type() method to use Enum
This commit is contained in:
parent
45600d034d
commit
045785c36f
@ -3049,7 +3049,7 @@ class AWXReceptorJob:
|
||||
_kw = {}
|
||||
if self.work_type == 'ansible-runner':
|
||||
_kw['node'] = self.task.instance.execution_node
|
||||
use_stream_tls = True if get_conn_type(_kw['node'], receptor_ctl) == 2 else False
|
||||
use_stream_tls = get_conn_type(_kw['node'], receptor_ctl).name == "STREAMTLS"
|
||||
_kw['tlsclient'] = get_tls_client(use_stream_tls)
|
||||
|
||||
result = receptor_ctl.submit_work(worktype=self.work_type, payload=sockout.makefile('rb'), params=self.receptor_params, **_kw)
|
||||
|
||||
@ -4,12 +4,20 @@ import time
|
||||
|
||||
from receptorctl.socket_interface import ReceptorControl
|
||||
|
||||
from enum import Enum, unique
|
||||
|
||||
logger = logging.getLogger('awx.main.utils.receptor')
|
||||
|
||||
__RECEPTOR_CONF = '/etc/receptor/receptor.conf'
|
||||
|
||||
|
||||
@unique
|
||||
class ReceptorConnectionType(Enum):
|
||||
DATAGRAM = 0
|
||||
STREAM = 1
|
||||
STREAMTLS = 2
|
||||
|
||||
|
||||
def get_receptor_sockfile():
|
||||
with open(__RECEPTOR_CONF, 'r') as f:
|
||||
data = yaml.safe_load(f)
|
||||
@ -47,20 +55,15 @@ def get_receptor_ctl():
|
||||
|
||||
|
||||
def get_conn_type(node_name, receptor_ctl):
|
||||
"""
|
||||
ConnType 0: Datagram
|
||||
ConnType 1: Stream
|
||||
ConnType 2: StreamTLS
|
||||
"""
|
||||
all_nodes = receptor_ctl.simple_command("status").get('Advertisements', None)
|
||||
for node in all_nodes:
|
||||
if node.get('NodeID') == node_name:
|
||||
return node.get('ConnType')
|
||||
return ReceptorConnectionType(node.get('ConnType'))
|
||||
|
||||
|
||||
def worker_info(node_name, work_type='ansible-runner'):
|
||||
receptor_ctl = get_receptor_ctl()
|
||||
use_stream_tls = True if get_conn_type(node_name, receptor_ctl) == 2 else False
|
||||
use_stream_tls = get_conn_type(node_name, receptor_ctl).name == "STREAMTLS"
|
||||
transmit_start = time.time()
|
||||
error_list = []
|
||||
data = {'errors': error_list, 'transmit_timing': 0.0}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user