Skip to content

Commit

Permalink
rm aux aws.amis method
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusdc committed Sep 18, 2024
1 parent 7df8ca2 commit 5a6bda3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 46 deletions.
30 changes: 0 additions & 30 deletions src/_nebari/provider/cloud/amazon_web_services.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import functools
import json
import os
import re
import time
Expand Down Expand Up @@ -110,35 +109,6 @@ def kubernetes_versions(region: str) -> List[str]:
return filter_by_highest_supported_k8s_version(supported_kubernetes_versions)


@functools.lru_cache()
def amis(region: str, k8s_version: str, ami_type: str = None) -> Dict[str, str]:
# do an ssm get-parameters-by-path to get the latest AMI for the k8s version
session = aws_session(region=region)
ssm_client = session.client("ssm")
ami_ssm_format = {
"AL2_x86_64": "/aws/service/eks/optimized-ami/{}/amazon-linux-2",
"AL2_x86_64_GPU": "/aws/service/eks/optimized-ami/{}/amazon-linux-2-gpu",
}
amis = {}

if ami_type and ami_type not in ami_ssm_format:
raise ValueError(f"Unsupported ami_type: {ami_type}")

for type, ssm_path_specifier in ami_ssm_format.items():
if ami_type and ami_type != type:
continue
ami_specifier = ssm_path_specifier.format(k8s_version)
paginator = ssm_client.get_paginator("get_parameters_by_path")
page_iterator = paginator.paginate(
Path=ami_specifier,
)
for page in page_iterator:
for parameter in page["Parameters"]:
values = json.loads(parameter["Value"])
amis[values["image_id"]] = values["image_name"]
return amis


@functools.lru_cache()
def instances(region: str) -> Dict[str, str]:
"""Return dict of available instance types for the AWS region."""
Expand Down
26 changes: 10 additions & 16 deletions src/_nebari/stages/infrastructure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,26 +545,20 @@ def _check_input(cls, data: Any) -> Any:
raise ValueError(
f"Amazon Web Services availability zone={zone} is not one of {available_zones}"
)
# check if instances and/or ami_ids are valid
if "node_groups" in data:
available_instances = set(amazon_web_services.instances(data["region"]))
# available_amis = set(
# amazon_web_services.amis(data["region"], data["kubernetes_version"])
# )

# check if instances are valid
available_instances = amazon_web_services.instances(data["region"])
if "node_groups" in data:
for _, node_group in data["node_groups"].items():
instance = node_group.get("instance")
if instance and instance not in available_instances:
instance = (
node_group["instance"]
if hasattr(node_group, "__getitem__")
else node_group.instance
)
if instance not in available_instances:
raise ValueError(
f"Amazon Web Services instance '{instance}' is not among the available instance types for your region or account."
f"Amazon Web Services instance {node_group.instance} not one of available instance types={available_instances}"
)
# launch_template = node_group.get("launch_template")
# if launch_template:
# ami_id = launch_template.get("ami_id")
# if ami_id and ami_id not in available_amis:
# raise ValueError(
# f"Invalid AMI ID '{ami_id}' specified in launch_template."
# )

return data

Expand Down

0 comments on commit 5a6bda3

Please sign in to comment.