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


Python utils_net.get_linux_ifname函数代码示例

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


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

示例1: get_ip_by_mac

    def get_ip_by_mac(mac_addr, timeout=120):
        """
        Get interface IP address by given MAC address.
        """
        if vm.serial_console is not None:
            vm.cleanup_serial_console()
        vm.create_serial_console()
        session = vm.wait_for_serial_login(timeout=240)

        def get_ip():
            return utils_net.get_guest_ip_addr(session, mac_addr)

        try:
            ip_addr = ""
            iface_name = utils_net.get_linux_ifname(session, mac_addr)
            if iface_name is None:
                test.fail("no interface with MAC address %s found" % mac_addr)
            session.cmd("pkill -9 dhclient", ignore_all_errors=True)
            session.cmd("dhclient %s " % iface_name, ignore_all_errors=True)
            ip_addr = utils_misc.wait_for(get_ip, 20)
            logging.debug("The ip addr is %s", ip_addr)
        except Exception:
            logging.warning("Find %s with MAC address %s but no ip for it" % (iface_name, mac_addr))
        finally:
            session.close()
        return ip_addr
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:26,代码来源:sriov.py

示例2: run_enable_mq

def run_enable_mq(test, params, env):
    """
    Enable MULTI_QUEUE feature in guest

    1) Boot up VM(s)
    2) Login guests one by one
    3) Enable MQ for all virtio nics by ethtool -L

    :param test: QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env: Dictionary with test environment.
    """

    login_timeout = int(params.get("login_timeout", 360))
    queues = int(params.get("queues", 1))
    vms = params.get("vms").split()
    if queues == 1:
        logging.info("No need to enable MQ feature for single queue")
        return

    for vm in vms:
        vm = env.get_vm(vm)
        vm.verify_alive()
        session = vm.wait_for_login(timeout=login_timeout)
        for i, nic in enumerate(vm.virtnet):
            if "virtio" in nic["nic_model"]:
                ifname = utils_net.get_linux_ifname(session, vm.get_mac_address(0))
                session.cmd_output("ethtool -L %s combined %d" % (ifname, queues))
                o = session.cmd_output("ethtool -l %s" % ifname)
                if len(re.findall("Combined:\s+%d\s" % queues, o)) != 2:
                    raise error.TestError("Fail to enable MQ feature of (%s)" % nic.nic_name)

                logging.info("MQ feature of (%s) is enabled" % nic.nic_name)

        session.close()
开发者ID:nloopa,项目名称:virt-test,代码行数:35,代码来源:enable_mq.py

示例3: get_ip_by_mac

    def get_ip_by_mac(mac_addr, try_dhclint=False):
        """
        Get interface IP address by given MAC addrss. If try_dhclint is
        True, then try to allocate IP addrss for the interface.
        """
        session = vm.wait_for_login()

        def f():
            return utils_net.get_guest_ip_addr(session, mac_addr)

        try:
            ip_addr = utils_misc.wait_for(f, 10)
            if ip_addr is None:
                iface_name = utils_net.get_linux_ifname(session, mac_addr)
                if try_dhclint:
                    session.cmd("dhclient %s" % iface_name)
                    ip_addr = utils_misc.wait_for(f, 10)
                else:
                    # No IP for the interface, just print the interface name
                    logging.warn("Find '%s' with MAC address '%s', "
                                 "but which has no IP address", iface_name,
                                 mac_addr)
        finally:
            session.close()
        return ip_addr
开发者ID:Hao-Liu,项目名称:tp-libvirt,代码行数:25,代码来源:virsh_net_dhcp_leases.py

示例4: chk_mq_enabled

    def chk_mq_enabled(vm, queues):
        """
        Check whether MQ value set in qemu cmd line fits the value in guest

        :param vm: guest vm
        :param queues: queues value in qemu cmd line
        """
        login_timeout = int(params.get("login_timeout", 360))
        session = vm.wait_for_login(timeout=login_timeout)

        mac = vm.get_mac_address(0)
        ifname = utils_net.get_linux_ifname(session, mac)
        queues_status_list = get_queues_status(session, ifname)

        session.close()
        if not queues_status_list[0] == queues or \
                not queues_status_list[1] == min(queues, int(vm.cpuinfo.smp)):
            txt = "Pre-set maximums Combined should equals to queues in qemu"
            txt += " cmd line.\n"
            txt += "Current hardware settings Combined should be the min of "
            txt += "queues and smp.\n"
            txt += "Pre-set maximum Combined is: %s, " % queues_status_list[0]
            txt += " queues in qemu cmd line is: %s.\n" % queues
            txt += "Current hardware settings Combined "
            txt += "is: %s, " % queues_status_list[1]
            txt += " smp in qemu cmd line is: %s." % int(vm.cpuinfo.smp)
            test.fail(txt)
