From e7f94617ef01a31ca90550cfa661d1b2618671b1 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 1 Jun 2012 15:56:33 -0400 Subject: fixed caching of Collection objects; moved bcfg2-info packagesources code into Collection.py --- .../Bcfg2/Server/Plugins/Packages/Collection.py | 33 +++++++++++++++++++--- src/sbin/bcfg2-info | 25 +--------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Collection.py b/src/lib/Bcfg2/Server/Plugins/Packages/Collection.py index b2155dfa9..efa50f0a6 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Collection.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Collection.py @@ -1,4 +1,4 @@ -import sys + import sys import copy import logging import Bcfg2.Server.Plugin @@ -52,13 +52,38 @@ class Collection(Bcfg2.Server.Plugin.Debuggable): @property def cachekey(self): - return md5(self.get_config().encode(Bcfg2.Server.Plugin.encoding)).hexdigest() + return md5(self.sourcelist().encode(Bcfg2.Server.Plugin.encoding)).hexdigest() def get_config(self): - self.logger.error("Packages: Cannot generate config for host with " - "multiple source types (%s)" % self.metadata.hostname) + self.logger.error("Packages: Cannot generate config for host %s with " + "no sources or multiple source types" % + self.metadata.hostname) return "" + def sourcelist(self): + srcs = [] + for source in self.sources: + # get_urls() loads url_map as a side-effect + source.get_urls() + for url_map in source.url_map: + reponame = source.get_repo_name(url_map) + srcs.append("Name: %s" % reponame) + srcs.append(" Type: %s" % source.ptype) + if url_map['url']: + srcs.append(" URL: %s" % url_map['url']) + elif url_map['rawurl']: + srcs.append(" RAWURL: %s" % url_map['rawurl']) + if source.gpgkeys: + srcs.append(" GPG Key(s): %s" % ", ".join(source.gpgkeys)) + else: + srcs.append(" GPG Key(s): None") + if len(source.blacklist): + srcs.append(" Blacklist: %s" % ", ".join(source.blacklist)) + if len(source.whitelist): + srcs.append(" Whitelist: %s" % ", ".join(source.whitelist)) + srcs.append("") + return "\n".join(srcs) + def get_relevant_groups(self): groups = [] for source in self.sources: diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index fd1012925..859826e67 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -601,30 +601,7 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core): print("Unable to build metadata for host %s" % args) return collection = self.plugins['Packages']._get_collection(metadata) - for source in collection.sources: - # get_urls() loads url_map as a side-effect - source.get_urls() - for url_map in source.url_map: - for arch in url_map['arches']: - # make sure client is in all the proper arch groups - if arch not in metadata.groups: - continue - reponame = source.get_repo_name(url_map) - print("Name: %s" % reponame) - print(" Type: %s" % source.ptype) - if url_map['url'] != '': - print(" URL: %s" % url_map['url']) - elif url_map['rawurl'] != '': - print(" RAWURL: %s" % url_map['rawurl']) - if source.gpgkeys: - print(" GPG Key(s): %s" % ", ".join(source.gpgkeys)) - else: - print(" GPG Key(s): None") - if len(source.blacklist): - print(" Blacklist: %s" % ", ".join(source.blacklist)) - if len(source.whitelist): - print(" Whitelist: %s" % ", ".join(source.whitelist)) - print("") + print collection.sourcelist() def do_profile(self, arg): """.""" -- cgit v1.2.3-1-g7c22