示例#1
0
def database_change_parameters_retry(request, context, database):
    can_do_change_parameters, error = database.can_do_change_parameters_retry()
    if can_do_change_parameters:
        changed_parameters, parameter_error = DatabaseParameters.update_database_parameters(request.POST, database)

        if parameter_error:
            messages.add_message(request, messages.ERROR, error)
            return HttpResponseRedirect(
                reverse('admin:change_parameters_retry',
                        kwargs={'id': database.id})
            )

        last_change_parameters = database.change_parameters.last()

        if not last_change_parameters.is_status_error:
            error = "Cannot do retry, last change parameters status is '{}'!".format(
                last_change_parameters.get_status_display()
            )
        else:
            since_step = last_change_parameters.current_step

    if error:
        messages.add_message(request, messages.ERROR, error)
    else:
        TaskRegister.database_change_parameters(
            database=database,
            user=request.user,
            since_step=since_step
        )

    return HttpResponseRedirect(
        reverse('admin:logical_database_parameters', kwargs={'id': database.id})
    )
示例#2
0
 def recreate_slave(self, request, pk=None):
     host = self.get_object()
     if not host.is_database:
         return self._render_error(
             "The host must be Database instance",
             422
         )
     serializer = self.get_serializer()
     database = serializer.get_database(host)
     if database.is_being_used_elsewhere():
         return self._render_error(
             "Database {} is being used for another task".format(database),
             422
         )
     if not (database.databaseinfra.plan.replication_topology
             .can_recreate_slave):
         return self._render_error(
             "This topology cant recreate slave",
             422
         )
     instance = host.database_instance()
     driver = instance.databaseinfra.get_driver()
     if driver.check_instance_is_master(instance):
         return self._render_error(
             "Host is master. The host must be Slave",
             422
         )
         raise Exception()
     TaskRegister.recreate_slave(host=host, user=request.user)
     return Response(
         {'hostname': host.hostname, 'id': host.id},
         status=204
     )
示例#3
0
    def clone(cls, database, clone_name, plan, environment, user):
        from notification.tasks import TaskRegister

        TaskRegister.database_clone(
            origin_database=database, clone_name=clone_name, plan=plan,
            environment=environment, user=user
        )
示例#4
0
    def resize(cls, database, offering, user):
        from notification.tasks import TaskRegister

        TaskRegister.database_resize(
            database=database, user=user,
            offering=offering
        )
示例#5
0
def database_delete_host(request, database_id, host_id):
    database = Database.objects.get(id=database_id)
    instance = database.infra.instances.get(hostname_id=host_id)

    can_delete = True
    if not instance.read_only:
        messages.add_message(
            request, messages.ERROR,
            'Host is not read only, cannot be removed.'
        )
        can_delete = False

    if database.is_being_used_elsewhere():
        messages.add_message(
            request, messages.ERROR,
            'Host cannot be deleted because database is in use by another task.'
        )
        can_delete = False

    if can_delete:
        TaskRegister.database_remove_instance(database=database, instance=instance, user=request.user)

    return HttpResponseRedirect(
        reverse('admin:logical_database_hosts', kwargs={'id': database.id})
    )
示例#6
0
def database_configure_ssl_retry(request, context=None, database=None, id=None):

    if database is None:
        database = Database.objects.get(id=id)

    can_do_configure_ssl, error = database.can_do_configure_ssl_retry()

    if can_do_configure_ssl:
        last_configure_ssl = database.configure_ssl.last()
        if not last_configure_ssl:
            error = "Database does not have configure SSL task!"
        elif not last_configure_ssl.is_status_error:
            error = "Cannot do retry, last configure SSL status is '{}'!".format(
                last_configure_ssl.get_status_display()
            )
        else:
            since_step = last_configure_ssl.current_step

    if error:
        messages.add_message(request, messages.ERROR, error)
    else:
        TaskRegister.database_configure_ssl(
            database=database,
            user=request.user,
            since_step=since_step
        )

    return HttpResponseRedirect(
        reverse('admin:logical_database_credentials', kwargs={'id': database.id})
    )
示例#7
0
def database_delete_host(request, database_id, host_id):
    database = Database.objects.get(id=database_id)
    instance = database.infra.instances.get(hostname_id=host_id)

    can_delete = True
    if not instance.read_only:
        messages.add_message(
            request, messages.ERROR,
            'Host is not read only, cannot be removed.'
        )
        can_delete = False

    if database.is_being_used_elsewhere():
        messages.add_message(
            request, messages.ERROR,
            'Host cannot be deleted because database is in use by another task.'
        )
        can_delete = False

    if can_delete:
        TaskRegister.database_remove_instance(database=database, instance=instance, user=request.user)

    return HttpResponseRedirect(
        reverse('admin:logical_database_hosts', kwargs={'id': database.id})
    )
