|
114 | 114 | ) |
115 | 115 | from pcluster.validators.ec2_validators import ( |
116 | 116 | AmiOsCompatibleValidator, |
| 117 | + CapacityReservationResourceGroupValidator, |
| 118 | + CapacityReservationValidator, |
117 | 119 | CapacityTypeValidator, |
118 | 120 | InstanceTypeBaseAMICompatibleValidator, |
119 | 121 | InstanceTypeMemoryInfoValidator, |
@@ -2439,6 +2441,8 @@ def __init__(self, cluster_name: str, scheduling: SlurmScheduling, **kwargs): |
2439 | 2441 | super().__init__(cluster_name, **kwargs) |
2440 | 2442 | self.scheduling = scheduling |
2441 | 2443 | self.__image_dict = None |
| 2444 | + # Cache capacity reservations information together to reduce number of boto3 calls |
| 2445 | + AWSApi.instance().ec2.describe_capacity_reservations(self.all_relevant_capacity_reservation_ids) |
2442 | 2446 |
|
2443 | 2447 | def get_instance_types_data(self): |
2444 | 2448 | """Get instance type infos for all instance types used in the configuration file.""" |
@@ -2477,6 +2481,27 @@ def _register_validators(self): |
2477 | 2481 | instance_type=instance_type, |
2478 | 2482 | instance_type_data=instance_types_data[compute_resource.instance_type], |
2479 | 2483 | ) |
| 2484 | + self._register_validator( |
| 2485 | + InstanceTypeMemoryInfoValidator, |
| 2486 | + instance_type=compute_resource.instance_type, |
| 2487 | + instance_type_data=instance_types_data[compute_resource.instance_type], |
| 2488 | + ) |
| 2489 | + # The validation below has to be in cluster config class instead of queue class |
| 2490 | + # to make sure the subnet APIs are cached by previous validations. |
| 2491 | + if compute_resource.capacity_reservation_target: |
| 2492 | + cr_target = compute_resource.capacity_reservation_target |
| 2493 | + self._register_validator( |
| 2494 | + CapacityReservationValidator, |
| 2495 | + capacity_reservation_id=cr_target.capacity_reservation_id, |
| 2496 | + instance_type=compute_resource.instance_type, |
| 2497 | + subnet=queue.networking.subnet_ids[0], |
| 2498 | + ) |
| 2499 | + self._register_validator( |
| 2500 | + CapacityReservationResourceGroupValidator, |
| 2501 | + capacity_reservation_resource_group_arn=cr_target.capacity_reservation_resource_group_arn, |
| 2502 | + instance_type=compute_resource.instance_type, |
| 2503 | + subnet=queue.networking.subnet_ids[0], |
| 2504 | + ) |
2480 | 2505 |
|
2481 | 2506 | @property |
2482 | 2507 | def image_dict(self): |
@@ -2519,3 +2544,15 @@ def capacity_reservation_resource_group_arns(self): |
2519 | 2544 | if capacity_reservation_target.capacity_reservation_resource_group_arn: |
2520 | 2545 | result.add(capacity_reservation_target.capacity_reservation_resource_group_arn) |
2521 | 2546 | return list(result) |
| 2547 | + |
| 2548 | + @property |
| 2549 | + def all_relevant_capacity_reservation_ids(self): |
| 2550 | + """Return a list of capacity reservation ids specified in the config or used by resource groups.""" |
| 2551 | + capacity_reservation_ids = set(self.capacity_reservation_ids) |
| 2552 | + for capacity_reservation_resource_group_arn in self.capacity_reservation_resource_group_arns: |
| 2553 | + capacity_reservation_ids.update( |
| 2554 | + AWSApi.instance().resource_groups.get_capacity_reservation_ids_from_group_resources( |
| 2555 | + capacity_reservation_resource_group_arn |
| 2556 | + ) |
| 2557 | + ) |
| 2558 | + return list(capacity_reservation_ids) |
0 commit comments