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

Python instance.wvmInstances函数代码示例

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

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



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

示例1: insts_status

def insts_status(request, host_id):
    """
    Instances block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect("/login")

    errors = []
    instances = []
    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:
        instances.append(
            {
                "name": instance,
                "status": conn.get_instance_status(instance),
                "memory": conn.get_instance_memory(instance),
                "vcpu": conn.get_instance_vcpu(instance),
                "uuid": conn.get_uuid(instance),
                "host": host_id,
                "dump": conn.get_instance_managed_save_image(instance),
            }
        )

    data = json.dumps(instances)
    response = HttpResponse()
    response["Content-Type"] = "text/javascript"
    response.write(data)
    return response
开发者ID:Hikayesiz,项目名称:webvirtmgr,代码行数:35,代码来源:views.py


示例2: insts_status

def insts_status(request, host_id):
    """
    Instances block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login')

    errors = []
    instances = []
    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 msg_error:
        errors.append(msg_error.message)

    for instance in get_instances:
        instances.append({'name': instance,
                          'status': conn.get_instance_status(instance),
                          'memory': conn.get_instance_memory(instance),
                          'vcpu': conn.get_instance_vcpu(instance),
                          'uuid': conn.get_uuid(instance),
                          'host': host_id,
                          'dump': conn.get_instance_managed_save_image(instance)
                          })

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


示例3: instances

def instances(request, host_id):
    """
    Instances block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login')

    errors = []
    instances = []
    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 msg_error:
        errors.append(msg_error.message)

    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()
        instances.append({'name': instance,
                          'status': conn.get_instance_status(instance),
                          'uuid': uuid,
                          'memory': conn.get_instance_memory(instance),
                          'vcpu': conn.get_instance_vcpu(instance)})

    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 '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 msg_error:
        errors.append(msg_error.message)

    return render_to_response('instances.html', locals(), context_instance=RequestContext(request))
开发者ID:amitk79,项目名称:webvirtmgr,代码行数:58,代码来源:views.py


示例4: instances

def instances(request, host_id):
    """
    Instances block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect("/login")

    errors = []
    instances = []
    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 msg_error:
        errors.append(msg_error.message)

    for instance in get_instances:
        try:
            inst = Instance.objects.get(compute_id=host_id, name=instance)
            uuid = inst.uuid
        except Instance.DoesNotExist:
            uuid = None
        instances.append({"name": instance, "status": conn.get_instance_status(instance), "uuid": uuid})

    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 "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 msg_error:
        errors.append(msg_error.message)

    return render_to_response("instances.html", locals(), context_instance=RequestContext(request))
开发者ID:vitalidze,项目名称:webvirtmgr,代码行数:49,代码来源:views.py


示例5: instance


#.........这里部分代码省略.........
                    clear = request.POST.get('clear_pass', False)
                    if clear:
                        passwd = ''
                    if not passwd and not clear:
                        msg = _("Enter the console password or select Generate")
                        errors.append(msg)
                if not errors:
                    if not conn.set_console_passwd(passwd):
                        msg = _("Error setting console password. You should check that your instance have an graphic device.")
                        errors.append(msg)
                    else:
                        return HttpResponseRedirect(request.get_full_path() + '#console_pass')

            if 'set_console_keymap' in request.POST:
                keymap = request.POST.get('console_keymap', '')
                clear = request.POST.get('clear_keymap', False)
                if clear:
                    conn.set_console_keymap('')
                else:
                    conn.set_console_keymap(keymap)
                return HttpResponseRedirect(request.get_full_path() + '#console_keymap')

            if 'set_console_type' in request.POST:
                console_type = request.POST.get('console_type', '')
                conn.set_console_type(console_type)
                return HttpResponseRedirect(request.get_full_path() + '#console_type')

            if 'migrate' in request.POST:
                compute_id = request.POST.get('compute_id', '')
                live = request.POST.get('live_migrate', False)
                unsafe = request.POST.get('unsafe_migrate', False)
                xml_del = request.POST.get('xml_delete', False)
                new_compute = Compute.objects.get(id=compute_id)
                conn_migrate = wvmInstances(new_compute.hostname,
                                            new_compute.login,
                                            new_compute.password,
                                            new_compute.type)
                conn_migrate.moveto(conn, vname, live, unsafe, xml_del)
                conn_migrate.define_move(vname)
                conn_migrate.close()
                return HttpResponseRedirect(reverse('instance', args=[compute_id, vname]))
            if 'delete_snapshot' in request.POST:
                snap_name = request.POST.get('name', '')
                conn.snapshot_delete(snap_name)
                return HttpResponseRedirect(request.get_full_path() + '#istaceshapshosts')
            if 'revert_snapshot' in request.POST:
                snap_name = request.POST.get('name', '')
                conn.snapshot_revert(snap_name)
                msg = _("Successful revert snapshot: ")
                msg += snap_name
                messages.append(msg)
            if 'clone' in request.POST:
                clone_data = {}
                clone_data['name'] = request.POST.get('name', '')

                for post in request.POST:
                    if 'disk' or 'meta' in post:
                        clone_data[post] = request.POST.get(post, '')

                conn.clone_instance(clone_data)
                return HttpResponseRedirect(reverse('instance', args=[host_id, clone_data['name']]))
            if 'add_vf' in request.POST:
                from django.utils.translation import ugettext as _
                count_vf = 0
                for pf,vfs in vf_infos.items():
                    for vf in vfs:
