Skip to content

Commit

Permalink
sort the output of broken or retired
Browse files Browse the repository at this point in the history
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 <hostname> to print what cloud the host is in

Change-Id: I412d93aabd5805af2ee68d6ec522624f53dbcb8c
  • Loading branch information
kambiz-aghaiepour committed Oct 30, 2023
1 parent 1b1a17b commit 4c3f98a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions quads/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4c3f98a

Please sign in to comment.