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


Python virsh.qemu_monitor_command函数代码示例

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


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

示例1: hotplug_device

 def hotplug_device(hotplug_type, char_dev, index=1, id=0):
     if hotplug_type == "qmp":
         char_add_opt = "chardev-add "
         dev_add_opt = "device_add virtserialport,chardev="
         if char_dev == "file":
             char_add_opt += ("file,path=%s/file%s,id=file%s"
                              % (tmp_dir, index, index))
             dev_add_opt += ("file%s,name=file%s,bus=virtio-serial0.0,id=file%s"
                             % (index, index, index))
         elif char_dev == "socket":
             char_add_opt += ("socket,path=%s/socket%s,server,nowait,id=socket%s"
                              % (tmp_dir, index, index))
             dev_add_opt += ("socket%s,name=socket%s,bus=virtio-serial0.0,id=socket%s"
                             % (index, index, index))
         elif char_dev == "pty":
             char_add_opt += "pty,path=/dev/pts/%s,id=pty%s" % (id, index)
             dev_add_opt += ("pty%s,name=pty%s,bus=virtio-serial0.0,id=pty%s"
                             % (index, index, index))
         virsh.qemu_monitor_command(vm_name, char_add_opt, "--hmp")
         virsh.qemu_monitor_command(vm_name, dev_add_opt, "--hmp")
     elif hotplug_type == "attach":
         xml_file = "%s/xml_%s%s" % (tmp_dir, char_dev, index)
         if char_dev in ["file", "socket"]:
             prepare_channel_xml(xml_file, char_dev, index)
         elif char_dev == "pty":
             prepare_channel_xml(xml_file, char_dev, index, id)
         virsh.attach_device(vm_name, xml_file, flagstr="--live")
开发者ID:will-Do,项目名称:tp-libvirt_v2v,代码行数:27,代码来源:libvirt_bench_serial_hotplug.py

示例2: hotplug_device

 def hotplug_device(type, char_dev, id=0):
     tmp_file = os.path.join(tmp_dir, char_dev)
     if type == "qmp":
         char_add_opt = "chardev-add "
         dev_add_opt = "device_add virtserialport,chardev="
         if char_dev == "file":
             char_add_opt += "file,path=%s,id=file" % tmp_file
             dev_add_opt += "file,name=file,bus=virtio-serial0.0,id=file"
         elif char_dev == "socket":
             char_add_opt += "socket,path=%s,server,nowait,id=socket" % tmp_file
             dev_add_opt += "socket,name=socket,bus=virtio-serial0.0,id=socket"
         elif char_dev == "pty":
             char_add_opt += ("pty,path=/dev/pts/%s,id=pty" % id)
             dev_add_opt += "pty,name=pty,bus=virtio-serial0.0,id=pty"
         result = virsh.qemu_monitor_command(vm_name, char_add_opt, "--hmp")
         if result.exit_status:
             raise error.TestError('Failed to add chardev %s to %s. Result:\n %s'
                                   % (char_dev, vm_name, result))
         result = virsh.qemu_monitor_command(vm_name, dev_add_opt, "--hmp")
         if result.exit_status:
             raise error.TestError('Failed to add device %s to %s. Result:\n %s'
                                   % (char_dev, vm_name, result))
     elif type == "attach":
         xml_file = os.path.join(tmp_dir, "xml_%s" % char_dev)
         if char_dev in ["file", "socket"]:
             prepare_channel_xml(xml_file, char_dev)
         elif char_dev == "pty":
             prepare_channel_xml(xml_file, char_dev, id)
         result = virsh.attach_device(vm_name, xml_file)
     return result
开发者ID:Antique,项目名称:tp-libvirt,代码行数:30,代码来源:hotplug_serial.py