示例#8
0
    def resize(cls, database, offering, user):
        from notification.tasks import TaskRegister

        TaskRegister.database_resize(
            database=database, user=user,
            offering=offering
        )
示例#9
0
    def resize(cls, database, cloudstackpack, user):
        from notification.tasks import TaskRegister

        TaskRegister.database_resize(
            database=database, user=user,
            cloudstack_pack=cloudstackpack
        )
示例#10
0
    def clone(cls, database, clone_name, plan, environment, user):
        from notification.tasks import TaskRegister

        TaskRegister.database_clone(
            origin_database=database, clone_name=clone_name, plan=plan,
            environment=environment, user=user
        )
示例#11
0
def _add_read_only_instances(request, database):
    try:
        check_is_database_dead(database.id, 'Add read-only instances')
        check_is_database_enabled(database.id, 'Add read-only instances')
    except DisabledDatabase as err:
        messages.add_message(request, messages.ERROR, err.message)
        return

    if not database.plan.replication_topology.has_horizontal_scalability:
        messages.add_message(
            request, messages.ERROR,
            'Database topology do not have horizontal scalability')
        return

    if 'add_read_qtd' not in request.POST:
        messages.add_message(request, messages.ERROR, 'Quantity is required')
        return

    max_read_hosts = Configuration.get_by_name_as_int('max_read_hosts', 5)
    qtd_new_hosts = int(request.POST['add_read_qtd'])
    current_read_nodes = len(database.infra.instances.filter(read_only=True))
    total_read_hosts = qtd_new_hosts + current_read_nodes
    if total_read_hosts > max_read_hosts:
        messages.add_message(
            request, messages.ERROR,
            'Current limit of read only hosts is {} and you are trying to setup {}'
            .format(max_read_hosts, total_read_hosts))
        return

    TaskRegister.database_add_instances(database=database,
                                        user=request.user,
                                        number_of_instances=qtd_new_hosts)
示例#12
0
def database_configure_ssl_retry(request,
                                 context=None,
                                 database=None,
                                 id=None):

    if database is None:
        database = Database.objects.get(id=id)

    can_do_configure_ssl, error = database.can_do_configure_ssl_retry()

    if can_do_configure_ssl:
        last_configure_ssl = database.configure_ssl.last()
        if not last_configure_ssl:
            error = "Database does not have configure SSL task!"
        elif not last_configure_ssl.is_status_error:
            error = "Cannot do retry, last configure SSL status is '{}'!".format(
                last_configure_ssl.get_status_display())
        else:
            since_step = last_configure_ssl.current_step

    if error:
        messages.add_message(request, messages.ERROR, error)
    else:
        TaskRegister.database_configure_ssl(database=database,
                                            user=request.user,
                                            since_step=since_step)

    return HttpResponseRedirect(
        reverse('admin:logical_database_credentials',
                kwargs={'id': database.id}))
示例#13
0
def database_reinstall_vm(request, database_id, host_id):
    database = Database.objects.get(id=database_id)
    instances = database.infra.instances.filter(hostname_id=host_id)
    for instance in instances:
        if instance.is_database:
            break

    can_reinstall_vm = True

    if database.is_being_used_elsewhere():
        messages.add_message(
            request, messages.ERROR,
            'Can not reinstall VM because database is in use by another task.'
        )
        can_reinstall_vm = False

    if can_reinstall_vm:
        TaskRegister.database_reinstall_vm(
            instance=instance,
            user=request.user,
        )

    return HttpResponseRedirect(
        reverse('admin:logical_database_hosts', kwargs={'id': database.id})
    )
