コード例 #1
0
ファイル: manager.py プロジェクト: dtougas/tortuga
    def _cleanup_kit(self, session: Session, kit: Kit, force: bool,
                     skip_db: bool = False):
        """
        Uninstalls the kit and it's file repos.

        :param session: a database session
        :param kit:     the Kit instance
        :param force:   whether or not to force the deletion

        """
        repo_dir = kit.getKitRepoDir()

        #
        # Remove the kit from the DB
        #
        if not skip_db:
            self._kit_db_api.deleteKit(session, kit.getName(),
                                       kit.getVersion(), kit.getIteration(),
                                       force=force)

        #
        # Remove the files and repo
        #
        for repo in repoManager.getRepoList():
            #
            # Delete the repo
            #
            repo.delete(repo_dir)

            #
            # Remove repo files
            #
            full_repo_dir = os.path.join(repo.getLocalPath(), repo_dir)
            self._logger.debug(
                'Removing repo dir: {}'.format(full_repo_dir))
            #
            # When LINKOSKITMEDIA is used, the kit directory is a symlink
            # to the real media, delete the link instead of attempting
            # to delete the directory.
            #
            if os.path.islink(full_repo_dir):
                os.unlink(full_repo_dir)
            else:
                osUtility.removeDir(full_repo_dir)

        #
        # Check and clean up proxy
        #
        self.remove_proxy(repo_dir)

        #
        # Remove the kit installation dir
        #
        kit_dir = os.path.join(self._kits_root, kit.getDirName())
        if os.path.exists(kit_dir):
            self._logger.debug(
                'Removing kit installation directory: {}'.format(kit_dir))
            osUtility.removeDir(kit_dir)
コード例 #2
0
    def installKitPackage(self, kit_pkg_url, key=None):
        """
        Install kit from the given kit url (url might be a local file). Kit
        will be installed for all operating systems that:

            1) have repo configured on the local machine
            2) are specified in the kit.xml file

        :raisesKitAlreadyExists:
        :raisesEulaAcceptanceRequired:

        """
        self.getLogger().debug('Installing kit package:'.format(kit_pkg_url))

        #
        # Download/copy and unpack kit archive.
        #
        kit_src_path = os.path.basename(kit_pkg_url)
        kit_pkg_path = utils.retrieve(kit_src_path, kit_pkg_url,
                                      self._kits_root)
        kit_spec = utils.unpack_archive(kit_pkg_path, self._kits_root)

        #
        # Load and initialize kit installer
        #
        load_kits()
        installer = get_kit_installer(kit_spec)()

        if not installer.is_installable():
            self.getLogger().warning(
                'Kit is not installable: {}'.format(kit_spec))
            return

        kit = installer.get_kit()

        #
        # This method will throw KitAlreadyExists, if it does...
        #
        self._check_if_kit_exists(kit)

        #
        # Validate eula
        #
        eula = installer.get_eula()
        if not self._eula_validator.validate_eula(eula):
            raise EulaAcceptanceRequired(
                'You must accept the EULA to install this kit')

        #
        # Runs the kit pre install method
        #
        installer.run_action('pre_install')

        #
        # Get list of operating systems supported by this installer
        #
        os_info_list = [repo.getOsInfo() for repo in repoManager.getRepoList()]

        #
        # Install operating system specific packages
        #
        self._install_os_packages(kit, os_info_list)

        #
        # Initialize andy DB tables provided by the kit
        #
        db_manager = DbManager()
        db_manager.init_database()

        #
        # Add the kit to the database
        #
        self._kit_db_api.addKit(kit)

        #
        # Clean up the kit archive directory
        #
        self._clean_kit_achiv_dir(kit, installer.install_path)

        #
        # Install puppet modules
        #
        installer.run_action('install_puppet_modules')

        #
        # Run post install
        #
        installer.run_action('post_install')

        if eula:
            ActionManager().logAction(
                'Kit [{}] installed and EULA accepted at [{}]'
                ' local machine time.'.format(installer.spec, time.ctime()))
        else:
            ActionManager().logAction(
                'Kit [{}] installed at [{}] local machine time.'.format(
                    installer.spec, time.ctime()))

        return kit
