当前位置: 首页>>代码示例>>Python>>正文


Python TaskHistory.save方法代码示例

本文整理汇总了Python中notification.models.TaskHistory.save方法的典型用法代码示例。如果您正苦于以下问题:Python TaskHistory.save方法的具体用法?Python TaskHistory.save怎么用?Python TaskHistory.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在notification.models.TaskHistory的用法示例。


在下文中一共展示了TaskHistory.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
    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)

            task_history = TaskHistory()
            task_history.task_name="create_database"
            task_history.task_status= task_history.STATUS_PENDING
            task_history.arguments="Database name: {}".format(data['name'])
            task_history.save()

            result = create_database.delay(name=data['name'],
                                               plan=data['plan'],
                                               environment=data['environment'],
                                               team=data['team'],
                                               project=data['project'],
                                               description=data['description'],
                                               task_history=task_history,
                                               user=request.user)


            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)
开发者ID:itnihao,项目名称:database-as-a-service,代码行数:33,代码来源:database.py

示例2: delete_model

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
    def delete_model(modeladmin, request, obj):

        LOG.debug("Deleting {}".format(obj))
        database = obj
        if database.is_in_quarantine:

            if database.plan.provider == database.plan.CLOUDSTACK:

                LOG.debug(
                    "call destroy_database - name=%s, team=%s, project=%s, user=%s" % (
                        database.name, database.team, database.project, request.user))

                task_history = TaskHistory()
                task_history.task_name="destroy_database"
                task_history.task_status= task_history.STATUS_WAITING
                task_history.arguments="Database name: {}".format(database.name)
                task_history.user= request.user
                task_history.save()

                destroy_database.delay(database=database,
                                                    task_history=task_history,
                                                    user=request.user
                                                    )

                url = reverse('admin:notification_taskhistory_changelist')
            else:
                database.delete()
        else:
            database.delete()
开发者ID:mbergo,项目名称:database-as-a-service,代码行数:31,代码来源:database.py

示例3: register_task

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
 def register_task(self):
     task_history = TaskHistory()
     task_history.task_id = datetime.now().strftime("%Y%m%d%H%M%S")
     task_history.task_name = "switch_masters_in_zone"
     task_history.relevance = TaskHistory.RELEVANCE_WARNING
     task_history.task_status = TaskHistory.STATUS_RUNNING
     task_history.context = {'hostname': gethostname()}
     task_history.user = 'admin'
     task_history.save()
     return task_history
开发者ID:globocom,项目名称:database-as-a-service,代码行数:12,代码来源:switch_all_masters_in_zone.py

示例4: restore_snapshot

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
    def restore_snapshot(self, request, database_id):
        database = Database.objects.get(id=database_id)

        url = reverse('admin:logical_database_change', args=[database.id])

        if database.is_in_quarantine:
            self.message_user(
                request, "Database in quarantine and cannot be restored", level=messages.ERROR)
            return HttpResponseRedirect(url)

        if database.status != Database.ALIVE or not database.database_status.is_alive:
            self.message_user(
                request, "Database is dead  and cannot be restored", level=messages.ERROR)
            return HttpResponseRedirect(url)

        if database.is_beeing_used_elsewhere():
            self.message_user(
                request, "Database is beeing used by another task, please check your tasks", level=messages.ERROR)
            return HttpResponseRedirect(url)

        if database.has_migration_started():
            self.message_user(
                request, "Database {} cannot be restored because it is beeing migrated.".format(database.name), level=messages.ERROR)
            url = reverse('admin:logical_database_changelist')
            return HttpResponseRedirect(url)

        form = None
        if request.method == 'POST':
            form = RestoreDatabaseForm(
                request.POST, initial={"database_id": database_id},)
            if form.is_valid():
                target_snapshot = request.POST.get('target_snapshot')

                task_history = TaskHistory()
                task_history.task_name = "restore_snapshot"
                task_history.task_status = task_history.STATUS_WAITING
                task_history.arguments = "Restoring {} to an older version.".format(
                    database.name)
                task_history.user = request.user
                task_history.save()

                Database.recover_snapshot(database=database,
                                          snapshot=target_snapshot,
                                          user=request.user,
                                          task_history=task_history.id)

                url = reverse('admin:notification_taskhistory_changelist')

                return HttpResponseRedirect(url + "?user=%s" % request.user.username)
        else:
            form = RestoreDatabaseForm(initial={"database_id": database_id, })

        return render_to_response("logical/database/restore.html",
                                  locals(),
                                  context_instance=RequestContext(request))