示例#14
0
def _delete_snapshot(request, database):
    if 'restore_snapshot' not in request.POST:
        messages.add_message(request, messages.ERROR, 'Snapshot is required')
        return

    snapshot_id = request.POST.get('restore_snapshot')
    for instance in database.infra.instances.all():
        snapshot = instance.backup_instance.filter(id=snapshot_id).first()
        if snapshot:
            break
    else:
        messages.add_message(
            request, messages.ERROR, 'The snapshot {} is not from {}'.format(
                snapshot_id, database
            )
        )
        return

    if snapshot.purge_at:
        messages.add_message(
            request, messages.ERROR,
            'This snapshot, was deleted at {}'.format(snapshot.purge_at)
        )
        return
    elif snapshot.is_automatic:
        messages.add_message(
            request, messages.ERROR,
            'This is an automatic snapshot, it could not be deleted'
        )
        return

    TaskRegister.database_remove_backup(
        database=database, snapshot=snapshot, user=request.user.username
    )
    def retry_view(self, request, restore_id):
        retry_from = get_object_or_404(DatabaseRestore, pk=restore_id)

        error = False
        if not retry_from.is_status_error:
            error = True
            messages.add_message(
                request,
                messages.ERROR,
                "You can not do retry because restore status is '{}'".format(
                    retry_from.get_status_display()),
            )

        if not retry_from.can_do_retry:
            error = True
            messages.add_message(request, messages.ERROR,
                                 "Restore retry is disabled")

        if error:
            return HttpResponseRedirect(
                reverse('admin:maintenance_databaserestore_change',
                        args=(restore_id, )))

        TaskRegister.restore_snapshot(
            database=retry_from.database,
            snapshot=retry_from.group.backups.first().id,
            user=request.user,
            retry_from=retry_from)

        url = reverse('admin:notification_taskhistory_changelist')
        filter = "user={}".format(request.user.username)
        return HttpResponseRedirect('{}?{}'.format(url, filter))
def database_reinstall_vm_retry(request, context, database):

    last_reinstall_vm = database.reinstall_vm.last()
    can_reinstall_vm = True

    if not last_reinstall_vm:
        messages.add_message(
            request, messages.ERROR,
            'Can not retry reinstall VM because there is not any reinstall task in progress.'
        )
        can_reinstall_vm = False

    elif database.is_being_used_elsewhere(
        ['notification.tasks.reinstall_vm_database']):
        messages.add_message(
            request, messages.ERROR,
            'Can not retry reinstall VM because database is in use by another task.'
        )
        can_reinstall_vm = False

    else:
        instance = last_reinstall_vm.instance
        since_step = last_reinstall_vm.current_step

    if can_reinstall_vm:
        TaskRegister.database_reinstall_vm(
            instance=instance,
            user=request.user,
            since_step=since_step,
        )

    return HttpResponseRedirect(
        reverse('admin:logical_database_hosts', kwargs={'id': database.id}))
def database_change_parameters_retry(request, context, database):
    can_do_change_parameters, error = database.can_do_change_parameters_retry()
    if can_do_change_parameters:
        changed_parameters, parameter_error = DatabaseParameters.update_database_parameters(
            request.POST, database)

        if parameter_error:
            messages.add_message(request, messages.ERROR, error)
            return HttpResponseRedirect(
                reverse('admin:change_parameters_retry',
                        kwargs={'id': database.id}))

        last_change_parameters = database.change_parameters.last()

        if not last_change_parameters.is_status_error:
            error = "Cannot do retry, last change parameters status is '{}'!".format(
                last_change_parameters.get_status_display())
        else:
            since_step = last_change_parameters.current_step

    if error:
        messages.add_message(request, messages.ERROR, error)
    else:
        TaskRegister.database_change_parameters(database=database,
                                                user=request.user,
                                                since_step=since_step)

    return HttpResponseRedirect(
        reverse('admin:logical_database_parameters',
                kwargs={'id': database.id}))
    def post(self, request, format=None):
        validations = (self._validate_required_params,
                       self._validate_search_metadata_params,
                       self._validate_env, self._validate_database,
                       self._validate_user, self._validate_team,
                       self._validate_database_alocation,
                       self._validate_if_kubernetes_env, self._validate_plan)

        for validation in validations:
            err = validation()
            if err is not None:
                return err

        backup_hour, maintenance_hour, maintenance_day = (
            DatabaseForm.randomize_backup_and_maintenance_hour())

        TaskRegister.database_create(name=self.name_param,
                                     plan=self.dbaas_plan,
                                     environment=self.env,
                                     team=self.dbaas_team,
                                     project=None,
                                     description=self.description_param,
                                     user=self.dbaas_user,
                                     is_protected=True,
                                     backup_hour=backup_hour,
                                     maintenance_window=maintenance_hour,
                                     maintenance_day=maintenance_day,
                                     **self.extra_params)

        return Response(status=status.HTTP_201_CREATED)
def database_resize_rollback(request, context, database):
    last_resize = get_last_valid_resize(request, database)
    if last_resize:
        TaskRegister.database_resize_rollback(last_resize, request.user)

    return HttpResponseRedirect(
        reverse('admin:logical_database_resizes', kwargs={'id': database.id}))
