Example #1
0
    def unload_napp(self, username, napp_name):
        """Unload a specific NApp.

        Args:
            username (str): NApp username.
            napp_name (str): Name of the NApp to be unloaded.
        """
        napp = self.napps.pop((username, napp_name), None)

        if napp is None:
            self.log.warning('NApp %s/%s was not loaded', username, napp_name)
        else:
            self.log.info("Shutting down NApp %s/%s...", username, napp_name)
            napp_id = NApp(username, napp_name).id
            event = KytosEvent(name='kytos/core.shutdown.' + napp_id)
            napp_shutdown_fn = self.events_listeners[event.name][0]
            # Call listener before removing it from events_listeners
            napp_shutdown_fn(event)

            # Remove rest endpoints from that napp
            self.api_server.remove_napp_endpoints(napp)

            # Removing listeners from that napp
            # pylint: disable=protected-access
            for event_type, napp_listeners in napp._listeners.items():
                event_listeners = self.events_listeners[event_type]
                for listener in napp_listeners:
                    event_listeners.remove(listener)
                if not event_listeners:
                    del self.events_listeners[event_type]
Example #2
0
    def __init__(self, napp_path, tpl_path):
        """Instantiate an OpenAPI object.

        Args:
            napp_path (string): Napp directory
            tlp_path (string): File name from template

        """
        self._napp_path = napp_path
        self._template = tpl_path / 'openapi.yml.template'
        self._api_file = napp_path / 'openapi.yml'

        metadata = napp_path / 'kytos.json'
        self._napp = NApp.create_from_json(metadata)

        # Data for a path
        self._summary = None
        self._description = None

        # Part of template context
        self._paths = {}