开发者ID:jwestarb,项目名称:database-as-a-service,代码行数:57,代码来源:database.py

示例5: databaseregionmigration_view

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
    def databaseregionmigration_view(self, request, databaseregionmigration_id):
        form = DatabaseRegionMigrationDetailForm
        database_region_migration = DatabaseRegionMigration.objects.get(
            id=databaseregionmigration_id)

        if request.method == 'POST':
            form = DatabaseRegionMigrationDetailForm(request.POST)
            if form.is_valid():
                scheduled_for = form.cleaned_data['scheduled_for']

                database_region_migration_detail = DatabaseRegionMigrationDetail(
                    database_region_migration=database_region_migration,
                    step=database_region_migration.current_step,
                    scheduled_for=scheduled_for,
                    created_by=request.user.username)

                database_region_migration_detail.save()

                task_history = TaskHistory()
                task_history.task_name = "execute_database_region_migration"
                task_history.task_status = task_history.STATUS_WAITING

                description = database_region_migration.description()
                task_history.arguments = "Database name: {},\
                                          Macro step: {}".format(database_region_migration.database.name,
                                                                 description)
                task_history.user = request.user
                task_history.save()

                is_rollback = request.GET.get('rollback')
                scheduled_for.replace(
                    tzinfo=tz.tzlocal()).astimezone(tz.tzutc())

                if is_rollback:
                    LOG.info("Rollback!")
                    database_region_migration_detail.step -= 1
                    database_region_migration_detail.save()
                    task = execute_database_region_migration_undo.apply_async(args=[database_region_migration_detail.id,
                                                                                    task_history,
                                                                                    request.user],
                                                                              eta=scheduled_for)
                else:
                    task = execute_database_region_migration.apply_async(args=[database_region_migration_detail.id,
                                                                               task_history, request.user],
                                                                         eta=scheduled_for)

                database_region_migration_detail.celery_task_id = task.task_id
                database_region_migration_detail.save()

                url = reverse('admin:notification_taskhistory_changelist')
                return HttpResponseRedirect(url + "?user=%s" % request.user.username)

        return render_to_response("region_migration/databaseregionmigrationdetail/schedule_next_step.html",
                                  locals(),
                                  context_instance=RequestContext(request))
开发者ID:hunterfu,项目名称:database-as-a-service,代码行数:57,代码来源:databaseregionmigration.py

示例6: post

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
    def post(self, request, *args, **kwargs):
        from dbaas_services.analyzing.tasks import analyze_databases

        task_history = TaskHistory()
        task_history.task_name = "analyze_databases"
        task_history.task_status = task_history.STATUS_WAITING
        task_history.arguments = "Waiting to start"
        task_history.save()
        analyze_databases.delay(task_history=task_history)
        url = reverse('admin:notification_taskhistory_changelist')
        return HttpResponseRedirect(url)
开发者ID:flaviohenriqu,项目名称:database-as-a-service,代码行数:13,代码来源:views.py

示例7: resize

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
    def resize(cls, database, cloudstackpack, user):
        from notification.tasks import resize_database
        from notification.models import TaskHistory

        task_history = TaskHistory()
        task_history.task_name = "resize_database"
        task_history.task_status = task_history.STATUS_WAITING
        task_history.arguments = "Database name: {}".format(database.name)
        task_history.user = user
        task_history.save()

        resize_database.delay(database=database, cloudstackpack=cloudstackpack,
                              user=user, task_history=task_history
                              )
开发者ID:flaviohenriqu,项目名称:database-as-a-service,代码行数:16,代码来源:models.py