示例#20
0
    def disk_resize(cls, database, new_disk_offering, user):
        from physical.models import DiskOffering
        from notification.tasks import TaskRegister

        disk_offering = DiskOffering.objects.get(id=new_disk_offering)

        TaskRegister.database_disk_resize(database=database, user=user, disk_offering=disk_offering)
示例#21
0
def database_upgrade_retry(request, context, database):
    can_do_upgrade, error = database.can_do_upgrade_retry()
    if can_do_upgrade:
        source_plan = database.databaseinfra.plan
        upgrades = database.upgrades.filter(source_plan=source_plan)
        last_upgrade = upgrades.last()
        if not last_upgrade:
            error = "Database does not have upgrades from {} {}!".format(
                source_plan.engine.engine_type, source_plan.engine.version
            )
        elif not last_upgrade.is_status_error:
            error = "Cannot do retry, last upgrade status is '{}'!".format(
                last_upgrade.get_status_display()
            )
        else:
            since_step = last_upgrade.current_step

    if error:
        messages.add_message(request, messages.ERROR, error)
    else:

        TaskRegister.database_upgrade(
            database=database,
            user=request.user,
            since_step=since_step
        )
    return HttpResponseRedirect(
        reverse('admin:logical_database_resizes', kwargs={'id': database.id})
    )
示例#22
0
def database_upgrade_retry(request, context, database):
    can_do_upgrade, error = database.can_do_upgrade_retry()
    if can_do_upgrade:
        source_plan = database.databaseinfra.plan
        upgrades = database.upgrades.filter(source_plan=source_plan)
        last_upgrade = upgrades.last()
        if not last_upgrade:
            error = "Database does not have upgrades from {} {}!".format(
                source_plan.engine.engine_type, source_plan.engine.version
            )
        elif not last_upgrade.is_status_error:
            error = "Cannot do retry, last upgrade status is '{}'!".format(
                last_upgrade.get_status_display()
            )
        else:
            since_step = last_upgrade.current_step

    if error:
        messages.add_message(request, messages.ERROR, error)
    else:

        TaskRegister.database_upgrade(
            database=database,
            user=request.user,
            since_step=since_step
        )
    return HttpResponseRedirect(
        reverse('admin:logical_database_resizes', kwargs={'id': database.id})
    )
示例#23
0
    def retry_view(self, request, create_id):
        retry_from = get_object_or_404(DatabaseCreate, pk=create_id)

        success, redirect = self.check_status(request, create_id, 'retry')
        if not success:
            return redirect

        TaskRegister.database_create(
            name=retry_from.name,
            plan=retry_from.plan,
            environment=retry_from.environment,
            team=retry_from.team,
            project=retry_from.project,
            description=retry_from.description,
            backup_hour=retry_from.infra.backup_hour,
            maintenance_window=retry_from.infra.maintenance_window,
            maintenance_day=retry_from.infra.maintenance_day,
            subscribe_to_email_events=retry_from.subscribe_to_email_events,
            is_protected=retry_from.is_protected,
            user=request.user,
            retry_from=retry_from,
            **{'pool': retry_from.pool})

        url = reverse('admin:notification_taskhistory_changelist')
        filter = "user={}".format(request.user.username)
        return HttpResponseRedirect('{}?{}'.format(url, filter))
示例#24
0
    def disk_resize(cls, database, new_disk_offering, user):
        from physical.models import DiskOffering
        from notification.tasks import TaskRegister

        disk_offering = DiskOffering.objects.get(id=new_disk_offering)

        TaskRegister.database_disk_resize(database=database, user=user, disk_offering=disk_offering)
示例#25
0
def _delete_snapshot(request, database):
    if 'restore_snapshot' not in request.POST:
        messages.add_message(request, messages.ERROR, 'Snapshot is required')
        return

    snapshot_id = request.POST.get('restore_snapshot')
    for instance in database.infra.instances.all():
        snapshot = instance.backup_instance.filter(id=snapshot_id).first()
        if snapshot:
            break
    else:
        messages.add_message(
            request, messages.ERROR,
            'The snapshot {} is not from {}'.format(snapshot_id, database))
        return

    if snapshot.purge_at:
        messages.add_message(
            request, messages.ERROR,
            'This snapshot, was deleted at {}'.format(snapshot.purge_at))
        return
    elif snapshot.is_automatic:
        messages.add_message(
            request, messages.ERROR,
            'This is an automatic snapshot, it could not be deleted')
        return

    TaskRegister.database_remove_backup(database=database,
                                        snapshot=snapshot,
                                        user=request.user.username)
