Merge pull request #2444 from jakemcdermott/fix-2334

add host_status_counts to adhoc commands; fix status display for adhoc commands
This commit is contained in:
Jake McDermott
2018-07-09 12:08:25 -04:00
committed by GitHub
4 changed files with 77 additions and 49 deletions

View File

@@ -9,7 +9,7 @@ import operator
import re
import six
import urllib
from collections import defaultdict, OrderedDict
from collections import OrderedDict
from datetime import timedelta
# OAuth2
@@ -1477,23 +1477,11 @@ class ProjectUpdateDetailSerializer(ProjectUpdateSerializer):
def get_host_status_counts(self, obj):
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:
event_data = {}
counts = {}
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 host_status_counts
return counts
class ProjectUpdateListSerializer(ProjectUpdateSerializer, UnifiedJobListSerializer):
@@ -3274,23 +3262,11 @@ class JobDetailSerializer(JobSerializer):
def get_host_status_counts(self, obj):
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:
event_data = {}
counts = {}
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 host_status_counts
return counts
class JobCancelSerializer(BaseSerializer):
@@ -3470,6 +3446,25 @@ class AdHocCommandSerializer(UnifiedJobSerializer):
return vars_validate_or_raise(value)
class AdHocCommandDetailSerializer(AdHocCommandSerializer):
host_status_counts = serializers.SerializerMethodField(
help_text=_('A count of hosts uniquely assigned to each status.'),
)
class Meta:
model = AdHocCommand
fields = ('*', 'host_status_counts',)
def get_host_status_counts(self, obj):
try:
counts = obj.ad_hoc_command_events.only('event_data').get(event='playbook_on_stats').get_host_status_counts()
except AdHocCommandEvent.DoesNotExist:
counts = {}
return counts
class AdHocCommandCancelSerializer(AdHocCommandSerializer):
can_cancel = serializers.BooleanField(read_only=True)

View File

@@ -4569,7 +4569,7 @@ class HostAdHocCommandsList(AdHocCommandList, SubListCreateAPIView):
class AdHocCommandDetail(UnifiedJobDeletionMixin, RetrieveDestroyAPIView):
model = AdHocCommand
serializer_class = AdHocCommandSerializer
serializer_class = AdHocCommandDetailSerializer
class AdHocCommandCancel(RetrieveAPIView):