@@ -56,12 +56,46 @@ def __init__(self, config: VastAIConfig):
5656 def get_offers_by_requirements (
5757 self , requirements : Requirements
5858 ) -> List [InstanceOfferWithAvailability ]:
59+ def spot_filter (offer ):
60+ return not offer .instance .resources .spot
61+
62+ extra_filter = spot_filter
63+
64+ configured_regions = self .config .regions or []
65+ if configured_regions :
66+ normalized_exact_regions = {
67+ r .strip () for r in configured_regions if isinstance (r , str ) and r .strip ()
68+ }
69+ iso_country_codes = {
70+ r .strip ().upper ()
71+ for r in configured_regions
72+ if isinstance (r , str ) and len (r .strip ()) == 2 and r .strip ().isalpha ()
73+ }
74+
75+ def region_accepts (offer ):
76+ region_value = (offer .region or "" ).strip ()
77+ if not region_value :
78+ return False
79+ if region_value in normalized_exact_regions :
80+ return True
81+ if "," in region_value :
82+ trailing_code = region_value .split ("," )[- 1 ].strip ().upper ()
83+ if trailing_code in iso_country_codes :
84+ return True
85+ if len (region_value ) == 2 and region_value .isalpha () and region_value .upper () in iso_country_codes :
86+ return True
87+ return False
88+
89+ def combined_filter (offer ):
90+ return spot_filter (offer ) and region_accepts (offer )
91+
92+ extra_filter = combined_filter
93+
5994 offers = get_catalog_offers (
6095 backend = BackendType .VASTAI ,
61- locations = self .config .regions or None ,
6296 requirements = requirements ,
6397 # TODO(egor-s): spots currently not supported
64- extra_filter = lambda offer : not offer . instance . resources . spot ,
98+ extra_filter = extra_filter ,
6599 catalog = self .catalog ,
66100 )
67101 offers = [
0 commit comments