• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python instance.wvmInstance函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: get_vdi_url

def get_vdi_url(request, vname):
    instance = Instance.objects.get(name=vname)
    compute = instance.compute
    data = {}
    try:
        conn = wvmInstance(compute.hostname,
                           compute.login,
                           compute.password,
                           compute.type,
                           instance.name)

        fqdn = get_hostname_by_ip(compute.hostname)
        url = "{}://{}:{}".format(conn.get_console_type(), fqdn, conn.get_console_port())
        response = url
        return HttpResponse(response)
    
    except libvirtError as lib_err:
        err = "Error getting vdi url for {}".format(vname)
        raise Http404(err)
开发者ID:razvanboarta,项目名称:webvirtcloud,代码行数:19,代码来源:views.py


示例17: console

def console(request):
    """
    VNC instance block
    """
    if request.method == 'GET':
        reqtoken = request.GET.get("token")
        reqstr = base64.decodestring(reqtoken)
        temptoken = reqstr.split('|', 2)
        hostname = temptoken[0]
        name = temptoken[1]
        display = temptoken[2]
        password = None
        login = None
        htype = 1
        
    try:
        conn = wvmInstance(hostname,
                           login,
                           password,
                           htype,
                           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))
    token = hostname + "|"+name +"|"+display
    des = DES()  
    des.input_key(WS_DESKEY)  
    encryptval = des.encode(token)  
    response.set_cookie('token', encryptval)
    return response
开发者ID:darrentangdt,项目名称:cloudstack-novnc,代码行数:40,代码来源:views.py


示例18: instance

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

    error_messages = []
    messages = []
    compute = get_object_or_404(Compute, pk=compute_id)
    computes = Compute.objects.all()
    computes_count = len(computes)
    publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
    keymaps = QEMU_KEYMAPS
    console_types = QEMU_CONSOLE_TYPES
    try:
        userinstace = UserInstance.objects.get(instance__compute_id=compute_id,
                                               instance__name=vname,
                                               user__id=request.user.id)
    except UserInstance.DoesNotExist:
        userinstace = None

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

    def show_clone_disk(disks, vname=''):
        clone_disk = []
        for disk in disks:
            if disk['image'] is None:
                continue
            if disk['image'].count("-") and disk['image'].rsplit("-", 1)[0] == vname:
                name, suffix = disk['image'].rsplit("-", 1)
                image = name + "-clone" + "-" + suffix
            elif disk['image'].count(".") and len(disk['image'].rsplit(".", 1)[1]) <= 7:
                name, suffix = disk['image'].rsplit(".", 1)
                image = name + "-clone" + "." + suffix
            else:
                image = disk['image'] + "-clone"
            clone_disk.append(
                {'dev': disk['dev'], 'storage': disk['storage'],
                 'image': image, 'format': disk['format']})
        return clone_disk
    
    def filesizefstr(size_str):
        if size_str == '':
            return 0
        size_str = size_str.encode('ascii', 'ignore').upper().translate(None, " B")
        if 'K' == size_str[-1]:
            return long(float(size_str[:-1]))<<10
        elif 'M' == size_str[-1]:
            return long(float(size_str[:-1]))<<20
        elif 'G' == size_str[-1]:
            return long(float(size_str[:-1]))<<30
        elif 'T' == size_str[-1]:
            return long(float(size_str[:-1]))<<40
        elif 'P' == size_str[-1]:
            return long(float(size_str[:-1]))<<50
        else:
            return long(float(size_str))

    def get_clone_free_names(size=10):
        prefix = settings.CLONE_INSTANCE_DEFAULT_PREFIX
        free_names = []
        existing_names = [i.name for i in Instance.objects.filter(name__startswith=prefix)]
        index = 1
        while len(free_names) < size:
            new_name = prefix + str(index)
            if new_name not in existing_names:
                free_names.append(new_name)
            index += 1
        return free_names

    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"
#.........这里部分代码省略.........
开发者ID:AlexTEko,项目名称:webvirtcloud,代码行数:101,代码来源:views.py


示例19: instance