开发者ID:ldoktor,项目名称:tp-qemu,代码行数:27,代码来源:mq_enabled_chk.py

示例5: enable_multi_queues

 def enable_multi_queues(vm):
     sess = vm.wait_for_serial_login(timeout=login_timeout)
     error.context("Enable multi queues in guest.", logging.info)
     for nic_index, nic in enumerate(vm.virtnet):
         ifname = utils_net.get_linux_ifname(sess, nic.mac)
         queues = int(nic.queues)
         change_queues_number(sess, ifname, queues)
开发者ID:CongLi,项目名称:tp-qemu,代码行数:7,代码来源:mq_change_qnum.py

示例6: transfer_file

    def transfer_file(src):
        """
        Transfer file by scp, use tcpdump to capture packets, then check the
        return string.

        :param src: Source host of transfer file
        :return: Tuple (status, error msg/tcpdump result)
        """
        sess = vm.wait_for_login(timeout=login_timeout)
        session.cmd_output("rm -rf %s" % filename)
        dd_cmd = ("dd if=/dev/urandom of=%s bs=1M count=%s" %
                  (filename, params.get("filesize")))
        failure = (False, "Failed to create file using dd, cmd: %s" % dd_cmd)
        txt = "Creating file in source host, cmd: %s" % dd_cmd
        error.context(txt, logging.info)
        ethname = utils_net.get_linux_ifname(session,
                                             vm.get_mac_address(0))
        tcpdump_cmd = "tcpdump -lep -i %s -s 0 tcp -vv port ssh" % ethname
        if src == "guest":
            tcpdump_cmd += " and src %s" % guest_ip
            copy_files_func = vm.copy_files_from
            try:
                sess.cmd_output(dd_cmd, timeout=360)
            except aexpect.ShellCmdError, e:
                return failure
开发者ID:WenliQuan,项目名称:virt-test,代码行数:25,代码来源:ethtool.py

示例7: run_nic_promisc

