From 0562aa35e9974bae3d386c3f6809a78fb4a5a7be Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Aug 26 2022 00:47:52 +0000 Subject: copr: list also IBM Cloud volumes Unused and forgotten volumes are starting to pile up in the IBM Cloud. We need to list them in this script the same way we do it in `libvirt-list'. --- 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 0d1b372..07e5776 100755 --- a/roles/copr/backend/templates/resalloc/ibm-cloud-list-vms.j2 +++ b/roles/copr/backend/templates/resalloc/ibm-cloud-list-vms.j2 @@ -11,6 +11,7 @@ from ibm_cloud_sdk_core.authenticators import IAMAuthenticator DEFAULT_TOKEN_FILE = "{{ ibmcloud_token_file }}" SERVICE_URL = "https://jp-tok.iaas.cloud.ibm.com/v1" +LIMIT = 100 def _get_arg_parser(): @@ -36,13 +37,29 @@ def _main(): service = VpcV1(now.strftime('%Y-%m-%d'), authenticator=authenticator) service.set_service_url(SERVICE_URL) - resp = service.list_instances() - for server in resp.result["instances"]: + # Gather the list of all resources here + resources = set() + + instances = service.list_instances(limit=LIMIT).result["instances"] + for server in instances: # 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) + resources.add(name) + + volumes = service.list_volumes(limit=LIMIT).result["volumes"] + for volume in volumes: + # Resalloc works with underscores, which is not allowed in IBM Cloud + name = volume["name"].replace("-", "_") + if name.startswith(pool_id): + name = name.rsplit("_", 1)[0] + resources.add(name) + + # Print them out, so upper level tooling can work with the list + for name in resources: + # The only stdout output comes here! + print(name) + if __name__ == "__main__": sys.exit(_main())