From 4c3f98a3d1d2bbd5cffaf520c79ba06e26f4b817 Mon Sep 17 00:00:00 2001 From: Kambiz Aghaiepour Date: Mon, 30 Oct 2023 07:04:47 -0400 Subject: [PATCH] sort the output of broken or retired make sure the hosts are listed sorted alphabetically when querying with --ls-broken or --ls-retired Also bring a couple of changes made on the fly into a patch set 1) use of NamedTemporaryFile for host_metadata_export 2) quads-cli --host to print what cloud the host is in Change-Id: I412d93aabd5805af2ee68d6ec522624f53dbcb8c --- quads/cli/cli.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/quads/cli/cli.py b/quads/cli/cli.py index dff2148f1..a03c0bb26 100644 --- a/quads/cli/cli.py +++ b/quads/cli/cli.py @@ -6,6 +6,7 @@ import subprocess from collections import defaultdict from datetime import datetime, timedelta +from tempfile import NamedTemporaryFile from json import JSONDecodeError from typing import Tuple, Optional @@ -82,6 +83,11 @@ def run(self, action: str, cli_args: dict) -> Optional[int]: _date = datetime.now() if self.cli_args.get("datearg"): _date = datetime.strptime(self.cli_args["datearg"], "%Y-%m-%d %H:%M") + if self.cli_args.get("host"): + host = Host.objects(name=self.cli_args.get("host")).first() + self.logger.info(host.cloud.name) + return 0 + for cloud in clouds: if cloud.name == "cloud01": available = [] @@ -196,12 +202,12 @@ def action_version(self): self.logger.info(self.quads.get_version()) def action_ls_broken(self): - _hosts = Host.objects(broken=True, retired=False) + _hosts = Host.objects(broken=True, retired=False).order_by("name").all() for host in _hosts: self.logger.info(host.name) def action_ls_retired(self): - _hosts = Host.objects(retired=True) + _hosts = Host.objects(retired=True).order_by("name").all() for host in _hosts: self.logger.info(host.name) @@ -1102,8 +1108,9 @@ def action_host_metadata_export(self): content.append(host_meta) try: - with open(self.cli_args["host_metadata_export"], "w") as _file: - yaml.dump(content, _file) + with NamedTemporaryFile("w", delete=False) as temp: + yaml.dump(content, temp) + self.logger.info(f"Metadata successfully exported to {temp.name}.") except Exception as ಠ益ಠ: self.logger.debug(ಠ益ಠ, exc_info=ಠ益ಠ) raise BaseQuadsException(