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


Python models.Operation类代码示例

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


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

示例1: router_delete_view

def router_delete_view(request):

    if not settings.MULTI_ROUTER_ENABLED:
        return Response({"OPERATION_STATUS": 0,
                         "MSG": _('Cannot delete router '
                                  'under single router mode.')})

    router_id = request.data['router_id']

    try:
        router = Router.objects.get(pk=router_id)
    except Router.DoesNotExist:
        return Response({"OPERATION_STATUS": 0,
                         "MSG": _('The selected router does not exist')})

    if router.is_default:
        return Response({"OPERATION_STATUS": 0,
                         "MSG": _('Default Router can not be deleted')})

    if router.is_in_use:
        return Response({"OPERATION_STATUS": 0,
                         "MSG": _('This router is being used.')})

    router.fake_delete()
    Operation.log(obj=router, obj_name=router.name, action='terminate')
    router_delete_task.delay(router)

    return Response({"OPERATION_STATUS": 1, "MSG": _('Router deleted success')})
开发者ID:CannedFish,项目名称:initcloud_web,代码行数:28,代码来源:views.py

示例2: delete_pool

def delete_pool(request):

    pool_id = request.data['pool_id']

    try:
        pool = BalancerPool.objects.get(
            pk=pool_id, user=request.user,
            user_data_center=request.session["UDC_ID"])
    except BalancerPool.DoesNotExist:
        return fail(_('No balancer found.'))

    if not pool.pool_uuid:
        pool.deleted = True
        pool.save()
        return success(_('Balancer pool %(name)s is deleted')
                       % {'name': pool.name})

    pool.status = POOL_DELETING
    pool.save()
    Operation.log(pool, obj_name=pool.name, action='delete')

    try:
        pool_delete_task.delay(pool)
    except Exception:
        LOG.exception("Failed to delete balancer pool[%s]", pool)
        return error()

    return success(_('Deleting balancer pool %(name)s') % {'name': pool.name})
开发者ID:CannedFish,项目名称:initcloud_web,代码行数:28,代码来源:views.py

示例3: delete_network

def delete_network(request):

    try:
        network = Network.objects.get(pk=request.data["network_id"],
                                      user=request.user)
    except Network.DoesNotExist:
        return Response({"OPERATION_STATUS": 0,
                         "MSG": _('The selected network does not exist')})

    # 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 network when it is being used
    if network.is_in_use:
        return Response({
            "OPERATION_STATUS": 0,
            "MSG": _('This network is being used!')})

    network.change_status(NETWORK_STATE_DELETING)

    try:
        tasks.delete_network.delay(network)
    except Exception as e:
        network.change_status(NETWORK_STATE_ACTIVE)
        LOG.exception("Failed to delete network[%s], reason:[%s] ",
                      network.name, e)
        return Response({"OPERATION_STATUS": 1, "MSG": _('Network deleted error')})
    else:
        Operation.log(obj=network, obj_name=network.name,
                      action='terminate', result=1)
        return Response({"OPERATION_STATUS": 1,
                         "MSG": _('Network deleted success')})
开发者ID:CannedFish,项目名称:initcloud_web,代码行数:34,代码来源:views.py

示例4: attach_network_to_router

def attach_network_to_router(request):
    """ 现在是单子网 操作连接和断开操作传入network_id 取第一个子网操作,
        如果改为多子网,则需要页面传入指定子网进行连接和断开操作
        :param request:
        :return:
    """

    network_id = request.data['network_id']
    router_id = request.data['router_id']

    if not router_id:
        return Response({"OPERATION_STATUS": 0, "MSG": _('Unkown router')})

    network = Network.objects.get(pk=network_id)
    subnet = network.subnet_set.all()[0]

    if check_router_isexits_subnet(subnet):
        return Response({"OPERATION_STATUS": 0,
                         "MSG": _('network exist address , not operation')})

    network.change_status(NETWORK_STATE_UPDATING)

    Operation.log(obj=network,
                  obj_name=network.name,
                  action='attach_router')

    try:
        tasks.attach_network_to_router.delay(network_id, router_id, subnet.id)
        return Response({"OPERATION_STATUS": 1,
                         "MSG": _('Link router success')})
    except Exception as e:
        LOG.exception("Attach router error, msg: %s", e)
        return Response({"OPERATION_STATUS": 0, "MSG": _('Link router error')})
