Beispiel #1
0
    def _writeKickstartFile(self, session: Session, node: Node,
                            hardwareprofile: HardwareProfile,
                            softwareprofile: SoftwareProfile) -> None:
        """
        Generate kickstart file for specified node

        Raises:
            OsNotSupported
        """
        osFamilyName = softwareprofile.os.family.name

        try:
            osSupportModule = __import__('tortuga.os.%s.osSupport' %
                                         (osFamilyName),
                                         fromlist=['OSSupport'])
        except ImportError:
            raise OsNotSupported('Operating system family [%s] not supported' %
                                 (osFamilyName))

        OSSupport = osSupportModule.OSSupport

        tmpOsFamilyInfo = OsFamilyInfo(softwareprofile.os.family.name,
                                       softwareprofile.os.family.version,
                                       softwareprofile.os.family.arch)

        contents = OSSupport(tmpOsFamilyInfo).getKickstartFileContents(
            session, node, hardwareprofile, softwareprofile)

        with open(self.__get_kickstart_file_path(node), 'w') as fp:
            fp.write(contents)
Beispiel #2
0
    def getKickstartFile(self, node, hardwareprofile, softwareprofile):
        """
        Generate kickstart file for specified node

        Raises:
            OsNotSupported
        """

        osFamilyName = softwareprofile.os.family.name

        try:
            osSupportModule = __import__('tortuga.os.%s.osSupport' %
                                         (osFamilyName),
                                         fromlist=['OSSupport'])
        except ImportError:
            raise OsNotSupported('Operating system family [%s] not supported' %
                                 (osFamilyName))

        OSSupport = osSupportModule.OSSupport

        tmpOsFamilyInfo = OsFamilyInfo(softwareprofile.os.family.name,
                                       softwareprofile.os.family.version,
                                       softwareprofile.os.family.arch)

        return OSSupport(tmpOsFamilyInfo).getKickstartFileContents(
            node, hardwareprofile, softwareprofile)
Beispiel #3
0
def getOsConfigClass(name):
    osConfigClass = None

    for osConfigClass in find_subclasses(OSConfigBase):
        if osConfigClass.is_supported(name):
            break
    else:
        raise OsNotSupported('Operating system [%s] not supported' % (name))

    return osConfigClass
Beispiel #4
0
    def __get_ossupport_module(self, osFamilyName):         \
            # pylint: disable=no-self-use
        """
        Raises:
            OsNotSupported
        """

        try:
            return __import__('tortuga.os.%s.osSupport' % (osFamilyName),
                              fromlist=['OSSupport']).OSSupport
        except ImportError:
            raise OsNotSupported('Operating system family [%s] not supported' %
                                 (osFamilyName))
Beispiel #5
0
def _identify_rhel_variant():
    cmd = '/opt/puppetlabs/bin/facter operatingsystem'

    p = tortugaSubprocess.TortugaSubprocess(cmd)
    stdout, stderr = p.communicate()

    if p.returncode != 0:
        raise OsNotSupported(
            'Unable to determine OS type: stderr=[%s]' % (stderr))

    facterOperatingSystem = stdout.decode().rstrip().lower()

    if facterOperatingSystem == 'redhat':
        name = RHEL
    elif facterOperatingSystem == 'centos':
        name = CENTOS
    elif facterOperatingSystem == 'oraclelinux':
        name = ORACLE
    else:
        raise OsNotSupported(
            'Unsupported OS [%s]' % (facterOperatingSystem))

    return name
Beispiel #6
0
    def _getKitOpsClass(os_family_info) -> Any:
        """
        Import the KitOps class for the specified OS family name

        Raises:
            OsNotSupported
        """
        try:
            _temp = __import__(
                'tortuga.kit.%sOsKitOps' % os_family_info.getName(), globals(),
                locals(), ['KitOps'], 0)

            return getattr(_temp, 'KitOps')
        except ImportError:
            raise OsNotSupported('Currently unsupported distribution')