示例8: delete_model

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
    def delete_model(modeladmin, request, obj):

        LOG.debug("Deleting {}".format(obj))
        database = obj

        if database.status != Database.ALIVE or not database.database_status.is_alive:
            modeladmin.message_user(
                request, "Database {} is not alive and cannot be deleted".format(database.name), level=messages.ERROR)
            url = reverse('admin:logical_database_changelist')
            return HttpResponseRedirect(url)

        if database.is_beeing_used_elsewhere():
            modeladmin.message_user(
                request, "Database {} cannot be deleted because it is in use by another task.".format(database.name), level=messages.ERROR)
            url = reverse('admin:logical_database_changelist')
            return HttpResponseRedirect(url)

        if database.has_migration_started():
            modeladmin.message_user(
                request, "Database {} cannot be deleted because it is beeing migrated.".format(database.name), level=messages.ERROR)
            url = reverse('admin:logical_database_changelist')
            return HttpResponseRedirect(url)

        if database.is_in_quarantine:

            if database.plan.provider == database.plan.CLOUDSTACK:

                LOG.debug(
                    "call destroy_database - name=%s, team=%s, project=%s, user=%s" % (
                        database.name, database.team, database.project, request.user))

                task_history = TaskHistory()
                task_history.task_name = "destroy_database"
                task_history.task_status = task_history.STATUS_WAITING
                task_history.arguments = "Database name: {}".format(
                    database.name)
                task_history.user = request.user
                task_history.save()

                destroy_database.delay(database=database,
                                       task_history=task_history,
                                       user=request.user
                                       )

                url = reverse('admin:notification_taskhistory_changelist')
            else:
                database.delete()
        else:
            database.delete()
开发者ID:jwestarb,项目名称:database-as-a-service,代码行数:51,代码来源:database.py

示例9: clone

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
    def clone(cls, database, clone_name, plan, environment, user):
        from notification.tasks import clone_database
        from notification.models import TaskHistory

        task_history = TaskHistory()
        task_history.task_name = "clone_database"
        task_history.task_status = task_history.STATUS_WAITING
        task_history.arguments = "Database name: {}".format(database.name)
        task_history.user = user
        task_history.save()

        clone_database.delay(origin_database=database, clone_name=clone_name,
                             plan=plan, environment=environment, user=user,
                             task_history=task_history
                             )
开发者ID:flaviohenriqu,项目名称:database-as-a-service,代码行数:17,代码来源:models.py

示例10: register_task

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
 def register_task(self, database):
     task_history = TaskHistory()
     task_history.task_id = datetime.now().strftime("%Y%m%d%H%M%S")
     task_history.task_name = self.TASK_NAME
     task_history.relevance = TaskHistory.RELEVANCE_WARNING
     task_history.task_status = TaskHistory.STATUS_RUNNING
     task_history.context = {'hostname': gethostname()}
     task_history.user = 'admin'
     task_history.db_id = database.id
     task_history.object_class = "logical_database"
     task_history.object_id = database.id
     task_history.database_name = database.name
     task_history.arguments = 'Database_name: {}'.format(database.name)
     task_history.save()
     return task_history
开发者ID:globocom,项目名称:database-as-a-service,代码行数:17,代码来源:filer_migrate.py

示例11: mongodb_engine_version_upgrade

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
    def mongodb_engine_version_upgrade(self, request, database_id):
        from notification.tasks import upgrade_mongodb_24_to_30
        database = Database.objects.get(id=database_id)

        url = reverse('admin:logical_database_change', args=[database_id])

        if database.is_in_quarantine:
            self.message_user(
                request, "Database in quarantine and cannot be upgraded!",
                level=messages.ERROR)
            return HttpResponseRedirect(url)

        if database.status != Database.ALIVE or not database.database_status.is_alive:
            self.message_user(
                request, "Database is dead  and cannot be upgraded!",
                level=messages.ERROR)
            return HttpResponseRedirect(url)

        if database.has_migration_started():
            self.message_user(
                request, "Database {} is beeing migrated and cannot be upgraded!".format(database.name), level=messages.ERROR)
            return HttpResponseRedirect(url)

        if not database.is_mongodb_24:
            self.message_user(
                request, "Database {} cannot be upgraded, please contact you DBA.".format(database.name), level=messages.ERROR)
            return HttpResponseRedirect(url)

        task_history = TaskHistory()
        task_history.task_name = "upgrade_mongodb_24_to_30"
        task_history.task_status = task_history.STATUS_WAITING
        task_history.arguments = "Upgrading MongoDB 2.4 to 3.0"
        task_history.user = request.user
        task_history.save()

        upgrade_mongodb_24_to_30.delay(database=database, user=request.user,
                                       task_history=task_history)
        url = reverse('admin:notification_taskhistory_changelist')

        return HttpResponseRedirect(url)
开发者ID:flaviohenriqu,项目名称:database-as-a-service,代码行数:42,代码来源:database.py