示例#26
0
def database_reinstall_vm(request, database_id, host_id):
    database = Database.objects.get(id=database_id)
    instances = database.infra.instances.filter(hostname_id=host_id)
    for instance in instances:
        if instance.is_database:
            break

    can_reinstall_vm = True

    if database.is_being_used_elsewhere():
        messages.add_message(
            request, messages.ERROR,
            'Can not reinstall VM because database is in use by another task.'
        )
        can_reinstall_vm = False

    if can_reinstall_vm:
        TaskRegister.database_reinstall_vm(
            instance=instance,
            user=request.user,
        )

    return HttpResponseRedirect(
        reverse('admin:logical_database_hosts', kwargs={'id': database.id})
    )
示例#27
0
def database_reinstall_vm_retry(request, context, database):
    last_reinstall_vm = database.reinstall_vm.last()
    can_reinstall_vm = True

    if not last_reinstall_vm:
        messages.add_message(
            request, messages.ERROR,
            'Can not retry reinstall VM because there is not any reinstall task in progress.'
        )
        can_reinstall_vm = False

    elif database.is_being_used_elsewhere(['notification.tasks.reinstall_vm_database']):
        messages.add_message(
            request, messages.ERROR,
            'Can not retry reinstall VM because database is in use by another task.'
        )
        can_reinstall_vm = False

    else:
        instance = last_reinstall_vm.instance
        since_step = last_reinstall_vm.current_step

    if can_reinstall_vm:
        TaskRegister.database_reinstall_vm(
            instance=instance,
            user=request.user,
            since_step=since_step,
        )

    return HttpResponseRedirect(
        reverse('admin:logical_database_hosts', kwargs={'id': database.id})
    )
 def rollback_view(self, request, host_migrate_id):
     rollback_from = get_object_or_404(HostMigrate, pk=host_migrate_id)
     success, redirect = self.check_status(request, rollback_from,
                                           'rollback')
     if not success:
         return redirect
     TaskRegister.host_migrate_rollback(rollback_from, request.user)
     return self.redirect_to_database(rollback_from)
示例#29
0
def database_resize_rollback(request, context, database):
    last_resize = get_last_valid_resize(request, database)
    if last_resize:
        TaskRegister.database_resize_rollback(last_resize, request.user)

    return HttpResponseRedirect(
        reverse('admin:logical_database_resizes', kwargs={'id': database.id})
    )
示例#30
0
    def restore(cls, database, snapshot, user):
        from notification.tasks import TaskRegister

        LOG.info(
            "Changing database volume with params: database {} snapshot: {}, user: {}"
            .format(database, snapshot, user))
        TaskRegister.restore_snapshot(database=database,
                                      snapshot=snapshot,
                                      user=user)
示例#31
0
def database_upgrade(request, context, database):
    can_do_upgrade, error = database.can_do_upgrade()
    if not can_do_upgrade:
        messages.add_message(request, messages.ERROR, error)
    else:

        TaskRegister.database_upgrade(database=database, user=request.user)
    return HttpResponseRedirect(
        reverse('admin:logical_database_resizes', kwargs={'id': database.id}))
 def rollback_view(self, request, database_migrate_id):
     rollback_from = get_object_or_404(DatabaseMigrate, pk=database_migrate_id)
     success, redirect = self.check_status(
         request, rollback_from, 'rollback'
     )
     if not success:
         return redirect
     TaskRegister.database_migrate_rollback(rollback_from, request.user)
     return self.redirect_to_database(rollback_from)
