Пример #1
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 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.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 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']

            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_type.engines.all()[0]
            databaseinfra.plan = workflow_dict['plan']
            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 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']

            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_type.engines.all()[0]
            databaseinfra.plan = workflow_dict['plan']
            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
Пример #5
0
def create_database(name,
                    plan,
                    environment,
                    team,
                    project,
                    description,
                    task,
                    backup_hour,
                    maintenance_window,
                    maintenance_day,
                    subscribe_to_email_events=True,
                    is_protected=False,
                    user=None,
                    retry_from=None):
    topology_path = plan.replication_topology.class_path

    name = slugify(name)
    base_name = gen_infra_names(name, 0)
    infra = get_or_create_infra(base_name, plan, environment, backup_hour,
                                maintenance_window, maintenance_day,
                                retry_from)
    instances = get_instances_for(infra, topology_path)

    database_create = DatabaseCreate()
    database_create.task = task
    database_create.name = name
    database_create.plan = plan
    database_create.environment = environment
    database_create.team = team
    database_create.project = project
    database_create.description = description
    database_create.subscribe_to_email_events = subscribe_to_email_events
    database_create.is_protected = is_protected
    database_create.user = user.username if user else task.user
    database_create.infra = infra
    database_create.database = infra.databases.first()
    database_create.save()

    steps = get_deploy_settings(topology_path)

    since_step = None
    if retry_from:
        since_step = retry_from.current_step

    if steps_for_instances(steps,
                           instances,
                           task,
                           database_create.update_step,
                           since_step=since_step):
        database_create.set_success()
        task.set_status_success('Database created')
        database_create.database.finish_task()
    else:
        database_create.set_error()
        task.set_status_error('Could not create database\n'
                              'Please check error message and do retry')
Пример #6
0
def create_database(
    name, plan, environment, team, project, description, task,
    subscribe_to_email_events=True, is_protected=False, user=None,
    retry_from=None
):
    topology_path = plan.replication_topology.class_path

    number_of_vms = get_deploy_instances_size(topology_path)
    name = slugify(name)
    base_name = gen_infra_names(name, number_of_vms)

    infra = get_or_create_infra(base_name, plan, environment, retry_from)

    instances = []
    for i in range(number_of_vms):
        try:
            instance_name = '{}-0{}-{}'.format(
                base_name['name_prefix'], i+1, base_name['name_stamp']
            )
            instance = infra.instances.get(
                Q(hostname__hostname__startswith=instance_name) |
                Q(dns__startswith=instance_name)
            )
        except Instance.DoesNotExist:
            instance = Instance()
            instance.dns = base_name['vms'][i]
            instance.databaseinfra = infra

            driver = infra.get_driver()
            instance.port = driver.get_default_database_port()
            instance.instance_type = driver.get_default_instance_type()

        instance.vm_name = instance.dns
        instances.append(instance)

    database_create = DatabaseCreate()
    database_create.task = task
    database_create.name = name
    database_create.plan = plan
    database_create.environment = environment
    database_create.team = team
    database_create.project = project
    database_create.description = description
    database_create.subscribe_to_email_events = subscribe_to_email_events
    database_create.is_protected = is_protected
    database_create.user = '******'
    database_create.infra = infra
    database_create.database = infra.databases.first()
    database_create.save()

    steps = get_deploy_settings(topology_path)

    since_step = None
    if retry_from:
        since_step = retry_from.current_step

    if steps_for_instances(
        steps, instances, task, database_create.update_step,
        since_step=since_step
    ):
        database_create.set_success()
        task.set_status_success('Database created')
    else:
        database_create.set_error()
        task.set_status_error(
            'Could not create database\n'
            'Please check error message and do retry'
        )