Obtain receptor sockfile from the receptor.conf file (#10932)

This commit is contained in:
Alan Rominger 2021-08-24 11:20:21 -04:00 committed by GitHub
parent 274e487a96
commit 42484cf98d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,8 +8,24 @@ from receptorctl.socket_interface import ReceptorControl
logger = logging.getLogger('awx.main.utils.receptor')
def get_receptor_sockfile():
receptor_conf = '/etc/receptor/receptor.conf'
with open(receptor_conf, 'r') as f:
data = yaml.safe_load(f)
for section in data:
for entry_name, entry_data in section.items():
if entry_name == 'control-service':
if 'filename' in entry_data:
return entry_data['filename']
else:
raise RuntimeError(f'Receptor conf {receptor_conf} control-service entry does not have a filename parameter')
else:
raise RuntimeError(f'Receptor conf {receptor_conf} does not have control-service entry needed to get sockfile')
def get_receptor_ctl():
return ReceptorControl('/var/run/receptor/receptor.sock')
receptor_sockfile = get_receptor_sockfile()
return ReceptorControl(receptor_sockfile)
def worker_info(node_name):