示例#33
0
 def retry_view(self, request, host_migrate_id):
     retry_from = get_object_or_404(HostMigrate, pk=host_migrate_id)
     success, redirect = self.check_status(request, retry_from, 'retry')
     if not success:
         return redirect
     TaskRegister.host_migrate(retry_from.host, retry_from.zone,
                               retry_from.environment, request.user,
                               retry_from.current_step)
     return self.redirect_to_database(retry_from)
 def retry_view(self, request, manager_id):
     retry_from = get_object_or_404(UpdateSsl, pk=manager_id)
     success, redirect = self.check_status(request, retry_from, 'retry')
     if not success:
         return redirect
     TaskRegister.update_ssl(database=retry_from.database,
                             user=request.user,
                             since_step=retry_from.current_step,
                             step_manager=retry_from)
     return self.redirect_to_database(retry_from)
 def retry_view(self, request, manager_id):
     retry_from = get_object_or_404(RecreateSlave, pk=manager_id)
     success, redirect = self.check_status(request, retry_from, 'retry')
     if not success:
         return redirect
     TaskRegister.recreate_slave(host=retry_from.host,
                                 user=request.user,
                                 since_step=retry_from.current_step,
                                 step_manager=retry_from)
     return self.redirect_to_database(retry_from)
    def retry_view(self, request, database_migrate_id):
        retry_from = get_object_or_404(DatabaseMigrate, pk=database_migrate_id)
        success, redirect = self.check_status(request, retry_from, 'retry')
        if not success:
            return redirect

        TaskRegister.database_migrate(
            retry_from.database, retry_from.environment, retry_from.offering,
            request.user, retry_from.hosts_zones, retry_from.current_step, step_manager=retry_from
        )
        return self.redirect_to_database(retry_from)
示例#37
0
    def restore(cls, database, snapshot, user):
        from notification.tasks import TaskRegister

        LOG.info(
            "Changing database volume with params: database {} snapshot: {}, user: {}".format(
                database, snapshot, user
            )
        )
        TaskRegister.restore_snapshot(
            database=database, snapshot=snapshot, user=user
        )
示例#38
0
def database_change_parameters(request, context, database):
    can_do_change_parameters, error = database.can_do_change_parameters()
    if not can_do_change_parameters:
        messages.add_message(request, messages.ERROR, error)
    else:
        TaskRegister.database_change_parameters(database=database,
                                                user=request.user)

    return HttpResponseRedirect(
        reverse('admin:logical_database_parameters',
                kwargs={'id': database.id}))
    def test_database_disk_resize_with_task_name(self, mocked_delay,
                                                 mocked_create):
        TaskRegister.database_disk_resize(database=MagicMock(),
                                          user='******',
                                          disk_offering='disk_offering',
                                          task_name='custom task name')

        self.assertTrue(mocked_create.called)

        create_task_param = mocked_create.call_args[0][0]
        self.assertEqual(create_task_param['task_name'], 'custom task name')
def database_resize_retry(request, context, database):
    last_resize = get_last_valid_resize(request, database)
    if last_resize:
        TaskRegister.database_resize_retry(
            database=database,
            user=request.user,
            offering=last_resize.target_offer,
            original_offering=last_resize.source_offer,
            since_step=last_resize.current_step)

    return HttpResponseRedirect(
        reverse('admin:logical_database_resizes', kwargs={'id': database.id}))
    def test_database_disk_resize_with_task_name(self, mocked_delay, mocked_create):
        TaskRegister.database_disk_resize(
            database=MagicMock(),
            user='******',
            disk_offering='disk_offering',
            task_name='custom task name'
        )

        self.assertTrue(mocked_create.called)

        create_task_param = mocked_create.call_args[0][0]
        self.assertEqual(create_task_param['task_name'], 'custom task name')
示例#42
0
    def execute(self):
        status, message = self.check_database_status()
        if not status:
            raise exceptions.DatabaseNotAvailable(message)

        self.task_params = dict(database=self.database,
                                target_plan=self.target_plan,
                                user=self.request.user)

        if self.retry:
            self.task_params['since_step'] = self.manager.current_step

        TaskRegister.engine_migrate(**self.task_params)
def database_configure_ssl(request, context, database):

    can_do_configure_ssl, error = database.can_do_configure_ssl()

    if not can_do_configure_ssl:
        messages.add_message(request, messages.ERROR, error)
    else:
        TaskRegister.database_configure_ssl(database=database,
                                            user=request.user)

    return HttpResponseRedirect(
        reverse('admin:logical_database_credentials',
                kwargs={'id': database.id}))
示例#44
0
def database_upgrade(request, context, database):
    can_do_upgrade, error = database.can_do_upgrade()
    if not can_do_upgrade:
        messages.add_message(request, messages.ERROR, error)
    else:

        TaskRegister.database_upgrade(
            database=database,
            user=request.user
        )
    return HttpResponseRedirect(
        reverse('admin:logical_database_resizes', kwargs={'id': database.id})
    )
    def rollback_view(self, request, database_migrate_id):
        rollback_from = get_object_or_404(DatabaseMigrate,
                                          pk=database_migrate_id)

        if rollback_from.migration_stage == rollback_from.NOT_STARTED:
            success, redirect = self.check_status(request, rollback_from,
                                                  'rollback')
            if not success:
                return redirect
        TaskRegister.database_migrate_rollback(rollback_from.database,
                                               request.user,
                                               step_manager=rollback_from)
        return self.redirect_to_database(rollback_from)