def run_nic_promisc(test, params, env):
    """
    Test nic driver in promisc mode:

    1) Boot up a VM.
    2) Repeatedly enable/disable promiscuous mode in guest.
    3) Transfer file from host to guest, and from guest to host in the same time

    @param test: QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    timeout = int(params.get("login_timeout", 360))
    session_serial = vm.wait_for_serial_login(timeout=timeout)

    ethname = utils_net.get_linux_ifname(session_serial,
                                              vm.get_mac_address(0))

    try:
        transfer_thread = utils.InterruptedThread(
                                               utils_test.run_file_transfer,
                                               (test, params, env))
        transfer_thread.start()
        while transfer_thread.isAlive():
            session_serial.cmd("ip link set %s promisc on" % ethname)
            session_serial.cmd("ip link set %s promisc off" % ethname)
    except Exception:
        transfer_thread.join(suppress_exception=True)
        raise
    else:
        transfer_thread.join()
开发者ID:kmaehara,项目名称:virt-test,代码行数:33,代码来源:nic_promisc.py

示例8: check_output

    def check_output(ifaces_actual, vm, login_nic_index=0):
        """
        1. Get the interface details of the command output
        2. Get the interface details from xml file
        3. Check command output against xml and guest output
        """
        vm_name = vm.name

        try:
            session = vm.wait_for_login(nic_index=login_nic_index)
        except Exception as detail:
            test.fail("Unable to login to VM:%s" % detail)
        iface_xml = {}
        error_count = 0
        # Check for the interface values
        for item in ifaces_actual:
            # Check for mac and model
            model = item['model']
            iname = utils_net.get_linux_ifname(session, item['mac'])
            if iname is not None:
                cmd = 'ethtool -i %s | grep driver | awk \'{print $2}\'' % iname
                drive = session.cmd_output(cmd).strip()
                if driver_dict[model] != drive:
                    error_count += 1
                    logging.error("Mismatch in the model for the interface %s\n"
                                  "Expected Model:%s\nActual Model:%s",
                                  item['interface'], driver_dict[model],
                                  item['model'])
            else:
                error_count += 1
                logging.error("Mismatch in the mac for the interface %s\n",
                              item['interface'])
            iface_xml = vm_xml.VMXML.get_iface_by_mac(vm_name, item['mac'])
            if iface_xml is not None:
                if iface_xml['type'] != item['type']:
                    error_count += 1
                    logging.error("Mismatch in the network type for the "
                                  "interface %s \n Type in command output: %s\n"
                                  "Type in xml file: %s",
                                  item['interface'],
                                  item['type'],
                                  iface_xml['type'])
                if iface_xml['source'] != item['source']:
                    error_count += 1
                    logging.error("Mismatch in the network source for the"
                                  " interface %s \n Source in command output:"
                                  "%s\nSource in xml file: %s",
                                  item['interface'],
                                  item['source'],
                                  iface_xml['source'])

            else:
                error_count += 1
                logging.error("There is no interface in the xml file "
                              "with the below specified mac address\n"
                              "Mac:%s", item['mac'])
            iface_xml = {}
        if error_count > 0:
            test.fail("The test failed, consult previous error logs")
开发者ID:nasastry,项目名称:tp-libvirt,代码行数:59,代码来源:virsh_domiflist.py

示例9: run_nicdriver_unload

def run_nicdriver_unload(test, params, env):
    """
    Test nic driver.

    1) Boot a VM.
    2) Get the NIC driver name.
    3) Repeatedly unload/load NIC driver.
    4) Multi-session TCP transfer on test interface.
    5) Check whether the test interface should still work.

    @param test: QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    timeout = int(params.get("login_timeout", 360))
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    session_serial = vm.wait_for_serial_login(timeout=timeout)

    ethname = utils_net.get_linux_ifname(session_serial,
                                               vm.get_mac_address(0))

    # get ethernet driver from '/sys' directory.
    # ethtool can do the same thing and doesn't care about os type.
    # if we make sure all guests have ethtool, we can make a change here.
    sys_path = params.get("sys_path") % (ethname)

    # readlink in RHEL4.8 doesn't have '-e' param, should use '-f' in RHEL4.8.
    readlink_cmd = params.get("readlink_command", "readlink -e")
    driver = os.path.basename(session_serial.cmd("%s %s" % (readlink_cmd,
                                                 sys_path)).strip())

    logging.info("driver is %s", driver)

    try:
        threads = []
        for _ in range(int(params.get("sessions_num", "10"))):
            thread = utils.InterruptedThread(utils_test.run_file_transfer,
                                             (test, params, env))
            thread.start()
            threads.append(thread)

        time.sleep(10)
        while threads[0].isAlive():
            session_serial.cmd("sleep 10")
            session_serial.cmd("ifconfig %s down" % ethname)
            session_serial.cmd("modprobe -r %s" % driver)
            session_serial.cmd("modprobe %s" % driver)
            session_serial.cmd("ifconfig %s up" % ethname)
    except Exception:
        for thread in threads:
            thread.join(suppress_exception=True)
            raise
    else:
        for thread in threads:
            thread.join()
开发者ID:kmaehara,项目名称:virt-test,代码行数:56,代码来源:nicdriver_unload.py

示例10: check_iface_exist

 def check_iface_exist():
     try:
         session = vm.wait_for_serial_login(username=username,
                                            password=password)
         if utils_net.get_linux_ifname(session, iface['mac']):
             return True
         else:
             logging.debug("can not find interface in vm")
     except Exception:
         return False
开发者ID:nasastry,项目名称:tp-libvirt,代码行数:10,代码来源:iface_hotplug.py

示例11: run_nic_promisc

def run_nic_promisc(test, params, env):
    """
    Test nic driver in promisc mode:

    1) Boot up a VM.
    2) Repeatedly enable/disable promiscuous mode in guest.
    3) Transfer file between host and guest during nic promisc on/off

    @param test: QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env: Dictionary with test environment.
    """
    def set_nic_promisc_onoff(session):
        if os_type == "linux":
            session.cmd("ip link set %s promisc on" % ethname)
            session.cmd("ip link set %s promisc off" % ethname)
        else:
            cmd = "c:\\set_win_promisc.py"
            session.cmd(cmd)

    error.context("Boot vm and prepare test environment", logging.info)
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    timeout = int(params.get("login_timeout", 360))
    session_serial = vm.wait_for_serial_login(timeout=timeout)
    session = vm.wait_for_login(timeout=timeout)

    os_type = params.get("os_type")
    if os_type == "linux":
        ethname = utils_net.get_linux_ifname(session, vm.get_mac_address(0))
    else:
        script_path = os.path.join(test.virtdir, "scripts/set_win_promisc.py")
        vm.copy_files_to(script_path, "C:\\")

    try:
        transfer_thread = utils.InterruptedThread(utils_test.run_file_transfer,
                                                  (test, params, env))

        error.context("Run utils_test.file_transfer ...", logging.info)
        transfer_thread.start()

        error.context("Perform file transfer while turning nic promisc on/off",
                      logging.info)
        while transfer_thread.isAlive():
            set_nic_promisc_onoff(session_serial)
    except Exception:
        transfer_thread.join(suppress_exception=True)
        raise
    else:
        transfer_thread.join()
        if session_serial:
            session_serial.close()
        if session:
            session.close()
