From 6c7f2399f267a9164f8ebffb719fcca6165bf2de Mon Sep 17 00:00:00 2001 From: Tim H <72768464+timhll-amz@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:11:00 -0400 Subject: [PATCH] Create launch_template_obj_builder.py --- .../launch_template_obj_builder.py | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 DRS/DRS-Settings-Tool/object_builders/launch_template_obj_builder.py diff --git a/DRS/DRS-Settings-Tool/object_builders/launch_template_obj_builder.py b/DRS/DRS-Settings-Tool/object_builders/launch_template_obj_builder.py new file mode 100644 index 0000000..3040936 --- /dev/null +++ b/DRS/DRS-Settings-Tool/object_builders/launch_template_obj_builder.py @@ -0,0 +1,54 @@ +from classes.launch_template_settings import LaunchTemplateSettings +from classes.launch_template_settings import LaunchNetworkSettings +from classes.launch_template_settings import InstanceRoleSettings +from classes.launch_template_settings import TargetTags +import ast + + + +def launch_template_obj_builder_for_csv(info): + info = info['LaunchTemplateVersions'][0]['LaunchTemplateData'] + launch_template_settings_obj = LaunchTemplateSettings(**info) + return launch_template_settings_obj + +def instance_role_obj_builder_for_csv(info): + if info == None: + instance_role_settings_obj = InstanceRoleSettings() + else: + instance_role_settings_obj = InstanceRoleSettings(**info) + return instance_role_settings_obj + +def tag_obj_builder_for_csv(info): + for tags in info: + if tags['ResourceType'] == 'instance': + target_instance_tags_obj = TargetTags(**tags) + elif tags['ResourceType'] == 'volume': + target_volume_tags_obj = TargetTags(**tags) + return target_instance_tags_obj, target_volume_tags_obj + + +def launch_template_obj_builder(row): + + launch_template_obj = LaunchTemplateSettings() + launch_template_network_obj = LaunchNetworkSettings() + launch_template_instace_tags_obj = TargetTags(ResourceType='instance') + launch_template_volume_tags_obj = TargetTags(ResourceType='volume') + launch_template_instance_role_obj = InstanceRoleSettings() + + launch_template_obj.InstanceType = row[10].lower() + launch_template_obj.KeyName = row[11] + launch_template_obj.ImageId = row[12] + launch_template_network_obj = ast.literal_eval(row[13]) + launch_template_obj.NetworkInterfaces = launch_template_network_obj + launch_template_disk_obj = ast.literal_eval(row[14]) + launch_template_obj.BlockDeviceMappings = launch_template_disk_obj + launch_template_instance_role_obj.Name = row[15] + launch_template_obj.IamInstanceProfile = launch_template_instance_role_obj + + launch_template_obj.TagSpecifications = [] + launch_template_instace_tags_obj.Tags = ast.literal_eval(row[16]) + launch_template_volume_tags_obj.Tags = ast.literal_eval(row[17]) + launch_template_obj.TagSpecifications.append(launch_template_instace_tags_obj) + launch_template_obj.TagSpecifications.append(launch_template_volume_tags_obj) + + return launch_template_obj