def get_instances_for(infra, topology_path):
    instances = []
    group_instances = get_deploy_instances(topology_path)
    for count, group in enumerate(group_instances):
        for instance_type in group:
            instance_name = get_vm_name(infra.name_prefix, infra.name_stamp,
                                        count + 1)

            try:
                instance = infra.instances.get(
                    Q(hostname__hostname__startswith=instance_name)
                    | Q(dns__startswith=instance_name),
                    port=instance_type.port,
                )
            except Instance.DoesNotExist:
                instance = Instance()
                instance.dns = instance_name
                instance.databaseinfra = infra

                instance.port = instance_type.port
                instance.instance_type = instance_type.instance_type

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

    return instances
    def _create_instance(self):
        inst = Instance()
        inst.address = '127.0.0.1'
        inst.port = 27017
        inst.is_active = True
        inst.databaseinfra = physical_factory.DatabaseInfraFactory.create(
            plan=self.plan)
        inst.status = 1
        inst.instance_type = 2
        inst.total_size_in_bytes = 100
        inst.used_size_in_bytes = 50
        #TODO: Fix that vm_name. See better way to set vm_name not on instance directly
        inst.vm_name = inst.dns

        return inst
Пример #3
0
    def _create_instance(self):
        inst = Instance()
        inst.address = '127.0.0.1'
        inst.port = 27017
        inst.is_active = True
        inst.databaseinfra = physical_factory.DatabaseInfraFactory.create(
            plan=self.plan
        )
        inst.status = 1
        inst.instance_type = 2
        inst.total_size_in_bytes = 100
        inst.used_size_in_bytes = 50
        #TODO: Fix that vm_name. See better way to set vm_name not on instance directly
        inst.vm_name = inst.dns

        return inst
Пример #4
0
def add_instances_to_database(self,
                              database,
                              user,
                              task,
                              number_of_instances=1):
    from workflow.workflow import steps_for_instances_with_rollback
    from util.providers import get_add_database_instances_steps
    from util import get_vm_name

    worker_name = get_worker_name()
    task = TaskHistory.register(self.request, user, task, worker_name)

    infra = database.infra
    plan = infra.plan
    driver = infra.get_driver()

    class_path = plan.replication_topology.class_path
    steps = get_add_database_instances_steps(class_path)

    instances = []
    last_vm_created = infra.last_vm_created

    for i in range(number_of_instances):
        last_vm_created += 1
        vm_name = get_vm_name(prefix=infra.name_prefix,
                              sufix=infra.name_stamp,
                              vm_number=last_vm_created)
        new_instance = Instance(databaseinfra=infra,
                                dns=vm_name,
                                port=driver.get_default_database_port())
        new_instance.vm_name = vm_name
        instances.append(new_instance)

    success = steps_for_instances_with_rollback(
        steps,
        instances,
        task,
    )

    if success:
        task.update_status_for(TaskHistory.STATUS_SUCCESS, 'Done')
    else:
        task.update_status_for(TaskHistory.STATUS_ERROR, 'Done')
def get_instances_for(infra, topology_path):
    instances = []
    number_of_vms = get_deploy_instances_size(topology_path)
    for i in range(number_of_vms):
        instance_name = get_vm_name(infra.name_prefix, infra.name_stamp, i + 1)

        try:
            instance = infra.instances.get(
                Q(hostname__hostname__startswith=instance_name) |
                Q(dns__startswith=instance_name)
            )
        except Instance.DoesNotExist:
            instance = Instance()
            instance.dns = instance_name
            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)

    return instances
Пример #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'
        )