本文整理汇总了Python中notification.models.TaskHistory.user方法的典型用法代码示例。如果您正苦于以下问题:Python TaskHistory.user方法的具体用法?Python TaskHistory.user怎么用?Python TaskHistory.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类notification.models.TaskHistory
的用法示例。
在下文中一共展示了TaskHistory.user方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_model
# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import user [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()
示例2: register_task
# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import user [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
示例3: restore_snapshot
# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import user [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))
示例4: databaseregionmigration_view
# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import user [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))
示例5: resize
# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import user [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
)
示例6: delete_model
# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import user [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()
示例7: clone
# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import user [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
)
示例8: register_task
# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import user [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
示例9: mongodb_engine_version_upgrade
# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import user [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)
示例10: databaseregionmigration_view
# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import user [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))
示例11: add_view
# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import user [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)
示例12: region_migration_start
# 需要导入模块: from notification.models import TaskHistory [as 别名]
# 或者: from notification.models.TaskHistory import user [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()