示例#46
0
def database_change_parameters(request, context, database):
    can_do_change_parameters, error = database.can_do_change_parameters()
    if not can_do_change_parameters:
        messages.add_message(request, messages.ERROR, error)
    else:
        TaskRegister.database_change_parameters(
            database=database,
            user=request.user
        )

    return HttpResponseRedirect(
        reverse('admin:logical_database_parameters', kwargs={'id': database.id})
    )
示例#47
0
    def retry_view(self, request, database_migrate_id):
        retry_from = get_object_or_404(DatabaseMigrate, pk=database_migrate_id)
        success, redirect = self.check_status(request, retry_from, 'retry')
        if not success:
            return redirect

        TaskRegister.database_migrate(retry_from.database,
                                      retry_from.environment,
                                      retry_from.offering,
                                      request.user,
                                      retry_from.hosts_zones,
                                      retry_from.current_step,
                                      step_manager=retry_from)
        return self.redirect_to_database(retry_from)
示例#48
0
def database_resize_retry(request, context, database):
    last_resize = get_last_valid_resize(request, database)
    if last_resize:
        TaskRegister.database_resize_retry(
            database=database,
            user=request.user,
            offering=last_resize.target_offer,
            original_offering=last_resize.source_offer,
            since_step=last_resize.current_step
        )

    return HttpResponseRedirect(
        reverse('admin:logical_database_resizes', kwargs={'id': database.id})
    )
    def rollback_view(self, request, create_id):
        rollback_from = get_object_or_404(DatabaseCreate, pk=create_id)

        success, redirect = self.check_status(request, create_id, 'rollback')
        if not success:
            return redirect

        TaskRegister.database_create_rollback(
            rollback_from=rollback_from,
            user=request.user,
        )

        url = reverse('admin:notification_taskhistory_changelist')
        filter = "user={}".format(request.user.username)
        return HttpResponseRedirect('{}?{}'.format(url, filter))
示例#50
0
def database_configure_ssl(request, context, database):

    can_do_configure_ssl, error = database.can_do_configure_ssl()

    if not can_do_configure_ssl:
        messages.add_message(request, messages.ERROR, error)
    else:
        TaskRegister.database_configure_ssl(
            database=database,
            user=request.user
        )

    return HttpResponseRedirect(
        reverse('admin:logical_database_credentials', kwargs={'id': database.id})
    )
    def retry_view(self, request, destroy_id):
        rollback_from = get_object_or_404(DatabaseDestroy, pk=destroy_id)

        success, redirect = self.check_status(request, destroy_id, 'retry')
        if not success:
            return redirect

        TaskRegister.database_destroy_retry(
            rollback_from=rollback_from,
            user=request.user,
        )

        task_history_url = reverse('admin:notification_taskhistory_changelist')
        query_string = "user={}".format(request.user.username)
        return HttpResponseRedirect('{}?{}'.format(task_history_url, query_string))
def disk_auto_resize(database, current_size, usage_percentage):
    from notification.tasks import TaskRegister

    disk = DiskOffering.first_greater_than(current_size + 1024)

    if disk > DiskOffering.last_offering_available_for_auto_resize():
        raise DiskOfferingMaxAutoResize()

    if database.is_being_used_elsewhere():
        raise BusyDatabaseError("")

    user = AccountUser.objects.get(username='******')

    task = TaskRegister.database_disk_resize(
        database=database,
        user=user,
        disk_offering=disk,
        task_name='database_disk_auto_resize',
        register_user=False
    )

    email_notifications.disk_resize_notification(
        database=database, new_disk=disk, usage_percentage=usage_percentage
    )

    return task
示例#53
0
    def create(self, request):
        serializer = self.get_serializer(
            data=request.DATA, files=request.FILES)

        if serializer.is_valid():
            self.pre_save(serializer.object)
            data = serializer.restore_fields(request.DATA, request.FILES)

            result = TaskRegister.database_create(
                name=data['name'], plan=data['plan'],
                environment=data['environment'], team=data['team'],
                project=data['project'], description=data['description'],
                subscribe_to_email_events=data['subscribe_to_email_events'],
                user=request.user,
                register_user=False
            )
            headers = self.get_success_headers(data)
            task_url = Site.objects.get_current().domain + \
                '/api/task?task_id=%s' % str(result.id)

            return Response(
                {"task": task_url}, status=status.HTTP_201_CREATED,
                headers=headers
            )

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
    def test_create_obj_task_history(self):
        resp = TaskRegister.create_task(self.task_params)

        self.assertTrue(isinstance(resp, TaskHistory))
        self.assertEqual(resp.task_name, 'fake_task_name')
        self.assertEqual(resp.arguments, 'fake arguments')
        self.assertEqual(resp.object_id, None)
        self.assertEqual(resp.object_class, None)