开发者ID:FengYang,项目名称:virt-test,代码行数:54,代码来源:nic_promisc.py

示例12: check_nics_num

    def check_nics_num(expect_c, session):
        txt = "Check whether guest NICs info match with params setting."
        error.context(txt, logging.info)
        nics_list = utils_net.get_linux_ifname(session)
        actual_c = len(nics_list)
        msg = "Expected NICs count is: %d\n" % expect_c
        msg += "Actual NICs count is: %d\n" % actual_c

        if not expect_c == actual_c:
            msg += "Nics count mismatch!\n"
            return (False, msg)
        return (True, msg + 'Nics count match')
开发者ID:CongLi,项目名称:tp-qemu,代码行数:12,代码来源:multi_nics_verify.py

示例13: enable_multi_queues

 def enable_multi_queues(vm):
     session = vm.wait_for_login(timeout=login_timeout)
     error_context.context("Enable multi queues in guest.", logging.info)
     for nic_index, nic in enumerate(vm.virtnet):
         ifname = utils_net.get_linux_ifname(session, nic.mac)
         queues = int(nic.queues)
         mq_set_cmd = "ethtool -L %s combined %d" % (ifname, queues)
         status, output = session.cmd_status_output(mq_set_cmd)
         if status:
             msg = "Fail to enable multi queue in guest."
             msg += "Command %s, fail with output %s" % (mq_set_cmd, output)
             test.error(msg)
开发者ID:bssrikanth,项目名称:tp-qemu,代码行数:12,代码来源:boot_with_different_vectors.py

示例14: ping_hotplug_nic

 def ping_hotplug_nic(ip, mac, session, is_linux_guest):
     status, output = utils_test.ping(ip, 10, timeout=30)
     if status != 0:
         if not is_linux_guest:
             return status, output
         ifname = utils_net.get_linux_ifname(session, mac)
         add_route_cmd = "route add %s dev %s" % (ip, ifname)
         del_route_cmd = "route del %s dev %s" % (ip, ifname)
         logging.warn("Failed to ping %s from host.")
         logging.info("Add route and try again")
         session.cmd_output_safe(add_route_cmd)
         status, output = utils_test.ping(hotnic_ip, 10, timeout=30)
         logging.info("Del the route.")
         status, output = session.cmd_output_safe(del_route_cmd)
     return status, output
开发者ID:EIChaoYang,项目名称:tp-qemu,代码行数:15,代码来源:nic_hotplug.py

示例15: renew_ip_address

 def renew_ip_address(session, mac, is_linux_guest=True):
     if not is_linux_guest:
         utils_net.restart_windows_guest_network_by_key(session, "macaddress", mac)
         return None
     ifname = utils_net.get_linux_ifname(session, mac)
     p_cfg = "/etc/sysconfig/network-scripts/ifcfg-%s" % ifname
     cfg_con = "DEVICE=%s\nBOOTPROTO=dhcp\nONBOOT=yes" % ifname
     make_conf = "test -f %s || echo '%s' > %s" % (p_cfg, cfg_con, p_cfg)
     arp_clean = "arp -n|awk '/^[1-9]/{print \"arp -d \" $1}'|sh"
     session.cmd_output_safe(make_conf)
     session.cmd_output_safe("ifconfig %s up" % ifname)
     session.cmd_output_safe("dhclient -r", timeout=240)
     session.cmd_output_safe("dhclient %s" % ifname, timeout=240)
     session.cmd_output_safe(arp_clean)
     return None
开发者ID:MiriamDeng,项目名称:tp-qemu,代码行数:15,代码来源:nic_hotplug.py


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