From 228383b5765251dfc4055ee592996952c30422b7 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Thu, 14 Sep 2023 08:16:14 -0700 Subject: [PATCH 1/2] ENH: specify required fields when retrieving available gcp regions --- src/_nebari/provider/cloud/google_cloud.py | 16 ++++++++-------- src/_nebari/stages/infrastructure/__init__.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/_nebari/provider/cloud/google_cloud.py b/src/_nebari/provider/cloud/google_cloud.py index a6a824579..6c595a6db 100644 --- a/src/_nebari/provider/cloud/google_cloud.py +++ b/src/_nebari/provider/cloud/google_cloud.py @@ -2,7 +2,7 @@ import json import os import subprocess -from typing import Dict, List +from typing import Dict, List, Set from _nebari import constants from _nebari.provider.cloud.commons import filter_by_highest_supported_k8s_version @@ -27,14 +27,14 @@ def projects() -> Dict[str, str]: @functools.lru_cache() -def regions(project: str) -> Dict[str, str]: - """Return a dict of available regions.""" +def regions() -> Set[str]: + """Return a set of available regions.""" check_credentials() output = subprocess.check_output( - ["gcloud", "compute", "regions", "list", "--project", project, "--format=json"] + ["gcloud", "compute", "regions", "list", "--format=json(name)"] ) - data = json.loads(output.decode("utf-8")) - return {_["description"]: _["name"] for _ in data} + data = json.loads(output) + return {_["name"] for _ in data} @functools.lru_cache() @@ -93,9 +93,9 @@ def instances(project: str) -> Dict[str, str]: ### PYDANTIC VALIDATORS ### -def validate_region(project_id: str, region: str) -> str: +def validate_region(region: str) -> str: """Validate the GCP region is valid.""" - available_regions = regions(project_id) + available_regions = regions() if region not in available_regions: raise ValueError( f"Region {region} is not one of available regions {available_regions}" diff --git a/src/_nebari/stages/infrastructure/__init__.py b/src/_nebari/stages/infrastructure/__init__.py index 96122cde6..282bd0c56 100644 --- a/src/_nebari/stages/infrastructure/__init__.py +++ b/src/_nebari/stages/infrastructure/__init__.py @@ -351,7 +351,7 @@ def validate_all(cls, values): raise ValueError("The `google_cloud_platform.region` field is required.") # validate region - google_cloud.validate_region(project_id, region) + google_cloud.validate_region(region) # validate kubernetes version kubernetes_version = values.get("kubernetes_version") From 57df8185ee4e3f2509a4656c670283ca85bb902c Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 25 Sep 2023 13:16:44 -0700 Subject: [PATCH 2/2] update --- src/_nebari/subcommands/init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_nebari/subcommands/init.py b/src/_nebari/subcommands/init.py index 4c3412358..299efabd5 100644 --- a/src/_nebari/subcommands/init.py +++ b/src/_nebari/subcommands/init.py @@ -445,7 +445,7 @@ def check_cloud_provider_region(region: str, cloud_provider: str) -> str: if not region: region = GCP_DEFAULT_REGION rich.print(DEFAULT_REGION_MSG.format(region=region)) - if region not in google_cloud.regions(os.environ["PROJECT_ID"]): + if region not in google_cloud.regions(): raise ValueError( f"Invalid region `{region}`. Please refer to the GCP docs for a list of valid regions: {GCP_REGIONS}" )