开发者ID:fuwenbin,项目名称:webvirtmgr-nfv,代码行数:67,代码来源:views.py


示例6: instance


#.........这里部分代码省略.........
                conn.add_cdrom()
                return HttpResponseRedirect(request.get_full_path() + '#instancemedia')
            if 'set_autostart' in request.POST:
                conn.set_autostart(1)
                return HttpResponseRedirect(request.get_full_path() + '#instancesettings')
            if 'unset_autostart' in request.POST:
                conn.set_autostart(0)
                return HttpResponseRedirect(request.get_full_path() + '#instancesettings')
            if 'change_settings' in request.POST:
                description = request.POST.get('description', '')
                vcpu = request.POST.get('vcpu', '')
                cur_vcpu = request.POST.get('cur_vcpu', '')
                memory = request.POST.get('memory', '')
                memory_custom = request.POST.get('memory_custom', '')
                if memory_custom:
                    memory = memory_custom
                cur_memory = request.POST.get('cur_memory', '')
                cur_memory_custom = request.POST.get('cur_memory_custom', '')
                if cur_memory_custom:
                    cur_memory = cur_memory_custom
                conn.change_settings(description, cur_memory, memory, cur_vcpu, vcpu)
                return HttpResponseRedirect(request.get_full_path() + '#instancesettings')
            if 'change_xml' in request.POST:
                xml = request.POST.get('inst_xml', '')
                if xml:
                    conn._defineXML(xml)
                    return HttpResponseRedirect(request.get_full_path() + '#instancexml')
            if 'set_console_passwd' in request.POST:
                if request.POST.get('auto_pass', ''):
                    passwd = ''.join([choice(letters + digits) for i in xrange(12)])
                else:
                    passwd = request.POST.get('console_passwd', '')
                    clear = request.POST.get('clear_pass', False)
                    if clear:
                        passwd = ''
                    if not passwd and not clear:
                        msg = _("Enter the console password or select Generate")
                        errors.append(msg)
                if not errors:
                    if not conn.set_console_passwd(passwd):
                        msg = _("Error setting console password. You should check that your instance have an graphic device.")
                        errors.append(msg)
                    else:
                        return HttpResponseRedirect(request.get_full_path() + '#console_pass')

            if 'set_console_keymap' in request.POST:
                keymap = request.POST.get('console_keymap', '')
                clear = request.POST.get('clear_keymap', False)
                if clear:
                    conn.set_console_keymap('')
                else:
                    conn.set_console_keymap(keymap)
                return HttpResponseRedirect(request.get_full_path() + '#console_keymap')

            if 'set_console_type' in request.POST:
                console_type = request.POST.get('console_type', '')
                conn.set_console_type(console_type)
                return HttpResponseRedirect(request.get_full_path() + '#console_type')

            if 'migrate' in request.POST:
                compute_id = request.POST.get('compute_id', '')
                live = request.POST.get('live_migrate', False)
                unsafe = request.POST.get('unsafe_migrate', False)
                xml_del = request.POST.get('xml_delete', False)
                new_compute = Compute.objects.get(id=compute_id)
                conn_migrate = wvmInstances(new_compute.hostname,
                                            new_compute.login,
                                            new_compute.password,
                                            new_compute.type)
                conn_migrate.moveto(conn, vname, live, unsafe, xml_del)
                conn_migrate.define_move(vname)
                conn_migrate.close()
                return HttpResponseRedirect(reverse('instance', args=[compute_id, vname]))
            if 'delete_snapshot' in request.POST:
                snap_name = request.POST.get('name', '')
                conn.snapshot_delete(snap_name)
                return HttpResponseRedirect(request.get_full_path() + '#istaceshapshosts')
            if 'revert_snapshot' in request.POST:
                snap_name = request.POST.get('name', '')
                conn.snapshot_revert(snap_name)
                msg = _("Successful revert snapshot: ")
                msg += snap_name
                messages.append(msg)
            if 'clone' in request.POST:
                clone_data = {}
                clone_data['name'] = request.POST.get('name', '')

                for post in request.POST:
                    if 'disk' or 'meta' in post:
                        clone_data[post] = request.POST.get(post, '')

                conn.clone_instance(clone_data)
                return HttpResponseRedirect(reverse('instance', args=[host_id, clone_data['name']]))

        conn.close()

    except libvirtError as err:
        errors.append(err)

    return render_to_response('instance.html', locals(), context_instance=RequestContext(request))