Beispiel #7
0
    def _getKitOpsClass(self, osFamilyInfo):         \
            # pylint: disable=no-self-use
        """
        Import the KitOps class for the specified OS family name

        Raises:
            OsNotSupported
        """
        try:
            _temp = __import__(
                'tortuga.kit.%sOsKitOps' % (osFamilyInfo.getName()), globals(),
                locals(), ['KitOps'], 0)

            return getattr(_temp, 'KitOps')
        except ImportError:
            raise OsNotSupported('Currently unsupported distribution')
Beispiel #8
0
    def installOsKit(self, session: Session, os_media_urls: List[str],
                     **kwargs) -> Kit:
        """

        :param os_media_urls:
        :param kwargs:
        :return:
        """
        media_list: List[dict] = self._processMediaspec(os_media_urls)

        os_distro = None
        kit_ops = None
        enable_proxy = False
        mount_manager = None

        is_interactive = kwargs['bInteractive'] \
            if 'bInteractive' in kwargs else False

        use_symlinks = kwargs['bUseSymlinks'] \
            if 'bUseSymlinks' in kwargs else False

        # If 'mirror' is True, treat 'mediaspec' as a mirror, instead of
        # specific OS version. This affects the stored OS version.
        is_mirror = kwargs['mirror'] if 'mirror' in kwargs else False

        media: dict = media_list[0]  # For now, remove support for multiple ISOs / mirrors.
        source_path = None
        mount_manager_source_path = None

        try:
            if use_symlinks:
                source_path = media['urlparse'].path
            elif 'localFilePath' in media:
                # Remote ISO file has been transferred locally and
                # filename is stored in 'localFilePath'

                mount_manager_source_path = media['localFilePath']
            else:
                pr = media['urlparse']

                if pr.scheme.lower() in ('http', 'https'):
                    # This is a proxy URL
                    source_path = pr.geturl()

                    enable_proxy = True
                elif not pr.scheme or pr.scheme.lower() == 'file':
                    if os.path.ismount(pr.path):
                        # Mount point specified
                        source_path = pr.path
                    else:
                        mount_manager_source_path = pr.path
                else:
                    raise UnrecognizedKitMedia(
                        'Unhandled URL scheme [%s]' % pr.scheme)

            # Mount source media, as necessary
            if mount_manager_source_path:
                mount_manager = MountManager(mount_manager_source_path)
                mount_manager.mountMedia()

                source_path = mount_manager.mountpoint

            if os_distro is None:
                # Determine the OS we're working with...
                os_distro = DistributionFactory(source_path)()
                if os_distro is None:
                    raise OsNotSupported('Could not match media')

                os_info = os_distro.get_os_info()

                # Check if OS is already installed before attempting to
                # perform copy operation...
                try:
                    self._checkExistingKit(
                        session,
                        os_info.getName(),
                        os_info.getVersion(),
                        os_info.getArch())
                except KitAlreadyExists:
                    if mount_manager_source_path:
                        mount_manager.unmountMedia()

                        if 'localFilePath' in media:
                            if os.path.exists(
                                    media['localFilePath']):
                                os.unlink(media['localFilePath'])

                    raise

                kit_ops_class = self._getKitOpsClass(
                    os_info.getOsFamilyInfo())

                kit_ops = kit_ops_class(
                    os_distro, bUseSymlinks=use_symlinks, mirror=is_mirror)

                kit = kit_ops.prepareOSKit()

            # Copy files here
            if enable_proxy:
                kit_ops.addProxy(source_path)
            else:
                descr = None

                if is_interactive:
                    descr = "Installing..."

                kit_ops.copyOsMedia(descr=descr)
        finally:
            if mount_manager_source_path:
                # MountManager instance exists.  Unmount any mounted
                # path
                mount_manager.unmountMedia()

                if 'localFilePath' in media:
                    if os.path.exists(media['localFilePath']):
                        os.unlink(media['localFilePath'])

        kit_object = self._create_kit_db_entry(session, kit)

        self._postInstallOsKit(session, kit_object)

        return kit_object