45
45
from pcluster .config .cluster_config import (
46
46
AwsBatchClusterConfig ,
47
47
BaseSharedFsx ,
48
- CapacityType ,
49
48
ExistingFsxOntap ,
50
49
ExistingFsxOpenZfs ,
51
50
SchedulerPluginQueue ,
73
72
from pcluster .models .s3_bucket import S3Bucket
74
73
from pcluster .templates .awsbatch_builder import AwsBatchConstruct
75
74
from pcluster .templates .cdk_builder_utils import (
75
+ CdkLaunchTemplateBuilder ,
76
76
ComputeNodeIamResources ,
77
77
HeadNodeIamResources ,
78
78
PclusterLambdaConstruct ,
81
81
convert_deletion_policy ,
82
82
create_hash_suffix ,
83
83
generate_launch_template_version_cfn_parameter_hash ,
84
- get_block_device_mappings ,
85
84
get_cloud_watch_logs_policy_statement ,
86
85
get_cloud_watch_logs_retention_days ,
87
86
get_common_user_data_env ,
@@ -119,6 +118,7 @@ def __init__(
119
118
) -> None :
120
119
super ().__init__ (scope , construct_id , ** kwargs )
121
120
self ._stack_name = stack_name
121
+ self ._launch_template_builder = CdkLaunchTemplateBuilder ()
122
122
self .config = cluster_config
123
123
self .bucket = bucket
124
124
self .timestamp = datetime .utcnow ().strftime ("%Y%m%d%H%M%S" )
@@ -874,7 +874,9 @@ def _add_head_node(self):
874
874
"HeadNodeLaunchTemplate" ,
875
875
launch_template_data = ec2 .CfnLaunchTemplate .LaunchTemplateDataProperty (
876
876
instance_type = head_node .instance_type ,
877
- block_device_mappings = get_block_device_mappings (head_node .local_storage , self .config .image .os ),
877
+ block_device_mappings = self ._launch_template_builder .get_block_device_mappings (
878
+ head_node .local_storage .root_volume , self .config .image .os
879
+ ),
878
880
key_name = head_node .ssh .key_name ,
879
881
network_interfaces = head_lt_nw_interfaces ,
880
882
image_id = self .config .head_node_ami ,
@@ -1317,6 +1319,7 @@ def __init__(
1317
1319
self ._dynamodb_table = dynamodb_table
1318
1320
self ._compute_node_instance_profiles = compute_node_instance_profiles
1319
1321
self ._head_eni = head_eni
1322
+ self ._launch_template_builder = CdkLaunchTemplateBuilder ()
1320
1323
self ._add_resources ()
1321
1324
1322
1325
# -- Utility methods --------------------------------------------------------------------------------------------- #
@@ -1443,41 +1446,19 @@ def _add_compute_resource_launch_template(
1443
1446
)
1444
1447
)
1445
1448
1446
- instance_market_options = None
1447
- if queue .capacity_type == CapacityType .SPOT :
1448
- instance_market_options = ec2 .CfnLaunchTemplate .InstanceMarketOptionsProperty (
1449
- market_type = "spot" ,
1450
- spot_options = ec2 .CfnLaunchTemplate .SpotOptionsProperty (
1451
- spot_instance_type = "one-time" ,
1452
- instance_interruption_behavior = "terminate" ,
1453
- max_price = None if compute_resource .spot_price is None else str (compute_resource .spot_price ),
1454
- ),
1455
- )
1456
-
1457
1449
conditional_template_properties = {}
1458
-
1459
1450
if compute_resource .is_ebs_optimized :
1460
1451
conditional_template_properties .update ({"ebs_optimized" : True })
1461
1452
if isinstance (compute_resource , SlurmComputeResource ):
1462
1453
conditional_template_properties .update ({"instance_type" : compute_resource .instance_type })
1463
1454
1464
- capacity_reservation_specification = None
1465
- cr_target = compute_resource .capacity_reservation_target or queue .capacity_reservation_target
1466
- if cr_target :
1467
- capacity_reservation_specification = ec2 .CfnLaunchTemplate .CapacityReservationSpecificationProperty (
1468
- capacity_reservation_target = ec2 .CfnLaunchTemplate .CapacityReservationTargetProperty (
1469
- capacity_reservation_id = cr_target .capacity_reservation_id ,
1470
- capacity_reservation_resource_group_arn = cr_target .capacity_reservation_resource_group_arn ,
1471
- )
1472
- )
1473
-
1474
1455
return ec2 .CfnLaunchTemplate (
1475
1456
self ,
1476
1457
f"LaunchTemplate{ create_hash_suffix (queue .name + compute_resource .name )} " ,
1477
1458
launch_template_name = f"{ self .stack_name } -{ queue .name } -{ compute_resource .name } " ,
1478
1459
launch_template_data = ec2 .CfnLaunchTemplate .LaunchTemplateDataProperty (
1479
- block_device_mappings = get_block_device_mappings (
1480
- queue .compute_settings .local_storage , self ._config .image .os
1460
+ block_device_mappings = self . _launch_template_builder . get_block_device_mappings (
1461
+ queue .compute_settings .local_storage . root_volume , self ._config .image .os
1481
1462
),
1482
1463
# key_name=,
1483
1464
network_interfaces = compute_lt_nw_interfaces ,
@@ -1486,9 +1467,14 @@ def _add_compute_resource_launch_template(
1486
1467
iam_instance_profile = ec2 .CfnLaunchTemplate .IamInstanceProfileProperty (
1487
1468
name = instance_profiles [queue .name ]
1488
1469
),
1489
- instance_market_options = instance_market_options ,
1470
+ instance_market_options = self ._launch_template_builder .get_instance_market_options (
1471
+ queue , compute_resource
1472
+ ),
1490
1473
instance_initiated_shutdown_behavior = "terminate" ,
1491
- capacity_reservation_specification = capacity_reservation_specification ,
1474
+ capacity_reservation_specification = self ._launch_template_builder .get_capacity_reservation (
1475
+ queue ,
1476
+ compute_resource ,
1477
+ ),
1492
1478
metadata_options = ec2 .CfnLaunchTemplate .MetadataOptionsProperty (
1493
1479
http_tokens = get_http_tokens_setting (self ._config .imds .imds_support )
1494
1480
),
0 commit comments