Exemplo n.º 1
0
    def wait_for_get_address(self,
                             nic_index_or_name,
                             timeout=30,
                             internal_timeout=1,
                             ip_version='ipv4'):
        """
        Wait for a nic to acquire an IP address, then return it.
        For ipv6 linklocal address, we can generate it by nic mac,
        so we can ignore this case
        """

        # Don't let VMIPAddressMissingError/VMAddressVerificationError through
        def _get_address():
            try:
                return self.get_address(nic_index_or_name)
            except (VMIPAddressMissingError, VMAddressVerificationError):
                return False

        if not utils_misc.wait_for(_get_address, timeout, internal_timeout):
            if self.is_dead():
                raise VMIPAddressMissingError(
                    self.virtnet[nic_index_or_name].mac)
            try:
                s_session = None
                # for windows guest make sure your guest supports
                # login by serial_console
                s_session = self.wait_for_serial_login()
                nic_mac = self.get_mac_address(nic_index_or_name)
                os_type = self.params.get("os_type")
                try:
                    utils_net.renew_guest_ip(s_session, nic_mac, os_type,
                                             ip_version)
                    return self.get_address(nic_index_or_name)
                except (VMIPAddressMissingError, VMAddressVerificationError):
                    try:
                        nic_address = utils_net.get_guest_ip_addr(
                            s_session, nic_mac, os_type, ip_version)
                        if nic_address:
                            mac_key = nic_mac
                            if ip_version == "ipv6":
                                mac_key = "%s_6" % nic_mac
                            self.address_cache[mac_key.lower()] = nic_address
                            return nic_address
                    except Exception, err:
                        logging.debug("Can not get guest address, '%s'" % err)
                        raise VMIPAddressMissingError(nic_mac)
            finally:
                if s_session:
                    s_session.close()
        return self.get_address(nic_index_or_name)
Exemplo n.º 2
0
    def wait_for_get_address(self, nic_index_or_name, timeout=30,
                             internal_timeout=1, ip_version='ipv4'):
        """
        Wait for a nic to acquire an IP address, then return it.
        For ipv6 linklocal address, we can generate it by nic mac,
        so we can ignore this case
        """
        # Don't let VMIPAddressMissingError/VMAddressVerificationError through
        def _get_address():
            try:
                return self.get_address(nic_index_or_name)
            except (VMIPAddressMissingError, VMAddressVerificationError):
                return False

        if not utils_misc.wait_for(_get_address, timeout, internal_timeout):
            if self.is_dead():
                raise VMIPAddressMissingError(self.virtnet[nic_index_or_name].mac)
            try:
                s_session = None
                # for windows guest make sure your guest supports
                # login by serial_console
                s_session = self.wait_for_serial_login()
                nic_mac = self.get_mac_address(nic_index_or_name)
                os_type = self.params.get("os_type")
                try:
                    utils_net.renew_guest_ip(s_session, nic_mac,
                                             os_type, ip_version)
                    return self.get_address(nic_index_or_name)
                except (VMIPAddressMissingError, VMAddressVerificationError):
                    try:
                        nic_address = utils_net.get_guest_ip_addr(s_session,
                                                                  nic_mac,
                                                                  os_type,
                                                                  ip_version)
                        if nic_address:
                            mac_key = nic_mac
                            if ip_version == "ipv6":
                                mac_key = "%s_6" % nic_mac
                            self.address_cache[mac_key.lower()] = nic_address
                            return nic_address
                    except Exception, err:
                        logging.debug("Can not get guest address, '%s'" % err)
                        raise VMIPAddressMissingError(nic_mac)
            finally:
                if s_session:
                    s_session.close()
        return self.get_address(nic_index_or_name)
Exemplo n.º 3
0
 def wait_for_get_address(self, nic_index_or_name, timeout=30,
                          internal_timeout=1, ip_version='ipv4'):
     """
     Wait for a nic to acquire an IP address, then return it.
     """
     # Don't let VMIPAddressMissingError/VMAddressVerificationError through
     def _get_address():
         try:
             return self.get_address(nic_index_or_name)
         except (VMIPAddressMissingError, VMAddressVerificationError):
             return False
     if not utils_misc.wait_for(_get_address, timeout, internal_timeout):
         try:
             s_session = None
             s_session = self.wait_for_serial_login()
             nic_mac = self.get_mac_address(nic_index_or_name)
             os_type = self.params.get("os_type")
             try:
                 utils_net.renew_guest_ip(s_session, nic_mac, os_type)
                 return self.get_address(nic_index_or_name)
             except (VMIPAddressMissingError, VMAddressVerificationError):
                 try:
                     nic_address = utils_net.get_guest_ip_addr(s_session,
                                                               nic_mac,
                                                               os_type,
                                                               ip_version)
                     if nic_address:
                         self.address_cache[nic_mac.lower()] = nic_address
                         return nic_address
                 except Exception, err:
                     logging.debug("Can not get guest address, '%s'" % err)
                     raise VMIPAddressMissingError(nic_mac)
         finally:
             if s_session:
                 s_session.close()
     return self.get_address(nic_index_or_name)