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


Python Operation.log方法代码示例

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


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

示例1: delete_action

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def delete_action(volume):
    if volume.instance is not None:
        msg = _('Operation Failed. '
                'Volume %(volume)s is attached to instance:%(instance)s') \
            % {'instance': volume.instance.name, 'volume': volume.name}

        return fail(msg=msg)

    if volume.volume_id:
        volume.status = VOLUME_STATE_DELETING
        volume.save()

        try:
            volume_delete_action_task.delay(volume)
            Operation.log(volume, obj_name=volume.name,
                          action="terminate", result=1)
            return success(msg=_('Deleting volume'))
        except Exception as e:
            LOG.exception("Delete volume error, msg:%s", e)
            volume.status = VOLUME_STATE_ERROR
            volume.save()
            return error()
    else:
        volume.deleted = True
        volume.save()
        return success(msg=_('Volume is deleted.'))
开发者ID:coocla,项目名称:eonboard,代码行数:28,代码来源:views.py

示例2: volume_create_view

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def volume_create_view(request):
    try:
        serializer = VolumeSerializer(data=request.data,
                                      context={"request": request})
        if not serializer.is_valid():
            return fail(msg=_('Data is not valid.'),
                        status=status.HTTP_400_BAD_REQUEST)

        volume = serializer.save()
        Operation.log(volume, obj_name=volume.name, action="create", result=1)
        workflow = Workflow.get_default(ResourceType.VOLUME)

        if settings.SITE_CONFIG['WORKFLOW_ENABLED'] and workflow:

            volume.status = VOLUME_STATE_APPLYING
            volume.save()

            FlowInstance.create(volume, request.user, workflow, None)
            msg = _("Your application for %(size)d GB volume is successful, "
                    "please waiting for approval result!") \
                % {'size': volume.size}
            return success(msg=msg)
        else:
            try:
                volume_create_task.delay(volume)
                return success(msg=_('Creating volume'),
                               status=status.HTTP_201_CREATED)
            except Exception as e:
                LOG.exception("Failed to create volume, msg: %s", e)
                volume.status = VOLUME_STATE_ERROR
                volume.save()
                return error()
    except Exception as e:
        LOG.exception("create volume error, msg:[%s]", e)
        return error()
开发者ID:coocla,项目名称:eonboard,代码行数:37,代码来源:views.py

示例3: delete_backup_item

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def delete_backup_item(request, pk):

    backup_item = BackupItem.objects.get(pk=pk)

    if backup_item.status == BACKUP_STATE_ERROR or \
            backup_item.rbd_image is None:
        backup_item.deleted = True
        backup_item.change_status(BACKUP_STATE_DELETED)
        backup_item.save()
        return success(_("Backup item Deleted."))

    if BackupItem.is_any_node_untable(backup_item.chain_id):
        return fail(_("There is one task running on this chain."))

    BackupItem.mark_chain_delete(backup_item)

    Operation.log(backup_item, obj_name=backup_item.name, action="delete")

    try:
        tasks.delete_backup.delay(backup_item.id)
    except Exception:
        LOG.exception("Failed to delete backup item. %s", backup_item)
        return error()
    else:
        return success(_("Deleting"))
开发者ID:CannedFish,项目名称:initcloud_web,代码行数:27,代码来源:views.py

示例4: backup_volume

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def backup_volume(request):

    volume_id, name, is_full = retrieve_params(
        request.data, 'volume_id', 'name', 'is_full')

    udc = UserDataCenter.objects.get(pk=request.session["UDC_ID"])
    is_full = True if is_full == 'true' else False

    volume = Volume.objects.get(pk=volume_id)

    if BackupItem.is_any_unstable(resource=volume):
        return fail(_("Volume %(name)s has one backup task now.")
                    % {'name': volume.name})

    if BackupItem.has_error_node_on_default_chain(resource=volume):
        return fail(_("Volume %(name)s has one error backup node on "
                    "default backup chain. Please delete it first")
                    % {'name': volume.name})

    item = BackupItem.create(volume, name, request.user, udc, is_full=is_full)

    Operation.log(volume, obj_name=volume.name, action="backup")
    tasks.execute_backup.delay(item.id)

    return success(_("Backup is in process."))
