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


Python instance.wvmInstance函数代码示例

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


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

示例1: console

def console(request):
    """
    VNC instance block
    """
    if request.method == "GET":
        token = request.GET.get("token", "")

    try:
        temptoken = token.split("-", 1)
        host = int(temptoken[0])
        uuid = temptoken[1]
        instance = Instance.objects.get(compute_id=host, uuid=uuid)
        conn = wvmInstance(
            instance.compute.hostname,
            instance.compute.login,
            instance.compute.password,
            instance.compute.type,
            instance.name,
        )
        vnc_websocket_port = conn.get_vnc_websocket_port()
        vnc_passwd = conn.get_vnc_passwd()
    except:
        vnc_websocket_port = None
        vnc_passwd = None

    ws_port = vnc_websocket_port if vnc_websocket_port else WS_PORT
    ws_host = request.get_host()

    if ":" in ws_host:
        ws_host = re.sub(":[0-9]+", "", ws_host)

    response = render(None, "console.html", locals(), request)
    response.set_cookie("token", token)
    return response
开发者ID:CovertLamp,项目名称:virtkick-backend,代码行数:34,代码来源:views.py

示例2: console

def console(request):
    """
    VNC instance block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect("/login")

    if request.method == "GET":
        token = request.GET.get("token", "")

    try:
        temptoken = token.split("-", 1)
        host = int(temptoken[0])
        uuid = temptoken[1]
        instance = Instance.objects.get(compute_id=host, uuid=uuid)
        conn = wvmInstance(
            instance.compute.hostname,
            instance.compute.login,
            instance.compute.password,
            instance.compute.type,
            instance.name,
        )
        vnc_passwd = conn.get_vnc_passwd()
    except:
        vnc_passwd = None

    wsproxy_port = WS_PORT
    wsproxy_host = request.get_host()
    if ":" in wsproxy_host:
        wsproxy_host = re.sub(":[0-9]+", "", wsproxy_host)

    response = render_to_response("console.html", locals(), context_instance=RequestContext(request))
    response.set_cookie("token", token)
    return response
开发者ID:jsysgnu,项目名称:webvirtmgr,代码行数:34,代码来源:views.py

示例3: inst_status

def inst_status(request, host_id, vname):
    """
    Instance block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login'))

    compute = Compute.objects.get(id=host_id)

    try:
        conn = wvmInstance(compute.hostname,
                           compute.login,
                           compute.password,
                           compute.type,
                           vname)
        status = conn.get_status()
        conn.close()
    except libvirtError:
        status = None

    data = json.dumps({'status': status})
    response = HttpResponse()
    response['Content-Type'] = "text/javascript"
    response.write(data)
    return response
开发者ID:fuwenbin,项目名称:webvirtmgr-nfv,代码行数:25,代码来源:views.py

示例4: powerGroupInstance

def powerGroupInstance(request, group_id):

    if not request.user.is_authenticated():
       return HttpResponseRedirect(reverse('index'))
    if not request.user.is_superuser:
       return HttpResponseRedirect(reverse('index'))

    group = get_object_or_404(Group, pk=group_id)

    msg = ("Power On Group")
    try:
        group_instances = Instance.objects.filter(group=group).order_by('name')
    except:
        pass
    group_instances_status = []
    # get status for each instances of the group
    for instance in group_instances:
        conn = wvmInstance(instance.compute.hostname,
                           instance.compute.login,
                           instance.compute.password,
                           instance.compute.type,
                           instance.name)
        if conn.get_status() != 1:
            conn.start()
    return redirect('group', group_id=group_id)
开发者ID:Crypt0-M3lon,项目名称:webvirtcloud,代码行数:25,代码来源:views.py

示例5: delete_instance

