Begin work on context template
This commit is contained in:
40
sia/context_template.py
Normal file
40
sia/context_template.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from typing import List, Dict
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
def generate_context(containers: List[Dict[str, any]]) -> str:
|
||||
"""Generate full context XML string.
|
||||
|
||||
Args:
|
||||
containers: List of container status dictionaries
|
||||
|
||||
Returns:
|
||||
Formatted context XML string
|
||||
"""
|
||||
context_elem = ET.Element("context")
|
||||
context_elem.append(format_containers_xml(containers))
|
||||
ET.indent(context_elem, space="\t")
|
||||
return ET.tostring(context_elem, encoding='unicode')
|
||||
|
||||
def format_containers_xml(containers: List[Dict[str, any]]) -> ET.Element:
|
||||
"""Format container statuses as XML string.
|
||||
|
||||
Args:
|
||||
containers: List of dictionaries containing container information
|
||||
|
||||
Returns:
|
||||
ElementTree.Element representing the containers
|
||||
"""
|
||||
containers_elem = ET.Element("containers")
|
||||
|
||||
for container in containers:
|
||||
container_elem = ET.SubElement(containers_elem, "container")
|
||||
container_elem.set("name", container['name'])
|
||||
container_elem.set("status", container['status'])
|
||||
container_elem.set("started_at", container['started_at'])
|
||||
container_elem.set("stdout", str(container['stdout_size']))
|
||||
container_elem.set("stderr", str(container['stderr_size']))
|
||||
if 'exit_code' in container.keys():
|
||||
container_elem.set("exit_code", str(container['exit_code']))
|
||||
if 'error' in container.keys():
|
||||
container_elem.set("error", container['error'])
|
||||
return containers_elem
|
||||
@@ -269,3 +269,12 @@ class DockerModule:
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error getting status for container {name}: {str(e)}")
|
||||
raise
|
||||
|
||||
def get_all_container_statuses(self) -> List[Dict[str, any]]:
|
||||
"""Get current status information for all containers.
|
||||
Returns:
|
||||
List of dictionaries with container status information
|
||||
"""
|
||||
statuses = []
|
||||
for name, (container, socket) in self.containers.items():
|
||||
statuses.append(self.get_container_status(name))
|
||||
Reference in New Issue
Block a user