in src/modules/get_cluster_status_scs.py [0:0]
def _process_node_attributes(self, cluster_status_xml: ET.Element) -> Dict[str, Any]:
"""
Processes node attributes and identifies ASCS and ERS nodes.
:param cluster_status_xml: XML element containing node attributes.
:type cluster_status_xml: ET.Element
:return: Dictionary with ASCS and ERS node information.
:rtype: Dict[str, Any]
"""
result = {
"ascs_node": "",
"ers_node": "",
"cluster_status": {
"ascs_node": {},
"ers_node": {},
},
}
resources = cluster_status_xml.find("resources")
node_attributes = cluster_status_xml.find("node_attributes")
try:
if node_attributes is not None:
for node in node_attributes:
node_name = node.attrib.get("name")
for attribute in node:
if attribute.attrib.get("name") == f"runs_ers_{self.sap_sid.upper()}":
attr_value = attribute.attrib.get("value")
if attr_value == "1":
result["ers_node"] = node_name
elif attr_value == "0":
result["ascs_node"] = node_name
break
# If node attributes do not report correct ASCS/ERS nodes, exit
# and return empty values
if result["ascs_node"] == "" and result["ers_node"] == "":
return self.result
if resources is not None and self.ascs_resource_id and self.ers_resource_id:
ascs_resource = resources.find(f".//resource[@id='{self.ascs_resource_id}']")
ers_resource = resources.find(f".//resource[@id='{self.ers_resource_id}']")
for resource in [ascs_resource, ers_resource]:
if resource is None:
continue
resource_id = resource.attrib.get("id")
node_type = "ascs_node" if resource_id == self.ascs_resource_id else "ers_node"
node_element = resource.find("node")
if node_element is None:
result[node_type] = ""
continue
node_name = node_element.attrib.get("name")
if node_name is None:
continue
failed = resource.attrib.get("failed", "false").lower() == "true"
active = resource.attrib.get("active", "false").lower() == "true"
role = resource.attrib.get("role", "unknown").lower()
role_status = role == "started"
if not failed and active and role_status:
result[node_type] = (
node_name if result[node_type] == "" else result[node_type]
)
result["cluster_status"][node_type] = {
"name": node_name,
"id": resource.attrib.get("id"),
"resource_agent": resource.attrib.get("resource_agent"),
"role": role,
"active": "true",
"orphaned": resource.attrib.get("orphaned"),
"blocked": resource.attrib.get("blocked"),
"failed": "false",
"nodes_running_on": resource.attrib.get("nodes_running_on"),
"failure_ignored": resource.attrib.get("failure_ignored"),
}
else:
result[node_type] = ""
else:
self.log(
logging.ERROR,
"Failed to find resources in the cluster status XML.",
)
except Exception as ex:
self.handle_error(ex)
self.result.update(result)
return self.result