From b906469b405a299da89c95582c64d71017261da7 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Thu, 20 Oct 2016 13:24:12 -0400 Subject: [PATCH] Add execution node information --- awx/api/serializers.py | 2 +- awx/main/managers.py | 11 ++++------- awx/main/models/unified_jobs.py | 7 ++++++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 2a22a6b04f..82e44d4f24 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -562,7 +562,7 @@ class UnifiedJobSerializer(BaseSerializer): fields = ('*', 'unified_job_template', 'launch_type', 'status', 'failed', 'started', 'finished', 'elapsed', 'job_args', 'job_cwd', 'job_env', 'job_explanation', 'result_stdout', - 'result_traceback') + 'execution_node', 'result_traceback') extra_kwargs = { 'unified_job_template': { 'source': 'unified_job_template_id', diff --git a/awx/main/managers.py b/awx/main/managers.py index 86c3367140..176deb9483 100644 --- a/awx/main/managers.py +++ b/awx/main/managers.py @@ -31,13 +31,10 @@ class InstanceManager(models.Manager): hostname='localhost', uuid='00000000-0000-0000-0000-000000000000') - # If we can determine the instance we are on then return - # that, otherwise None which would be the standalone - # case - # TODO: Replace, this doesn't work if the hostname - # is different from the Instance.name - # node = self.filter(hostname=socket.gethostname()) - return self.all()[0] + node = self.filter(hostname=settings.CLUSTER_HOST_ID) + if node.exists(): + return node[0] + raise RuntimeError("No instance found with the current cluster host id") def my_role(self): # NOTE: TODO: Likely to repurpose this once standalone ramparts are a thing diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index 8c953c61e6..677be8136d 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -438,6 +438,11 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique editable=False, related_name='%(class)s_blocked_jobs+', ) + execution_node = models.TextField( + blank=True, + default='', + editable=False, + ) notifications = models.ManyToManyField( 'Notification', editable=False, @@ -801,7 +806,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique def pre_start(self, **kwargs): if not self.can_start: - self.job_explanation = u'%s is not in a startable status: %s, expecting one of %s' % (self._meta.verbose_name, self.status, str(('new', 'waiting'))) + self.job_explanation = u'%s is not in a startable state: %s, expecting one of %s' % (self._meta.verbose_name, self.status, str(('new', 'waiting'))) self.save(update_fields=['job_explanation']) return (False, None)