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

Python virsh.attach_device函数代码示例

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

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



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

def test_win_fibre_group(vm, params):
    """
    Try to attach device in iommu group to vm.

    1.Get original available disks before attaching.
    2.Attaching hostdev in iommu group to vm.
    3.Start vm and check it.
    4.Check added disk in vm.
    """
    pci_id = params.get("fibre_pci_id", "FIBRE:PCI.EXAMPLE")
    device_type = "Fibre"
    if pci_id.count("EXAMPLE"):
        raise error.TestNAError("Invalid pci device id.")

    # Login vm to get disks before attaching pci device.
    if vm.is_dead():
        vm.start()
    before_disks = get_windows_disks(vm)
    logging.debug("Disks before:%s",
                  before_disks)
    vm.destroy()

    xmlfile = utlv.create_hostdev_xml(pci_id)
    prepare_devices(pci_id, device_type)
    try:
        virsh.attach_device(domain_opt=vm.name, file_opt=xmlfile,
                            flagstr="--config", debug=True,
                            ignore_status=False)
        vm.start()
    except (error.CmdError, virt_vm.VMStartError), detail:
        cleanup_devices(pci_id, device_type)
        raise error.TestFail("New device does not work well: %s" % detail)
开发者ID:Chenditang,项目名称:tp-libvirt,代码行数:32,代码来源:vfio.py


示例3: test_nic_fibre_group

def test_nic_fibre_group(vm, params):
    """
    Try to attach nic and fibre device at same time in iommu group to vm.

    1.Get original available interfaces&disks before attaching.
    2.Attaching hostdev in iommu group to vm.
    3.Start vm and check it.
    4.Check added interface&disk in vm.
    """
    nic_pci_id = params.get("nic_pci_id", "ETH:PCI.EXAMPLE")
    fibre_pci_id = params.get("fibre_pci_id", "FIBRE:PCI.EXAMPLE")
    if nic_pci_id.count("EXAMPLE"):
        raise error.TestNAError("Invalid Ethernet pci device id.")
    if fibre_pci_id.count("EXAMPLE"):
        raise error.TestNAError("Invalid Fibre pci device id.")
    disk_check = "yes" == params.get("fibre_pci_disk_check", "no")

    nic_ip = params.get("nic_pci_ip")
    nic_mask = params.get("nic_pci_mask", "255.255.0.0")
    nic_gateway = params.get("nic_pci_gateway")

    # Login vm to get interfaces before attaching pci device.
    if vm.is_dead():
        vm.start()
    before_pci_nics = vm.get_pci_devices("Ethernet")
    before_interfaces = vm.get_interfaces()
    before_pci_fibres = vm.get_pci_devices("Fibre")
    before_disks = vm.get_disks()
    logging.debug("Ethernet PCI devices before:%s",
                  before_pci_nics)
    logging.debug("Ethernet interfaces before:%s",
                  before_interfaces)
    logging.debug("Fibre PCI devices before:%s",
                  before_pci_fibres)
    logging.debug("Disks before:%s",
                  before_disks)
    vm.destroy()

    prepare_devices(nic_pci_id, "Ethernet")
    prepare_devices(fibre_pci_id, "Fibre")
    try:
        nicxmlfile = utlv.create_hostdev_xml(nic_pci_id)
        virsh.attach_device(domain_opt=vm.name, file_opt=nicxmlfile,
                            flagstr="--config", debug=True,
                            ignore_status=False)
        fibrexmlfile = utlv.create_hostdev_xml(fibre_pci_id)
        virsh.attach_device(domain_opt=vm.name, file_opt=fibrexmlfile,
                            flagstr="--config", debug=True,
                            ignore_status=False)
        vm.start()
    except (error.CmdError, virt_vm.VMStartError), detail:
        cleanup_devices(nic_pci_id, "Ethernet")
        cleanup_devices(fibre_pci_id, "Fibre")
        raise error.TestFail("New device does not work well: %s" % detail)
开发者ID:Chenditang,项目名称:tp-libvirt,代码行数:54,代码来源:vfio.py


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


示例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)
     return result
开发者ID:Antique,项目名称:tp-libvirt,代码行数:30,代码来源:hotplug_serial.py


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


示例7: attach_additional_device

