Example #1
0
 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
Example #2
0
    def renew_ip_address(session, mac, guest_os_type):
        """
        Renew ip for plugged nic

        :param session: Vm session
        :param mac: The mac address of plugged interface
        :param guest_os_type: Guest os type, Linux or Windows
        """
        if guest_os_type == 'Windows':
            utils_net.restart_windows_guest_network_by_key(
                session, "macaddress", mac)
        ifname = utils_net.get_linux_ifname(session, mac)
        utils_net.create_network_script(ifname, mac, 'dhcp', '255.255.255.0')
        utils_net.restart_guest_network(session, mac)
        arp_clean = "arp -n|awk '/^[1-9]/{print \"arp -d \" $1}'|sh"
        session.cmd_output_safe(arp_clean)
Example #3
0
 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
Example #4
0
 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)
     if params.get("make_change") == "yes":
         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)
     else:
         make_conf = "nmcli connection add type ethernet con-name %s ifname" \
                     " %s autoconnect yes" % (ifname, ifname)
     arp_clean = "arp -n|awk '/^[1-9]/{print \"arp -d \" $1}'|sh"
     session.cmd_output_safe(make_conf)
     session.cmd_output_safe("ip link set dev %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
Example #5
0
    def check_nic_removed(mac, session):
        """
        Get interface IP address by given MAC addrss. If try_dhclint is
        True, then try to allocate IP addrss for the interface.

        :param mac: The mac address of plugged interface
        :param session: Vm session
        """
        except_mesg = ''
        try:
            if guest_os_type == 'Windows':
                except_mesg = "Get nic netconnectionid failed"
                utils_net.restart_windows_guest_network_by_key(
                    session, "macaddress", mac)
            else:
                except_mesg = ("Failed to determine interface"
                               " name with mac %s" % mac)
                utils_net.get_linux_ifname(session, mac)
        except exceptions.TestError as e:
            if except_mesg in str(e):
                return True
        else:
            return False