mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
move host_status_counts logic into event model
This commit is contained in:
@@ -9,7 +9,7 @@ import operator
|
|||||||
import re
|
import re
|
||||||
import six
|
import six
|
||||||
import urllib
|
import urllib
|
||||||
from collections import defaultdict, OrderedDict
|
from collections import OrderedDict
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
# OAuth2
|
# OAuth2
|
||||||
@@ -1474,23 +1474,11 @@ class ProjectUpdateDetailSerializer(ProjectUpdateSerializer):
|
|||||||
|
|
||||||
def get_host_status_counts(self, obj):
|
def get_host_status_counts(self, obj):
|
||||||
try:
|
try:
|
||||||
event_data = obj.project_update_events.only('event_data').get(event='playbook_on_stats').event_data
|
counts = obj.project_update_events.only('event_data').get(event='playbook_on_stats').get_host_status_counts()
|
||||||
except ProjectUpdateEvent.DoesNotExist:
|
except ProjectUpdateEvent.DoesNotExist:
|
||||||
event_data = {}
|
counts = {}
|
||||||
|
|
||||||
host_status = {}
|
return counts
|
||||||
host_status_keys = ['skipped', 'ok', 'changed', 'failures', 'dark']
|
|
||||||
|
|
||||||
for key in host_status_keys:
|
|
||||||
for host in event_data.get(key, {}):
|
|
||||||
host_status[host] = key
|
|
||||||
|
|
||||||
host_status_counts = defaultdict(lambda: 0)
|
|
||||||
|
|
||||||
for value in host_status.values():
|
|
||||||
host_status_counts[value] += 1
|
|
||||||
|
|
||||||
return host_status_counts
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectUpdateListSerializer(ProjectUpdateSerializer, UnifiedJobListSerializer):
|
class ProjectUpdateListSerializer(ProjectUpdateSerializer, UnifiedJobListSerializer):
|
||||||
@@ -3271,23 +3259,11 @@ class JobDetailSerializer(JobSerializer):
|
|||||||
|
|
||||||
def get_host_status_counts(self, obj):
|
def get_host_status_counts(self, obj):
|
||||||
try:
|
try:
|
||||||
event_data = obj.job_events.only('event_data').get(event='playbook_on_stats').event_data
|
counts = obj.job_events.only('event_data').get(event='playbook_on_stats').get_host_status_counts()
|
||||||
except JobEvent.DoesNotExist:
|
except JobEvent.DoesNotExist:
|
||||||
event_data = {}
|
counts = {}
|
||||||
|
|
||||||
host_status = {}
|
return counts
|
||||||
host_status_keys = ['skipped', 'ok', 'changed', 'failures', 'dark']
|
|
||||||
|
|
||||||
for key in host_status_keys:
|
|
||||||
for host in event_data.get(key, {}):
|
|
||||||
host_status[host] = key
|
|
||||||
|
|
||||||
host_status_counts = defaultdict(lambda: 0)
|
|
||||||
|
|
||||||
for value in host_status.values():
|
|
||||||
host_status_counts[value] += 1
|
|
||||||
|
|
||||||
return host_status_counts
|
|
||||||
|
|
||||||
|
|
||||||
class JobCancelSerializer(BaseSerializer):
|
class JobCancelSerializer(BaseSerializer):
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models, DatabaseError
|
from django.db import models, DatabaseError
|
||||||
@@ -39,6 +40,21 @@ def sanitize_event_keys(kwargs, valid_keys):
|
|||||||
kwargs[key] = Truncator(kwargs[key]).chars(1024)
|
kwargs[key] = Truncator(kwargs[key]).chars(1024)
|
||||||
|
|
||||||
|
|
||||||
|
def create_host_status_counts(event_data):
|
||||||
|
host_status = {}
|
||||||
|
host_status_keys = ['skipped', 'ok', 'changed', 'failures', 'dark']
|
||||||
|
|
||||||
|
for key in host_status_keys:
|
||||||
|
for host in event_data.get(key, {}):
|
||||||
|
host_status[host] = key
|
||||||
|
|
||||||
|
host_status_counts = defaultdict(lambda: 0)
|
||||||
|
|
||||||
|
for value in host_status.values():
|
||||||
|
host_status_counts[value] += 1
|
||||||
|
|
||||||
|
return dict(host_status_counts)
|
||||||
|
|
||||||
|
|
||||||
class BasePlaybookEvent(CreatedModifiedModel):
|
class BasePlaybookEvent(CreatedModifiedModel):
|
||||||
'''
|
'''
|
||||||
@@ -194,6 +210,9 @@ class BasePlaybookEvent(CreatedModifiedModel):
|
|||||||
def event_level(self):
|
def event_level(self):
|
||||||
return self.LEVEL_FOR_EVENT.get(self.event, 0)
|
return self.LEVEL_FOR_EVENT.get(self.event, 0)
|
||||||
|
|
||||||
|
def get_host_status_counts(self):
|
||||||
|
return create_host_status_counts(getattr(self, 'event_data', {}))
|
||||||
|
|
||||||
def get_event_display2(self):
|
def get_event_display2(self):
|
||||||
msg = self.get_event_display()
|
msg = self.get_event_display()
|
||||||
if self.event == 'playbook_on_play_start':
|
if self.event == 'playbook_on_play_start':
|
||||||
|
|||||||
Reference in New Issue
Block a user