OBS-URL: https://build.opensuse.org/request/show/394859 OBS-URL: https://build.opensuse.org/package/show/systemsmanagement:saltstack/salt?expand=0&rev=68
104 lines
3.2 KiB
Diff
104 lines
3.2 KiB
Diff
From 92f17a79c53bb5b75b9dac4aa0add94dfe2f447f Mon Sep 17 00:00:00 2001
|
|
From: Bo Maryniuk <bo@suse.de>
|
|
Date: Mon, 9 May 2016 10:33:44 +0200
|
|
Subject: [PATCH 17/17] Add SUSE Manager plugin
|
|
|
|
---
|
|
scripts/zypper/plugins/commit/README.md | 3 ++
|
|
scripts/zypper/plugins/commit/susemanager | 73 +++++++++++++++++++++++++++++++
|
|
2 files changed, 76 insertions(+)
|
|
create mode 100644 scripts/zypper/plugins/commit/README.md
|
|
create mode 100755 scripts/zypper/plugins/commit/susemanager
|
|
|
|
diff --git a/scripts/zypper/plugins/commit/README.md b/scripts/zypper/plugins/commit/README.md
|
|
new file mode 100644
|
|
index 0000000..01c8917
|
|
--- /dev/null
|
|
+++ b/scripts/zypper/plugins/commit/README.md
|
|
@@ -0,0 +1,3 @@
|
|
+# Zypper plugins
|
|
+
|
|
+Plugins here are required to interact with SUSE Manager in conjunction of SaltStack and Zypper.
|
|
diff --git a/scripts/zypper/plugins/commit/susemanager b/scripts/zypper/plugins/commit/susemanager
|
|
new file mode 100755
|
|
index 0000000..e64d683
|
|
--- /dev/null
|
|
+++ b/scripts/zypper/plugins/commit/susemanager
|
|
@@ -0,0 +1,73 @@
|
|
+#!/usr/bin/python
|
|
+#
|
|
+# Copyright (c) 2016 SUSE Linux LLC
|
|
+# All Rights Reserved.
|
|
+#
|
|
+# This software is licensed to you under the GNU General Public License,
|
|
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
|
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
|
|
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
|
|
+# along with this software; if not, see
|
|
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
|
+#
|
|
+# Author: Bo Maryniuk <bo@suse.de>
|
|
+
|
|
+import sys
|
|
+import os
|
|
+
|
|
+import salt.client
|
|
+import salt.utils
|
|
+
|
|
+from zypp_plugin import Plugin
|
|
+
|
|
+
|
|
+class SpacewalkDriftDetector(Plugin):
|
|
+ """
|
|
+ Return diff of the installed packages outside the Salt.
|
|
+ """
|
|
+ def __init__(self):
|
|
+ Plugin.__init__(self)
|
|
+ self.salt = salt.client.Caller().sminion.functions
|
|
+
|
|
+ def _within_salt(self):
|
|
+ """
|
|
+ Return true, if Zypper is running from within the SaltStack.
|
|
+ """
|
|
+ return 'SALT_RUNNING' in os.environ
|
|
+
|
|
+ def _get_packages(self):
|
|
+ """
|
|
+ Get the list of the packages at the current time.
|
|
+ """
|
|
+ ret = dict()
|
|
+ cmd = "rpm -qa --queryformat '%{NAME}_|-%{VERSION}_|-%{RELEASE}_|-%|EPOCH?{%{EPOCH}}:{}|\\n'"
|
|
+ for line in os.popen(cmd).read().split("\n"):
|
|
+ if not line:
|
|
+ continue
|
|
+ name, pkgver, rel, epoch = line.split('_|-')
|
|
+ if epoch:
|
|
+ pkgver = '{0}:{1}'.format(epoch, pkgver)
|
|
+ if rel:
|
|
+ pkgver += '-{0}'.format(rel)
|
|
+ ret[name] = pkgver
|
|
+
|
|
+ return ret
|
|
+
|
|
+ def PLUGINBEGIN(self, headers, body):
|
|
+ """
|
|
+ Hook when plugin begins Zypper's transaction.
|
|
+ """
|
|
+ if not self._within_salt():
|
|
+ self._pkg_before = self._get_packages()
|
|
+ self.ack()
|
|
+
|
|
+ def PLUGINEND(self, headers, body):
|
|
+ """
|
|
+ Hook when plugin closes Zypper's transaction.
|
|
+ """
|
|
+ if not self._within_salt():
|
|
+ self.salt['event.send']('zypper/changed', salt.utils.compare_dicts(self._pkg_before, self._get_packages()))
|
|
+ self.ack()
|
|
+
|
|
+
|
|
+SpacewalkDriftDetector().main()
|
|
--
|
|
2.8.2
|
|
|