<commit_before>#!/usr/bin/python3

from amazonia.classes.security_enabled_object import SecurityEnabledObject
from troposphere import Tags, Ref, rds, Join, Output, GetAtt, Parameter


class DatabaseUnit(SecurityEnabledObject):
    def __init__(self, unit_title, template, network_config, database_config):
        """
        Class to create an RDS and DB subnet group in a vpc
        http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html
        https://github.com/cloudtools/troposphere/blob/master/troposphere/rds.py
        :param unit_title: Title of the autoscaling application e.g 'webApp1', 'api2' or 'dataprocessing'
        :param template: Troposphere stack to append resources to
        :param network_config: object containing network related variables
        :param database_config: object containing database related variablea
        """
        self.title = unit_title + 'Rds'
        self.dependencies = []
        self.db_subnet_group_title = unit_title + 'Dsg'
        self.port = database_config.db_port
        super(DatabaseUnit, self).__init__(vpc=network_config.vpc, title=self.title, template=template)

        self.trop_db_subnet_group = template.add_resource(
            rds.DBSubnetGroup(self.db_subnet_group_title,
                              DBSubnetGroupDescription=self.db_subnet_group_title,
                              SubnetIds=[Ref(x) for x in network_config.private_subnets],
                              Tags=Tags(Name=self.db_subnet_group_title)))
        rds_params = {
            'AllocatedStorage': database_config.db_hdd_size,
            'AllowMajorVersionUpgrade': True,
            'AutoMinorVersionUpgrade': True,
            'MultiAZ': True,
            'DBInstanceClass': database_config.db_instance_type,
            'DBSubnetGroupName': Ref(self.trop_db_subnet_group),
            'DBName': database_config.db_name,
            'Engine': database_config.db_engine,
            'Port': self.port,
            'VPCSecurityGroups': [Ref(self.security_group)],
            'Tags': Tags(Name=Join('', [Ref('AWS::StackName'), '-', self.title]))
        }

        # Optional RDS Params
        opt_rds_params = {
            'PreferredBackupWindow': database_config.db_backup_window,
            'BackupRetentionPeriod': database_config.db_backup_retention,
            'PreferredMaintenanceWindow': database_config.db_maintenance_window,
            'StorageType': database_config.db_storage_type,
        }
<commit_msg>adding DB Instance to DB unit<commit_after>#!/usr/bin/python3

from amazonia.classes.security_enabled_object import SecurityEnabledObject
from troposphere import Tags, Ref, rds, Join, Output, GetAtt, Parameter


class DatabaseUnit(SecurityEnabledObject):
    def __init__(self, unit_title, template, network_config, database_config):
        """
        Class to create an RDS and DB subnet group in a vpc
        http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html
        https://github.com/cloudtools/troposphere/blob/master/troposphere/rds.py
        :param unit_title: Title of the autoscaling application e.g 'webApp1', 'api2' or 'dataprocessing'
        :param template: Troposphere stack to append resources to
        :param network_config: object containing network related variables
        :param database_config: object containing database related variablea
        """
        self.title = unit_title + 'Rds'
        self.dependencies = []
        self.db_subnet_group_title = unit_title + 'Dsg'
        self.port = database_config.db_port
        super(DatabaseUnit, self).__init__(vpc=network_config.vpc, title=self.title, template=template)

        self.trop_db_subnet_group = template.add_resource(
            rds.DBSubnetGroup(self.db_subnet_group_title,
                              DBSubnetGroupDescription=self.db_subnet_group_title,
                              SubnetIds=[Ref(x) for x in network_config.private_subnets],
                              Tags=Tags(Name=self.db_subnet_group_title)))
        rds_params = {
            'AllocatedStorage': database_config.db_hdd_size,
            'AllowMajorVersionUpgrade': True,
            'AutoMinorVersionUpgrade': True,
            'MultiAZ': True,
            'DBInstanceClass': database_config.db_instance_type,
            'DBSubnetGroupName': Ref(self.trop_db_subnet_group),
            'DBName': database_config.db_name,
            'DBInstanceIdentifier': Join('', [Ref('AWS::StackName'), self.title]),
            'Engine': database_config.db_engine,
            'Port': self.port,
            'VPCSecurityGroups': [Ref(self.security_group)],
            'Tags': Tags(Name=Join('', [Ref('AWS::StackName'), '-', self.title]))
        }

        # Optional RDS Params
        opt_rds_params = {
            'PreferredBackupWindow': database_config.db_backup_window,
            'BackupRetentionPeriod': database_config.db_backup_retention,
            'PreferredMaintenanceWindow': database_config.db_maintenance_window,
            'StorageType': database_config.db_storage_type,
        }

{'fraction_non_alphanumeric': 0.0944713870029098, 'fraction_numerical': 0.0011639185257032007, 'mean_word_length': 2.850634802091113, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1058569', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1472, 'n_words': 271}