开发者ID:CannedFish,项目名称:initcloud_web,代码行数:33,代码来源:views.py

示例5: volume_attach_or_detach

def volume_attach_or_detach(data, volume, action):
    if 'attach' == action:
        volume.status = VOLUME_STATE_ATTACHING
        instance = Instance.objects.get(pk=data.get('instance_id'))
        volume.save()
        Operation.log(volume, obj_name=volume.name, action="attach_volume", result=1)
        try:
            volume_attach_or_detach_task.delay(instance=instance, volume=volume, action=action)
            return Response({"OPERATION_STATUS": 1, "MSG": _('Attaching volume')}, status=status.HTTP_201_CREATED)
        except Exception as e:
            volume.status = VOLUME_STATE_AVAILABLE
            volume.save()
            LOG.error("Attach volume error ,msg: %s" % e)
            return Response({"OPERATION_STATUS": 0, "MSG": _('Attach volume error')}, status=status.HTTP_201_CREATED)
    elif 'detach' == action:
        volume.status = VOLUME_STATE_DOWNLOADING
        instance = Instance.objects.get(pk=volume.instance.id)
        volume.save()
        Operation.log(volume, obj_name=volume.name, action="detach_volume", result=1)
        try:
            volume_attach_or_detach_task.delay(instance=instance, volume=volume, action=action)
            return Response({"OPERATION_STATUS": 1, "MSG": _('Detaching volume')}, status=status.HTTP_201_CREATED)
        except Exception as e:
            LOG.error("Detach volume error , msg: % s" % e)
            volume.status = VOLUME_STATE_IN_USE
            volume.save()
            return Response({"OPERATION_STATUS": 0, "MSG": _('Detach volume error')}, status=status.HTTP_201_CREATED)
开发者ID:lyndonChen,项目名称:eonboard,代码行数:27,代码来源:views.py

示例6: firewall_delete_view

def firewall_delete_view(request, **kwargs):
    data = request.data
    if data.get('id') is None or data.get('id') == '':
        return Response({"OPERATION_STATUS": 0, "MSG": _('Not selected Firewall')})
    firewall = Firewall.objects.get(pk=data.get('id'))
    if firewall is None:
        return Response({"OPERATION_STATUS": 0, "MSG": _('Firewall not exists')})
    if firewall.is_default:
        return Response({"OPERATION_STATUS": 0, "MSG": _('Firewall default can not delete')})
    if check_firewall_use(request, firewall.id):
        return Response({"OPERATION_STATUS": 0, "MSG": _('Firewall used can not delete')})
    else:
        if firewall.firewall_id:
            try:
                security_group_delete_task.delay(firewall)
            except Exception as e:
                LOG.error("Delete firewall error, msg:%s" % e)
                return Response({"OPERATION_STATUS": 0, "MSG": _('Firewall delete error')})
            firewall.deleted = True
            firewall.save()
            Operation.log(firewall, obj_name=firewall.name, action="terminate", result=1)
        else:
            firewall.deleted = True
            firewall.save()
    return Response({"OPERATION_STATUS": 1, "MSG": _('Firewall delete success')})
开发者ID:coocla,项目名称:eonboard,代码行数:25,代码来源:views.py

示例7: instance_change_firewall_view

def instance_change_firewall_view(request, **kwargs):
    data = request.data
    if data.get('instance_id') is None:
        return Response({"OPERATION_STATUS": 0, 'MSG': 'No Select Instance'}, status=status.HTTP_200_OK)
    if data.get("firewall_id") is None:
        return Response({"OPERATION_STATUS": 0, 'MSG': 'No Select Firewall'}, status=status.HTTP_200_OK)
    try:
        instance = Instance.objects.get(pk=data.get('instance_id'))
    except Exception as e:
        LOG.error("No find Instance,msg: %s" % e)
        return Response({"OPERATION_STATUS": 0, 'MSG': 'No find Instance'}, status=status.HTTP_200_OK)
    try:
        firewall = Firewall.objects.get(pk=data.get('firewall_id'))
    except Exception as e:
        LOG.error("No find Firewall,msg: %s" % e)
        return Response({"OPERATION_STATUS": 0, 'MSG': 'No find Firewall'}, status=status.HTTP_200_OK)
    try:
        server_update_security_groups_task.delay(instance, firewall)
        instance.firewall_group = firewall
        instance.save()
        Operation.log(instance, obj_name=instance.name, action="change_firewall", result=1)
        return Response({"OPERATION_STATUS": 1, 'MSG': 'Security update firewall success'}, status=status.HTTP_200_OK)
    except Exception as e:
        LOG.error("Server update security group error,msg: %s" % e)
        return Response({"OPERATION_STATUS": 0, 'MSG': 'No find Firewall'}, status=status.HTTP_200_OK)