def delete_instance(instance, delete_disk=False):
    compute = instance.compute
    instance_name = instance.name
    try:
        conn = wvmInstance(compute.hostname,
                           compute.login,
                           compute.password,
                           compute.type,
                           instance.name)

        del_userinstance = UserInstance.objects.filter(instance=instance)
        if del_userinstance:
            print("Deleting UserInstances")
            print(del_userinstance)
            del_userinstance.delete()

        if conn.get_status() == 1:
            print("Forcing shutdown")
            conn.force_shutdown()
        if delete_disk:
            snapshots = sorted(conn.get_snapshot(), reverse=True, key=lambda k:k['date'])
            for snap in snapshots:
                print("Deleting snapshot {}".format(snap['name']))
                conn.snapshot_delete(snap['name'])
            print("Deleting disks")
            conn.delete_disk()

        conn.delete()
        instance.delete()

        print("Instance {} on compute {} sucessfully deleted".format(instance_name, compute.hostname))

    except libvirtError as lib_err:
        print("Error removing instance {} on compute {}".format(instance_name, compute.hostname))
        raise lib_err
开发者ID:razvanboarta,项目名称:webvirtcloud,代码行数:35,代码来源:views.py

示例6: console

def console(request):
    """
    VNC instance block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login')

    if request.method == 'GET':
        token = request.GET.get('token', '')

    try:
        temptoken = token.split('-', 1)
        host = int(temptoken[0])
        uuid = temptoken[1]
        instance = Instance.objects.get(compute_id=host, uuid=uuid)
        conn = wvmInstance(instance.compute.hostname,
                           instance.compute.login,
                           instance.compute.password,
                           instance.compute.type,
                           instance.name)
        vnc_websocket_port = conn.get_vnc_websocket_port()
        vnc_passwd = conn.get_vnc_passwd()
    except:
        vnc_websocket_port = None
        vnc_passwd = None

    ws_port = vnc_websocket_port if vnc_websocket_port else WS_PORT
    ws_host = request.get_host()

    if ':' in ws_host:
        ws_host = re.sub(':[0-9]+', '', ws_host)

    response = render_to_response('console.html', locals(), context_instance=RequestContext(request))
    response.set_cookie('token', token)
    return response
开发者ID:Dreadchild,项目名称:webvirtmgr,代码行数:35,代码来源:views.py

示例7: check_user_quota

 def check_user_quota(instance, cpu, memory, disk_size):
     user_instances = UserInstance.objects.filter(user_id=request.user.id, instance__is_template=False)
     instance += len(user_instances)
     for usr_inst in user_instances:
         if connection_manager.host_is_up(usr_inst.instance.compute.type,
                                          usr_inst.instance.compute.hostname):
             conn = wvmInstance(usr_inst.instance.compute,
                                   usr_inst.instance.compute.login,
                                   usr_inst.instance.compute.password,
                                   usr_inst.instance.compute.type,
                                   usr_inst.instance.name)
             cpu += int(conn.get_vcpu())
             memory += int(conn.get_memory())
             for disk in conn.get_disk_device():
                 disk_size += int(disk['size'])>>30
     
     ua = request.user.userattributes
     msg = ""
     if ua.max_instances > 0 and instance > ua.max_instances:
         msg = "instance"
         if settings.QUOTA_DEBUG:
             msg += " (%s > %s)" % (instance, ua.max_instances)
     if ua.max_cpus > 0 and cpu > ua.max_cpus:
         msg = "cpu"
         if settings.QUOTA_DEBUG:
             msg += " (%s > %s)" % (cpu, ua.max_cpus)
     if ua.max_memory > 0 and memory > ua.max_memory:
         msg = "memory"
         if settings.QUOTA_DEBUG:
             msg += " (%s > %s)" % (memory, ua.max_memory)
     if ua.max_disk_size > 0 and disk_size > ua.max_disk_size:
         msg = "disk"
         if settings.QUOTA_DEBUG:
             msg += " (%s > %s)" % (disk_size, ua.max_disk_size)
     return msg
开发者ID:AlexTEko,项目名称:webvirtcloud,代码行数:35,代码来源:views.py

示例8: cpuusage

def cpuusage(request, host_id, vname):
    """
    VM cpu usage
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login')

    datasets = []
    compute = Compute.objects.get(id=host_id)

    try:
        conn = wvmInstance(compute.hostname,
                           compute.login,
                           compute.password,
                           compute.type,
                           vname)
        cpu_usage = conn.cpu_usage()
        conn.close()
    except libvirtError:
        cpu_usage = 0

    try:
        cookies = request._cookies['cpu_usage']
    except KeyError:
        cookies = None

    if not cookies:
        datasets.append(0)
    else:
        datasets = eval(cookies)
    if len(datasets) > 10:
        while datasets:
            del datasets[0]
            if len(datasets) == 10:
                break
    if len(datasets) <= 9:
        datasets.append(int(cpu_usage['cpu']))
    if len(datasets) == 10:
        datasets.append(int(cpu_usage['cpu']))
        del datasets[0]

    cpu = {
        'labels': [""] * 10,
        'datasets': [
            {
                "fillColor": "rgba(241,72,70,0.5)",
                "strokeColor": "rgba(241,72,70,1)",
                "pointColor": "rgba(241,72,70,1)",
                "pointStrokeColor": "#fff",
                "data": datasets
            }
        ]
    }

    data = simplejson.dumps(cpu)
    response = HttpResponse()
    response['Content-Type'] = "text/javascript"
    response.cookies['cpu_usage'] = datasets
    response.write(data)
    return response
