feat: execution failure reports, auto-printer for WMT, UTC timezone fix for all timestamps
This commit is contained in:
@@ -26,7 +26,7 @@ __all__ = [
|
||||
'Base', 'Device', 'MessageTemplate', 'LogEntry', 'FileUpload',
|
||||
'AnsibleExecution', 'SystemStats', 'InventoryGroup', 'PlaybookExecution',
|
||||
'PlaybookHostResult', 'ExecutionQueue', 'device_inventory_association',
|
||||
'WMTGlobalConfig', 'WMTUpdateRequest',
|
||||
'WMTGlobalConfig', 'WMTUpdateRequest', 'ExecutionFailureReport',
|
||||
]
|
||||
|
||||
class Device(Base):
|
||||
@@ -626,4 +626,48 @@ class WMTUpdateRequest(Base):
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
return f"<WMTUpdateRequest(mac='{self.mac_address}', status='{self.status}')>"
|
||||
return f"<WMTUpdateRequest(mac='{self.mac_address}', status='{self.status}')>"
|
||||
|
||||
|
||||
class ExecutionFailureReport(Base):
|
||||
"""Saved report of failed/unreachable hosts from a playbook execution."""
|
||||
__tablename__ = 'execution_failure_reports'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
execution_id = Column(String(36), nullable=False, index=True)
|
||||
playbook_name = Column(String(255), nullable=False)
|
||||
saved_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
|
||||
# Counts
|
||||
failed_count = Column(Integer, default=0)
|
||||
unreachable_count = Column(Integer, default=0)
|
||||
|
||||
# JSON list of {hostname, status, reason} objects
|
||||
failed_hosts = Column(Text, nullable=False, default='[]')
|
||||
|
||||
# Optional note added by user when saving
|
||||
note = Column(Text)
|
||||
|
||||
@property
|
||||
def hosts_list(self):
|
||||
try:
|
||||
return json.loads(self.failed_hosts)
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'execution_id': self.execution_id,
|
||||
'playbook_name': self.playbook_name,
|
||||
'saved_at': self.saved_at.isoformat() if self.saved_at else None,
|
||||
'failed_count': self.failed_count,
|
||||
'unreachable_count': self.unreachable_count,
|
||||
'failed_hosts': self.hosts_list,
|
||||
'note': self.note,
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
return (f"<ExecutionFailureReport(execution_id='{self.execution_id}', "
|
||||
f"playbook='{self.playbook_name}', failed={self.failed_count}, "
|
||||
f"unreachable={self.unreachable_count})>")
|
||||
Reference in New Issue
Block a user