def attach_additional_device(vm_name, disksize, targetdev, params):
    """
    Create a disk with disksize, then attach it to given vm.

    @param vm: Libvirt VM name.
    @param disksize: size of attached disk
    @param targetdev: target of disk device
    """
    logging.info("Attaching disk...")
    disk_path = os.path.join(data_dir.get_tmp_dir(), targetdev)
    cmd = "qemu-img create %s %s" % (disk_path, disksize)
    status, output = commands.getstatusoutput(cmd)
    if status:
        return (False, output)

    # Update params for source file
    params['source_file'] = disk_path
    params['target_dev'] = targetdev

    # Create a file of device
    xmlfile = create_disk_xml(params)

    # To confirm attached device do not exist.
    virsh.detach_disk(vm_name, targetdev, extra="--config")

    return virsh.attach_device(domain_opt=vm_name, file_opt=xmlfile,
                               flagstr="--config", debug=True)
开发者ID:CongLi,项目名称:tp-libvirt,代码行数:27,代码来源:multifunction.py


示例8: guest_config

    def guest_config(vm, ip_addr):
        """
        Add a new nic to guest and set a static ip address

        :param vm: Configured guest
        :param ip_addr: Set ip address
        """
        # Attach an interface device
        # Use attach-device, not attach-interface, because attach-interface
        # doesn't support 'direct'
        interface_class = vm_xml.VMXML.get_device_class('interface')
        interface = interface_class(type_name="direct")
        interface.source = dict(dev=str(eth_card_no), mode=str(iface_mode))
        interface.model = "virtio"
        interface.xmltreefile.write()
        if vm.is_alive():
            vm.destroy(gracefully=False)
        virsh.attach_device(vm.name, interface.xml, flagstr="--config")
        os.remove(interface.xml)
        vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm.name)
        new_nic = vmxml.get_devices(device_type="interface")[-1]

        # Modify new interface's IP
        vm.start()
        session = vm.wait_for_login()
        eth_name = utils_net.get_linux_ifname(session, new_nic.mac_address)
        eth_config_detail_list = ['DEVICE=%s' % eth_name,
                                  'HWADDR=%s' % new_nic.mac_address,
                                  'ONBOOT=yes',
                                  'BOOTPROTO=static',
                                  'IPADDR=%s' % ip_addr]
        remote_file = remote.RemoteFile(vm.get_address(), 'scp', 'root',
                                        params.get('password'), 22,
                                        eth_config_file)
        remote_file.truncate()
        remote_file.add(eth_config_detail_list, linesep='\n')
        try:
            # Attached interface maybe already active
            session.cmd("ifdown %s" % eth_name)
        except aexpect.ShellCmdError:
            raise error.TestFail("ifdown %s failed." % eth_name)

        try:
            session.cmd("ifup %s" % eth_name)
        except aexpect.ShellCmdError:
            raise error.TestFail("ifup %s failed." % eth_name)
        return session
开发者ID:noxdafox,项目名称:tp-libvirt,代码行数:47,代码来源:macvtap.py


示例9: test_win_fibre_group

def test_win_fibre_group(test, vm, params):
    """
    Try to attach device in iommu group to vm.

    1.Get original available disks before attaching.
    2.Attaching hostdev in iommu group to vm.
    3.Start vm and check it.
    4.Check added disk in vm.
    """
    pci_id = params.get("fibre_pci_id", "FIBRE:PCI.EXAMPLE")
    device_type = "Fibre"
    if pci_id.count("EXAMPLE"):
        test.cancel("Invalid pci device id.")

    # Login vm to get disks before attaching pci device.
    if vm.is_dead():
        vm.start()
    before_disks = get_windows_disks(vm)
    logging.debug("Disks before:%s",
                  before_disks)
    vm.destroy()

    xmlfile = utlv.create_hostdev_xml(pci_id)
    prepare_devices(test, pci_id, device_type)
    try:
        virsh.attach_device(domain_opt=vm.name, file_opt=xmlfile,
                            flagstr="--config", debug=True,
                            ignore_status=False)
        vm.start()
    except (process.CmdError, virt_vm.VMStartError) as detail:
        cleanup_devices(pci_id, device_type)
        test.fail("New device does not work well: %s" % detail)

    # Get devices in vm again after attaching
    after_disks = get_windows_disks(vm)
    logging.debug("Disks after:%s",
                  after_disks)
    new_disk = "".join(list(set(before_disks) ^ set(after_disks)))
    try:
        if not new_disk:
            test.fail("Cannot find attached host device in vm.")
        # TODO: Support to configure windows partition
    finally:
        if vm.is_alive():
            vm.destroy()
        cleanup_devices(pci_id, device_type)
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:46,代码来源:vfio.py


