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
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
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))
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)
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)