def get_or_create_infra(base_name, plan, environment, retry_from=None):
    if retry_from:
        infra = retry_from.infra
        base_name['infra'] = infra.name
        base_name['name_prefix'] = infra.name_prefix
        base_name['name_stamp'] = infra.name_stamp
    else:
        infra = DatabaseInfra()
        infra.name = base_name['infra']
        infra.name_prefix = base_name['name_prefix']
        infra.name_stamp = base_name['name_stamp']
        infra.last_vm_created = 0
        infra.engine = plan.engine
        infra.plan = plan
        infra.disk_offering = plan.disk_offering
        infra.environment = environment
        infra.capacity = 1
        infra.per_database_size_mbytes = plan.max_db_size
        infra.save()

        driver = infra.get_driver()
        user, password, key = driver.build_new_infra_auth()
        infra.user = user
        infra.password = password
        infra.database_key = key
        infra.save()

    return infra
예제 #2
0
    def do(self, workflow_dict):
        try:
            workflow_dict['names'] = gen_infra_names(
                name=workflow_dict['name'], qt=workflow_dict['qt'])

            databaseinfra = DatabaseInfra()
            databaseinfra.name = workflow_dict['names']['infra']
            databaseinfra.user = ''
            databaseinfra.password = make_db_random_password()
            databaseinfra.engine = workflow_dict['plan'].engine
            databaseinfra.plan = workflow_dict['plan']
            databaseinfra.disk_offering = workflow_dict['plan'].disk_offering
            databaseinfra.environment = workflow_dict['environment']
            databaseinfra.capacity = 1
            databaseinfra.per_database_size_mbytes = workflow_dict[
                'plan'].max_db_size
            databaseinfra.save()

            LOG.info("DatabaseInfra created!")
            workflow_dict['databaseinfra'] = databaseinfra

            return True
        except Exception:

            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0002)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False
def get_or_create_infra(base_name,
                        plan,
                        environment,
                        backup_hour=None,
                        maintenance_window=None,
                        maintenance_day=None,
                        retry_from=None,
                        pool=None):
    if retry_from:
        infra = retry_from.infra
        base_name['infra'] = infra.name
        base_name['name_prefix'] = infra.name_prefix
        base_name['name_stamp'] = infra.name_stamp
    else:
        random_backup_hour, random_maintenance_hour, random_maintenance_day = (
            DatabaseForm.randomize_backup_and_maintenance_hour())
        infra = DatabaseInfra()
        infra.name = base_name['infra']
        infra.name_prefix = base_name['name_prefix']
        infra.name_stamp = base_name['name_stamp']
        infra.last_vm_created = 0
        infra.engine = plan.engine
        infra.plan = plan
        infra.disk_offering = plan.disk_offering
        infra.disk_offering_type = plan.disk_offering_type
        infra.environment = environment
        infra.capacity = 1
        infra.per_database_size_mbytes = plan.max_db_size
        infra.backup_hour = backup_hour or random_backup_hour
        infra.maintenance_window = (maintenance_window
                                    or random_maintenance_hour)
        infra.maintenance_day = maintenance_day or random_maintenance_day
        infra.engine_patch = plan.engine.default_engine_patch
        infra.pool = pool
        infra.save()

        driver = infra.get_driver()
        user, password, key = driver.build_new_infra_auth()
        infra.user = user
        infra.password = password
        infra.database_key = key
        infra.save()

    return infra
예제 #4
0
def get_or_create_infra(base_name, plan, environment, retry_from=None):
    if retry_from:
        infra = retry_from.infra
        base_name['infra'] = infra.name
        base_name['name_prefix'] = infra.name_prefix
        base_name['name_stamp'] = infra.name_stamp
    else:
        infra = DatabaseInfra()
        infra.name = base_name['infra']
        infra.name_prefix = base_name['name_prefix']
        infra.name_stamp = base_name['name_stamp']
        infra.last_vm_created = 0
        infra.password = make_db_random_password()
        infra.engine = plan.engine
        infra.plan = plan
        infra.disk_offering = plan.disk_offering
        infra.environment = environment
        infra.capacity = 1
        infra.per_database_size_mbytes = plan.max_db_size
        infra.save()

    return infra
예제 #5
0
    def do(self, workflow_dict):
        try:
            workflow_dict['names'] = gen_infra_names(
                name=workflow_dict['name'], qt=workflow_dict['qt'])

            databaseinfra = DatabaseInfra()
            databaseinfra.name = workflow_dict['names']['infra']
            databaseinfra.name_prefix = workflow_dict['names']['name_prefix']
            databaseinfra.name_stamp = workflow_dict['names']['name_stamp']
            databaseinfra.last_vm_created = 0

            credentials = get_engine_credentials(engine=str(workflow_dict['plan'].engine_type),
                                                 environment=workflow_dict['environment'])
            databaseinfra.user = credentials.user
            databaseinfra.password = credentials.password
            databaseinfra.engine = workflow_dict['plan'].engine
            databaseinfra.plan = workflow_dict['plan']
            databaseinfra.disk_offering = workflow_dict['plan'].disk_offering
            databaseinfra.environment = workflow_dict['environment']
            databaseinfra.capacity = 1
            databaseinfra.per_database_size_mbytes = workflow_dict[
                'plan'].max_db_size
            databaseinfra.save()

            LOG.info("DatabaseInfra created!")
            workflow_dict['databaseinfra'] = databaseinfra

            return True
        except Exception:

            traceback = full_stack()

            workflow_dict['exceptions']['error_codes'].append(DBAAS_0002)
            workflow_dict['exceptions']['traceback'].append(traceback)

            return False