@@ -2385,9 +2385,8 @@ class SlurmComputeResource(_BaseSlurmComputeResource):
2385
2385
2386
2386
def __init__ (self , instance_type = None , ** kwargs ):
2387
2387
super ().__init__ (** kwargs )
2388
- _instance_type = instance_type if instance_type else self ._instance_type_from_capacity_reservation ()
2389
- self .instance_type = Resource .init_param (_instance_type )
2390
2388
self .__instance_type_info = None
2389
+ self ._instance_type = Resource .init_param (instance_type )
2391
2390
2392
2391
def is_flexible (self ):
2393
2392
"""Return False because the ComputeResource can not contain multiple instance types."""
@@ -2398,6 +2397,14 @@ def instance_types(self) -> List[str]:
2398
2397
"""List of instance types under this compute resource."""
2399
2398
return [self .instance_type ]
2400
2399
2400
+ @property
2401
+ # Do not invoke in update path
2402
+ def instance_type (self ):
2403
+ """Instance type of this compute resource."""
2404
+ if not self ._instance_type :
2405
+ self ._instance_type = Resource .init_param (self ._instance_type_from_capacity_reservation ())
2406
+ return self ._instance_type
2407
+
2401
2408
def _register_validators (self , context : ValidatorContext = None ):
2402
2409
super ()._register_validators (context )
2403
2410
self ._register_validator (
@@ -2446,13 +2453,9 @@ def _instance_type_from_capacity_reservation(self):
2446
2453
self .capacity_reservation_target .capacity_reservation_id if self .capacity_reservation_target else None
2447
2454
)
2448
2455
if capacity_reservation_id :
2449
- try :
2450
- capacity_reservations = AWSApi .instance ().ec2 .describe_capacity_reservations ([capacity_reservation_id ])
2451
- if capacity_reservations :
2452
- instance_type = capacity_reservations [0 ].instance_type ()
2453
- except AWSClientError :
2454
- # In case the CR has expired and we are unable to retrieve the instance type
2455
- instance_type = None
2456
+ capacity_reservations = AWSApi .instance ().ec2 .describe_capacity_reservations ([capacity_reservation_id ])
2457
+ if capacity_reservations :
2458
+ instance_type = capacity_reservations [0 ].instance_type ()
2456
2459
return instance_type
2457
2460
2458
2461
0 commit comments