Beispiel #1
0
    def _initiate_cfor_api(self):
        """
    Initialize and setup REST API in a different thread.

    :return: None
    """
        # set bounded layer name here to avoid circular dependency problem
        handler = CONFIG.get_cfor_api_class()
        handler.bounded_layer = self._core_name
        params = CONFIG.get_cfor_agent_params()
        # can override from global config
        if 'prefix' in params:
            handler.prefix = params['prefix']
        if 'unify_interface' in params:
            handler.virtualizer_format_enabled = params['unify_interface']
        if 'diff' in params:
            handler.DEFAULT_DIFF = bool(params['diff'])
        address = (params.get('address'), params.get('port'))
        self.cfor_api = RESTServer(handler, *address)
        # Virtualizer ID of the Cf-Or interface
        self.cfor_api.api_id = handler.LOGGER_NAME = "Cf-Or"
        # Virtualizer type for Cf-Or API
        self.cfor_api.virtualizer_type = CONFIG.get_api_virtualizer(
            layer_name=LAYER_NAME, api_name=self.cfor_api.api_id)
        handler.log.info("Init REST-API for %s on %s:%s!" %
                         (self.cfor_api.api_id, address[0], address[1]))
        self.cfor_api.start()
        handler.log.debug(
            "Enforced configuration for %s: virtualizer type: %s, interface: %s, "
            "diff: %s" % (self.cfor_api.api_id, self.cfor_api.virtualizer_type,
                          "UNIFY" if handler.virtualizer_format_enabled else
                          "Internal-NFFG", handler.DEFAULT_DIFF))
Beispiel #2
0
    def _handle_GetVirtResInfoEvent(self, event):
        """
    Generate virtual resource info and send back to SAS.

    :param event: event object contains service layer id
    :type event: :any:`GetVirtResInfoEvent`
    :return: None
    """
        log.getChild('API').debug(
            "Received <Virtual View> request from %s layer" %
            str(event.source._core_name).title())
        # Currently view is a Virtualizer to keep ESCAPE fast
        # Virtualizer type for Sl-Or API
        virtualizer_type = CONFIG.get_api_virtualizer(layer_name=LAYER_NAME,
                                                      api_name=event.sid)
        v = self.resource_orchestrator.virtualizerManager.get_virtual_view(
            event.sid, type=virtualizer_type)
        log.getChild('API').debug("Sending back <Virtual View>: %s..." % v)
        self.raiseEventNoErrors(VirtResInfoEvent, v)