开发者ID:CannedFish,项目名称:initcloud_web,代码行数:27,代码来源:views.py

示例5: create_quotas

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def create_quotas(request):
    try:

        contract = Contract.objects.get(pk=request.data['contract_id'])
        quota_ids = request.data.getlist('ids[]')
        resources = request.data.getlist('resources[]')
        limits = request.data.getlist('limits[]')

        for index, quota_id in enumerate(quota_ids):

            resource, limit = resources[index], limits[index]

            if quota_id and Quota.living.filter(contract=contract,
                                                pk=quota_id).exists():
                Quota.objects.filter(pk=quota_id).update(resource=resource,
                                                         limit=limit,
                                                         update_date=timezone.now())
            else:
                Quota.objects.create(resource=resource, limit=limit,
                                     contract=contract)

        Operation.log(contract, contract.name + " quota", 'update',
                      udc=contract.udc, user=request.user)

        return Response({'success': True,
                         "msg": _('Quotas have been saved successfully!')},
                        status=status.HTTP_201_CREATED)
    except Exception as e:
        LOG.error("Failed to save quotas, msg:[%s]" % e)
        return Response({"success": False,
                         "msg": _('Failed to save quotas for unknown reason.')})
开发者ID:hpplinux,项目名称:initcloud_web,代码行数:33,代码来源:views.py

示例6: management

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def management(request):
    if request.user.is_superuser or request.user.has_perm("workflow.system_user") or request.user.has_perm("workflow.safety_user") or request.user.has_perm("workflow.audit_user"):
        return render(request, 'management.html',
                      {'inited': DataCenter.objects.exists()})
    else:
        Operation.log(request.user, obj_name="management", action="access_manage", result=0)
        return render(request, "cloud.html")
开发者ID:litterbear,项目名称:initcloud_web,代码行数:9,代码来源:views.py

示例7: pool_create_view

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def pool_create_view(request):
    serializer = BalancerPoolSerializer(data=request.data, context={"request": request})
    if serializer.is_valid():
        pool_id = request.POST.get("pool_id", '')
        '''
        if pool_id is '' add pool ,else update pool
        '''
        if not pool_id:
            pool = serializer.save()
            try:
                pool_create_task.delay(pool)
                Operation.log(pool, obj_name=pool.name, action='create', result=1)
                return Response({"OPERATION_STATUS": 1, "MSG": _('Create balancer pool success')})
            except Exception as e:
                LOG.error("Create pool error, msg: %s " % e)
                pool.status = POOL_ERROR
                pool.save()
        else:
            try:
                pool = BalancerPool.objects.get(pk=pool_id, user=request.user)
                pool.lb_method = request.POST.get("lb_method", pool.lb_method)
                pool.name = request.POST.get("name", pool.name)
                pool.description = request.POST.get('description', pool.description)
                pool.status = POOL_UPDATING
                pool.save()
                pool_update_task.delay(pool)
                Operation.log(pool, obj_name=pool.name, action='update', result=1)
                return Response({"OPERATION_STATUS": 1, "MSG": _('Update balancer pool success')})
            except Exception as e:
                LOG.error(e)
                return Response({"OPERATION_STATUS": 0, "MSG": _('Selected balancer no exist')})
    else:
        return Response({"OPERATION_STATUS": 0, "MSG": _('Balancer data valid no pass')})
开发者ID:coocla,项目名称:eonboard,代码行数:35,代码来源:views.py