开发者ID:luxflow,项目名称:webvirtmgr,代码行数:101,代码来源:views.py


示例7: instances

def instances(request, host_id):
    """
    Instances block
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login'))

    errors = []
    instances = []
    time_refresh = 8000
    get_instances = []
    cnt_max = settings.vf_cnt_max
    conn = None
    meta_prealloc = False
    compute = Compute.objects.get(id=host_id)
    memory_range = [2048, 4096, 6144, 8192, 16384]
    ifaces_all = util.get_free_vfs()
    ifaces_all = sorted(ifaces_all.iteritems(),key=lambda ax:ax[0])

    try:
        conn = wvmInstances(compute.hostname,
                            compute.login,
                            compute.password,
                            compute.type)
        conn_create = wvmCreate(compute.hostname,
                         compute.login,
                         compute.password,
                         compute.type)
        conn_storage = wvmStorage(compute.hostname,
                          compute.login,
                          compute.password,
                          compute.type,
                          'Images')
        state = conn_storage.is_active()
        if state:
            conn_storage.refresh()
            volumes = conn_storage.update_volumes()
            conn_storage.close()
        else:
            volumes = None
        get_images = volumes
        get_instances = conn.get_instances()
    except libvirtError as err:
        pass
#        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()
        instances.append({'name': instance,
                          'status': conn.get_instance_status(instance),
                          'uuid': uuid,
                          'memory': conn.get_instance_memory(instance),
                          'vcpu': conn.get_instance_vcpu(instance),
                          'has_managed_save_image': conn.get_instance_managed_save_image(instance)})
    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())
                if 'create' in request.POST:
                
                    volumes = {}
                    interfaces = []
                    vm_vfs_info = {}
                    form = NewVMForm(request.POST)
                    if form.is_valid():
                        data = form.cleaned_data
                        if instances:
                            if data['name'] in instances:
                                msg = _("A virtual machine with this name already exists")
                                errors.append(msg)
                        if not errors:
                        
                            if data['hdd_size']:
#.........这里部分代码省略.........
开发者ID:fuwenbin,项目名称:webvirtmgr-nfv,代码行数:101,代码来源:views.py


示例8: 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


示例9: instance


#.........这里部分代码省略.........
                conn.change_settings(description, cur_memory, memory, cur_vcpu, vcpu)
                return HttpResponseRedirect(request.get_full_path() + '#instancesettings')
            if 'change_xml' in request.POST:
                xml = request.POST.get('inst_xml', '')
                if xml:
                    conn._defineXML(xml)
                    return HttpResponseRedirect(request.get_full_path() + '#instancexml')
            if 'set_vnc_passwd' in request.POST:
                if request.POST.get('auto_pass', ''):
                    passwd = ''.join([choice(letters + digits) for i in xrange(12)])
                else:
                    passwd = request.POST.get('vnc_passwd', '')
                    clear = request.POST.get('clear_pass', False)
                    if not passwd and not clear:
                        msg = _("Enter the VNC password or select Generate")
                        errors.append(msg)
                if not errors:
                    conn.set_vnc_passwd(passwd)
                    return HttpResponseRedirect(request.get_full_path() + '#vnc_pass')

            if 'set_vnc_keymap' in request.POST:
                keymap = request.POST.get('vnc_keymap', '')
                clear = request.POST.get('clear_keymap', False)
                if clear:
                    conn.set_vnc_keymap('')
                else:
                    conn.set_vnc_keymap(keymap)
                return HttpResponseRedirect(request.get_full_path() + '#vnc_keymap')

            if 'migrate' in request.POST:
                compute_id = request.POST.get('compute_id', '')
                live = request.POST.get('live_migrate', False)
                unsafe = request.POST.get('unsafe_migrate', False)
                xml_del = request.POST.get('xml_delete', False)
                new_compute = Compute.objects.get(id=compute_id)
                conn_migrate = wvmInstances(new_compute.hostname,
                                            new_compute.login,
                                            new_compute.password,
                                            new_compute.type)
                conn_migrate.moveto(conn, vname, live, unsafe, xml_del)
                conn_migrate.define_move(vname)
                conn_migrate.close()
                return HttpResponseRedirect('/%s/instance/%s' % (compute_id, vname))
            if 'delete_snapshot' in request.POST:
                snap_name = request.POST.get('name', '')
                conn.snapshot_delete(snap_name)
                return HttpResponseRedirect(request.get_full_path() + '#istaceshapshosts')
            if 'revert_snapshot' in request.POST:
                snap_name = request.POST.get('name', '')
                conn.snapshot_revert(snap_name)
                msg = _("Successful revert snapshot: ")
                msg += snap_name
                messages.append(msg)
            if 'clone' in request.POST:
                clone_data = {}
                clone_data['name'] = request.POST.get('name', '')

                for post in request.POST:
                    if 'disk' or 'meta' in post:
                        clone_data[post] = request.POST.get(post, '')

                conn.clone_instance(clone_data)
                return HttpResponseRedirect('/%s/instance/%s' % (host_id, clone_data['name']))

        conn.close()

    except libvirtError as err:
        errors.append(err)

    object = {
        'errors': [str(error) for error in errors],
        'response': {
            'name': vname,
            'status': status,
            'autostart': autostart,
            'vcpu': vcpu,
            'cur_vcpu': cur_vcpu,
            'uuid': uuid,
            'memory': memory,
            'cur_memory': cur_memory,
            'description': description,
            'disks': disks,
            'media': media,
            'networks': networks,
            'media_iso': media_iso,
            'vcpu_range': vcpu_range.__len__(),
            'memory_host': memory_host,
            'vcpu_host': vcpu_host,
            'telnet_port': telnet_port,
            'vnc_port': vnc_port,
            'vnc_keymap': vnc_keymap,
            'snapshots': snapshots,
            'inst_xml': inst_xml.__str__(),
            'has_managed_save_image': has_managed_save_image,
            'clone_disks': clone_disks,
            'cpu_usage': cpu_usage,
            'vnc_password': vnc_password
        }
    }
    return render(object, 'instance.html', locals(), request)
开发者ID:CovertLamp,项目名称:virtkick-backend,代码行数:101,代码来源:views.py


示例10: instances

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

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

    error_messages = []
    all_host_vms = {}
    all_user_vms = {}
    computes = Compute.objects.all()

    if not request.user.is_superuser:
        user_instances = UserInstance.objects.filter(user_id=request.user.id)
        for usr_inst in user_instances:
            if connection_manager.host_is_up(usr_inst.instance.compute.type,
                                             usr_inst.instance.compute.hostname):
                conn = wvmHostDetails(usr_inst.instance.compute,
                                      usr_inst.instance.compute.login,
                                      usr_inst.instance.compute.password,
                                      usr_inst.instance.compute.type)
                all_user_vms[usr_inst] = conn.get_user_instances(usr_inst.instance.name)
                all_user_vms[usr_inst].update({'compute_id': usr_inst.instance.compute.id})
    else:
        for comp in computes:
            if connection_manager.host_is_up(comp.type, comp.hostname):
                try:
                    conn = wvmHostDetails(comp, comp.login, comp.password, comp.type)
                    if conn.get_host_instances():
                        all_host_vms[comp.id, comp.name] = conn.get_host_instances()
                        for vm, info in conn.get_host_instances().items():
                            try:
                                check_uuid = Instance.objects.get(compute_id=comp.id, name=vm)
                                if check_uuid.uuid != info['uuid']:
                                    check_uuid.save()
                            except Instance.DoesNotExist:
                                check_uuid = Instance(compute_id=comp.id, name=vm, uuid=info['uuid'])
                                check_uuid.save()
                    conn.close()
                except libvirtError as lib_err:
                    error_messages.append(lib_err)

    if request.method == 'POST':
        name = request.POST.get('name', '')
        compute_id = request.POST.get('compute_id', '')
        instance = Instance.objects.get(compute_id=compute_id, name=name)
        try:
            conn = wvmInstances(instance.compute.hostname,
                                instance.compute.login,
                                instance.compute.password,
                                instance.compute.type)
            if 'poweron' in request.POST:
                msg = _("Power On")
                addlogmsg(request.user.username, instance.name, msg)
                conn.start(name)
                return HttpResponseRedirect(request.get_full_path())

            if 'poweroff' in request.POST:
                msg = _("Power Off")
                addlogmsg(request.user.username, instance.name, msg)
                conn.shutdown(name)
                return HttpResponseRedirect(request.get_full_path())

            if 'powercycle' in request.POST:
                msg = _("Power Cycle")
                conn.force_shutdown(name)
                conn.start(name)
                addlogmsg(request.user.username, instance.name, msg)
                return HttpResponseRedirect(request.get_full_path())

            if request.user.is_superuser:

                if 'suspend' in request.POST:
                    msg = _("Suspend")
                    addlogmsg(request.user.username, instance.name, msg)
                    conn.suspend(name)
                    return HttpResponseRedirect(request.get_full_path())

                if 'resume' in request.POST:
                    msg = _("Resume")
                    addlogmsg(request.user.username, instance.name, msg)
                    conn.resume(name)
                    return HttpResponseRedirect(request.get_full_path())

        except libvirtError as lib_err:
            error_messages.append(lib_err)
            addlogmsg(request.user.username, instance.name, lib_err.message)

    return render(request, 'instances.html', locals())
开发者ID:savichev,项目名称:webvirtcloud,代码行数:91,代码来源:views.py


示例11: instance


#.........这里部分代码省略.........
                    conn.resume()
                    msg = _("Resume")
                    addlogmsg(request.user.username, instance.name, msg)
                    return HttpResponseRedirect(request.get_full_path() + '#suspend')

                if 'set_autostart' in request.POST:
                    conn.set_autostart(1)
                    msg = _("Set autostart")
                    addlogmsg(request.user.username, instance.name, msg)
                    return HttpResponseRedirect(request.get_full_path() + '#autostart')

                if 'unset_autostart' in request.POST:
                    conn.set_autostart(0)
                    msg = _("Unset autostart")
                    addlogmsg(request.user.username, instance.name, msg)
                    return HttpResponseRedirect(request.get_full_path() + '#autostart')

                if 'change_xml' in request.POST:
                    exit_xml = request.POST.get('inst_xml', '')
                    if exit_xml:
                        conn._defineXML(exit_xml)
                        msg = _("Edit XML")
                        addlogmsg(request.user.username, instance.name, msg)
                        return HttpResponseRedirect(request.get_full_path() + '#xmledit')

                if 'set_console_passwd' in request.POST:
                    if request.POST.get('auto_pass', ''):
                        passwd = randomPasswd()
                    else:
                        passwd = request.POST.get('console_passwd', '')
                        clear = request.POST.get('clear_pass', False)
                        if clear:
                            passwd = ''
                        if not passwd and not clear:
                            msg = _("Enter the console password or select Generate")
                            error_messages.append(msg)
                    if not error_messages:
                        if not conn.set_console_passwd(passwd):
                            msg = _("Error setting console password. You should check that your instance have an graphic device.")
                            error_messages.append(msg)
                        else:
                            msg = _("Set VNC password")
                            addlogmsg(request.user.username, instance.name, msg)
                            return HttpResponseRedirect(request.get_full_path() + '#vncsettings')

                if 'set_console_keymap' in request.POST:
                    keymap = request.POST.get('console_keymap', '')
                    clear = request.POST.get('clear_keymap', False)
                    if clear:
                        conn.set_console_keymap('')
                    else:
                        conn.set_console_keymap(keymap)
                    msg = _("Set VNC keymap")
                    addlogmsg(request.user.username, instance.name, msg)
                    return HttpResponseRedirect(request.get_full_path() + '#vncsettings')

                if 'set_console_type' in request.POST:
                    console_type = request.POST.get('console_type', '')
                    conn.set_console_type(console_type)
                    msg = _("Set VNC type")
                    addlogmsg(request.user.username, instance.name, msg)
                    return HttpResponseRedirect(request.get_full_path() + '#vncsettings')

                if 'migrate' in request.POST:
                    compute_id = request.POST.get('compute_id', '')
                    live = request.POST.get('live_migrate', False)
                    unsafe = request.POST.get('unsafe_migrate', False)
                    xml_del = request.POST.get('xml_delete', False)
                    new_compute = Compute.objects.get(id=compute_id)
                    conn_migrate = wvmInstances(new_compute.hostname,
                                                new_compute.login,
                                                new_compute.password,
                                                new_compute.type)
                    conn_migrate.moveto(conn, vname, live, unsafe, xml_del)
                    conn_migrate.define_move(vname)
                    conn_migrate.close()
                    msg = _("Migrate")
                    addlogmsg(request.user.username, instance.name, msg)
                    return HttpResponseRedirect(reverse('instance', args=[compute_id, vname]))

                if 'clone' in request.POST:
                    clone_data = {}
                    clone_data['name'] = request.POST.get('name', '')

                    for post in request.POST:
                        if 'disk' or 'meta' in post:
                            clone_data[post] = request.POST.get(post, '')

                    conn.clone_instance(clone_data)
                    msg = _("Clone")
                    addlogmsg(request.user.username, instance.name, msg)
                    return HttpResponseRedirect(reverse('instance', args=[compute_id, clone_data['name']]))

        conn.close()

    except libvirtError as lib_err:
        error_messages.append(lib_err.message)
        addlogmsg(request.user.username, vname, lib_err.message)

    return render(request, 'instance.html', locals())
开发者ID:olivierb2,项目名称:webvirtcloud,代码行数:101,代码来源:views.py


示例12: instances

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

    error_messages = []
    all_host_vms = {}
    all_user_vms = {}
    computes = Compute.objects.all().order_by("name")

    def get_userinstances_info(instance):
        info = {}
        uis = UserInstance.objects.filter(instance=instance)
        info['count'] = uis.count()
        if info['count'] > 0:
            info['first_user'] = uis[0]
        else:
            info['first_user'] = None
        return info

    def refresh_instance_database(comp, vm, info):
        instances = Instance.objects.filter(name=vm)
        if instances.count() > 1:
            for i in instances:
                user_instances_count = UserInstance.objects.filter(instance=i).count()
                if user_instances_count == 0:
                    addlogmsg(request.user.username, i.name, _("Deleting due to multiple records."))
                    i.delete()
        
        try:
            check_uuid = Instance.objects.get(compute_id=comp["id"], name=vm)
            if check_uuid.uuid != info['uuid']:
                check_uuid.save()

            all_host_vms[comp["id"],
                         comp["name"],
                         comp["status"],
                         comp["cpu"],
                         comp["mem_size"],
                         comp["mem_perc"]][vm]['is_template'] = check_uuid.is_template
            all_host_vms[comp["id"],
                         comp["name"],
                         comp["status"],
                         comp["cpu"],
                         comp["mem_size"],
                         comp["mem_perc"]][vm]['userinstances'] = get_userinstances_info(check_uuid)
        except Instance.DoesNotExist:
            check_uuid = Instance(compute_id=comp["id"], name=vm, uuid=info['uuid'])
            check_uuid.save()
    
    if not request.user.is_superuser:
        user_instances = UserInstance.objects.filter(user_id=request.user.id)
        for usr_inst in user_instances:
            if connection_manager.host_is_up(usr_inst.instance.compute.type,
                                             usr_inst.instance.compute.hostname):
                conn = wvmHostDetails(usr_inst.instance.compute,
                                      usr_inst.instance.compute.login,
                                      usr_inst.instance.compute.password,
                                      usr_inst.instance.compute.type)
                all_user_vms[usr_inst] = conn.get_user_instances(usr_inst.instance.name)
                all_user_vms[usr_inst].update({'compute_id': usr_inst.instance.compute.id})
    else:
        for comp in computes:
            status = connection_manager.host_is_up(comp.type, comp.hostname)
            if status:
                try:
                    conn = wvmHostDetails(comp, comp.login, comp.password, comp.type)
                    comp_node_info = conn.get_node_info()
                    comp_mem = conn.get_memory_usage()
                    comp_instances = conn.get_host_instances(True)

                    if comp_instances:
                        comp_info= {
                            "id": comp.id,
                            "name": comp.name,
                            "status": status,
                            "cpu": comp_node_info[3],
                            "mem_size": comp_node_info[2],
                            "mem_perc": comp_mem['percent']
                        }
                        all_host_vms[comp_info["id"], comp_info["name"], comp_info["status"], comp_info["cpu"],
                                     comp_info["mem_size"], comp_info["mem_perc"]] = comp_instances
                        for vm, info in comp_instances.items():
                            refresh_instance_database(comp_info, vm, info)

                    conn.close()
                except libvirtError as lib_err:
                    error_messages.append(lib_err)

    if request.method == 'POST':
        name = request.POST.get('name', '')
        compute_id = request.POST.get('compute_id', '')
        instance = Instance.objects.get(compute_id=compute_id, name=name)
        try:
            conn = wvmInstances(instance.compute.hostname,
                                instance.compute.login,
                                instance.compute.password,
                                instance.compute.type)
            if 'poweron' in request.POST:
#.........这里部分代码省略.........
开发者ID:razvanboarta,项目名称:webvirtcloud,代码行数:101,代码来源:views.py


示例13: instance


#.........这里部分代码省略.........
                if 'set_console_keymap' in request.POST:
                    keymap = request.POST.get('console_keymap', '')
                    clear = request.POST.get('clear_keymap', False)
                    if clear:
                        conn.set_console_keymap('')
                    else:
                        conn.set_console_keymap(keymap)
                    msg = _("Set VNC keymap")
                    addlogmsg(request.user.username, instance.name, msg)
                    return HttpResponseRedirect(request.get_full_path() + '#vncsettings')

                if 'set_console_type' in request.POST:
                    console_type = request.POST.get('console_type', '')
                    conn.set_console_type(console_type)
                    msg = _("Set VNC type")
                    addlogmsg(request.user.username, instance.name, msg)
                    return HttpResponseRedirect(request.get_full_path() + '#vncsettings')
                
                if 'set_console_listen_address' in request.POST:
                    console_type = request.POST.get('console_listen_address', '')
                    conn.set_console_listen_addr(console_type)
                    msg = _("Set VNC listen address")
                    addlogmsg(request.user.username, instance.name, msg)
                    return HttpResponseRedirect(request.get_full_path() + '#vncsettings')

            if request.user.is_superuser:
                if 'migrate' in request.POST:
                    compute_id = request.POST.get('compute_id', '')
                    live = request.POST.get('live_migrate', False)
                    unsafe = request.POST.get('unsafe_migrate', False)
                    xml_del = request.POST.get('xml_delete', False)
                    offline = request.POST.get('offline_migrate', False)
                    new_compute = Compute.objects.get(id=compute_id)
                    conn_migrate = wvmInstances(new_compute.hostname,
                                                new_compute.login,
                                                new_compute.password,
                                                new_compute.type)
                    conn_migrate.moveto(conn, vname, live, unsafe, xml_del, offline)
                    instance.compute = new_compute
                    instance.save()
                    conn_migrate.close()
                    if autostart:
                        conn_new = wvmInstance(new_compute.hostname,
                                               new_compute.login,
                                               new_compute.password,
                                               new_compute.type,
                                               vname)
                        conn_new.set_autostart(1)
                        conn_new.close()
                    msg = _("Migrate to %s" % new_compute.hostname)
                    addlogmsg(request.user.username, instance.name, msg)
                    return HttpResponseRedirect(reverse('instance', args=[compute_id, vname]))

                if 'change_network' in request.POST:
                    network_data = {}

                    for post in request.POST:
                        if post.startswith('net-source-'):
                            (source, source_type) = get_network_tuple(request.POST.get(post))
                            network_data[post] = source
                            network_data[post + '-type'] = source_type
                        elif post.startswith('net-'):
                            network_data[post] = request.POST.get(post, '')

                    conn.change_network(network_data)
                    msg = _("Edit network")
开发者ID:razvanboarta,项目名称:webvirtcloud,代码行数:67,代码来源:views.py


示例14: instance

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.get_xml_path函数代码示例发布时间:2022-05-26
下一篇:
Python instance.wvmInstance函数代码示例发布时间: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