コード例 #3
0
ファイル: manager.py プロジェクト: dtougas/tortuga
    def _run_installer(self, db_manager: DbManager, installer):
        """
        Runs the installation process for a kit installer.

        :param db_manager: the DbManager instance
        :param installer: the KitInstaller instance to run the install process
                          for

        """
        kit = installer.get_kit()

        #
        # This method will throw KitAlreadyExists, if it does...
        #
        self._check_if_kit_exists(installer.session, kit)

        #
        # Validate eula
        #
        eula = installer.get_eula()
        if not eula:
            self._logger.debug('No EULA acceptance required')
        else:
            if not self._eula_validator.validate_eula(eula):
                raise EulaAcceptanceRequired(
                    'You must accept the EULA to install this kit')

        #
        # Runs the kit pre install method
        #
        installer.run_action('pre_install')

        #
        # Get list of operating systems supported by this installer
        #
        os_info_list = [
            repo.getOsInfo() for repo in repoManager.getRepoList()
        ]

        #
        # Install operating system specific packages
        #
        self._install_os_packages(kit, os_info_list)

        #
        # Initialize any DB tables provided by the kit
        #
        db_manager.init_database()

        #
        # Add the kit to the database
        #
        self._kit_db_api.addKit(installer.session, kit)

        #
        # Clean up the kit archive directory
        #
        self._clean_kit_achiv_dir(kit, installer.install_path)

        #
        # Install puppet modules
        #
        installer.run_action('install_puppet_modules')

        #
        # Run post install
        #
        installer.run_action('post_install')

        if eula:
            ActionManager().logAction(
                'Kit [{}] installed and EULA accepted at [{}]'
                ' local machine time.'.format(
                    installer.spec, time.ctime())
            )
        else:
            ActionManager().logAction(
                'Kit [{}] installed at [{}] local machine time.'.format(
                    installer.spec, time.ctime())
            )
コード例 #4
0
ファイル: manager.py プロジェクト: joedborg/tortuga
    def installKitPackage(self, db_manager, kit_pkg_url, key=None):
        """
        Install kit from the given kit url (url might be a local file). Kit
        will be installed for all operating systems that:

            1) have repo configured on the local machine
            2) are specified in the kit.xml file

        :raisesKitAlreadyExists:
        :raisesEulaAcceptanceRequired:

        """
        self.getLogger().debug('Installing kit package: {}'.format(kit_pkg_url))

        #
        # Download/copy kit archive.
        #
        kit_src_path = os.path.basename(kit_pkg_url)
        kit_pkg_path = utils.retrieve(
            kit_src_path, kit_pkg_url, self._kits_root)

        #
        # Make sure the kit version is compatible
        #
        kit_meta = utils.get_metadata_from_archive(kit_pkg_path)
        requires_core = kit_meta.get('requires_core', VERSION)
        if not version_is_compatible(requires_core):
            errmsg = 'The {} kit requires tortuga core >= {}'.format(
                kit_meta['name'],requires_core)

            raise OperationFailed(errmsg)

        #
        # Unpack the archive
        #
        kit_spec = utils.unpack_archive(kit_pkg_path, self._kits_root)

        #
        # Load and initialize kit installer
        #
        load_kits()
        installer = get_kit_installer(kit_spec)()

        if not installer.is_installable():
            self.getLogger().warning(
                'Kit is not installable: {}'.format(kit_spec))
            return

        with db_manager.session() as session:
            installer.session = session

            kit = installer.get_kit()

            #
            # This method will throw KitAlreadyExists, if it does...
            #
            self._check_if_kit_exists(session, kit)

            #
            # Validate eula
            #
            eula = installer.get_eula()
            if not eula:
                self.getLogger().debug('No EULA acceptance required')
            else:
                if not self._eula_validator.validate_eula(eula):
                    raise EulaAcceptanceRequired(
                        'You must accept the EULA to install this kit')

            #
            # Runs the kit pre install method
            #
            installer.run_action('pre_install')

            #
            # Get list of operating systems supported by this installer
            #
            os_info_list = [
                repo.getOsInfo() for repo in repoManager.getRepoList()
            ]

            #
            # Install operating system specific packages
            #
            self._install_os_packages(kit, os_info_list)

            #
            # Initialize any DB tables provided by the kit
            #
            # db_manager = DbManager()
            db_manager.init_database()

            #
            # Add the kit to the database
            #
            self._kit_db_api.addKit(session, kit)

            #
            # Clean up the kit archive directory
            #
            self._clean_kit_achiv_dir(kit, installer.install_path)

            #
            # Install puppet modules
            #
            installer.run_action('install_puppet_modules')

            #
            # Run post install
            #
            try:
                installer.run_action('post_install')
            except Exception as e:
                self._uninstall_kit(session, kit, True)
                raise KitInstallError(
                    'Kit installation failed during post_install: {}'.format(e))

            if eula:
                ActionManager().logAction(
                    'Kit [{}] installed and EULA accepted at [{}]'
                    ' local machine time.'.format(
                        installer.spec, time.ctime())
                )
            else:
                ActionManager().logAction(
                    'Kit [{}] installed at [{}] local machine time.'.format(
                        installer.spec, time.ctime())
                )

            return kit