示例8: update_contract

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def update_contract(request):
    try:

        pk = request.data['id']

        contract = Contract.objects.get(pk=pk)
        contract.name = request.data['name']
        contract.customer = request.data['customer']
        contract.start_date = datetime.strptime(request.data['start_date'],
                                                '%Y-%m-%d %H:%M:%S')
        contract.end_date = datetime.strptime(request.data['end_date'],
                                              '%Y-%m-%d %H:%M:%S')

        contract.save()
        Operation.log(contract, contract.name, 'update', udc=contract.udc,
                      user=request.user)

        return Response(
            {'success': True, "msg": _('Contract is updated successfully!')},
            status=status.HTTP_201_CREATED)

    except Exception as e:
        LOG.error("Failed to update contract, msg:[%s]" % e)
        return Response({"success": False, "msg": _(
            'Failed to update contract for unknown reason.')})
开发者ID:hpplinux,项目名称:initcloud_web,代码行数:27,代码来源:views.py

示例9: pool_monitor_association_option_view

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def pool_monitor_association_option_view(request):
    pool_id = request.POST.get("pool_id", "")
    monitor_id = request.POST.get("monitor_id", "")
    action = request.POST.get("action", '')
    if not pool_id or not monitor_id:
        return Response({"OPERATION_STATUS": 0, "MSG": _('No select balancer or monitor')})

    try:
        pool = BalancerPool.objects.get(pk=pool_id, user=request.user)
        monitor = BalancerMonitor.objects.get(pk=monitor_id, user=request.user)

        if action == 'attach':
            p = pool_monitor_association_create(pool, monitor.monitor_uuid)
            Operation.log(pool, obj_name=pool.name, action='attach', result=1)
            if p:
                BalancerPoolMonitor.objects.create(pool=pool, monitor=monitor)
                return Response({"OPERATION_STATUS": 1, "MSG": _('Balancer monitor association success')})
            else:
                return Response({"OPERATION_STATUS": 0, "MSG": _('Balancer monitor association fail')})

        elif action == 'detach':
            p = pool_monitor_association_delete(pool, monitor.monitor_uuid)
            Operation.log(pool, obj_name=pool.name, action='detach', result=1)
            if p:
                pool_monitor_set = BalancerPoolMonitor.objects.filter(pool=pool.id, monitor=monitor.id)
                for pool_monitor in pool_monitor_set:
                    pool_monitor.delete()
                return Response({"OPERATION_STATUS": 1, "MSG": _('Balancer monitor cancel association success')})
            else:
                return Response({"OPERATION_STATUS": 0, "MSG": _('Balancer monitor cancel association fail')})
    except Exception as e:
        LOG.error(e)
        return Response({"OPERATION_STATUS": 0, "MSG": _('balancer or monitor no exist')})
开发者ID:coocla,项目名称:eonboard,代码行数:35,代码来源:views.py

示例10: pool_monitor_create_view

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def pool_monitor_create_view(request):
    serializer = BalancerMonitorSerializer(data=request.data, context={'request': request})
    if serializer.is_valid():
        monitor_id = request.POST.get('monitor_id','')
        '''
        if monitor_id is '' add monitor ,else update monitor
        '''
        if monitor_id == '':
            monitor = serializer.save()
            m = pool_monitor_create(monitor)

            if m:
                monitor.monitor_uuid = m.id
                monitor.save()
                Operation.log(monitor, obj_name=monitor.get_type_display(), action='create', result=1)
                return Response({"OPERATION_STATUS": 1, "MSG": _('Create balancer monitor success')})
            else:
                monitor.delete()
                return Response({"OPERATION_STATUS": 0, "MSG": _('Create balancer monitor Fail')})
        else:
            monitor = BalancerMonitor.objects.get(pk=monitor_id, user=request.user)
            if not monitor:
                return Response({"OPERATION_STATUS": 0, "MSG": _('Monitor no exists')})
            monitor.delay = request.POST.get('delay', monitor.delay)
            monitor.timeout = request.POST.get('timeout', monitor.timeout)
            monitor.max_retries = request.POST.get('max_retries', monitor.max_retries)
            m = pool_monitor_update(monitor)
            if m:
                monitor.save()
                Operation.log(monitor, obj_name=monitor.get_type_display(), action='update', result=1)
                return Response({"OPERATION_STATUS": 1, "MSG": _('Update balancer monitor success')})
            else:
                return Response({"OPERATION_STATUS": 0, "MSG": _('Update balancer monitor Fail')})
    else:
        return Response({"OPERATION_STATUS": 0, "MSG": _('Monitor data valid no pass')})
