예제 #1
0
    def enable(self, napp_uri):
        """Enable a NApp if not already enabled.

        Raises:
            FileNotFoundError: If NApp is not installed.
            PermissionError: No filesystem permission to enable NApp.
        """
        napp = NApp.create_from_uri(napp_uri)
        enabled = self._enabled / napp.username / napp.name
        installed = self._installed / napp.username / napp.name

        if not installed.is_dir():
            log.error("Failed to enable NApp %s. NApp not installed.", napp.id)
        elif not enabled.exists():
            self._create_module(enabled.parent)
            try:
                # Create symlink
                enabled.symlink_to(installed)
                if self._controller is not None:
                    self._controller.load_napp(napp.username, napp.name)
                log.info("NApp enabled: %s", napp.id)
            except FileExistsError:
                pass  # OK, NApp was already enabled
            except PermissionError:
                log.error("Failed to enable NApp %s. Permission denied.",
                          napp.id)
예제 #2
0
    def test_create_from_uri(self):
        """Test create_from_uri method."""
        napp = NApp.create_from_uri('file://any/kytos/napp:1.0')

        self.assertEqual(napp.username, 'kytos')
        self.assertEqual(napp.name, 'napp')
        self.assertEqual(napp.version, '1.0')
        self.assertEqual(napp.repository, 'file://any')
예제 #3
0
 def disable(self, napp_uri):
     """Disable a NApp if it is enabled."""
     napp = NApp.create_from_uri(napp_uri)
     enabled = self._enabled / napp.username / napp.name
     try:
         enabled.unlink()
         log.info("NApp disabled: %s", napp.id)
         if self._controller is not None:
             self._controller.unload_napp(napp.username, napp.name)
     except FileNotFoundError:
         pass  # OK, it was already disabled
예제 #4
0
    def uninstall(self, napp_uri):
        """Remove a NApp from filesystem, if existent."""
        napp = NApp.create_from_uri(napp_uri)

        if self.is_enabled(napp_uri):
            log.warning("Unable to uninstall NApp %s. NApp currently in use.",
                        napp)
            return False

        if self.is_installed(napp_uri):
            installed = self._installed / napp.username / napp.name
            if installed.is_symlink():
                installed.unlink()
            else:
                shutil.rmtree(str(installed))
            log.info("NApp uninstalled: %s", napp)
        else:
            log.warning("Unable to uninstall NApp %s. Already uninstalled.",
                        napp)
        return True
예제 #5
0
파일: manager.py 프로젝트: rubiruchi/kytos
    def install(self, napp_uri, enable=True):
        """Install and enable a NApp from its repository.

        By default, install procedure will also enable the NApp. If you only
        want to install and keep NApp disabled, please use enable=False.
        """
        napp = NApp.create_from_uri(napp_uri)

        if napp in self.get_all_napps():
            LOG.warning("Unable to install NApp %s. Already installed.", napp)
            return False

        if not napp.repository:
            napp.repository = self._controller.options.napps_repositories[0]

        pkg_folder = None
        try:
            pkg_folder = napp.download()
            napp_folder = self._find_napp(napp, pkg_folder)
            dst = self._installed_path / napp.username / napp.name
            self._create_module(dst.parent)
            shutil.move(str(napp_folder), str(dst))
        finally:
            if pkg_folder and pkg_folder.exists():
                shutil.rmtree(str(pkg_folder))

        LOG.info("New NApp installed: %s", napp)

        napp = NApp.create_from_json(dst / 'kytos.json')
        for uri in napp.napp_dependencies:
            self.install(uri, enable)

        if enable:
            return self.enable(napp.username, napp.name)

        return True
예제 #6
0
파일: manager.py 프로젝트: kytos/kyco
    def install(self, napp_uri, enable=True):
        """Install and enable a NApp from its repository.

        By default, install procedure will also enable the NApp. If you only
        want to install and keep NApp disabled, please use enable=False.
        """
        napp = NApp.create_from_uri(napp_uri)

        if napp in self.get_all_napps():
            LOG.warning("Unable to install NApp %s. Already installed.", napp)
            return False

        if not napp.repository:
            napp.repository = self._controller.options.napps_repositories[0]

        pkg_folder = None
        try:
            pkg_folder = napp.download()
            napp_folder = self._find_napp(napp, pkg_folder)
            dst = self._installed_path / napp.username / napp.name
            self._create_module(dst.parent)
            shutil.move(str(napp_folder), str(dst))
        finally:
            if pkg_folder and pkg_folder.exists():
                shutil.rmtree(str(pkg_folder))

        LOG.info("New NApp installed: %s", napp)

        napp = NApp.create_from_json(dst/'kytos.json')
        for uri in napp.napp_dependencies:
            self.install(uri, enable)

        if enable:
            return self.enable(napp.username, napp.name)

        return True
예제 #7
0
파일: manager.py 프로젝트: rubiruchi/kytos
 def is_installed(self, username, napp_name):
     """Whether a NApp is installed or not on this controller."""
     napp_id = "{}/{}".format(username, napp_name)
     napp = NApp.create_from_uri(napp_id)
     return napp in self.get_all_napps()
예제 #8
0
    def test_create_from_uri__not(self):
        """Test create_from_uri method when uri does not match."""
        napp = NApp.create_from_uri('')

        self.assertIsNone(napp)
예제 #9
0
 def is_installed(self, napp_uri):
     """Whether a NApp is installed or not on this controller."""
     napp = NApp.create_from_uri(napp_uri)
     return napp in self.list()
예제 #10
0
파일: manager.py 프로젝트: kytos/kyco
 def is_installed(self, username, napp_name):
     """Whether a NApp is installed or not on this controller."""
     napp_id = "{}/{}".format(username, napp_name)
     napp = NApp.create_from_uri(napp_id)
     return napp in self.get_all_napps()