From f3a10d72678fbe020eb950a90fb8962421cf775a Mon Sep 17 00:00:00 2001 From: Mikita Pilinka Date: Wed, 13 Mar 2024 14:10:14 +0100 Subject: [PATCH] fix: proper message when invalid cloud credentials Ticket: ENT-11134 Changelog: None Signed-off-by: Mikita Pilinka --- cf_remote/commands.py | 3 +++ cf_remote/spawn.py | 18 +++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cf_remote/commands.py b/cf_remote/commands.py index 2fceb1d..94ef7a7 100644 --- a/cf_remote/commands.py +++ b/cf_remote/commands.py @@ -403,6 +403,9 @@ def spawn( role=role, spawned_cb=print_progress_dot, ) + if len(vms) == 0: + print("No VMs spawned") + return 0 print("DONE") if public_ip and (not all(vm.public_ips for vm in vms)): diff --git a/cf_remote/spawn.py b/cf_remote/spawn.py index c785592..1db76e8 100644 --- a/cf_remote/spawn.py +++ b/cf_remote/spawn.py @@ -4,6 +4,7 @@ from enum import Enum from multiprocessing.dummy import Pool +from libcloud.common.types import InvalidCredsError from libcloud.compute.types import Provider from libcloud.compute.providers import get_driver from libcloud.compute.base import NodeSize, NodeImage @@ -307,9 +308,12 @@ def spawn_vm_in_aws( size=None, role=None, ): - driver = get_cloud_driver(Providers.AWS, aws_creds, region) - existing_vms = driver.list_nodes() - + try: + driver = get_cloud_driver(Providers.AWS, aws_creds, region) + existing_vms = driver.list_nodes() + except InvalidCredsError as error: + print("\nInvalid credentials, check cloud_config.json file, details: \n" + str(error)) + return None if name is None: name = _get_unused_name( [vm.name for vm in existing_vms], platform, _NAME_RANDOM_PART_LENGTH @@ -370,7 +374,6 @@ def spawn_vm_in_gcp( ): driver = get_cloud_driver(Providers.GCP, gcp_creds, region) existing_vms = driver.list_nodes() - if name is None: name = _get_unused_name( [vm.name for vm in existing_vms], platform, _NAME_RANDOM_PART_LENGTH @@ -457,9 +460,10 @@ def spawn_vms( req.size, role, ) - if spawned_cb is not None: - spawned_cb(vm) - ret.append(vm) + if vm is not None: + ret.append(vm) + if spawned_cb is not None: + spawned_cb(vm) else: tasks = [ GCPSpawnTask(