@@ -132,7 +132,8 @@ def _supported_instances_with_reservation(offer: InstanceOffer) -> bool:
132132 availability_offers = []
133133 for offer in offers :
134134 availability = InstanceAvailability .UNKNOWN
135- if not _has_quota (regions_to_quotas [offer .region ], offer .instance .name ):
135+ quota = _has_quota (regions_to_quotas [offer .region ], offer .instance .name )
136+ if quota is not None and not quota :
136137 availability = InstanceAvailability .NO_QUOTA
137138 availability_offers .append (
138139 InstanceOfferWithAvailability (
@@ -782,10 +783,18 @@ def _get_regions_to_quotas(
782783) -> Dict [str , Dict [str , int ]]:
783784 def get_region_quotas (client : botocore .client .BaseClient ) -> Dict [str , int ]:
784785 region_quotas = {}
785- for page in client .get_paginator ("list_service_quotas" ).paginate (ServiceCode = "ec2" ):
786- for q in page ["Quotas" ]:
787- if "On-Demand" in q ["QuotaName" ]:
788- region_quotas [q ["UsageMetric" ]["MetricDimensions" ]["Class" ]] = q ["Value" ]
786+ try :
787+ for page in client .get_paginator ("list_service_quotas" ).paginate (ServiceCode = "ec2" ):
788+ for q in page ["Quotas" ]:
789+ if "On-Demand" in q ["QuotaName" ]:
790+ region_quotas [q ["UsageMetric" ]["MetricDimensions" ]["Class" ]] = q ["Value" ]
791+ except botocore .exceptions .ClientError as e :
792+ if len (e .args ) > 0 and "TooManyRequestsException" in e .args [0 ]:
793+ logger .warning (
794+ "Failed to get quotas due to rate limits. Quotas won't be accounted for."
795+ )
796+ else :
797+ logger .exception (e )
789798 return region_quotas
790799
791800 regions_to_quotas = {}
@@ -801,12 +810,15 @@ def get_region_quotas(client: botocore.client.BaseClient) -> Dict[str, int]:
801810 return regions_to_quotas
802811
803812
804- def _has_quota (quotas : Dict [str , int ], instance_name : str ) -> bool :
813+ def _has_quota (quotas : Dict [str , int ], instance_name : str ) -> Optional [bool ]:
814+ quota = quotas .get ("Standard/OnDemand" )
805815 if instance_name .startswith ("p" ):
806- return quotas .get ("P/OnDemand" , 0 ) > 0
816+ quota = quotas .get ("P/OnDemand" )
807817 if instance_name .startswith ("g" ):
808- return quotas .get ("G/OnDemand" , 0 ) > 0
809- return quotas .get ("Standard/OnDemand" , 0 ) > 0
818+ quota = quotas .get ("G/OnDemand" )
819+ if quota is None :
820+ return None
821+ return quota > 0
810822
811823
812824def _get_regions_to_zones (session : boto3 .Session , regions : List [str ]) -> Dict [str , List [str ]]:
0 commit comments