开发者ID:gpns,项目名称:webvirtmgr,代码行数:60,代码来源:views.py

示例9: console

def console(request):
    """
    VNC instance block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login')

    if request.method == 'GET':
        uuid = request.GET.get('token', '')

    try:
        instance = Instance.objects.get(uuid=uuid)
        conn = wvmInstance(instance.compute.hostname,
                           instance.compute.login,
                           instance.compute.password,
                           instance.compute.type,
                           instance.name)
        vnc_passwd = conn.get_vnc_passwd()
    except:
        vnc_passwd = None

    wsproxy_port = WS_PORT
    wsproxy_host = request.get_host()
    if ':' in wsproxy_host:
        wsproxy_host = re.sub(':[0-9]+', '', wsproxy_host)

    response = render_to_response('console.html', locals(), context_instance=RequestContext(request))
    response.set_cookie('token', uuid)
    return response
开发者ID:GSMAi,项目名称:webvirtmgr,代码行数:29,代码来源:views.py

示例10: inst_status

def inst_status(request, compute_id, vname):
    """
    :param request:
    :return:
    """

    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login'))

    compute = get_object_or_404(Compute, pk=compute_id)
    response = HttpResponse()
    response['Content-Type'] = "text/javascript"

    try:
        conn = wvmInstance(compute.hostname,
                           compute.login,
                           compute.password,
                           compute.type,
                           vname)
        data = json.dumps({'status': conn.get_status()})
        conn.close()
    except libvirtError:
        data = json.dumps({'error': 'Error 500'})
    response.write(data)
    return response
开发者ID:olivierb2,项目名称:webvirtcloud,代码行数:25,代码来源:views.py

示例11: query_machine

 def query_machine(hostname):
     try:
         conn = wvmInstance(compute.hostname,
                            compute.login,
                            compute.password,
                            compute.type, hostname)
         object[hostname] = {
             'status': conn.get_status(),
             'cur_memory': conn.get_cur_memory(),
             'disks': conn.get_disk_device(),
             'vcpu': conn.get_vcpu()
         }
     except libvirtError:
         status = None
开发者ID:mehulsbhatt,项目名称:virtkick-backend,代码行数:14,代码来源:views.py

示例12: console

def console(request):
    """
    Console instance block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login'))

    if request.method == 'GET':
        token = request.GET.get('token', '')

    try:
        temptoken = token.split('-', 1)
        host = int(temptoken[0])
        uuid = temptoken[1]
        instance = Instance.objects.get(compute_id=host, uuid=uuid)
        conn = wvmInstance(instance.compute.hostname,
                           instance.compute.login,
                           instance.compute.password,
                           instance.compute.type,
                           instance.name)
        name = instance.name
        console_type = conn.get_console_type()
        console_websocket_port = conn.get_console_websocket_port()
        console_passwd = conn.get_console_passwd()
    except:
        console_type = None
        console_websocket_port = None
        console_passwd = None

    ws_port = console_websocket_port if console_websocket_port else WS_PORT
    ws_host = WS_PUBLIC_HOST if WS_PUBLIC_HOST else request.get_host()

    if ':' in ws_host:
        ws_host = re.sub(':[0-9]+', '', ws_host)

    if console_type == 'vnc':
        response = render_to_response('console-vnc.html', locals(),
                                      context_instance=RequestContext(request))
    elif console_type == 'spice':
        response = render_to_response('console-spice.html', locals(),
                                      context_instance=RequestContext(request))
    else:
        response = "Console type %s no support" % console_type

    response.set_cookie('token', token)
    return response