开发者ID:coocla,项目名称:eonboard,代码行数:37,代码来源:views.py

示例11: pool_vip_associate_view

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def pool_vip_associate_view(request):
    vip_id = request.POST.get("vip_id", "")
    float_ip_id = request.POST.get("floating_ip_id", "")
    action = request.POST.get("action", '')
    if not vip_id or not float_ip_id:
        return Response({"OPERATION_STATUS": 0, "MSG": _('No select float ip or vip')})
    try:
        vip = BalancerVIP.objects.get(pk=vip_id, user=request.user)
        floating = Floating.objects.get(pk=float_ip_id, user=request.user)

        if action == 'bind':
            p = vip_associate_floating_ip(vip, floating.uuid)
            Operation.log(vip, obj_name=vip.name, action='associate', result=1)
            if p:
                vip.public_address = floating.ip
                vip.save()
                return Response({"OPERATION_STATUS": 1, "MSG": _('Vip association floating success')})
            else:
                return Response({"OPERATION_STATUS": 0, "MSG": _('Vip association floating fail')})

        elif action == 'unbind':
            p = vip_disassociate_floating_ip(vip, floating.uuid)
            if p:
                vip.public_address = ''
                vip.save()
                return Response({"OPERATION_STATUS": 1, "MSG": _('Vip disassociation floating success')})
            else:
                return Response({"OPERATION_STATUS": 0, "MSG": _('Vip disassociation floating fail')})
    except Exception as e:
        LOG.error(e)
        return Response({"OPERATION_STATUS": 0, "MSG": _('Vip or Floating no exist')})
开发者ID:coocla,项目名称:eonboard,代码行数:33,代码来源:views.py

示例12: delete_action

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def delete_action(volume):
    if volume.instance is not None:
        msg = _('Operation Failed. '
                'Volume %(volume)s is attached to instance: %(instance)s') \
            % {'instance': volume.instance.name, 'volume': volume.name}

        return fail(msg=msg)

    if BackupItem.living.filter(resource_id=volume.id,
                                resource_type=Volume.__name__).exists():
        return fail(_("This volume has backups, please delete them first."))

    if volume.volume_id:
        volume.change_status(VOLUME_STATE_DELETING)

        try:
            volume_delete_task.delay(volume)
            Operation.log(volume, obj_name=volume.name,
                          action="terminate", result=1)
            return success(msg=_('Deleting volume'))
        except Exception:
            LOG.exception("Delete volume error")
            volume.change_status(VOLUME_STATE_ERROR)
            return error()
    else:
        volume.fake_delete()
        return success(msg=_('Volume is deleted.'))
开发者ID:hpplinux,项目名称:initcloud_web,代码行数:29,代码来源:views.py