def instance(request, host_id, vname):
    """
    Instance block
    """
    def show_clone_disk(disks):
        clone_disk = []
        for disk in disks:
            if disk['image'].count(".") and len(disk['image'].rsplit(".", 1)[1]) <= 7:
                name, suffix = disk['image'].rsplit(".", 1)
                image = name + "-clone" + "." + suffix
            else:
                image = disk['image'] + "-clone"
            clone_disk.append(
                {'dev': disk['dev'], 'storage': disk['storage'], 'image': image, 'format': disk['format']})
        return clone_disk

    errors = []
    messages = []
    time_refresh = TIME_JS_REFRESH
    compute = Compute.objects.get(id=host_id)
    computes = Compute.objects.all()
    computes_count = len(computes)
    keymaps = QEMU_KEYMAPS

    try:
        conn = wvmInstance(compute.hostname,
                           compute.login,
                           compute.password,
                           compute.type,
                           vname)

        status = conn.get_status()
        autostart = conn.get_autostart()
        vcpu = conn.get_vcpu()
        cur_vcpu = conn.get_cur_vcpu()
        uuid = conn.get_uuid()
        memory = conn.get_memory()
        cur_memory = conn.get_cur_memory()
        description = conn.get_description()
        disks = conn.get_disk_device()
        media = conn.get_media_device()
        networks = conn.get_net_device()
        media_iso = sorted(conn.get_iso_media())
        vcpu_range = conn.get_max_cpus()
        memory_range = [256, 512, 1024, 2048, 4096, 6144, 8192, 16384]
        memory_host = conn.get_max_memory()
        vcpu_host = len(vcpu_range)
        telnet_port = conn.get_telnet_port()
        vnc_port = conn.get_vnc_port()
        vnc_keymap = conn.get_vnc_keymap()
        vnc_password = conn.get_vnc_passwd()
        snapshots = sorted(conn.get_snapshot(), reverse=True)
        inst_xml = conn._XMLDesc(VIR_DOMAIN_XML_SECURE)
        has_managed_save_image = conn.get_managed_save_image()
        clone_disks = show_clone_disk(disks)
        cpu_usage = conn.cpu_usage()['cpu']
    except libvirtError as err:
        errors.append(err)

    try:
        instance = Instance.objects.get(compute_id=host_id, name=vname)
        if instance.uuid != uuid:
            instance.uuid = uuid
            instance.save()
    except Instance.DoesNotExist:
        instance = Instance(compute_id=host_id, name=vname, uuid=uuid)
        instance.save()

    try:
        if request.method == 'POST':
            if 'start' in request.POST:
                conn.start()
                return HttpResponseRedirect(request.get_full_path() + '#shutdown')
            if 'power' in request.POST:
                if 'shutdown' == request.POST.get('power', ''):
                    conn.shutdown()
                    return HttpResponseRedirect(request.get_full_path() + '#shutdown')
                if 'destroy' == request.POST.get('power', ''):
                    conn.force_shutdown()
                    return HttpResponseRedirect(request.get_full_path() + '#forceshutdown')
                if 'managedsave' == request.POST.get('power', ''):
                    conn.managedsave()
                    return HttpResponseRedirect(request.get_full_path() + '#managedsave')
            if 'deletesaveimage' in request.POST:
                conn.managed_save_remove()
                return HttpResponseRedirect(request.get_full_path() + '#managedsave')
            if 'suspend' in request.POST:
                conn.suspend()
                return HttpResponseRedirect(request.get_full_path() + '#suspend')
            if 'resume' in request.POST:
                conn.resume()
                return HttpResponseRedirect(request.get_full_path() + '#suspend')
            if 'delete' in request.POST:
                if conn.get_status() == 1:
                    conn.force_shutdown()
                if request.POST.get('delete_disk', ''):
                    print 'yeah'
                    conn.delete_disk()
                try:
                    instance = Instance.objects.get(compute_id=host_id, name=vname)
#.........这里部分代码省略.........
开发者ID:CovertLamp,项目名称:virtkick-backend,代码行数:101,代码来源:views.py


示例20: instances

def instances(request, host_id):
    """
    Instances block
    """
    errors = []
    instances = []
    time_refresh = 8000
    get_instances = []
    conn = None
    compute = Compute.objects.get(id=host_id)

    try:
        conn = wvmInstances(compute.hostname,
                            compute.login,
                            compute.password,
                            compute.type)
        get_instances = conn.get_instances()
    except libvirtError as err:
        errors.append(err)

    for instance in get_instances:
        try:
            inst = Instance.objects.get(compute_id=host_id, name=instance)
            uuid = inst.uuid
        except Instance.DoesNotExist:
            uuid = conn.get_uuid(instance)
            inst = Instance(compute_id=host_id, name=instance, uuid=uuid)
            inst.save()

        conn2 = wvmInstance(compute.hostname,
            compute.login,
            compute.password,
            compute.type,
            instance)

        instances.append({'name': instance,
                          'status': conn.get_instance_status(instance),
                          'uuid': uuid,
                          'memory': conn.get_instance_memory(instance),
                          'vcpu': conn.get_instance_vcpu(instance),
                          'storage': conn2.get_disk_device(),
                          'has_managed_save_image': conn.get_instance_managed_save_image(instance)})

        conn2.close()

    if conn:
        try:
            if request.method == 'POST':
                name = request.POST.get('name', '')
                if 'start' in request.POST:
                    conn.start(name)
                    return HttpResponseRedirect(request.get_full_path())
                if 'shutdown' in request.POST:
                    conn.shutdown(name)
                    return HttpResponseRedirect(request.get_full_path())
                if 'destroy' in request.POST:
                    conn.force_shutdown(name)
                    return HttpResponseRedirect(request.get_full_path())
                if 'managedsave' in request.POST:
                    conn.managedsave(name)
                    return HttpResponseRedirect(request.get_full_path())
                if 'deletesaveimage' in request.POST:
                    conn.managed_save_remove(name)
                    return HttpResponseRedirect(request.get_full_path())
                if 'suspend' in request.POST:
                    conn.suspend(name)
                    return HttpResponseRedirect(request.get_full_path())
                if 'resume' in request.POST:
                    conn.resume(name)
                    return HttpResponseRedirect(request.get_full_path())

            conn.close()
        except libvirtError as err:
            errors.append(err)

    object = {
        'response': {
            'instances': instances
        },
        'errors': [str(error) for error in errors]
    }
    return render(object, 'instances.html', locals(), request)
开发者ID:CovertLamp,项目名称:virtkick-backend,代码行数:82,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python instance.wvmInstances函数代码示例发布时间:2022-05-26
下一篇:
Python hostdetails.wvmHostDetails函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap