Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENT-11134: proper message when invalid cloud credentials #82

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading