def __init__(self): rhnSQL.initDB() self.repository_tree = CdnRepositoryTree() self._populate_repository_tree() f = None try: try: # Channel to repositories mapping f = open(constants.CONTENT_SOURCE_MAPPING_PATH, 'r') self.content_source_mapping = json.load(f) f.close() # Channel to kickstart repositories mapping f = open(constants.KICKSTART_SOURCE_MAPPING_PATH, 'r') self.kickstart_source_mapping = json.load(f) f.close() # Kickstart metadata f = open(constants.KICKSTART_DEFINITIONS_PATH, 'r') self.kickstart_metadata = json.load(f) f.close() except IOError: e = sys.exc_info()[1] log2stderr(0, "ERROR: Problem with loading file: %s" % e) raise CdnMappingsLoadError() finally: if f is not None: f.close()
def print_channel_tree(self, repos=False): available_channel_tree = self._list_available_channels() backend = SQLBackend() if not available_channel_tree: log2stderr(0, "No available channels were found. Is your %s activated for CDN?" % PRODUCT_NAME) return log(0, "p = previously imported/synced channel") log(0, ". = channel not yet imported/synced") log(0, "? = No CDN source provided to count number of packages") log(0, "Base channels:") for channel in sorted(available_channel_tree): status = 'p' if channel in self.synced_channels else '.' sources = self._get_content_sources(channel, backend) if sources: packages_number = '0' else: packages_number = '?' try: packages_number = open(constants.CDN_REPODATA_ROOT + '/' + channel + "/packages_num", 'r').read() # pylint: disable=W0703 except Exception: pass log(0, " %s %s %s" % (status, channel, packages_number)) if repos: if sources: for source in sources: log(0, " %s" % source['source_url']) else: log(0, " No CDN source provided!") # print information about child channels for channel in sorted(available_channel_tree): # Print only if there are any child channels if len(available_channel_tree[channel]) > 0: log(0, "%s:" % channel) for child in sorted(available_channel_tree[channel]): status = 'p' if child in self.synced_channels else '.' sources = self._get_content_sources(child, backend) if sources: packages_number = '0' else: packages_number = '?' try: packages_number = open(constants.CDN_REPODATA_ROOT + '/' + child + "/packages_num", 'r').read() # pylint: disable=W0703 except Exception: pass log(0, " %s %s %s" % (status, child, packages_number)) if repos: if sources: for source in sources: log(0, " %s" % source['source_url']) else: log(0, " No CDN source provided!")
def _list_available_channels(self): # Select channel families in DB h = rhnSQL.prepare(""" select label from rhnChannelFamilyPermissions cfp inner join rhnChannelFamily cf on cfp.channel_family_id = cf.id where cf.org_id is null """) h.execute() families = h.fetchall_dict() or [] # collect all channel from available families all_channels = [] channel_tree = {} # Not available parents of child channels not_available_channels = [] for family in families: label = family['label'] try: family = self.families[label] except KeyError: log2stderr(0, "ERROR: Unknown channel family: %s" % label) continue channels = [c for c in family['channels'] if c is not None] all_channels.extend(channels) # filter available channels all_channels = [ x for x in all_channels if self.cdn_repository_manager.check_channel_availability( x, self.no_kickstarts) ] for base_channel in [ x for x in all_channels if not self.channel_metadata[x]['parent_channel'] ]: channel_tree[base_channel] = [] for child_channel in [ x for x in all_channels if self.channel_metadata[x]['parent_channel'] ]: parent_channel = self.channel_metadata[child_channel][ 'parent_channel'] # Parent not available, orphaned child channel if parent_channel not in channel_tree: channel_tree[parent_channel] = [] not_available_channels.append(parent_channel) channel_tree[parent_channel].append(child_channel) return channel_tree, not_available_channels
def _list_available_channels(self): # Select channel families in DB h = rhnSQL.prepare(""" select label from rhnChannelFamilyPermissions cfp inner join rhnChannelFamily cf on cfp.channel_family_id = cf.id where cf.org_id is null """) h.execute() families = h.fetchall_dict() or [] # collect all channel from available families all_channels = [] base_channels = {} for family in families: label = family['label'] try: family = self.families[label] except KeyError: log2stderr(0, "ERROR: Unknown channel family: %s" % label) continue channels = [c for c in family['channels'] if c is not None] all_channels.extend(channels) # filter available channels all_channels = [ x for x in all_channels if self.cdn_repository_manager.check_channel_availability(x) ] # fill base_channel for channel in all_channels: try: # Only base channels as key in dictionary if self.channel_metadata[channel]['parent_channel'] is None: base_channels[channel] = [ k for k in all_channels if self.channel_metadata[k] ['parent_channel'] == channel ] except KeyError: log(1, "Channel %s not found in channel metadata" % channel) continue return base_channels
def _list_available_channels(self): # Select channel families in DB h = rhnSQL.prepare(""" select label from rhnChannelFamilyPermissions cfp inner join rhnChannelFamily cf on cfp.channel_family_id = cf.id where cf.org_id is null """) h.execute() families = h.fetchall_dict() or [] # collect all channel from available families all_channels = [] channel_tree = {} # Not available parents of child channels not_available_channels = [] for family in families: label = family['label'] try: family = self.families[label] except KeyError: log2stderr(0, "ERROR: Unknown channel family: %s" % label) continue channels = [c for c in family['channels'] if c is not None] all_channels.extend(channels) # filter available channels all_channels = [x for x in all_channels if self.cdn_repository_manager.check_channel_availability(x, self.no_kickstarts)] for base_channel in [x for x in all_channels if not self.channel_metadata[x]['parent_channel']]: channel_tree[base_channel] = [] for child_channel in [x for x in all_channels if self.channel_metadata[x]['parent_channel']]: parent_channel = self.channel_metadata[child_channel]['parent_channel'] # Parent not available, orphaned child channel if parent_channel not in channel_tree: channel_tree[parent_channel] = [] not_available_channels.append(parent_channel) channel_tree[parent_channel].append(child_channel) return channel_tree, not_available_channels
def print_channel_tree(self, repos=False): available_channel_tree = self._list_available_channels() backend = SQLBackend() if not available_channel_tree: log2stderr( 0, "No available channels were found. Is your %s activated for CDN?" % PRODUCT_NAME) return log(0, "p = previously imported/synced channel") log(0, ". = channel not yet imported/synced") log(0, "? = No CDN source provided to count number of packages") log(0, "Base channels:") for channel in sorted(available_channel_tree): if channel in self.synced_channels: status = 'p' else: status = '.' sources = self._get_content_sources(channel, backend) if sources: packages_number = '0' else: packages_number = '?' try: packages_number = open( constants.CDN_REPODATA_ROOT + '/' + channel + "/packages_num", 'r').read() # pylint: disable=W0703 except Exception: pass log(0, " %s %s %s" % (status, channel, packages_number)) if repos: if sources: for source in sources: log(0, " %s" % source['source_url']) else: log(0, " No CDN source provided!") # print information about child channels for channel in sorted(available_channel_tree): # Print only if there are any child channels if len(available_channel_tree[channel]) > 0: log(0, "%s:" % channel) for child in sorted(available_channel_tree[channel]): if child in self.synced_channels: status = 'p' else: status = '.' sources = self._get_content_sources(child, backend) if sources: packages_number = '0' else: packages_number = '?' try: packages_number = open( constants.CDN_REPODATA_ROOT + '/' + child + "/packages_num", 'r').read() # pylint: disable=W0703 except Exception: pass log(0, " %s %s %s" % (status, child, packages_number)) if repos: if sources: for source in sources: log(0, " %s" % source['source_url']) else: log(0, " No CDN source provided!")
def __init__(self, no_packages=False, no_errata=False, no_rpms=False, no_kickstarts=False, log_level=None): self.no_packages = no_packages self.no_errata = no_errata self.no_rpms = no_rpms self.no_kickstarts = no_kickstarts if log_level is None: log_level = 0 self.log_level = log_level CFG.set('DEBUG', log_level) rhnLog.initLOG(self.log_path, self.log_level) log2disk(0, "Command: %s" % str(sys.argv)) rhnSQL.initDB() initCFG('server.satellite') f = None # try block in try block - this is hack for python 2.4 compatibility # to support finally try: try: # Channel families mapping to channels f = open(constants.CHANNEL_FAMILY_MAPPING_PATH, 'r') self.families = json.load(f) f.close() # Channel metadata f = open(constants.CHANNEL_DEFINITIONS_PATH, 'r') self.channel_metadata = json.load(f) f.close() # Dist/Release channel mapping f = open(constants.CHANNEL_DIST_MAPPING_PATH, 'r') self.channel_dist_mapping = json.load(f) f.close() # Channel to repositories mapping f = open(constants.CONTENT_SOURCE_MAPPING_PATH, 'r') self.content_source_mapping = json.load(f) f.close() # Kickstart metadata f = open(constants.KICKSTART_DEFINITIONS_PATH, 'r') self.kickstart_metadata = json.load(f) f.close() # Channel to kickstart repositories mapping f = open(constants.KICKSTART_SOURCE_MAPPING_PATH, 'r') self.kickstart_source_mapping = json.load(f) f.close() except IOError: e = sys.exc_info()[1] log2stderr(0, "ERROR: Problem with loading file: %s" % e) raise CdnMappingsLoadError() finally: if f is not None: f.close() # Map channels to their channel family self.channel_to_family = {} for family in self.families: for channel in self.families[family]['channels']: self.channel_to_family[channel] = family # Set already synced channels h = rhnSQL.prepare(""" select label from rhnChannel where org_id is null """) h.execute() channels = h.fetchall_dict() or [] self.synced_channels = [ch['label'] for ch in channels] # Set SSL-keys for channel family self.family_keys = {}
def __init__(self, no_packages=False, no_errata=False, no_rpms=False, no_kickstarts=False, log_level=None): self.no_packages = no_packages self.no_errata = no_errata self.no_rpms = no_rpms self.no_kickstarts = no_kickstarts if log_level is None: log_level = 0 self.log_level = log_level CFG.set('DEBUG', log_level) rhnLog.initLOG(self.log_path, self.log_level) log2disk(0, "Command: %s" % str(sys.argv)) rhnSQL.initDB() initCFG('server.satellite') try: # Channel families mapping to channels with open(constants.CHANNEL_FAMILY_MAPPING_PATH, 'r') as f: self.families = json.load(f) # Channel metadata with open(constants.CHANNEL_DEFINITIONS_PATH, 'r') as f: self.channel_metadata = json.load(f) # Dist/Release channel mapping with open(constants.CHANNEL_DIST_MAPPING_PATH, 'r') as f: self.channel_dist_mapping = json.load(f) # Channel to repositories mapping with open(constants.CONTENT_SOURCE_MAPPING_PATH, 'r') as f: self.content_source_mapping = json.load(f) # Kickstart metadata with open(constants.KICKSTART_DEFINITIONS_PATH, 'r') as f: self.kickstart_metadata = json.load(f) # Channel to kickstart repositories mapping with open(constants.KICKSTART_SOURCE_MAPPING_PATH, 'r') as f: self.kickstart_source_mapping = json.load(f) except IOError: e = sys.exc_info()[1] log2stderr(0, "ERROR: Problem with loading file: %s" % e) raise CdnMappingsLoadError() # Map channels to their channel family self.channel_to_family = {} for family in self.families: for channel in self.families[family]['channels']: self.channel_to_family[channel] = family # Set already synced channels h = rhnSQL.prepare(""" select label from rhnChannel where org_id is null """) h.execute() channels = h.fetchall_dict() or [] self.synced_channels = [ch['label'] for ch in channels] # Set SSL-keys for channel family self.family_keys = {}