def find_disabled_repos(self): """Find repos disabled in redhat.repo""" repo_file = repolib.YumRepoFile() repo_file.read() disabled_in_redhat_repo = [] for section in repo_file.sections(): repo = repo_file.section(section) if not utils.is_true_value(repo.get('enabled', '0')): disabled_in_redhat_repo.append(repo.id) return disabled_in_redhat_repo
def enable_extra_channels(self, subscribed_channels): # Check if system was subscribed to extra channels like supplementary, optional, fastrack etc. # If so, enable them in the redhat.repo file extra_channels = { 'supplementary': False, 'productivity': False, 'optional': False } for subscribedChannel in subscribed_channels: if 'supplementary' in subscribedChannel: extra_channels['supplementary'] = True elif 'optional' in subscribedChannel: extra_channels['optional'] = True elif 'productivity' in subscribedChannel: extra_channels['productivity'] = True if True not in list(extra_channels.values()): return # create and populate the redhat.repo file # use the injection cp_providers consumer auth repolib.RepoActionInvoker().update() # read in the redhat.repo file repofile = repolib.YumRepoFile() repofile.read() # enable any extra channels we are using and write out redhat.repo try: for rhsmChannel in repofile.sections(): if ((extra_channels['supplementary'] and re.search('supplementary$', rhsmChannel)) or (extra_channels['optional'] and re.search('optional-rpms$', rhsmChannel)) or (extra_channels['productivity'] and re.search('productivity-rpms$', rhsmChannel))): log.info("Enabling extra channel '%s'" % rhsmChannel) repofile.set(rhsmChannel, 'enabled', '1') repofile.write() except Exception: print(_("\nCouldn't enable extra repositories.")) command = "subscription-manager repos --help" print( _("Please ensure system has subscriptions attached, and see '%s' to enable additional repositories" ) % command)
def find_temp_disabled_repos(self, enabled): """Find repo from redhat.repo that have been disabled from cli.""" yum_enabled = [x[1] for x in enabled] # Read the redhat.repo file so we can check if any of our # repos have been disabled by --disablerepo or another plugin. repo_file = repolib.YumRepoFile() repo_file.read() enabled_in_redhat_repo = [] for section in repo_file.sections(): repo = repo_file.section(section) if utils.is_true_value(repo.get('enabled', '0')): enabled_in_redhat_repo.append(repo.id) temp_disabled = [] for enabled_repo in enabled_in_redhat_repo: if enabled_repo not in yum_enabled: temp_disabled.append(enabled_repo) return temp_disabled