def _listChannels(channelList, is_source, include_checksums): # Lists the packages from these channels # Uniquify the channels channels = set(channelList) rez = [] for channel in channels: c_info = rhnChannel.channel_info(channel) if not c_info: # No packages in this channel continue if is_source: packageList = rhnChannel.list_packages_source(c_info['id']) else: if include_checksums: packageList = rhnChannel.list_packages_checksum_sql( c_info['id']) else: packageList = rhnChannel.list_packages_sql(c_info['id']) for p in packageList: if is_source: for pkg in range(len(p)): if p[pkg] is None: p[pkg] = "" print(p) rez.append([p[0], p[1], p[2], p[3], channel]) else: if include_checksums: rez.append([p[0], p[1], p[2], p[3], p[4], p[6], p[7], channel]) else: rez.append([p[0], p[1], p[2], p[3], p[4], channel]) return rez
def _listChannels(channelList, is_source, include_checksums): # Lists the packages from these channels # Uniquify the channels channels = set(channelList) rez = [] for channel in channels: c_info = rhnChannel.channel_info(channel) if not c_info: # No packages in this channel continue if is_source: packageList = rhnChannel.list_packages_source(c_info['id']) else: if include_checksums: packageList = rhnChannel.list_packages_checksum_sql( c_info['id']) else: packageList = rhnChannel.list_packages_sql(c_info['id']) for p in packageList: if is_source: for pkg in range(len(p)): if p[pkg] is None: p[pkg] = "" print p rez.append([p[0], p[1], p[2], p[3], channel]) else: if include_checksums: rez.append( [p[0], p[1], p[2], p[3], p[4], p[6], p[7], channel]) else: rez.append([p[0], p[1], p[2], p[3], p[4], channel]) return rez
def get_comps_file(self): """ Return a file-like object of the comps.xml for the channel. """ if self.channel.comps: comps_view = view.CompsView(self.channel.comps) return comps_view.get_file() elif self.channel.label in comps_mapping: comps_view = view.CompsView( Comps( None, os.path.join(CFG.mount_point, comps_mapping[self.channel.label]))) return comps_view.get_file() else: if self.channel.cloned_from_id is not None: log_debug( 1, "No comps and no comps_mapping for [%s] cloned from [%s] trying to get comps from the original one." % (self.channel.id, self.channel.cloned_from_id)) cloned_from_channel = rhnChannel.Channel().load_by_id( self.channel.cloned_from_id) cloned_from_channel_label = cloned_from_channel._row['label'] return Repository( rhnChannel.channel_info( cloned_from_channel_label)).get_comps_file() return None
def setup_repos_and_sync(self, channels=None, add_repos=None, delete_repos=None): # Fix format of relative url if add_repos: repos = set() for repo in add_repos: repo = repo.replace(CFG.CDN_ROOT, '') repo_dirs = self.cdn_repository_manager.repository_tree.normalize_url(repo) repo = os.path.join('/', '/'.join(repo_dirs)) repos.add(repo) add_repos = list(repos) if delete_repos: repos = set() for repo in delete_repos: repo = repo.replace(CFG.CDN_ROOT, '') repo_dirs = self.cdn_repository_manager.repository_tree.normalize_url(repo) repo = os.path.join('/', '/'.join(repo_dirs)) repos.add(repo) delete_repos = list(repos) # We need single custom channel if not channels or len(channels) > 1: raise CustomChannelSyncError("Single custom channel needed.") channel = list(channels)[0] db_channel = channel_info(channel) if add_repos and not self._can_add_repos(db_channel, add_repos): raise CustomChannelSyncError("Unable to attach requested repositories to this channel.") # Add custom repositories to custom channel changed = self.cdn_repository_manager.assign_repositories_to_channel(channel, delete_repos=delete_repos, add_repos=add_repos) # Add to synced channels and sync if there are any changed repos if changed and channel not in self.synced_channels: self.synced_channels[channel] = db_channel['org_id'] return self.sync(channels=channels)
def _listChannels(channelList, is_source): # Lists the packages from these channels # Uniquify the channels channels = set(channelList) rez = [] for channel in channels: c_info = rhnChannel.channel_info(channel) if not c_info: # No packages in this channel continue if is_source: packageList = rhnChannel.list_packages_source(c_info['id']) else: packageList = rhnChannel.list_packages_sql(c_info['id']) for p in packageList: if is_source: for pkg in range(len(p)): if p[pkg] is None: p[pkg] = "" print p rez.append([p[0], p[1], p[2], p[3], channel]) else: # We don't care about the size for now, even if we all know size # matters :-) rez.append([p[0], p[1], p[2], p[3], p[4], channel]) return rez
def _repodata_python(self, file_name): log_debug(3, 'repodata', file_name) c_info = rhnChannel.channel_info(self.channelName) repo = repository.get_repository(c_info) output = None content_type = "application/x-gzip" if file_name == "repomd.xml": content_type = "text/xml" output = repo.get_repomd_file() elif file_name == "primary.xml.gz": output = repo.get_primary_xml_file() elif file_name == "other.xml.gz": output = repo.get_other_xml_file() elif file_name == "filelists.xml.gz": output = repo.get_filelists_xml_file() elif file_name == "updateinfo.xml.gz": output = repo.get_updateinfo_xml_file() elif file_name == "comps.xml": content_type = "text/xml" output = repo.get_comps_file() else: log_debug(2, "Unknown repomd file requested: %s" % file_name) raise rhnFault(6) output = rpclib.transports.File(output, name=file_name) rhnFlags.set('Content-Type', content_type) return output
def get_repomd_file(self, repomd_obj, func_name): """ Return a file-like object of the comps.xml/modules.yaml for the channel. """ if repomd_obj: repomd_view = view.RepoMDView(repomd_obj) return repomd_view.get_file() elif func_name == 'get_comps_file' and self.channel.label in comps_mapping: comps_view = view.RepoMDView( RepoMD( None, os.path.join(CFG.mount_point, comps_mapping[self.channel.label]))) return comps_view.get_file() else: if self.channel.cloned_from_id is not None: log_debug( 1, "No comps/modules and no comps_mapping for [%s] cloned from [%s] trying to get comps from the original one." % (self.channel.id, self.channel.cloned_from_id)) cloned_from_channel = rhnChannel.Channel().load_by_id( self.channel.cloned_from_id) cloned_from_channel_label = cloned_from_channel._row['label'] func = getattr( Repository( rhnChannel.channel_info(cloned_from_channel_label)), func_name) return func() return None
def _is_channel_available(self, label): # Checking channel availability, it means either: # 1. Trying to sync custom channel - in this case, it has to have already associated CDN repositories, # it's ensured by query populating synced_channels variable # 2. Trying to sync channel from mappings - it may not exists so we check requirements from mapping files db_channel = channel_info(label) if db_channel and db_channel['org_id']: # Custom channel doesn't have any null-org repositories assigned if label not in self.synced_channels: log2(0, 0, "ERROR: Custom channel '%s' doesn't contain any CDN repositories." % label, stream=sys.stderr) return False else: if label not in self.channel_metadata: log2(1, 1, "WARNING: Channel '%s' not found in channel metadata mapping." % label, stream=sys.stderr) return False elif label not in self.channel_to_family: log2(0, 0, "ERROR: Channel '%s' not found in channel family mapping." % label, stream=sys.stderr) return False family = self.channel_to_family[label] if family not in self.entitled_families: log2(0, 0, "ERROR: Channel family '%s' containing channel '%s' is not entitled." % (family, label), stream=sys.stderr) return False elif not self.cdn_repository_manager.check_channel_availability(label, self.no_kickstarts): log2(0, 0, "ERROR: Channel '%s' repositories are not available." % label, stream=sys.stderr) return False return True
def listChannels(channelList): # Lists the packages from these channels # Uniquify the channels channelHash = {} channels = [] for channel in channelList: if channelHash.has_key(channel): # Already seen continue channels.append(channel) channelHash[channel] = None # channels is the unique list of channels now rez = [] for channel in channels: c_info = rhnChannel.channel_info(channel) if not c_info: # No packages in this channel continue packageList = rhnChannel.list_packages_sql(c_info['id']) for p in packageList: # We don't care about the size for now, even if we all know size # matters :-) rez.append([p[0], p[1], p[2], p[3], p[4], channel]) return rez
def listChannelsSource(channelList): # Lists the packages from these channels # Uniquify the channels channelHash = {} channels = [] for channel in channelList: if channelHash.has_key(channel): # Already seen continue channels.append(channel) channelHash[channel] = None # channels is the unique list of channels now rez = [] for channel in channels: c_info = rhnChannel.channel_info(channel) if not c_info: # No packages in this channel continue packageList = rhnChannel.list_packages_source(c_info['id']) for p in packageList: for pkg in range(len(p)): if p[pkg] is None: p[pkg] = "" print p rez.append([p[0], p[1], p[2], p[3], channel]) return rez
def setup_repos_and_sync(self, channels=None, add_repos=None, delete_repos=None): # Fix format of relative url if add_repos: for index, repo in enumerate(add_repos): repo = repo.replace(CFG.CDN_ROOT, '') repo = os.path.join('/', repo) add_repos[index] = repo if delete_repos: for index, repo in enumerate(delete_repos): repo = repo.replace(CFG.CDN_ROOT, '') repo = os.path.join('/', repo) delete_repos[index] = repo # We need single custom channel if not channels or len(channels) > 1: raise CustomChannelSyncError("Single custom channel needed.") channel = list(channels)[0] db_channel = channel_info(channel) if add_repos and not self._can_add_repos(db_channel, add_repos): raise CustomChannelSyncError("Unable to attach requested repositories to this channel.") # Add custom repositories to custom channel new_repos_count = self.cdn_repository_manager.assign_repositories_to_channel(channel, delete_repos=delete_repos, add_repos=add_repos) if new_repos_count: # Add to synced channels if there are any repos if channel not in self.synced_channels: self.synced_channels[channel] = db_channel['org_id'] error_messages = self.sync(channels=channels) else: log(0, "No repositories attached to channel. Skipping sync.") error_messages = None return error_messages
def _repodata_python(self, file_name): log_debug(3, 'repodata', file_name) c_info = rhnChannel.channel_info(self.channelName) repo = repository.get_repository(c_info) output = None content_type = "application/x-gzip" if file_name == "repomd.xml": content_type = "text/xml" output = repo.get_repomd_file() elif file_name == "primary.xml.gz": output = repo.get_primary_xml_file() elif file_name == "other.xml.gz": output = repo.get_other_xml_file() elif file_name == "filelists.xml.gz": output = repo.get_filelists_xml_file() elif file_name == "updateinfo.xml.gz": output = repo.get_updateinfo_xml_file() elif file_name == "comps.xml": content_type = "text/xml" output = repo.get_comps_file() elif file_name == "modules.yaml": output = repo.get_modules_file() else: log_debug(2, "Unknown repomd file requested: %s" % file_name) raise rhnFault(6) output = rpclib.transports.File(output, name=file_name) rhnFlags.set('Content-Type', content_type) return output
def _is_channel_available(self, label): # Checking channel availability, it means either: # 1. Trying to sync custom channel - in this case, it has to have already associated CDN repositories, # it's ensured by query populating synced_channels variable # 2. Trying to sync channel from mappings - it may not exists so we check requirements from mapping files db_channel = channel_info(label) if db_channel and db_channel['org_id']: # Custom channel doesn't have any null-org repositories assigned if label not in self.synced_channels: log2(0, 0, "ERROR: Custom channel '%s' doesn't contain any CDN repositories." % label, stream=sys.stderr) return False else: if label not in self.channel_metadata: log2(0, 0, "ERROR: Channel '%s' not found in channel metadata mapping." % label, stream=sys.stderr) return False elif label not in self.channel_to_family: log2(0, 0, "ERROR: Channel '%s' not found in channel family mapping." % label, stream=sys.stderr) return False family = self.channel_to_family[label] if family not in self.entitled_families: log2(0, 0, "ERROR: Channel family '%s' containing channel '%s' is not entitled." % (family, label), stream=sys.stderr) return False elif not self.cdn_repository_manager.check_channel_availability(label, self.no_kickstarts): log2(0, 0, "ERROR: Channel '%s' repositories are not available." % label, stream=sys.stderr) return False return True
def preprocess(self): for content_source in self.batch: # Link back content sources to channel objects to subscribe them to existing channels right after import if 'channels' in content_source and content_source['channels'] is not None: for channel_label in content_source['channels']: if channel_label not in self.channels_to_link: db_channel = channel_info(channel_label) channel_obj = Channel() channel_obj.id = db_channel['id'] channel_obj['content-sources'] = [] self.channels_to_link[channel_label] = channel_obj self.channels_to_link[channel_label]['content-sources'].append(content_source)
def get_comps_file(self): """ Return a file-like object of the comps.xml for the channel. """ if self.channel.comps: comps_view = view.CompsView(self.channel.comps) return comps_view.get_file() elif comps_mapping.has_key(self.channel.label): comps_view = view.CompsView(Comps(None, os.path.join(CFG.mount_point, comps_mapping[self.channel.label]))) return comps_view.get_file() else: if self.channel.cloned_from_id is not None: log_debug(1, "No comps and no comps_mapping for [%s] cloned from [%s] trying to get comps from the original one." % (self.channel.id, self.channel.cloned_from_id)) cloned_from_channel = rhnChannel.Channel().load_by_id(self.channel.cloned_from_id) cloned_from_channel_label = cloned_from_channel._row['label'] return Repository(rhnChannel.channel_info(cloned_from_channel_label)).get_comps_file() return None
def get_repomd_file(self, repomd_obj, func_name): """ Return a file-like object of the comps.xml/modules.yaml for the channel. """ if repomd_obj: repomd_view = view.RepoMDView(repomd_obj) return repomd_view.get_file() elif func_name == 'get_comps_file' and self.channel.label in comps_mapping: comps_view = view.RepoMDView(RepoMD(None, os.path.join(CFG.mount_point, comps_mapping[self.channel.label]))) return comps_view.get_file() else: if self.channel.cloned_from_id is not None: log_debug(1, "No comps/modules and no comps_mapping for [%s] cloned from [%s] trying to get comps from the original one." % (self.channel.id, self.channel.cloned_from_id)) cloned_from_channel = rhnChannel.Channel().load_by_id(self.channel.cloned_from_id) cloned_from_channel_label = cloned_from_channel._row['label'] func = getattr(Repository(rhnChannel.channel_info(cloned_from_channel_label)), func_name) return func() return None
def setup_repos_and_sync(self, channels=None, add_repos=None, delete_repos=None): # Fix format of relative url if add_repos: for index, repo in enumerate(add_repos): repo = repo.replace(CFG.CDN_ROOT, '') repo = os.path.join('/', repo) add_repos[index] = repo if delete_repos: for index, repo in enumerate(delete_repos): repo = repo.replace(CFG.CDN_ROOT, '') repo = os.path.join('/', repo) delete_repos[index] = repo # We need single custom channel if not channels or len(channels) > 1: raise CustomChannelSyncError("Single custom channel needed.") channel = list(channels)[0] db_channel = channel_info(channel) if add_repos and not self._can_add_repos(db_channel, add_repos): raise CustomChannelSyncError( "Unable to attach requested repositories to this channel.") # Add custom repositories to custom channel new_repos_count = self.cdn_repository_manager.assign_repositories_to_channel( channel, delete_repos=delete_repos, add_repos=add_repos) if new_repos_count: # Add to synced channels if there are any repos if channel not in self.synced_channels: self.synced_channels[channel] = db_channel['org_id'] error_messages = self.sync(channels=channels) else: log(0, "No repositories attached to channel. Skipping sync.") error_messages = None return error_messages
def __save(self, channel): tokens_obj = rhnFlags.get("registration_token") if self.server.real: server_id = self.server["id"] self.server.save() else: # create new entry self.gen_secret() server_id = self.getid() org_id = self.server["org_id"] if self.user: user_id = self.user.getid() else: user_id = None # some more default values self.server["auto_update"] = "N" if self.user and not self.server.has_key("creator_id"): # save the link to the user that created it if we have # that information self.server["creator_id"] = self.user.getid() # and create the server entry self.server.create(server_id) server_lib.create_server_setup(server_id, org_id) self.handle_virtual_guest() # if we're using a token, then the following channel # subscription request can allow no matches since the # token code will fix up or fail miserably later. # subscribe the server to applicable channels # bretm 02/17/2007 -- TODO: refactor activation key codepaths # to allow us to not have to pass in none_ok=1 in any case # # This can now throw exceptions which will be caught at a higher level if channel is not None: channel_info = dict(rhnChannel.channel_info(channel)) log_debug(4, "eus channel id %s" % str(channel_info)) rhnChannel.subscribe_sql(server_id, channel_info['id']) else: rhnChannel.subscribe_server_channels(self, none_ok=tokens_obj, user_id=user_id) if not tokens_obj: # Attempt to auto-entitle, can throw the following exceptions: # rhnSystemEntitlementException # rhnNoSystemEntitlementsException self.autoentitle() # If a new server that was registered by an user (i.e. not # with a registration token), look for this user's default # groups self.join_groups() server_lib.join_rhn(org_id) # Update virtual guest attributes on re-registration if tokens_obj and tokens_obj.is_rereg_token: self.handle_virtual_guest() # Update the uuid - but don't commit yet self.update_uuid(self.uuid, commit=0) self.create_perm_cache() # And save the extra profile data... self.save_packages_byid(server_id, schedule=1) self.save_hardware_byid(server_id) self.save_history_byid(server_id) return 0
def __save(self, channel): tokens_obj = rhnFlags.get("registration_token") if self.server.real: server_id = self.server["id"] self.server.save() else: # create new entry self.gen_secret() server_id = self.getid() org_id = self.server["org_id"] if self.user: user_id = self.user.getid() else: user_id = None # some more default values self.server["auto_update"] = "N" if self.user and not self.server.has_key("creator_id"): # save the link to the user that created it if we have # that information self.server["creator_id"] = self.user.getid() # and create the server entry self.server.create(server_id) server_lib.create_server_setup(server_id, org_id) self.handle_virtual_guest() # if we're using a token, then the following channel # subscription request can allow no matches since the # token code will fix up or fail miserably later. # subscribe the server to applicable channels # bretm 02/17/2007 -- TODO: refactor activation key codepaths # to allow us to not have to pass in none_ok=1 in any case # # This can now throw exceptions which will be caught at a higher level if channel is not None: channel_info = dict(rhnChannel.channel_info(channel)) log_debug(4, "eus channel id %s" % str(channel_info)) rhnChannel.subscribe_sql(server_id, channel_info['id']) else: rhnChannel.subscribe_server_channels(self, none_ok=tokens_obj, user_id=user_id) if not tokens_obj: # Attempt to auto-entitle, can throw the following exceptions: # rhnSystemEntitlementException # rhnNoSystemEntitlementsException self.autoentitle() # If a new server that was registered by an user (i.e. not # with a registration token), look for this user's default # groups self.join_groups() server_lib.join_rhn(org_id) # Update virtual guest attributes on re-registration if getattr(tokens_obj, "is_rereg_token", False): self.handle_virtual_guest() # Update the uuid - but don't commit yet self.update_uuid(self.uuid, commit=0) self.create_perm_cache() # And save the extra profile data... self.save_suse_products_byid(server_id) self.save_packages_byid(server_id, schedule=1) self.save_hardware_byid(server_id) self.save_history_byid(server_id) return 0
def load_channel(self): return rhnChannel.channel_info(self.channel_label)