diff --git a/cf_remote/commands.py b/cf_remote/commands.py index 2fceb1d..4927fbf 100644 --- a/cf_remote/commands.py +++ b/cf_remote/commands.py @@ -328,7 +328,6 @@ def spawn( public_ip=True, extend_group=False, ): - if os.path.exists(CLOUD_CONFIG_FPATH): creds_data = read_json(CLOUD_CONFIG_FPATH) else: @@ -392,17 +391,21 @@ def spawn( ) print("Spawning VMs...", end="") sys.stdout.flush() - vms = spawn_vms( - requests, - creds, - region, - key_pair, - security_groups=sec_groups, - provider=provider, - network=network, - role=role, - spawned_cb=print_progress_dot, - ) + try: + vms = spawn_vms( + requests, + creds, + region, + key_pair, + security_groups=sec_groups, + provider=provider, + network=network, + role=role, + spawned_cb=print_progress_dot, + ) + except ValueError as e: + print("Failed to spawn VMs with following error:\n" + str(e)) + return 1 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..e4350c8 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,14 @@ 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: + raise ValueError( + "Invalid credentials, check cloud_config.json file, details: \n" + + str(error) + ) if name is None: name = _get_unused_name( [vm.name for vm in existing_vms], platform, _NAME_RANDOM_PART_LENGTH @@ -457,9 +463,6 @@ def spawn_vms( req.size, role, ) - if spawned_cb is not None: - spawned_cb(vm) - ret.append(vm) else: tasks = [ GCPSpawnTask(