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

update gcp instance validation #2875

Merged
merged 1 commit into from
Dec 9, 2024
Merged
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
18 changes: 10 additions & 8 deletions src/_nebari/provider/cloud/google_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,21 @@ def regions() -> Set[str]:


@functools.lru_cache()
def instances(region: str) -> Set[str]:
def instances(region: str) -> set[str]:
"""Return a set of available compute instances in a region."""
credentials, project_id = load_credentials()
zones_client = compute_v1.services.region_zones.RegionZonesClient(
credentials=credentials
)
instances_client = compute_v1.InstancesClient(credentials=credentials)

return {
instance.machine_type.split("/")[-1]
for zone in zones_client.list(project=project_id, region=region)
for instance in instances_client.list(project=project_id, zone=zone.name)
}
instances_client = compute_v1.MachineTypesClient(credentials=credentials)
zone_list = zones_client.list(project=project_id, region=region)
zones = [zone for zone in zone_list]
instance_set: set[str] = set()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to use type hints here but nowhere else in the variable definitions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because mypy wanted me to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I did not realize we were using mypy. I don't have a problem with using type hints but it's the first time I see we are using them within variable definitions

for zone in zones:
instance_list = instances_client.list(project=project_id, zone=zone.name)
for instance in instance_list:
instance_set.add(instance.name)
return instance_set


@functools.lru_cache()
Expand Down
Loading