示例#55
0
    def destroy(self, user):
        if not self.is_in_quarantine:
            self.delete()
            return

        if self.plan.provider != self.plan.CLOUDSTACK:
            self.delete()
            return

        LOG.debug(
            "call destroy_database - name={}, team={}, project={}, "
            "user={}".format(self.name, self.team, self.project, user)
        )

        from notification.tasks import TaskRegister

        TaskRegister.database_destroy(database=self, user=user)
        return
示例#56
0
def database_make_backup(request, context, database):
    error = None
    try:
        check_is_database_dead(database.id, 'Backup')
        check_is_database_enabled(database.id, 'Backup')
    except DisabledDatabase as err:
        error = err.message

    if not context['is_dba']:
        error = "Only DBA's can do database backup"

    if error:
        messages.add_message(request, messages.ERROR, error)
    else:
        TaskRegister.database_backup(
            database=database, user=request.user.username
        )

    return HttpResponseRedirect(
        reverse('admin:logical_database_backup', kwargs={'id': database.id})
    )
示例#57
0
def team_pre_save(sender, **kwargs):
    from notification.tasks import TaskRegister

    team = kwargs.get('instance')
    if not team.id:
        return
    before_update_team = Team.objects.get(pk=team.pk)
    if team.organization != before_update_team.organization:

        for database in team.databases.all():
            TaskRegister.update_organization_name_monitoring(
                database=database,
                organization_name=team.organization.name)

        if before_update_team.organization and \
            before_update_team.organization.external:
            for database in before_update_team.databases.all():
                TaskRegister.update_database_monitoring(
                    database=database,
                    hostgroup=before_update_team.organization.grafana_hostgroup,
                    action='remove')

        if team.organization and team.organization.external:
            for database in team.databases.all():
                TaskRegister.update_database_monitoring(
                    database=database,
                    hostgroup=team.organization.grafana_hostgroup,
                    action='add')
示例#58
0
def organization_pre_save(sender, **kwargs):
    from notification.tasks import TaskRegister

    def add_monit(organization):
        for database in organization.databases:
            TaskRegister.update_database_monitoring(
                database=database,
                hostgroup=organization.grafana_hostgroup,
                action='add')

    def remove_monit(organization):
        for database in organization.databases:
            TaskRegister.update_database_monitoring(
                database=database,
                hostgroup=organization.grafana_hostgroup,
                action='remove')

    organization = kwargs.get('instance')
    if not organization.id:
        return
    before_update_org = Organization.objects.get(pk=organization.pk)

    if before_update_org.external != organization.external:
        if before_update_org.external:
            remove_monit(before_update_org)
        if organization.external:
            add_monit(organization)

    if before_update_org.grafana_hostgroup != organization.grafana_hostgroup:
        if before_update_org.external:
            remove_monit(before_update_org)
        if organization.external:
            add_monit(organization)

    if before_update_org.name != organization.name:
        for database in organization.databases:
            TaskRegister.update_organization_name_monitoring(
                database=database,
                organization_name=organization.name)
示例#59
0
def purge_unused_exports_task(self):
    from notification.tasks import TaskRegister
    task = TaskRegister.purge_unused_exports()

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

    task.add_detail('Getting all inactive exports without snapshots')
    if purge_unused_exports(task):
        task.set_status_success('Done')
    else:
        task.set_status_error('Error')
    def retry_view(self, request, create_id):
        retry_from = get_object_or_404(DatabaseCreate, pk=create_id)

        success, redirect = self.check_status(request, create_id, 'retry')
        if not success:
            return redirect

        TaskRegister.database_create(
            name=retry_from.name,
            plan=retry_from.plan,
            environment=retry_from.environment,
            team=retry_from.team,
            project=retry_from.project,
            description=retry_from.description,
            subscribe_to_email_events=retry_from.subscribe_to_email_events,
            is_protected=retry_from.is_protected,
            user=request.user,
            retry_from=retry_from
        )

        url = reverse('admin:notification_taskhistory_changelist')
        filter = "user={}".format(request.user.username)
        return HttpResponseRedirect('{}?{}'.format(url, filter))