Example #1
0
    def _detect_protocol(self, protocols):
        """
        Probe protocol endpoints in turn.
        """
        self.clear_protocol()

        for retry in range(0, MAX_RETRY):
            for protocol_name in protocols:
                try:
                    protocol = self._detect_wire_protocol() \
                                if protocol_name == "WireProtocol" \
                                else self._detect_metadata_protocol()

                    IOErrorCounter.set_protocol_endpoint(
                        endpoint=protocol.endpoint)

                    return protocol

                except ProtocolError as e:
                    logger.info("Protocol endpoint not found: {0}, {1}",
                                protocol_name, e)

            if retry < MAX_RETRY - 1:
                logger.info("Retry detect protocols: retry={0}", retry)
                time.sleep(PROBE_INTERVAL)
        raise ProtocolNotFoundError("No protocol found.")
    def _get_protocol(self):
        """
        Get protocol instance based on previous detecting result.
        """
        protocol_file_path = self._get_protocol_file_path()
        if not os.path.isfile(protocol_file_path):
            raise ProtocolNotFoundError("No protocol found")

        protocol_name = fileutil.read_file(protocol_file_path)
        if protocol_name == prots.WireProtocol:
            endpoint = self._get_wireserver_endpoint()
            return WireProtocol(endpoint)
        elif protocol_name == prots.MetadataProtocol:
            return MetadataProtocol()
        else:
            raise ProtocolNotFoundError(("Unknown protocol: {0}"
                                         "").format(protocol_name))
Example #3
0
    def _get_protocol(self):
        """
        Get protocol instance based on previous detecting result.
        """
        protocol_file_path = os.path.join(conf.get_lib_dir(),
                                          PROTOCOL_FILE_NAME)
        if not os.path.isfile(protocol_file_path):
            raise ProtocolNotFoundError("No protocol found")

        protocol_name = fileutil.read_file(protocol_file_path)
        if protocol_name == "WireProtocol":
            endpoint = self._get_wireserver_endpoint()
            return WireProtocol(endpoint)
        elif protocol_name == "MetadataProtocol":
            return MetadataProtocol()
        else:
            raise ProtocolNotFoundError(("Unknown protocol: {0}"
                                         "").format(protocol_name))
Example #4
0
    def _detect_protocol(self):
        """
        Probe protocol endpoints in turn.
        """
        self.clear_protocol()

        for retry in range(0, MAX_RETRY):
            try:
                endpoint = self.dhcp_handler.endpoint
                if endpoint is None:
                    # pylint: disable=W0105
                    '''
                    Check if DHCP can be used to get the wire protocol endpoint
                    '''
                    # pylint: enable=W0105
                    dhcp_available = self.osutil.is_dhcp_available()
                    if dhcp_available:
                        logger.info(
                            "WireServer endpoint is not found. Rerun dhcp handler"
                        )
                        try:
                            self.dhcp_handler.run()
                        except DhcpError as e:
                            raise ProtocolError(ustr(e))
                        endpoint = self.dhcp_handler.endpoint
                    else:
                        logger.info("_detect_protocol: DHCP not available")
                        endpoint = self.get_wireserver_endpoint()

                try:
                    protocol = WireProtocol(endpoint)
                    protocol.detect()
                    self._set_wireserver_endpoint(endpoint)
                    return protocol

                except ProtocolError as e:
                    logger.info(
                        "WireServer is not responding. Reset dhcp endpoint")
                    self.dhcp_handler.endpoint = None
                    self.dhcp_handler.skip_cache = True
                    raise e

            except ProtocolError as e:
                logger.info("Protocol endpoint not found: {0}", e)

            if retry < MAX_RETRY - 1:
                logger.info("Retry detect protocol: retry={0}", retry)
                time.sleep(PROBE_INTERVAL)
        raise ProtocolNotFoundError("No protocol found.")
Example #5
0
    def check_wire_protocol_version(self):
        uri = VERSION_INFO_URI.format(self.endpoint)
        version_info_xml = self.fetch_config(uri, None)
        version_info = VersionInfo(version_info_xml)

        preferred = version_info.get_preferred()
        if PROTOCOL_VERSION == preferred:
            logger.info("Wire protocol version:{0}", PROTOCOL_VERSION)
        elif PROTOCOL_VERSION in version_info.get_supported():
            logger.info("Wire protocol version:{0}", PROTOCOL_VERSION)
            logger.warn("Server prefered version:{0}", preferred)
        else:
            error = ("Agent supported wire protocol version: {0} was not "
                     "advised by Fabric.").format(PROTOCOL_VERSION)
            raise ProtocolNotFoundError(error)
Example #6
0
    def _detect_protocol(self, protocols):
        """
        Probe protocol endpoints in turn.
        """
        self.clear_protocol()

        for retry in range(0, MAX_RETRY):
            for protocol in protocols:
                try:
                    if protocol == "WireProtocol":
                        return self._detect_wire_protocol()

                    if protocol == "MetadataProtocol":
                        return self._detect_metadata_protocol()

                except ProtocolError as e:
                    logger.info("Protocol endpoint not found: {0}, {1}",
                                protocol, e)

            if retry < MAX_RETRY - 1:
                logger.info("Retry detect protocols: retry={0}", retry)
                time.sleep(PROBE_INTERVAL)
        raise ProtocolNotFoundError("No protocol found.")