示例12: databaseregionmigration_view

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
 def databaseregionmigration_view(self, request, databaseregionmigration_id):
     
     database_region_migration = DatabaseRegionMigration.objects.get(id=databaseregionmigration_id)
     database_region_migration_detail = DatabaseRegionMigrationDetail(
         database_region_migration=database_region_migration,
         step = database_region_migration.next_step,
         scheduled_for = datetime.now(),
         created_by = request.user.username)
     database_region_migration_detail.save()
     
     task_history = TaskHistory()
     task_history.task_name = "execute_database_region_migration"
     task_history.task_status = task_history.STATUS_WAITING
     
     task_history.arguments = "Database name: {}, Step: {}".format(database_region_migration.database.name, 
                               database_region_migration_detail.database_region_migration.next_step_description())
     task_history.user = request.user
     task_history.save()
     
     task = execute_database_region_migration.apply_async(args=[database_region_migration_detail.id, task_history, request.user], countdown=1)
     
     
     url = reverse('admin:notification_taskhistory_changelist')
     return HttpResponseRedirect(url + "?user=%s" % request.user.username)  # Redirect after POST
     
     #return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
     
     
     #databaseregionmigration = DatabaseRegionMigration.objects.get(id=databaseregionmigration_id)
     #if request.method == 'POST':
     #    form = DatabaseRegionMigrationDetailForm(request.POST)
     #    return HttpResponseRedirect(url + "?user=%s" % request.user.username)
     
     #print locals()
     #url = reverse('admin:schedulenextstep', args=[databaseregionmigration.id])
     #form = DatabaseRegionMigrationDetailForm(initial={"database_region_migration": databaseregionmigration})
     form = None
     return render_to_response("region_migration/databaseregionmigrationdetail/schedule_next_step.html",
                               locals(),
                               context_instance=RequestContext(request))
开发者ID:mbergo,项目名称:database-as-a-service,代码行数:42,代码来源:databaseregionmigration.py

