Пример #1
0
    def addOsIfNotFound(self, session: Session, osInfo: OsInfo) \
            -> OperatingSystem:
        """
        Insert operating system into the db if it is not found.
        """
        try:
            return self.getOsInfo(session, osInfo.getName(),
                                  osInfo.getVersion(), osInfo.getArch())
        except OsNotFound:
            pass

        # Translate osInfo
        tmpOsInfo = osHelper.getOsInfo(osInfo.getName(), osInfo.getVersion(),
                                       osInfo.getArch())

        # Check for existence of OS family
        dbOsFamily = self.addOsFamilyIfNotFound(session,
                                                tmpOsInfo.getOsFamilyInfo())

        dbOs = OperatingSystem(name=osInfo.getName(),
                               version=osInfo.getVersion(),
                               arch=osInfo.getArch())

        dbOs.family = dbOsFamily

        session.add(dbOs)

        return dbOs
Пример #2
0
    def _checkExistingKit(self, session: Session, kitname: str,
                          kitversion: str, kitarch: str):
        """
        Raises:
            KitAlreadyExists
        """

        try:
            kit = self._kit_db_api.getKit(session, kitname, kitversion)

            longname = format_kit_descriptor(kitname, kitversion, kitarch)

            # Attempt to get matching OS component
            for c in kit.getComponentList(session):
                if c.getName() != longname:
                    continue

                for cOs in c.getOsInfoList():
                    if cOs == OsInfo(kitname, kitversion, kitarch):
                        raise KitAlreadyExists(
                            "OS kit [%s] already installed" % longname)

            # Kit exists, but doesn't have a matching os component
        except KitNotFound:
            pass
Пример #3
0
    def createHardwareProfile(self):
        """
        Create hardware profile
        """

        response = None

        postdata = cherrypy.request.json

        hwProfileDict = postdata['hardwareProfile']

        settingsDict = postdata['settingsDict'] \
            if 'settingsDict' in postdata else {}

        if 'osInfo' in settingsDict and settingsDict['osInfo']:
            settingsDict['osInfo'] = OsInfo.getFromDict(settingsDict['osInfo'])

        hwProfile = HardwareProfile.getFromDict(hwProfileDict)

        try:
            HardwareProfileManager().createHardwareProfile(
                cherrypy.request.db, hwProfile, settingsDict=settingsDict)
        except Exception as ex:
            self.getLogger().exception(
                'hardware profile WS API createHardwareProfile() failed')

            self.getLogger().exception(ex)

            self.handleException(ex)

            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
Пример #4
0
def _process_component_os(osNode, component):
    bIsOsFamily = not osNode.hasAttribute('name')

    osName = osNode.getAttribute('name') \
        if not bIsOsFamily else osNode.getAttribute('family')

    osVersion = osNode.getAttribute('version') \
        if osNode.hasAttribute('version') else None

    osArch = osNode.getAttribute('arch') \
        if osNode.hasAttribute('arch') else None

    osFamilyInfo = None
    osInfo = None

    if bIsOsFamily:
        osFamilyInfo = OsFamilyInfo(osName, osVersion, osArch)
        component.addOsFamilyInfo(osFamilyInfo)
    else:
        osInfo = OsInfo(osName, osVersion, osArch)
        component.addOsInfo(osInfo)

    for pNode in osNode.getElementsByTagName('package'):
        component.addPackage(PackageFile(pNode.getAttribute('path')))

    return osInfo or osFamilyInfo
Пример #5
0
    def getFromDbDict(cls, _dict, ignore: Optional[Iterable[str]] = None):
        osDict = _dict.get(OsInfo.ROOT_TAG)
        osInfo = OsInfo.getFromDbDict(osDict.__dict__, ignore=ignore)

        osComponent = super(OsComponent, cls).getFromDict(_dict)

        osComponent.setOsInfo(osInfo)

        return osComponent
Пример #6
0
    def getFromDbDict(cls, _dict):
        osDict = _dict.get(OsInfo.ROOT_TAG)
        osInfo = OsInfo.getFromDbDict(osDict.__dict__)

        osComponent = super(OsComponent, cls).getFromDict(_dict)

        osComponent.setOsInfo(osInfo)

        return osComponent