示例13: volume_attach_or_detach

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def volume_attach_or_detach(data, volume, action):

    if 'attach' == action:
        instance = Instance.objects.get(pk=data.get('instance_id'))
        volume.change_status(VOLUME_STATE_ATTACHING)

        Operation.log(volume, obj_name=volume.name, action="attach_volume")
        try:
            tasks.attach_volume_to_instance.delay(
                instance=instance, volume=volume)
        except Exception:
            volume.change_status(VOLUME_STATE_AVAILABLE)
            LOG.exception("Attach volume error")
            return error()
        else:
            return success(msg=_('Attaching volume'),
                           status=status.HTTP_201_CREATED)

    elif 'detach' == action:
        volume.change_status(VOLUME_STATE_DETACHING)
        Operation.log(volume, obj_name=volume.name, action="detach_volume")
        try:
            tasks.detach_volume_from_instance.delay(volume)
        except Exception:
            LOG.exception("Detach volume error")
            volume.change_status(VOLUME_STATE_IN_USE)
            return error()
        else:
            return success(msg=_('Detaching volume'),
                           status=status.HTTP_201_CREATED)
开发者ID:hpplinux,项目名称:initcloud_web,代码行数:32,代码来源:views.py

示例14: delete_action

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def delete_action(request):
    try:
        network = Network.objects.get(pk=request.POST.get("network_id", ''), user=request.user)

        # Defalut network can not be deleted
        if network.is_default:
            return Response({"OPERATION_STATUS": 0, "MSG": _('Default network can not be deleted')})
        # Was unable to delete the use of the network
        if check_network_is_use(network.id):
            return Response({"OPERATION_STATUS": 0, "MSG": _('Was unable to delete the use of the network')})
        if not network.network_id:
            network.deleted = True
            network.save()
            return Response({"OPERATION_STATUS": 1, "MSG": _('Network deleted success')})

        network.status = NETWORK_STATE_DELETING
        network.save()
        try:
            network_delete_task.delay(network)
            Operation.log(obj=network, obj_name=network.name, action='terminate', result=1)
            return Response({"OPERATION_STATUS": 1, "MSG": _('Network deleted success')})
        except Exception as e:
            network.status = NETWORK_STATE_ACTIVE
            network.save()
            LOG.error(e)
            return Response({"OPERATION_STATUS": 1, "MSG": _('Network deleted error')})
    except Network.DoesNotExist:
        return Response({"OPERATION_STATUS": 0, "MSG": _('The selected network does not exist')})
开发者ID:lyndonChen,项目名称:eonboard,代码行数:30,代码来源:views.py

示例15: router_create_view

# 需要导入模块: from biz.account.models import Operation [as 别名]
# 或者: from biz.account.models.Operation import log [as 别名]
def router_create_view(request):
    data = request.data
    if (not request.POST.get('id', '')) and \
            settings.SITE_CONFIG.get("MULTI_ROUTER_ENABLED", False):
        try:
            serializer = RouterSerializer(data=request.data, context={"request": request})
            if serializer.is_valid():
                router = serializer.save()
                router_create_task.delay(router)
                Operation.log(obj=router, obj_name=router.name, action='create', result=1)
                return Response({"OPERATION_STATUS": 1, "MSG": _('Create router success')})
            else:
                return Response({"OPERATION_STATUS": 0, "MSG": _('Valid Router fail')})
        except Exception as e:
            LOG.error("Create router error ,msg:%s" % e)
            return Response({"OPERATION_STATUS": 0, "MSG": _('Create router fail')})
    else:
        router = Router.objects.get(pk=data.get('id'))
        if router is None:
            return Response({"OPERATION_STATUS": 0, "MSG": _('The selected router not exist')})
        router.name = data.get('name')
        router.deleted = False
        Operation.log(obj=router, obj_name=router.name, action='update', result=1)
        if not router.is_gateway and request.POST.get('is_gateway') == u'true':
            router.status = NETWORK_STATE_UPDATING
            router.save()
            router_add_gateway_task.delay(router)
        elif router.is_gateway and request.POST.get('is_gateway') == u'false':
            router.status = NETWORK_STATE_UPDATING
            router.save()
            router_remove_gateway_task.delay(router)
        else:
            router.save()
        return Response({"OPERATION_STATUS": 1, "MSG": _('Update router success')})
开发者ID:lyndonChen,项目名称:eonboard,代码行数:36,代码来源:views.py


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