示例13: any

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
        if any(plan):
            dbaas_plan = Plan.objects.get(pk=plan[0]['pk'])
        else:
            msg = "Plan was not found"
            return log_and_response(msg=msg, http_status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        try:
            dbaas_environment = Environment.objects.get(name= env)
        except(ObjectDoesNotExist,IndexError), e:
            msg = "Environment does not exist."
            return log_and_response(msg=msg, http_status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        task_history = TaskHistory()
        task_history.task_name="create_database"
        task_history.arguments="Database name: {}".format(name)
        task_history.save()

        create_database.delay(name=name, plan=dbaas_plan, environment=dbaas_environment,
            team=dbaas_team,project=None, description='Database from Tsuru',
            task_history=task_history, user=dbaas_user)

        return Response(status=status.HTTP_201_CREATED,)


class ServiceRemove(APIView):
    renderer_classes = (JSONRenderer, JSONPRenderer)
    model = Database

    def delete(self, request, database_name, format=None):
        env = get_url_env(request)
        try:
开发者ID:mbergo,项目名称:database-as-a-service,代码行数:33,代码来源:views.py

示例14: add_view

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
    def add_view(self, request, form_url='', extra_context=None):
        self.form = DatabaseForm

        try:

            if request.method == 'POST':

                teams = Team.objects.filter(users=request.user)
                LOG.info("user %s teams: %s" % (request.user, teams))
                if not teams:
                    self.message_user(request, self.database_add_perm_message, level=messages.ERROR)
                    return HttpResponseRedirect(reverse('admin:logical_database_changelist'))

                # if no team is specified and the user has only one team, then set it to the database
                if teams.count() == 1 and request.method == 'POST' and not request.user.has_perm(
                    self.perm_add_database_infra):
                    post_data = request.POST.copy()
                    if 'team' in post_data:
                        post_data['team'] = u"%s" % teams[0].pk

                    request.POST = post_data

                form = DatabaseForm(request.POST)

                if not form.is_valid():
                    return super(DatabaseAdmin, self).add_view(request, form_url, extra_context=extra_context)


                LOG.debug(
                    "call create_database - name=%s, plan=%s, environment=%s, team=%s, project=%s, description=%s, user=%s" % (
                        form.cleaned_data['name'], form.cleaned_data['plan'], form.cleaned_data['environment'],
                        form.cleaned_data['team'], form.cleaned_data['project'], form.cleaned_data['description'],
                        request.user))

                task_history = TaskHistory()
                task_history.task_name="create_database"
                task_history.task_status= task_history.STATUS_WAITING
                task_history.arguments="Database name: {}".format(form.cleaned_data['name'])
                task_history.user= request.user
                task_history.save()

                create_database.delay(name=form.cleaned_data['name'],
                                               plan=form.cleaned_data['plan'],
                                               environment=form.cleaned_data['environment'],
                                               team=form.cleaned_data['team'],
                                               project=form.cleaned_data['project'],
                                               description=form.cleaned_data['description'],
                                               task_history=task_history,
                                               user=request.user)

                url = reverse('admin:notification_taskhistory_changelist')
                return HttpResponseRedirect(url + "?user=%s" % request.user.username)  # Redirect after POST

            else:
                return super(DatabaseAdmin, self).add_view(request, form_url, extra_context=extra_context)

        except DatabaseAlreadyExists:
            self.message_user(request, _(
                'An inconsistency was found: The database "%s" already exists in infra-structure but not in DBaaS.') %
                              request.POST['name'], level=messages.ERROR)
            request.method = 'GET'
            return super(DatabaseAdmin, self).add_view(request, form_url, extra_context=extra_context)
开发者ID:mbergo,项目名称:database-as-a-service,代码行数:64,代码来源:database.py

示例15: region_migration_start

# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import save [as 别名]
def region_migration_start(self, infra, instances, since_step=None):
    steps = [{
        'Disable monitoring and alarms': (
            'workflow.steps.util.zabbix.DestroyAlarms',
            'workflow.steps.util.db_monitor.DisableMonitoring',
        )}, {
        'Stopping infra': (
            'workflow.steps.util.database.Stop',
            'workflow.steps.util.database.CheckIsDown',
        )}, {
        'Creating new virtual machine': (
            'workflow.steps.util.vm.MigrationCreateNewVM',
        )}, {
        'Creating new infra': (
            'workflow.steps.util.vm.MigrationWaitingBeReady',
            'workflow.steps.util.infra.MigrationCreateInstance',
            'workflow.steps.util.disk.MigrationCreateExport',
        )}, {
        'Configuring new infra': (
            'workflow.steps.util.volume_provider.MountDataVolume',
            'workflow.steps.util.plan.InitializationMigration',
            'workflow.steps.util.plan.ConfigureMigration',
            'workflow.steps.util.metric_collector.ConfigureTelegraf',
        )}, {
        'Preparing new environment': (
            'workflow.steps.util.disk.AddDiskPermissionsOldest',
            'workflow.steps.util.disk.MountOldestExportMigration',
            'workflow.steps.util.disk.CopyDataBetweenExportsMigration',
            'workflow.steps.util.disk.FilePermissionsMigration',
            'workflow.steps.util.disk.UnmountNewerExportMigration',
            'workflow.steps.util.vm.ChangeInstanceHost',
            'workflow.steps.util.vm.UpdateOSDescription',
            'workflow.steps.util.infra.OfferingMigration',
            'workflow.steps.util.infra.UpdateMigrateEnvironment',
            'workflow.steps.util.infra.UpdateMigratePlan',
        )}, {
        'Starting new infra': (
            'workflow.steps.util.database.Start',
            'workflow.steps.util.database.CheckIsUp',
            'workflow.steps.util.metric_collector.RestartTelegraf',
        )}, {
        'Enabling access': (
            'workflow.steps.util.dns.ChangeEndpoint',
            'workflow.steps.util.acl.ReplicateAclsMigration',
        )}, {
        'Destroying old infra': (
            'workflow.steps.util.disk.DisableOldestExportMigration',
            'workflow.steps.util.disk.DiskUpdateHost',
            'workflow.steps.util.vm.RemoveHostMigration',
        )}, {
        'Enabling monitoring and alarms': (
            'workflow.steps.util.db_monitor.EnableMonitoring',
            'workflow.steps.util.zabbix.CreateAlarms',
        )}, {
        'Restart replication': (
            'workflow.steps.util.database.SetSlavesMigration',
        )
    }]

    task = TaskHistory()
    task.task_id = self.request.id
    task.task_name = "migrating_zone"
    task.task_status = TaskHistory.STATUS_RUNNING
    task.context = {'infra': infra, 'instances': instances}
    task.arguments = {'infra': infra, 'instances': instances}
    task.user = 'admin'
    task.save()

    if steps_for_instances(steps, instances, task, since_step=since_step):
        task.set_status_success('Region migrated with success')
    else:
        task.set_status_error('Could not migrate region')

    database = infra.databases.first()
    database.environment = infra.environment
    database.save()
开发者ID:globocom,项目名称:database-as-a-service,代码行数:78,代码来源:tasks.py


注:本文中的notification.models.TaskHistory.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。