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 18, 2024
1 parent 6436208 commit b16bba9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
27 changes: 15 additions & 12 deletions cf_remote/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)):
Expand Down
12 changes: 9 additions & 3 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,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
Expand Down

0 comments on commit b16bba9

Please sign in to comment.