in services/jenkins-autoscaling/lambda_mxnet_ci/autoscaling/handler.py [0:0]
def _managed_node_label(node) -> str:
"""
Extract the node label e.g. mxnet-linux-cpu or mxnet-windows-gpu from a jenkins node item.
Nodes have several labels: such as mxnetlinux-cpu and mxnetlinux-cpu_<random tag> we return the managed one.
:param node: Node
:return: string
"""
display_name = node['displayName']
assigned_labels = set()
# Convert list of tuples ('name' : 'label') to set
for labels_dict in node['assignedLabels']:
assigned_labels.add(labels_dict['name'])
# Check if blacklisted
intersection_blacklist = assigned_labels.intersection(_ignored_jenkins_node_labels())
if intersection_blacklist:
logging.debug('Node %s matches blacklisted labels (%s)',
display_name, ' & '.join(intersection_blacklist))
return next(iter(intersection_blacklist))
intersection_match = assigned_labels.intersection(_managed_jenkins_node_labels())
if len(intersection_match) > 1:
logging.error('Node %s has %d matching managed labels: (%s)',
display_name, len(intersection_match), ' & '.join(intersection_match))
return None
if not intersection_match:
logging.warning('Node %s has no matching managed labels. Assigned labels: (%s)',
display_name, ' & '.join(assigned_labels))
return None
# Found one matching label - that's the one we're looking for
return next(iter(intersection_match))