Esempio n. 1
0
    def _prepare_installer(self, kit_pkg_url):
        """
        Extracts a kit archive and prepares the kit installer for the
        installation process.

        :param kit_pkg_url: the URL to the kit package archive

        :return: the KitInstaller instance

        """
        #
        # 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)
        kit_spec = (kit_meta['name'], kit_meta['version'],
                    kit_meta['iteration'])
        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_dir = utils.unpack_kit_archive(kit_pkg_path, self._kits_root)

        #
        # Load and initialize kit installer
        #
        load_kits()
        try:
            installer = get_kit_installer(kit_spec)()
            assert installer.is_installable()

        except Exception as ex:
            if os.path.exists(kit_dir):
                self._logger.debug(
                    'Removing kit installation directory: {}'.format(kit_dir))
                osUtility.removeDir(kit_dir)
            self._logger.warning(
                'Kit is not installable: {}'.format(kit_spec))
            return

        return installer
Esempio n. 2
0
    def get_kit_package_eula(self, 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)

        #
        # Get the EULA from the installer
        #
        installer = get_kit_installer(kit_spec)()
        eula = installer.get_eula()

        return eula
Esempio n. 3
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
Esempio n. 4
0
    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