From: Kienan Stewart Date: Mon, 7 Oct 2024 14:19:23 +0000 (-0400) Subject: ansible: Add info command to `manage_jenkins_node.py` X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2cad7c3e58845e55e8e4f314487f3990ee81130a;p=lttng-ci.git ansible: Add info command to `manage_jenkins_node.py` Change-Id: I0ce0177ae637d56e865594ce253b9ab52619f546 Signed-off-by: Kienan Stewart --- diff --git a/automation/ansible/scripts/manage_jenkins_node.py b/automation/ansible/scripts/manage_jenkins_node.py index 66bb293..50e25bc 100755 --- a/automation/ansible/scripts/manage_jenkins_node.py +++ b/automation/ansible/scripts/manage_jenkins_node.py @@ -2,8 +2,11 @@ import argparse import configparser +import enum +import json import logging import pathlib +import pprint import requests import re import sys @@ -13,6 +16,15 @@ import xml.etree.ElementTree import jenkins +class OutputFormat(enum.Enum): + pprint = "pprint" + json = "json" + pjson = "pjson" # Pretty json + + def __str__(self): + return self.value + + def get_hypervisor(server, nodes, args): found = 0 for node in nodes: @@ -31,6 +43,21 @@ def get_hypervisor(server, nodes, args): sys.exit(2) +def get_info(server, nodes, args): + data = [] + for node in nodes: + data.append(server.get_node_info(node["name"])) + + if args.format == OutputFormat.pprint: + pprint.PrettyPrinter().pprint(data) + elif args.format == OutputFormat.json: + print(json.dumps(data)) + elif args.format == OutputFormat.pjson: + print(json.dumps(data, sort_keys=True, indent=4)) + else: + raise Exception("Unknown output format") + + def toggle_nodes(server, nodes, args, want_offline=True): changed = [] for node in nodes: @@ -213,6 +240,20 @@ def get_argument_parser(): "node", default="", help="A python regex to filter nodes by", nargs="?" ) + info_parser = subparsers.add_parser("info", help="Get node info") + info_parser.set_defaults(callback=get_info) + info_parser.add_argument( + "node", default="", help="A python regex to filter nodes by", nargs="?" + ) + info_parser.add_argument( + "-f", + "--format", + default="pprint", + help="The output format", + type=OutputFormat, + choices=list(OutputFormat), + ) + return parser