2016-10-27 07:20:16 +00:00
|
|
|
# ~*~ coding: utf-8 ~*~
|
|
|
|
from __future__ import unicode_literals, absolute_import
|
|
|
|
|
|
|
|
import logging
|
2016-10-28 06:58:09 +00:00
|
|
|
import json
|
2016-08-08 16:43:11 +00:00
|
|
|
|
|
|
|
from django.db import models
|
2016-10-27 07:20:16 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2016-10-28 05:41:11 +00:00
|
|
|
class AnsiblePlay(models.Model):
|
|
|
|
uuid = models.CharField(max_length=128, verbose_name=_('UUID'), primary_key=True)
|
2016-10-27 07:20:16 +00:00
|
|
|
name = models.CharField(max_length=128, verbose_name=_('Name'))
|
|
|
|
completed = models.BooleanField(default=False, verbose_name=_('IsCompleted'))
|
|
|
|
status_code = models.IntegerField(default=0, verbose_name=_('StatusCode'))
|
|
|
|
|
|
|
|
def __unicode__(self):
|
2016-10-28 05:41:11 +00:00
|
|
|
return "AnsiblePlay: %s<%s>" % (self.name, self.uuid)
|
2016-10-27 07:20:16 +00:00
|
|
|
|
|
|
|
|
2016-10-28 05:41:11 +00:00
|
|
|
class AnsibleTask(models.Model):
|
|
|
|
uuid = models.CharField(max_length=128, verbose_name=_('UUID'), primary_key=True)
|
|
|
|
play = models.ForeignKey(AnsiblePlay, related_name='tasks', blank=True)
|
|
|
|
name = models.CharField(max_length=128, blank=True, verbose_name=_('Name'))
|
2016-10-27 07:20:16 +00:00
|
|
|
|
|
|
|
def __unicode__(self):
|
2016-10-28 05:41:11 +00:00
|
|
|
return "AnsibleTask: %s<%s>" % (self.name, self.uuid)
|
2016-10-27 07:20:16 +00:00
|
|
|
|
2016-10-28 05:41:11 +00:00
|
|
|
def failed(self):
|
|
|
|
pass
|
2016-10-27 07:20:16 +00:00
|
|
|
|
2016-10-28 05:41:11 +00:00
|
|
|
def success(self):
|
|
|
|
pass
|
2016-08-08 16:43:11 +00:00
|
|
|
|
2016-10-28 05:41:11 +00:00
|
|
|
|
|
|
|
class AnsibleHostResult(models.Model):
|
|
|
|
task = models.ForeignKey(AnsibleTask, related_name='host_results', blank=True)
|
|
|
|
name = models.CharField(max_length=128, blank=True, verbose_name=_('Name'))
|
|
|
|
status = models.BooleanField(blank=True, default=False, verbose_name=_('Status'))
|
|
|
|
success = models.TextField(blank=True, verbose_name=_('Success'))
|
|
|
|
skipped = models.TextField(blank=True, verbose_name=_('Skipped'))
|
|
|
|
failed = models.TextField(blank=True, verbose_name=_('Failed'))
|
|
|
|
unreachable = models.TextField(blank=True, verbose_name=_('Unreachable'))
|
|
|
|
no_host = models.TextField(blank=True, verbose_name=_('NoHost'))
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return "AnsibleHostResult: %s<%s>" % (self.name, str(self.status))
|
|
|
|
|
2016-10-28 06:58:09 +00:00
|
|
|
@property
|
2016-10-28 05:41:11 +00:00
|
|
|
def is_failed(self):
|
2016-10-28 06:58:09 +00:00
|
|
|
if self.failed or self.unreachable or self.no_host:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def success_data(self):
|
|
|
|
if self.success:
|
|
|
|
return json.loads(self.success)
|
|
|
|
elif self.skipped:
|
|
|
|
return json.loads(self.skipped)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def failed_data(self):
|
|
|
|
if self.failed:
|
|
|
|
return json.loads(self.failed)
|
|
|
|
elif self.unreachable:
|
|
|
|
return json.loads(self.unreachable)
|
|
|
|
elif self.no_host:
|
|
|
|
return {"msg": self.no_host}
|
2016-10-28 05:41:11 +00:00
|
|
|
|