示例10: test_nic_single

def test_nic_single(vm, params):
    """
    Try to attach device in iommu group to vm with adding only this
    device to iommu group.

    1.Get original available interfaces before attaching.
    2.Attaching hostdev in iommu group to vm.
    3.Start vm and check it.
    4.Check added interface in vm.
    """
    pci_id = params.get("nic_pci_id", "ETH:PCI.EXAMPLE")
    if pci_id.count("EXAMPLE"):
        raise error.TestNAError("Invalid pci device id.")

    device_type = "Ethernet"
    nic_ip = params.get("nic_pci_ip")
    nic_mask = params.get("nic_pci_mask", "255.255.0.0")
    nic_gateway = params.get("nic_pci_gateway")

    # Login vm to get interfaces before attaching pci device.
    if vm.is_dead():
        vm.start()
    before_pci_nics = vm.get_pci_devices("Ethernet")
    before_interfaces = vm.get_interfaces()
    logging.debug("Ethernet PCI devices before:%s",
                  before_pci_nics)
    logging.debug("Ethernet interfaces before:%s",
                  before_interfaces)
    vm.destroy()

    xmlfile = utlv.create_hostdev_xml(pci_id)

    # Add only this device to corresponding iommu group
    prepare_devices(pci_id, device_type, only=True)
    try:
        virsh.attach_device(domain_opt=vm.name, file_opt=xmlfile,
                            flagstr="--config", debug=True,
                            ignore_status=False)
        vm.start()
        # Start successfully, but not expected.
        vm.destroy(gracefully=False)
        cleanup_devices(pci_id, device_type)
        raise error.TestFail("Start vm succesfully after attaching single "
                             "device to iommu group.Not expected.")
    except (error.CmdError, virt_vm.VMStartError), detail:
        logging.debug("Expected:New device does not work well: %s" % detail)
开发者ID:Antique,项目名称:tp-libvirt,代码行数:46,代码来源:vfio.py


示例11: attach_channel_xml

    def attach_channel_xml():
        """
        Create channel xml and attach it to guest configuration
        """
        # Check if pty channel exists already
        for elem in new_xml.devices.by_device_tag('channel'):
            if elem.type_name == channel_type_name:
                logging.debug("{0} channel already exists in guest. "
                              "No need to add new one".format(channel_type_name))
                return

        params = {'channel_type_name': channel_type_name,
                  'target_type': target_type,
                  'target_name': target_name}
        channel_xml = libvirt.create_channel_xml(params)
        virsh.attach_device(domain_opt=vm_name, file_opt=channel_xml.xml,
                            flagstr="--config", ignore_status=False)
        logging.debug("New VMXML with channel:\n%s", virsh.dumpxml(vm_name))
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:18,代码来源:migrate_options_shared.py


示例12: test_nic_group

def test_nic_group(vm, params):
    """
    Try to attach device in iommu group to vm.

    1.Get original available interfaces before attaching.
    2.Attaching hostdev in iommu group to vm.
    3.Start vm and check it.
    4.Check added interface in vm.
    """
    pci_id = params.get("nic_pci_id", "ETH:PCI.EXAMPLE")
    if pci_id.count("EXAMPLE"):
        raise error.TestNAError("Invalid pci device id.")

    device_type = "Ethernet"
    nic_ip = params.get("nic_pci_ip")
    nic_mask = params.get("nic_pci_mask", "255.255.0.0")
    nic_gateway = params.get("nic_pci_gateway")

    # Login vm to get interfaces before attaching pci device.
    if vm.is_dead():
        vm.start()
    before_pci_nics = vm.get_pci_devices("Ethernet")
    before_interfaces = vm.get_interfaces()
    logging.debug("Ethernet PCI devices before:%s",
                  before_pci_nics)
    logging.debug("Ethernet interfaces before:%s",
                  before_interfaces)
    vm.destroy()

    boot_order = int(params.get("boot_order", 0))
    prepare_devices(pci_id, device_type)
    try:
        if boot_order:
            utlv.alter_boot_order(vm.name, pci_id, boot_order)
        else:
            xmlfile = utlv.create_hostdev_xml(pci_id)
            virsh.attach_device(domain_opt=vm.name, file_opt=xmlfile,
                                flagstr="--config", debug=True,
                                ignore_status=False)
        logging.debug("VMXML with disk boot:\n%s", virsh.dumpxml(vm.name))
        vm.start()
    except (error.CmdError, virt_vm.VMStartError), detail:
        cleanup_devices(pci_id, device_type)
        raise error.TestFail("New device does not work well: %s" % detail)
