From af9a95c445adb2306bdca4588a4212e5da5d2999 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Tue, 21 Jun 2022 09:48:55 +0200 Subject: [PATCH] copr-be: clean stdout for the resalloc's cmd_list commands --- roles/copr/backend/files/provision/libvirt-list | 5 +++-- roles/copr/backend/templates/resalloc/ibm-cloud-list-vms.j2 | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/roles/copr/backend/files/provision/libvirt-list b/roles/copr/backend/files/provision/libvirt-list index 3eb22fafc1..118ba1198c 100755 --- a/roles/copr/backend/files/provision/libvirt-list +++ b/roles/copr/backend/files/provision/libvirt-list @@ -24,7 +24,7 @@ def _main(): pool_id = args.pool or os.getenv("RESALLOC_POOL_ID") if not pool_id: - print("Specify pool ID by --pool or $RESALLOC_POOL_ID") + sys.stderr.write("Specify pool ID by --pool or $RESALLOC_POOL_ID\n") sys.exit(1) connection = args.connection if args.connection else \ @@ -33,7 +33,7 @@ def _main(): try: conn = libvirt.openReadOnly(connection) except libvirt.libvirtError: - print('Failed to open connection to the hypervisor') + sys.stderr.write('Failed to open connection to the hypervisor\n') sys.exit(1) # Gather the list of all domains here @@ -56,6 +56,7 @@ def _main(): # Print them out, so upper level tooling can work with the list. See: # roles/copr/backend/files/provision/libvirt-list for name in vm_names: + # The only stdout output comes here! print(name) if __name__ == "__main__": diff --git a/roles/copr/backend/templates/resalloc/ibm-cloud-list-vms.j2 b/roles/copr/backend/templates/resalloc/ibm-cloud-list-vms.j2 index 9debe68a1d..0d1b372e69 100755 --- a/roles/copr/backend/templates/resalloc/ibm-cloud-list-vms.j2 +++ b/roles/copr/backend/templates/resalloc/ibm-cloud-list-vms.j2 @@ -25,7 +25,7 @@ def _main(): pool_id = opts.pool or os.getenv("RESALLOC_POOL_ID") if not pool_id: - print("Specify pool ID by --pool or $RESALLOC_POOL_ID") + sys.stderr.write("Specify pool ID by --pool or $RESALLOC_POOL_ID\n") sys.exit(1) cmd = f"source {opts.token_file} ; echo $IBMCLOUD_API_KEY" @@ -41,6 +41,7 @@ def _main(): # Resalloc works with underscores, which is not allowed in IBM Cloud name = server["name"].replace("-", "_") if name.startswith(pool_id): + # The only stdout output comes here! print(name) if __name__ == "__main__":