Vinzenz Feenstra has uploaded a new change for review. Change subject: agent: Added APT package list support (BZ#838632) ......................................................................
agent: Added APT package list support (BZ#838632) The newly added functionality allows the guest agent to report installed packages and their version even on systems with APT package managers (e.g Debian) Change-Id: I42d9d599b1effdd1b8c205ac9523e9b31922cd73 Signed-off-by: Vinzenz Feenstra <[email protected]> --- M ovirt-guest-agent/GuestAgentLinux2.py 1 file changed, 31 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-guest-agent refs/changes/42/8642/1 diff --git a/ovirt-guest-agent/GuestAgentLinux2.py b/ovirt-guest-agent/GuestAgentLinux2.py index 55ce105..f21f840 100644 --- a/ovirt-guest-agent/GuestAgentLinux2.py +++ b/ovirt-guest-agent/GuestAgentLinux2.py @@ -31,13 +31,41 @@ (app['name'], app['version'], app['release'])) return apps + def apt_list_packages(self, app_list): + INSTALLED_STATE = self.apt_pkg.CURSTATE_INSTALLED + apps = [] + cache = self.apt_pkg.Cache() + for app in app_list.split(): + if app in cache: + pkg = cache[app] + # Normal package + if pkg.current_state == INSTALLED_STATE: + detail = (app, pkg.current_ver.ver_str) + apps.append("%s-%s" % (detail)) + # virtual package + elif len(pkg.provides_list) > 0: + for _, _, pkg in pkg.provides_list: + if pkg.parent_pkg.current_state == INSTALLED_STATE: + detail = (app, pkg.parent_pkg.current_ver.ver_str) + apps.append("%s-%s" % (detail)) + logging.debug("apt_list_packages returns: %s" % (str(apps))) + return apps + def __init__(self): - if os.path.exists('/etc/redhat-release'): + try: + # RHEL and Fedora should have the rpm package available import rpm self.rpm = rpm self.list_pkgs = self.rpm_list_packages - else: - raise NotImplementedError + except: + try: + # Debian should have apt + from apt import apt_pkg + apt_pkg.init() + self.apt_pkg = apt_pkg + self.list_pkgs = self.apt_list_packages + except: + raise NotImplementedError class NicMgr(object): -- To view, visit http://gerrit.ovirt.org/8642 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I42d9d599b1effdd1b8c205ac9523e9b31922cd73 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-guest-agent Gerrit-Branch: master Gerrit-Owner: Vinzenz Feenstra <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