开发者ID:Chenditang,项目名称:tp-libvirt,代码行数:44,代码来源:vfio.py


示例13: test_fibre_group

def test_fibre_group(vm, params):
    """
    Try to attach device in iommu group to vm.

    1.Get original available disks before attaching.
    2.Attaching hostdev in iommu group to vm.
    3.Start vm and check it.
    4.Check added disk in vm.
    """
    pci_id = params.get("fibre_pci_id", "FIBRE:PCI.EXAMPLE")
    device_type = "Fibre"
    if pci_id.count("EXAMPLE"):
        raise error.TestNAError("Invalid pci device id.")
    disk_check = "yes" == params.get("fibre_pci_disk_check", "no")

    # Login vm to get disks before attaching pci device.
    if vm.is_dead():
        vm.start()
    before_pci_fibres = vm.get_pci_devices("Fibre")
    before_disks = vm.get_disks()
    logging.debug("Fibre PCI devices before:%s",
                  before_pci_fibres)
    logging.debug("Disks before:%s",
                  before_disks)
    vm.destroy()

    boot_order = int(params.get("boot_order", 0))
    prepare_devices(pci_id, device_type)
    try:
        if boot_order:
            utlv.alter_boot_order(vm.name, pci_id, boot_order)
        else:
            xmlfile = utlv.create_hostdev_xml(pci_id)
            virsh.attach_device(domain_opt=vm.name, file_opt=xmlfile,
                                flagstr="--config", debug=True,
                                ignore_status=False)
        logging.debug("VMXML with disk boot:\n%s", virsh.dumpxml(vm.name))
        vm.start()
    except (process.CmdError, virt_vm.VMStartError), detail:
        cleanup_devices(pci_id, device_type)
        raise error.TestFail("New device does not work well: %s" % detail)
开发者ID:bssrikanth,项目名称:tp-libvirt,代码行数:41,代码来源:vfio.py


示例14: device_hotplug

 def device_hotplug():
     if not libvirt_version.version_compare(3, 10, 0):
         detach_device(pci_devs, pci_ids)
     # attach the device in hotplug mode
     result = virsh.attach_device(vm_name, dev.xml,
                                  flagstr="--live", debug=True)
     if result.exit_status:
         test.error(result.stdout.strip())
     else:
         logging.debug(result.stdout.strip())
     if not utils_misc.wait_for(check_attach_pci, timeout):
         test.fail("timeout value is not sufficient")
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:12,代码来源:libvirt_pci_passthrough_hotplug.py


示例15: add_device

 def add_device(dev_xml, at_error=False):
     """
     Add memory device by attachment or modify domain xml.
     """
     if attach_device:
         ret = virsh.attach_device(vm_name, dev_xml.xml, flagstr=attach_option)
         libvirt.check_exit_status(ret, at_error)
     else:
         vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm.name)
         if numa_cells:
             del vmxml.max_mem
             del vmxml.current_mem
         vmxml.add_device(dev_xml)
         vmxml.sync()
开发者ID:uni-peter-zheng,项目名称:tp-libvirt,代码行数:14,代码来源:libvirt_mem.py


