Skip to content

Commit

Permalink
fix: proper message when invalid cloud credentials
Browse files Browse the repository at this point in the history
Ticket: ENT-11134
Changelog: None

Signed-off-by: Mikita Pilinka <[email protected]>
  • Loading branch information
mineralsfree committed Mar 14, 2024
1 parent 6436208 commit f3a10d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 3 additions & 0 deletions cf_remote/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
18 changes: 11 additions & 7 deletions cf_remote/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f3a10d7

Please sign in to comment.