Esempio n. 1
0
    def mount_honeycomb_on_odl(node):
        """Tell ODL client to mount Honeycomb instance over netconf.

        :param node: Honeycomb node.
        :type node: dict
        :raises HoneycombError: When the response is not code 200: OK.
        """

        path = HcUtil.read_path_from_url_file(
            "odl_client/odl_netconf_connector")

        url_file = "{0}/{1}".format(Const.RESOURCES_TPL_HC,
                                    "odl_client/mount_honeycomb.xml")

        with open(url_file) as template:
            data = template.read()

        status_code, _ = HTTPRequest.post(
            node,
            path,
            headers={"Content-Type": "application/xml"},
            payload=data,
            timeout=10,
            enable_logging=False)

        if status_code == HTTPCodes.OK:
            logger.info("ODL mount point configured successfully.")
        elif status_code == HTTPCodes.CONFLICT:
            logger.info("ODL mount point was already configured.")
        else:
            raise HoneycombError('Mount point configuration not successful')
Esempio n. 2
0
    def post_honeycomb_data(node, url_file, data=None,
                            data_representation=DataRepresentation.JSON,
                            timeout=10):
        """Send a POST request and return the status code and response content.

        :param node: Honeycomb node.
        :param url_file: URL file. The argument contains only the name of file
            without extension, not the full path.
        :param data: Configuration data to be sent to Honeycomb.
        :param data_representation: How the data is represented.
        :param timeout: How long to wait for the server to send data before
            giving up.
        :type node: dict
        :type url_file: str
        :type data: dict, str
        :type data_representation: DataRepresentation
        :type timeout: int
        :returns: Status code and content of response.
        :rtype: tuple
        :raises HoneycombError: If the given data representation is not defined
            in HEADERS.
        """

        try:
            header = HEADERS[data_representation]
        except AttributeError as err:
            raise HoneycombError("Wrong data representation: {0}.".
                                 format(data_representation), repr(err))
        if data_representation == DataRepresentation.JSON:
            data = dumps(data)

        path = HoneycombUtil.read_path_from_url_file(url_file)
        return HTTPRequest.post(
            node=node, path=path, headers=header, payload=data, timeout=timeout)