示例16: attach_interface

    def attach_interface():
        """
            Attach interface:

            1.Attach interface from xml;
            2.Check the vf driver after attach interface;
            3.Check the live xml after attach interface;
        """
        if managed == "no":
            result = virsh.nodedev_detach(nodedev_pci_addr)
            utils_test.libvirt.check_exit_status(result, expect_error=False)
        logging.debug("attach interface xml:\n %s", new_iface)
        result = virsh.attach_device(vm_name, file_opt=new_iface.xml, flagstr=option, debug=True)
        utils_test.libvirt.check_exit_status(result, expect_error=False)
        if option == "--config":
            result = virsh.start(vm_name)
            utils_test.libvirt.check_exit_status(result, expect_error=False)
        # For option == "--persistent", after VM destroyed and then start, the device should still be there.
        if option == "--persistent":
            virsh.destroy(vm_name)
            result = virsh.start(vm_name, debug=True)
            utils_test.libvirt.check_exit_status(result, expect_error=False)
        live_xml = vm_xml.VMXML.new_from_dumpxml(vm_name)
        logging.debug(live_xml)
        get_ip_by_mac(mac_addr, timeout=60)
        device = live_xml.devices
        if vf_type == "vf" or vf_type == "vf_pool":
            for interface in device.by_device_tag("interface"):
                if interface.type_name == "hostdev":
                    if interface.driver.driver_attr['name'] != 'vfio':
                        test.fail("The driver of the hostdev interface is not vfio\n")
                    break
            vf_addr_attrs = interface.hostdev_address.attrs
            pci_addr = addr_to_pci(vf_addr_attrs)
            nic_driver = os.readlink(os.path.join(pci_device_dir, vf_addr, "driver")).split('/')[-1]
            if nic_driver != "vfio-pci":
                test.fail("The driver of the hostdev interface is not vfio\n")
        elif vf_type == "macvtap" or vf_type == "macvtap_network":
            for interface in device.by_device_tag("interface"):
                if interface.type_name == "direct":
                    if vf_type == "macvtap":
                        if interface.source["dev"] == new_iface.source["dev"]:
                            match = "yes"
                            vf_name = interface.source["dev"]
                    elif interface.source['dev'] in vf_name_list:
                        match = "yes"
                        vf_name = interface.source["dev"]
                if match != "yes":
                    test.fail("The dev name or mode of macvtap interface is wrong after attach\n")
        return interface
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:50,代码来源:sriov.py


示例17: guest_config

    def guest_config(vm, ip_addr):
        """
        Add a new nic to guest and set a static ip address

        :param vm: Configured guest
        :param ip_addr: Set ip address
        """
        # Attach an interface device
        # Use attach-device, not attach-interface, because attach-interface
        # doesn't support 'direct'
        interface_class = vm_xml.VMXML.get_device_class('interface')
        interface = interface_class(type_name="direct")
        interface.source = dict(dev=str(eth_card_no), mode=str(iface_mode))
        interface.model = "virtio"
        interface.xmltreefile.write()
        if vm.is_alive():
            vm.destroy(gracefully=False)
        virsh.attach_device(vm.name, interface.xml, flagstr="--config")
        os.remove(interface.xml)
        vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm.name)
        new_nic = vmxml.get_devices(device_type="interface")[-1]

        # Modify new interface's IP
        vm.start()
        session = vm.wait_for_login()
        eth_name = utils_net.get_linux_ifname(session, new_nic.mac_address)
        eth_config_detail = "DEVICE=%s\nHWADDR=%s\nONBOOT=yes\n"\
                            "BOOTPROTO=static\nIPADDR=%s"\
                            % (eth_name, new_nic.mac_address, ip_addr)
        add_cmd = "echo %s >> %s" % (eth_config_detail, eth_config_file)
        session.cmd(add_cmd)
        session.cmd("sync")
        try:
            session.cmd("ifup %s" % eth_name)
        except aexpect.ShellCmdError:
            pass
开发者ID:libvirt-qe,项目名称:tp-libvirt,代码行数:36,代码来源:macvtap.py


示例18: attach_additional_device

def attach_additional_device(vm_name, targetdev, disk_path, params):
    """
    Create a disk with disksize, then attach it to given vm.

    :param vm_name: Libvirt VM name.
    :param disk_path: path of attached disk
    :param targetdev: target of disk device
    :param params: dict include necessary configurations of device
    """
    logging.info("Attaching disk...")

    # Update params for source file
    params['source_file'] = disk_path
    params['target_dev'] = targetdev

    # Create a file of device
    xmlfile = create_disk_xml(params)

    # To confirm attached device do not exist.
    virsh.detach_disk(vm_name, targetdev, extra="--config")

    return virsh.attach_device(domain_opt=vm_name, file_opt=xmlfile,
                               flagstr="--config", debug=True)