示例3: hotplug_device

 def hotplug_device(type, char_dev, id=0):
     tmp_file = "/tmp/%s" % char_dev
     if type == "qmp":
         char_add_opt = "chardev-add "
         dev_add_opt = "device_add virtserialport,chardev="
         if char_dev == "file":
             char_add_opt += "file,path=/tmp/file,id=file"
             dev_add_opt += "file,name=file,bus=virtio-serial0.0,id=file"
         elif char_dev == "socket":
             char_add_opt += "socket,path=/tmp/socket,server,nowait,id=socket"
             dev_add_opt += "socket,name=socket,bus=virtio-serial0.0,id=socket"
         elif char_dev == "pty":
             char_add_opt += ("pty,path=/dev/pts/%s,id=pty" % id)
             dev_add_opt += "pty,name=pty,bus=virtio-serial0.0,id=pty"
         result = virsh.qemu_monitor_command(vm_name, char_add_opt, "--hmp")
         if result.exit_status:
             raise error.TestError('Failed to add chardev %s to %s. Result:\n %s'
                                   % (char_dev, vm_name, result))
         result = virsh.qemu_monitor_command(vm_name, dev_add_opt, "--hmp")
         if result.exit_status:
             raise error.TestError('Failed to add device %s to %s. Result:\n %s'
                                   % (char_dev, vm_name, result))
     elif type == "attach":
         if char_dev in ["file", "socket"]:
             xml_info = create_channel_xml(vm_name, char_dev)
         elif char_dev == "pty":
             xml_info = create_channel_xml(vm_name, char_dev, id)
         f = open(xml_file, "w")
         f.write(xml_info)
         f.close()
         if os.path.exists(tmp_file):
             os.chmod(tmp_file, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
         result = virsh.attach_device(vm_name, xml_file)
     return result
开发者ID:zcyes,项目名称:tp-libvirt,代码行数:34,代码来源:hotplug_serial.py

示例4: dup_hotplug

 def dup_hotplug(type, char_dev, id, dup_charid=False, dup_devid=False, diff_devid=False):
     tmp_file = os.path.join(tmp_dir, char_dev)
     if type == "qmp":
         char_add_opt = "chardev-add "
         dev_add_opt = "device_add virtserialport,chardev="
         if char_dev == "file":
             if dup_charid:
                 char_add_opt += "file,path=%s,id=file" % tmp_file
             if dup_devid:
                 dev_add_opt += "file,name=file,bus=virtio-serial0.0,id=file"
             if diff_devid:
                 dev_add_opt += "file,name=file,bus=virtio-serial0.0,id=file1"
         elif char_dev == "socket":
             if dup_charid:
                 char_add_opt += "socket,path=%s,server,nowait,id=socket" % tmp_file
             if dup_devid:
                 dev_add_opt += "socket,name=socket,bus=virtio-serial0.0,id=socket"
             if diff_devid:
                 dev_add_opt += "socket,name=socket,bus=virtio-serial0.0,id=socket1"
         elif char_dev == "pty":
             if dup_charid:
                 char_add_opt += "pty,path=/dev/pts/%s,id=pty" % id
             if dup_devid:
                 dev_add_opt += "pty,name=pty,bus=virtio-serial0.0,id=pty"
             if diff_devid:
                 dev_add_opt += "pty,name=pty,bus=virtio-serial0.0,id=pty1"
         if dup_charid:
             result = virsh.qemu_monitor_command(vm_name, char_add_opt, "--hmp")
         if dup_devid or diff_devid:
             result = virsh.qemu_monitor_command(vm_name, dev_add_opt, "--hmp")
     elif type == "attach":
         if dup_devid:
             result = hotplug_device(type, char_dev, id)
     return result
开发者ID:Hao-Liu,项目名称:tp-libvirt,代码行数:34,代码来源:hotplug_serial.py

示例5: hotplug_device

 def hotplug_device(type, char_dev, id=0):
     tmp_file = os.path.join(tmp_dir, char_dev)
     if type == "qmp":
         char_add_opt = "chardev-add "
         dev_add_opt = "device_add virtserialport,chardev="
         if char_dev == "file":
             char_add_opt += "file,path=%s,id=file" % tmp_file
             dev_add_opt += "file,name=file,bus=virtio-serial0.0,id=file"
         elif char_dev == "socket":
             char_add_opt += "socket,path=%s,server,nowait,id=socket" % tmp_file
             dev_add_opt += "socket,name=socket,bus=virtio-serial0.0,id=socket"
         elif char_dev == "pty":
             char_add_opt += "pty,path=/dev/pts/%s,id=pty" % id
             dev_add_opt += "pty,name=pty,bus=virtio-serial0.0,id=pty"
         result = virsh.qemu_monitor_command(vm_name, char_add_opt, "--hmp")
         if result.exit_status:
             raise error.TestError("Failed to add chardev %s to %s. Result:\n %s" % (char_dev, vm_name, result))
         result = virsh.qemu_monitor_command(vm_name, dev_add_opt, "--hmp")
         if result.exit_status:
             raise error.TestError("Failed to add device %s to %s. Result:\n %s" % (char_dev, vm_name, result))
     elif type == "attach":
         xml_file = os.path.join(tmp_dir, "xml_%s" % char_dev)
         if char_dev in ["file", "socket"]:
             prepare_channel_xml(xml_file, char_dev)
         elif char_dev == "pty":
             prepare_channel_xml(xml_file, char_dev, id)
         result = virsh.attach_device(vm_name, xml_file)
         # serial device was introduced by the following commit,
         # http://libvirt.org/git/?
         # p=libvirt.git;a=commit;h=b63ea467617e3cbee4282ab2e5e780b4119cef3d
         if "unknown device type" in result.stderr:
             raise error.TestNAError("Failed to attach %s to %s. Result:\n %s" % (char_dev, vm_name, result))
     return result
开发者ID:chloerh,项目名称:tp-libvirt,代码行数:33,代码来源:hotplug_serial.py

示例6: unhotplug_serial_device

 def unhotplug_serial_device(hotplug_type, char_dev, index=1):
     if hotplug_type == "qmp":
         del_dev_opt = "device_del %s%s" % (char_dev, index)
         del_char_opt = "chardev-remove %s%s" % (char_dev, index)
         virsh.qemu_monitor_command(vm_name, del_dev_opt, "--hmp")
         virsh.qemu_monitor_command(vm_name, del_char_opt, "--hmp")
     elif hotplug_type == "attach":
         xml_file = "%s/xml_%s%s" % (tmp_dir, char_dev, index)
         virsh.detach_device(vm_name, xml_file, flagstr="--live")
开发者ID:will-Do,项目名称:tp-libvirt_v2v,代码行数:9,代码来源:libvirt_bench_serial_hotplug.py

示例7: unhotplug_serial_device

 def unhotplug_serial_device(type, char_dev):
     if type == "qmp":
         del_dev_opt = "device_del %s" % char_dev
         del_char_opt = "chardev-remove %s" % char_dev
         result = virsh.qemu_monitor_command(vm_name, del_dev_opt, "--hmp")
         if result.exit_status:
             raise error.TestError('Failed to del device %s from %s.Result:\n%s'
                                   % (char_dev, vm_name, result))
         result = virsh.qemu_monitor_command(vm_name, del_char_opt, "--hmp")
     elif type == "attach":
         result = virsh.detach_device(vm_name, xml_file)
开发者ID:zcyes,项目名称:tp-libvirt,代码行数:11,代码来源:hotplug_serial.py

示例8: confirm_hotplug_result

 def confirm_hotplug_result(char_dev, id=0):
     tmp_file = os.path.join(tmp_dir, char_dev)
     serial_file = os.path.join("/dev/virtio-ports", char_dev)
     result = virsh.qemu_monitor_command(vm_name, "info qtree", "--hmp")
     h_o = result.stdout.strip()
     if not h_o.count('name = "%s"' % char_dev):
         raise error.TestFail("Cann't find device(%s) from:\n%s" % (char_dev, h_o))
     if char_dev == "file":
         session.cmd("echo test > %s" % serial_file)
         f = open(tmp_file, "r")
         r_o = f.read()
         f.close()
     elif char_dev == "socket":
         session.cmd("echo test > /tmp/file")
         sock = socket.socket(socket.AF_UNIX)
         sock.connect(tmp_file)
         session.cmd("dd if=/tmp/file of=%s" % serial_file)
         r_o = sock.recv(1024)
     elif char_dev == "pty":
         session.cmd("echo test > /tmp/file")
         session.cmd("dd if=/tmp/file of=%s &" % serial_file)
         dev_file = "/dev/pts/%s" % id
         if not os.path.exists(dev_file):
             raise error.TestFail("%s doesn't exist." % dev_file)
         p = subprocess.Popen(["/usr/bin/cat", dev_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         session.cmd("echo test >> /tmp/file &")
         while True:
             r_o = p.stdout.readline()
             if r_o or p.poll():
                 break
             time.sleep(0.2)
         p.kill()
     if not r_o.count("test"):
         err_info = "%s device file doesn't match 'test':%s" % (char_dev, r_o)
         raise error.TestFail(err_info)
开发者ID:chloerh,项目名称:tp-libvirt,代码行数:35,代码来源:hotplug_serial.py

示例9: hotplug_supported

def hotplug_supported(vm_name, mtype):
    """
    hotplug support check for ppc64le

    :param vm_name: VM name
    :param mtype: machine type

    :return: True if supported and False in all other cases
    """
    supported = False
    if "ppc64" in platform.machine():
        cmd = '{\"execute\":\"query-machines\"}'
        json_result = virsh.qemu_monitor_command(vm_name, cmd, "--pretty",
                                                 debug=False)
        try:
            result = json.loads(results_stdout_52lts(json_result))
        except Exception:
            # Failure to parse json output and default support to False
            # TODO: Handle for failure cases
            return supported
        for item in result['return']:
            try:
                if item['name'] == mtype:
                    try:
                        if item['hotpluggable-cpus'] == 'True':
                            supported = True
                    except KeyError:
                        pass
            except KeyError:
                pass
    else:
        # For now returning for other arch by default true
        supported = True
    return supported
开发者ID:ldoktor,项目名称:avocado-vt,代码行数:34,代码来源:utils_hotplug.py

示例10: confirm_unhotplug_result

 def confirm_unhotplug_result(char_dev):
     serial_file = os.path.join("/dev/virtio-ports", char_dev)
     result = virsh.qemu_monitor_command(vm_name, "info qtree", "--hmp")
     uh_o = result.stdout.strip()
     if uh_o.count('chardev = "%s"' % char_dev):
         raise error.TestFail("Still can get serial device(%s) from: '%s'" % (char_dev, uh_o))
     if os.path.exists(serial_file):
         raise error.TestFail("File '%s' still exists after unhotplug" % serial_file)
开发者ID:chloerh,项目名称:tp-libvirt,代码行数:8,代码来源:hotplug_serial.py

示例11: confirm_unhotplug_result

 def confirm_unhotplug_result(char_dev, index=1):
     serial_file = "/dev/virtio-ports/%s%s" % (char_dev, index)
     result = virsh.qemu_monitor_command(vm_name, "info qtree", "--hmp")
     uh_o = result.stdout.strip()
     if uh_o.count("chardev = %s%s" % (char_dev, index)):
         raise error.TestFail("Still can get serial device info: '%s'" % uh_o)
     if not session.cmd_status("test -e %s" % serial_file):
         raise error.TestFail("File '%s' still exists after unhotplug" % serial_file)
开发者ID:will-Do,项目名称:tp-libvirt_v2v,代码行数:8,代码来源:libvirt_bench_serial_hotplug.py

示例12: run_job_acquire

def run_job_acquire(params, libvirtd, vm):
    """
    Save domain after queried block info
    """
    vm.start()
    res = virsh.qemu_monitor_command(vm.name, 'info block', '--hmp')
    logging.debug(res)
    save_path = os.path.join(data_dir.get_tmp_dir(), 'tmp.save')
    virsh.save(vm.name, save_path)
    vm.wait_for_shutdown()
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:10,代码来源:crash_regression.py

示例13: check_dom_iothread

 def check_dom_iothread():
     """
     Check iothread by qemu-monitor-command.
     """
     ret = virsh.qemu_monitor_command(vm_name,
                                      '{"execute": "query-iothreads"}',
                                      "--pretty")
     libvirt.check_exit_status(ret)
     logging.debug("Domain iothreads: %s", ret.stdout)
     iothreads_ret = json.loads(ret.stdout)
     if len(iothreads_ret['return']) != int(dom_iothreads):
         raise error.TestFail("Failed to check domain iothreads")
开发者ID:nertpinx,项目名称:tp-libvirt,代码行数:12,代码来源:virtual_disks_multidisks.py

示例14: confirm_hotplug_result

    def confirm_hotplug_result(char_dev, index=1, id=0):
        result = virsh.qemu_monitor_command(vm_name, "info qtree", "--hmp")
        h_o = result.stdout.strip()
        chardev_c = h_o.count("chardev = %s%s" % (char_dev, index))
        name_c = h_o.count("name = \"%s%s\"" % (char_dev, index))
        if chardev_c == 0 and name_c == 0:
            raise error.TestFail("Cannot get serial device info: '%s'" % h_o)

        tmp_file = "%s/%s%s" % (tmp_dir, char_dev, index)
        serial_file = "/dev/virtio-ports/%s%s" % (char_dev, index)
        if char_dev == "file":
            session.cmd("echo test > %s" % serial_file)
            f = open(tmp_file, "r")
            output = f.read()
            f.close()
        elif char_dev == "socket":
            session.cmd("echo test > /tmp/file")
            sock = socket.socket(socket.AF_UNIX)
            sock.connect(tmp_file)
            session.cmd("dd if=/tmp/file of=%s" % serial_file)
            output = sock.recv(1024)
            sock.close()
        elif char_dev == "pty":
            session.cmd("echo test > /tmp/file")
            session.cmd("dd if=/tmp/file of=%s &" % serial_file)
            dev_file = "/dev/pts/%s" % id
            if not os.path.exists(dev_file):
                raise error.TestFail("%s doesn't exist." % dev_file)
            p = subprocess.Popen(["/usr/bin/cat", dev_file],
                                 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            while True:
                output = p.stdout.readline()
                if output or p.poll():
                    break
                time.sleep(0.2)
            p.kill()
        if not output.count("test"):
            err_info = "%s device file doesn't match 'test':%s" % (char_dev, output)
            raise error.TestFail(err_info)
开发者ID:will-Do,项目名称:tp-libvirt_v2v,代码行数:39,代码来源:libvirt_bench_serial_hotplug.py

示例15: run

def run(test, params, env):
    """
    1. Configure kernel cmdline to support kdump
    2. Start kdump service
    3. Inject NMI to the guest
    4. Check NMI times
    """
    for cmd in 'inject-nmi', 'qemu-monitor-command':
        if not virsh.has_help_command(cmd):
            raise error.TestNAError("This version of libvirt does not "
                                    " support the %s test", cmd)

    vm_name = params.get("main_vm", "virt-tests-vm1")
    vm = env.get_vm(vm_name)
    start_vm = params.get("start_vm")
    expected_nmi_times = params.get("expected_nmi_times", '0')
    unprivileged_user = params.get('unprivileged_user')
    if unprivileged_user:
        if unprivileged_user.count('EXAMPLE'):
            unprivileged_user = 'testacl'

    if not libvirt_version.version_compare(1, 1, 1):
        if params.get('setup_libvirt_polkit') == 'yes':
            raise error.TestNAError("API acl test not supported in current"
                                    " libvirt version.")

    if start_vm == "yes":
        # start kdump service in the guest
        cmd = "which kdump"
        try:
            run_cmd_in_guest(vm, cmd)
        except:
            try:
                # try to install kexec-tools on fedoraX/rhelx.y guest
                run_cmd_in_guest(vm, "yum install -y kexec-tools")
            except:
                raise error.TestNAError("Requires kexec-tools(or the "
                                        "equivalent for your distro)")

        # enable kdump service in the guest
        cmd = "service kdump start"
        run_cmd_in_guest(vm, cmd)

        # filter original 'NMI' information from the /proc/interrupts
        cmd = "grep NMI /proc/interrupts"
        nmi_str = run_cmd_in_guest(vm, cmd)

        # filter CPU from the /proc/cpuinfo and count number
        cmd = "grep -E '^process' /proc/cpuinfo | wc -l"
        vcpu_num = run_cmd_in_guest(vm, cmd).strip()

        logging.info("Inject NMI to the guest via virsh inject_nmi")
        virsh.inject_nmi(vm_name, debug=True, ignore_status=False)

        logging.info("Inject NMI to the guest via virsh qemu_monitor_command")
        virsh.qemu_monitor_command(vm_name, '{"execute":"inject-nmi"}')

        # injects a Non-Maskable Interrupt into the default CPU (x86/s390)
        # or all CPUs (ppc64), as usual, the default CPU index is 0
        cmd = "grep NMI /proc/interrupts | awk '{print $2}'"
        nmi_from_default_vcpu = run_cmd_in_guest(vm, cmd)
        real_nmi_times = nmi_from_default_vcpu.splitlines()[0]
        logging.debug("The current Non-Maskable Interrupts: %s", real_nmi_times)

        # check Non-maskable interrupts times
        if real_nmi_times != expected_nmi_times:
            raise error.TestFail("NMI times aren't expected %s:%s",
                                 real_nmi_times, expected_nmi_times)
开发者ID:Antique,项目名称:tp-libvirt,代码行数:68,代码来源:nmi_test.py


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