开发者ID:fuwenbin,项目名称:webvirtmgr-nfv,代码行数:46,代码来源:views.py

示例13: inst_status

def inst_status(request, compute_id, vname):
    """
    :param request:
    :return:
    """

    compute = get_object_or_404(Compute, pk=compute_id)
    response = HttpResponse()
    response["Content-Type"] = "text/javascript"

    try:
        conn = wvmInstance(compute.hostname, compute.login, compute.password, compute.type, vname)
        data = json.dumps({"status": conn.get_status()})
        conn.close()
    except libvirtError:
        data = json.dumps({"error": "Error 500"})
    response.write(data)
    return response
开发者ID:pirogoeth,项目名称:webvirtcloud,代码行数:18,代码来源:views.py

示例14: editGroup

def editGroup(request, group_id):
    """
    :param request:
    :return:
    """
    if not request.user.is_authenticated():
       return HttpResponseRedirect(reverse('index'))
    if not request.user.is_superuser:
       return HttpResponseRedirect(reverse('index'))
    error_messages = []

    if request.method == 'POST':
        form = groupInstanceAddForm(request.POST)
        if form.is_valid():
             groupInstance = form.cleaned_data
             group = get_object_or_404(Group, pk=group_id)
             instance = get_object_or_404(Instance, pk=groupInstance['instance_id'])
             instance.group = group
             instance.save()
             return HttpResponseRedirect(request.get_full_path())
        else:
             for msg_err in form.errors.values():
                    error_messages.append(msg_err.as_text())

    group = get_object_or_404(Group, pk=group_id)
    available_instances = Instance.objects.filter(group=None).order_by('name')
    group_instances = []
    try:
        group_instances = Instance.objects.filter(group=group).order_by('name')
    except:
        pass
    group_instances_status = []
    # get status for each instances of the group
    for instance in group_instances:
        conn = wvmInstance(instance.compute.hostname,
                           instance.compute.login,
                           instance.compute.password,
                           instance.compute.type,
                           instance.name)

        status = conn.get_status()
        group_instances_status.append((instance,status))

    return render(request, 'group.html', locals())
开发者ID:Crypt0-M3lon,项目名称:webvirtcloud,代码行数:44,代码来源:views.py

示例15: console

def console(request):
    """
    :param request:
    :return:
    """

    if request.method == 'GET':
        token = request.GET.get('token', '')

    try:
        temptoken = token.split('-', 1)
        host = int(temptoken[0])
        uuid = temptoken[1]
        instance = Instance.objects.get(compute_id=host, uuid=uuid)
        conn = wvmInstance(instance.compute.hostname,
                           instance.compute.login,
                           instance.compute.password,
                           instance.compute.type,
                           instance.name)
        console_type = conn.get_console_type()
        console_websocket_port = conn.get_console_websocket_port()
        console_passwd = conn.get_console_passwd()
    except libvirtError as lib_err:
        console_type = None
        console_websocket_port = None
        console_passwd = None

    ws_port = console_websocket_port if console_websocket_port else WS_PORT
    ws_host = WS_PUBLIC_HOST if WS_PUBLIC_HOST else request.get_host()
    ws_path = WS_PATH

    if ':' in ws_host:
        ws_host = re.sub(':[0-9]+', '', ws_host)

    if console_type == 'vnc':
        response = render(request, 'console-vnc.html', locals())
    elif console_type == 'spice':
        response = render(request, 'console-spice.html', locals())
    else:
        response = "Console type %s no support" % console_type

    response.set_cookie('token', token)
    return response
开发者ID:Menollo,项目名称:webvirtcloud,代码行数:43,代码来源:views.py


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