开发者ID:giuseppe,项目名称:virt-test,代码行数:23,代码来源:libvirt.py


示例19: range

            for i in range(len(disks)):
                attach_option = ""
                if len(device_attach_option) > i:
                    attach_option = device_attach_option[i]
                ret = virsh.attach_disk(vm_name, disks[i]["source"],
                                        device_targets[i],
                                        attach_option)
                libvirt.check_exit_status(ret)

        elif hotplug:
            for i in range(len(disks_xml)):
                disks_xml[i].xmltreefile.write()
                attach_option = ""
                if len(device_attach_option) > i:
                    attach_option = device_attach_option[i]
                ret = virsh.attach_device(vm_name, disks_xml[i].xml,
                                          flagstr=attach_option)
                attach_error = False
                if len(device_attach_error) > i:
                    attach_error = "yes" == device_attach_error[i]
                libvirt.check_exit_status(ret, attach_error)

    except virt_vm.VMStartError:
        if status_error:
            pass
        else:
            raise error.TestFail('VM Failed to start for some reason!')
    except xcepts.LibvirtXMLError:
        if define_error:
            pass
        else:
            raise error.TestFail("Failed to define VM")
开发者ID:nertpinx,项目名称:tp-libvirt,代码行数:32,代码来源:virtual_disks_multidisks.py


示例20: run


#.........这里部分代码省略.........
        for driver_opt in driver_dict.keys():
            if (not cmd_opt.has_key(driver_opt) or
                    not cmd_opt[driver_opt] == driver_dict[driver_opt]):
                raise error.TestFail("Can't see option '%s=%s' in qemu-kvm "
                                     " command line" %
                                     (driver_opt, driver_dict[driver_opt]))
        if test_backend:
            guest_pid = ret.stdout.rsplit()[1]
            cmd = "lsof %s | grep %s" % (backend["tap"], guest_pid)
            if utils.system(cmd, ignore_status=True):
                raise error.TestFail("Guest process didn't open backend file"
                                     % backend["tap"])
            cmd = "lsof %s | grep %s" % (backend["vhost"], guest_pid)
            if utils.system(cmd, ignore_status=True):
                raise error.TestFail("Guest process didn't open backend file"
                                     % backend["tap"])

    def get_guest_ip(session, mac):
        """
        Wrapper function to get guest ip address
        """
        utils_net.restart_guest_network(session, mac)
        # Wait for IP address is ready
        utils_misc.wait_for(
            lambda: utils_net.get_guest_ip_addr(session, mac), 10)
        return utils_net.get_guest_ip_addr(session, mac)

    def check_user_network(session):
        """
        Check user network ip address on guest
        """
        vm_ips = []
        vm_ips.append(get_guest_ip(session, iface_mac_old))
        if attach_device:
            vm_ips.append(get_guest_ip(session, iface_mac))
        logging.debug("IP address on guest: %s", vm_ips)
        if len(vm_ips) != len(set(vm_ips)):
            raise error.TestFail("Duplicated IP address on guest. "
                                 "Check bug: https://bugzilla.redhat."
                                 "com/show_bug.cgi?id=1147238")

        for vm_ip in vm_ips:
            if vm_ip is None or not vm_ip.startswith("10.0.2."):
                raise error.TestFail("Found wrong IP address"
                                     " on guest")
        # Check gateway address
        gateway = utils_net.get_net_gateway(session.cmd_output)
        if gateway != "10.0.2.2":
            raise error.TestFail("The gateway on guest is not"
                                 " right")
        # Check dns server address
        ns_list = utils_net.get_net_nameserver(session.cmd_output)
        if "10.0.2.3" not in ns_list:
            raise error.TestFail("The dns server can't be found"
                                 " on guest")

    def check_mcast_network(session):
        """
        Check multicast ip address on guests
        """
        src_addr = ast.literal_eval(iface_source)['address']
        add_session = additional_vm.wait_for_serial_login()
        vms_sess_dict = {vm_name: session,
                         additional_vm.name: add_session}

        # Check mcast address on host
开发者ID:nertpinx,项目名称:tp-libvirt,代码行数:67,代码来源:iface_options.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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