mirror of
https://github.com/ansible/awx.git
synced 2026-02-27 15:58:45 -03:30
Merge pull request #4389 from chrismeyersfsu/fix-run_wsbroadcast_status_3_7_1
awx-manage run_wsbroadcast --status doesn't work in openshift
This commit is contained in:
@@ -37,7 +37,7 @@ def get_broadcast_hosts():
|
|||||||
.order_by('hostname') \
|
.order_by('hostname') \
|
||||||
.values('hostname', 'ip_address') \
|
.values('hostname', 'ip_address') \
|
||||||
.distinct()
|
.distinct()
|
||||||
return [i['ip_address'] or i['hostname'] for i in instances]
|
return {i['hostname']: i['ip_address'] or i['hostname'] for i in instances}
|
||||||
|
|
||||||
|
|
||||||
def get_local_host():
|
def get_local_host():
|
||||||
@@ -149,19 +149,33 @@ class BroadcastWebsocketTask(WebsocketTask):
|
|||||||
class BroadcastWebsocketManager(object):
|
class BroadcastWebsocketManager(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.event_loop = asyncio.get_event_loop()
|
self.event_loop = asyncio.get_event_loop()
|
||||||
|
'''
|
||||||
|
{
|
||||||
|
'hostname1': BroadcastWebsocketTask(),
|
||||||
|
'hostname2': BroadcastWebsocketTask(),
|
||||||
|
'hostname3': BroadcastWebsocketTask(),
|
||||||
|
}
|
||||||
|
'''
|
||||||
self.broadcast_tasks = dict()
|
self.broadcast_tasks = dict()
|
||||||
# parallel dict to broadcast_tasks that tracks stats
|
|
||||||
self.local_hostname = get_local_host()
|
self.local_hostname = get_local_host()
|
||||||
self.stats_mgr = BroadcastWebsocketStatsManager(self.event_loop, self.local_hostname)
|
self.stats_mgr = BroadcastWebsocketStatsManager(self.event_loop, self.local_hostname)
|
||||||
|
|
||||||
async def run_per_host_websocket(self):
|
async def run_per_host_websocket(self):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
future_remote_hosts = get_broadcast_hosts()
|
known_hosts = get_broadcast_hosts()
|
||||||
|
future_remote_hosts = known_hosts.keys()
|
||||||
current_remote_hosts = self.broadcast_tasks.keys()
|
current_remote_hosts = self.broadcast_tasks.keys()
|
||||||
deleted_remote_hosts = set(current_remote_hosts) - set(future_remote_hosts)
|
deleted_remote_hosts = set(current_remote_hosts) - set(future_remote_hosts)
|
||||||
new_remote_hosts = set(future_remote_hosts) - set(current_remote_hosts)
|
new_remote_hosts = set(future_remote_hosts) - set(current_remote_hosts)
|
||||||
|
|
||||||
|
remote_addresses = {k: v.remote_host for k, v in self.broadcast_tasks.items()}
|
||||||
|
for hostname, address in known_hosts.items():
|
||||||
|
if hostname in self.broadcast_tasks and \
|
||||||
|
address != remote_addresses[hostname]:
|
||||||
|
deleted_remote_hosts.add(hostname)
|
||||||
|
new_remote_hosts.add(hostname)
|
||||||
|
|
||||||
if deleted_remote_hosts:
|
if deleted_remote_hosts:
|
||||||
logger.warn(f"Removing {deleted_remote_hosts} from websocket broadcast list")
|
logger.warn(f"Removing {deleted_remote_hosts} from websocket broadcast list")
|
||||||
if new_remote_hosts:
|
if new_remote_hosts:
|
||||||
@@ -177,7 +191,7 @@ class BroadcastWebsocketManager(object):
|
|||||||
broadcast_task = BroadcastWebsocketTask(name=self.local_hostname,
|
broadcast_task = BroadcastWebsocketTask(name=self.local_hostname,
|
||||||
event_loop=self.event_loop,
|
event_loop=self.event_loop,
|
||||||
stats=stats,
|
stats=stats,
|
||||||
remote_host=h)
|
remote_host=known_hosts[h])
|
||||||
broadcast_task.start()
|
broadcast_task.start()
|
||||||
self.broadcast_tasks[h] = broadcast_task
|
self.broadcast_tasks[h] = broadcast_task
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user