Пример #7
0
    def __call__(self, parser, namespace, values, option_string=None):
        osValues = values.split('-', 3)

        if len(osValues) != 3:
            raise InvalidCliRequest(
                _('Error: Incorrect operating system specification.'
                  '\n\n--os argument should be in'
                  ' OSNAME-OSVERSION-OSARCH format'))

        name = osValues[0]
        version = osValues[1]
        arch = osValues[2]

        setattr(namespace, 'osInfo', OsInfo(name, version, arch))
Пример #8
0
def getPlatformOsInfo(flag=False):
    """
    Return the platform specific OS information... typically the native
    call is desired.
    """

    # (osName, osVersion, osDesc) = platform.dist()
    vals = platform.dist()

    osName = vals[0]
    osVersion = vals[1]

    # Check for multiple periods in version
    version_vals = osVersion.split('.')
    if len(version_vals) >= 2:
        osVersion = version_vals[0] + '.' + version_vals[1]

    osArch = platform.machine()

    if osArch in ['i486', 'i586', 'i686', 'i786']:
        osArch = 'i386'

    if not osName:
        vals = platform.uname()

        # (osName, hostName, osVersion, release, machine,
        #  osArch) = platform.uname()

        osName = vals[0].lower()

    if flag:
        if osName == 'redhat':
            osName = _identify_rhel_variant()
    else:
        osName = mapOsName(osName)

    return OsInfo(osName, osVersion, osArch)
Пример #9
0
    def __configure(self):
        """ Configure all repositories from the config file. """

        self._kitArchiveDir = self._cm.getKitDir()
        configFile = self._cm.getRepoConfigFile()

        if not os.path.exists(configFile):
            self._logger.debug('Repo configuration file [%s] not found' %
                               (configFile))
        else:
            self._logger.debug('Reading repo configuration file [%s]' %
                               (configFile))

        configParser = configparser.ConfigParser()
        configParser.read(configFile)

        try:
            osKeyList = configParser.sections()

            if osKeyList:
                self._logger.debug('Found OS sections [%s]' %
                                   (' '.join(osKeyList)))

            for osKey in osKeyList:
                self._logger.debug('Parsing OS section [%s]' % (osKey))

                osData = osKey.split('__')
                osName = osData[0]
                osVersion = osData[1]
                osArch = osData[2]
                osInfo = OsInfo(osName, osVersion, osArch)

                # Ignore all repos that weren't enabled
                bEnabled = True
                if configParser.has_option(osKey, 'enabled'):
                    value = configParser.get(osKey, 'enabled')
                    bEnabled = value.lower() == 'true'

                if not bEnabled:
                    self._logger.debug('Repo for [%s] is disabled' % (osInfo))

                    continue

                localPath = None
                if configParser.has_option(osKey, 'localPath'):
                    localPath = configParser.get(osKey, 'localPath', True)

                if not localPath:
                    localPath = self._repoRoot

                remoteUrl = None
                if configParser.has_option(osKey, 'remoteUrl'):
                    remoteUrl = configParser.get(osKey, 'remoteUrl', True)

                repo = self.__configureRepo(osInfo, localPath, remoteUrl)

                self._repoMap[osKey] = repo

            if not os.path.exists(self._kitArchiveDir):
                self._logger.debug('Creating kit archive directory [%s]' %
                                   (self._kitArchiveDir))

                os.makedirs(self._kitArchiveDir)

            osInfo = osUtility.getNativeOsInfo()

            repo = self.__configureRepo(osInfo, self._repoRoot)

            osKey = '%s__%s__%s' % (osInfo.getName(), osInfo.getVersion(),
                                    osInfo.getArch())

            # Configure repo for native os if there are no repos configured.
            if osKey not in self._repoMap:
                self._repoMap[osKey] = repo
        except ConfigurationError:
            raise
        except Exception as ex:
            raise ConfigurationError(exception=ex)