|
| 1 | +from classes.launch_template_settings import LaunchTemplateSettings |
| 2 | +from classes.launch_template_settings import LaunchNetworkSettings |
| 3 | +from classes.launch_template_settings import InstanceRoleSettings |
| 4 | +from classes.launch_template_settings import TargetTags |
| 5 | +import ast |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +def launch_template_obj_builder_for_csv(info): |
| 10 | + info = info['LaunchTemplateVersions'][0]['LaunchTemplateData'] |
| 11 | + launch_template_settings_obj = LaunchTemplateSettings(**info) |
| 12 | + return launch_template_settings_obj |
| 13 | + |
| 14 | +def instance_role_obj_builder_for_csv(info): |
| 15 | + if info == None: |
| 16 | + instance_role_settings_obj = InstanceRoleSettings() |
| 17 | + else: |
| 18 | + instance_role_settings_obj = InstanceRoleSettings(**info) |
| 19 | + return instance_role_settings_obj |
| 20 | + |
| 21 | +def tag_obj_builder_for_csv(info): |
| 22 | + for tags in info: |
| 23 | + if tags['ResourceType'] == 'instance': |
| 24 | + target_instance_tags_obj = TargetTags(**tags) |
| 25 | + elif tags['ResourceType'] == 'volume': |
| 26 | + target_volume_tags_obj = TargetTags(**tags) |
| 27 | + return target_instance_tags_obj, target_volume_tags_obj |
| 28 | + |
| 29 | + |
| 30 | +def launch_template_obj_builder(row): |
| 31 | + |
| 32 | + launch_template_obj = LaunchTemplateSettings() |
| 33 | + launch_template_network_obj = LaunchNetworkSettings() |
| 34 | + launch_template_instace_tags_obj = TargetTags(ResourceType='instance') |
| 35 | + launch_template_volume_tags_obj = TargetTags(ResourceType='volume') |
| 36 | + launch_template_instance_role_obj = InstanceRoleSettings() |
| 37 | + |
| 38 | + launch_template_obj.InstanceType = row[10].lower() |
| 39 | + launch_template_obj.KeyName = row[11] |
| 40 | + launch_template_obj.ImageId = row[12] |
| 41 | + launch_template_network_obj = ast.literal_eval(row[13]) |
| 42 | + launch_template_obj.NetworkInterfaces = launch_template_network_obj |
| 43 | + launch_template_disk_obj = ast.literal_eval(row[14]) |
| 44 | + launch_template_obj.BlockDeviceMappings = launch_template_disk_obj |
| 45 | + launch_template_instance_role_obj.Name = row[15] |
| 46 | + launch_template_obj.IamInstanceProfile = launch_template_instance_role_obj |
| 47 | + |
| 48 | + launch_template_obj.TagSpecifications = [] |
| 49 | + launch_template_instace_tags_obj.Tags = ast.literal_eval(row[16]) |
| 50 | + launch_template_volume_tags_obj.Tags = ast.literal_eval(row[17]) |
| 51 | + launch_template_obj.TagSpecifications.append(launch_template_instace_tags_obj) |
| 52 | + launch_template_obj.TagSpecifications.append(launch_template_volume_tags_obj) |
| 53 | + |
| 54 | + return launch_template_obj |
0 commit comments