开发者ID:coocla,项目名称:eonboard,代码行数:25,代码来源:views.py

示例8: create_pool_vip

def create_pool_vip(request):

    pool_id = request.data['pool_id']
    try:
        pool = BalancerPool.objects.get(
            pk=pool_id, user=request.user,
            user_data_center=request.session["UDC_ID"])
    except BalancerPool.DoesNotExist:
        return fail(_("No balancer pool found!"))

    serializer = BalancerVIPSerializer(data=request.data,
                                       context={'request': request})

    if not serializer.is_valid():
        return fail(_('Data is not valid'))

    vip = serializer.save()
    Operation.log(vip, obj_name=vip.name, action='create')

    pool.status = POOL_UPDATING
    pool.save()

    try:
        pool_vip_create_task.delay(vip, pool)
    except Exception:
        vip.delete()
        return error()

    return success(_('Creating balancer vip.'))
开发者ID:CannedFish,项目名称:initcloud_web,代码行数:29,代码来源:views.py

示例9: router_create_view

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,代码行数:34,代码来源:views.py

示例10: volume_create_view

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,代码行数:35,代码来源:views.py

示例11: volume_attach_or_detach

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,代码行数:30,代码来源:views.py

示例12: delete_action

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,代码行数:27,代码来源:views.py

示例13: backup_action

def backup_action(user, DATA):
    """
    Backup action, delete, restore
    """
    action, pk = DATA.get('action'), DATA.get('pk')

    if action not in ["delete", "restore"]:
        return {"OPERATION_STATUS": OPERATION_FAILED,
                "status": "un supported action [%s]" % action}
    try:    
        backup = Backup.objects.get(pk=pk, user=user) 
        Operation.log(backup, obj_name=backup.name, action=action, result=1)

        if action == "restore":
            if backup.instance:
                ins = Instance.objects.get(pk=backup.instance)
                if ins.status != INSTANCE_STATE_POWEROFF:
                    return {"OPERATION_STATUS": OPERATION_FORBID,
                            "status": backup.status}

            backup.mark_restore(DATA.get('item_id'))

        if action == "delete":
            backup.mark_delete()

        # celery call
        backup_action_task.delay(backup, action)

        return {"OPERATION_STATUS": OPERATION_SUCCESS, "status": backup.status}
    except Exception as ex:
        LOG.exception(ex)
        return {"OPERATION_STATUS": OPERATION_FAILED}
开发者ID:CannedFish,项目名称:initcloud_web,代码行数:32,代码来源:utils.py

示例14: delete_action

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,代码行数:28,代码来源:views.py

示例15: create_view

def create_view(request):
    floating = Floating.objects.create(
        ip="N/A",
        status=FLOATING_ALLOCATE,
        bandwidth=int(request.POST["bandwidth"]),
        user=request.user,
        user_data_center=UserDataCenter.objects.get(pk=request.session["UDC_ID"])
    )

    pay_type = request.data['pay_type']
    pay_num = int(request.data['pay_num'])

    Operation.log(floating, obj_name=floating.ip, action='allocate', result=1)

    workflow = Workflow.get_default(ResourceType.FLOATING)

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

        floating.status = FLOATING_APPLYING
        floating.save()

        FlowInstance.create(floating, request.user, workflow, None)
        msg = _("Your application for %(bandwidth)d Mbps floating ip is successful, "
                "please waiting for approval result!") % {'bandwidth': floating.bandwidth}
    else:
        msg = _("Your operation is successful, please wait for allocation.")
        allocate_floating_task.delay(floating)
        Order.for_floating(floating, pay_type, pay_num)

    return Response({"OPERATION_STATUS": 1, 'msg': msg})
开发者ID:CannedFish,项目名称:initcloud_web,代码行数:30,代码来源:views.py


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