]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
script: subscription-manager support 7907/head
authorLoic Dachary <ldachary@redhat.com>
Thu, 3 Mar 2016 16:07:10 +0000 (23:07 +0700)
committerLoic Dachary <ldachary@redhat.com>
Thu, 17 Mar 2016 10:07:34 +0000 (11:07 +0100)
The script is designed to create a fact file for subscription-manager to
consume. It is run hourly from /etc/cron.hourly on RHEL.

http://tracker.ceph.com/issues/14972 Fixes: #14972

Signed-off-by: Loic Dachary <loic@dachary.org>
ceph.spec.in
configure.ac
src/Makefile.am
src/script/subman.py [new file with mode: 0755]

index a8b1f0228492b2d422e15929fa86e5dd11b9af91..1775d8dcec8a63a9d16c20d1aae36b41f9e1ad2e 100644 (file)
@@ -692,6 +692,9 @@ export RPM_OPT_FLAGS=`echo $RPM_OPT_FLAGS | sed -e 's/i386/i486/'`
                 --libexecdir=%{_libexecdir} \
                --localstatedir=/var \
                --sysconfdir=/etc \
+%if 0%{?rhel}
+                --enable-subman \
+%endif
 %if 0%{?_with_systemd}
                --with-systemdsystemunitdir=%_unitdir \
 %endif
@@ -1183,6 +1186,9 @@ fi
 %{_mandir}/man8/ceph-clsinfo.8*
 %{_mandir}/man8/ceph-disk.8*
 %{_mandir}/man8/ceph-osd.8*
+%if 0%{?rhel}
+/etc/cron.hourly/subman.py
+%endif
 %if 0%{?_with_systemd}
 %{_unitdir}/ceph-osd@.service
 %{_unitdir}/ceph-osd.target
index b95b8e9708a3dbd5492c171656e2c832a37f325f..42e16a12885dd5723bb1f26aae5024bd4b5ef64b 100644 (file)
@@ -207,6 +207,13 @@ AC_ARG_ENABLE([server],
 AM_CONDITIONAL(ENABLE_SERVER, test "$enable_server" = "yes")
 #AS_IF([test "$enable_server" = "yes"], [AC_DEFINE([WITH_MON, WITH_OSD, WITH_MDS, ENABLE_SERVER])])
 
+# subscription manager?
+AC_ARG_ENABLE([subman],
+       [AS_HELP_STRING([--enable-subman], [enable subman])],
+       [],
+       [enable_subman=yes])
+AM_CONDITIONAL([ENABLE_SUBMAN], test "$enable_subman" = "yes")
+
 # cython is required to build python bindings for libraries
 if test x"$with_cython" = xyes; then
     AC_CHECK_PROG(CYTHON_CHECK, cython, yes)
index d2f99b85a70415c9b654125eb3a43f8cea80e758..c3f59654f218658124c0591abf8ca800cc9342c4 100644 (file)
@@ -107,6 +107,7 @@ EXTRA_DIST += \
        $(srcdir)/.git_version \
        $(srcdir)/ceph-rbdnamer \
        $(srcdir)/tools/ceph-monstore-update-crush.sh \
+       $(srcdir)/script/subman.py \
        $(srcdir)/upstart/ceph-all.conf \
        $(srcdir)/upstart/ceph-disk.conf \
        $(srcdir)/upstart/ceph-mon.conf \
@@ -149,6 +150,10 @@ doc_DATA = $(srcdir)/sample.ceph.conf sample.fetch_config
 ceph_libexecdir = $(libexecdir)/ceph
 ceph_libexec_SCRIPTS = ceph_common.sh ceph-osd-prestart.sh
 
+if ENABLE_SUBMAN
+submandir = /etc/cron.hourly
+subman_SCRIPTS = script/subman.py
+endif
 
 # tests to actually run on "make check"; if you need extra, non-test,
 # executables built, you need to replace this with manual assignments
diff --git a/src/script/subman.py b/src/script/subman.py
new file mode 100755 (executable)
index 0000000..9bd69c5
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+import json
+import re
+import subprocess
+
+disks = json.loads(subprocess.check_output("ceph-disk list --format json", shell=True))
+used = 0
+
+for disk in disks:
+    for partition in disk.get('partition', []):
+        if partition.get('type') == 'data':
+            df = subprocess.check_output("df --output=used " + partition['path'], shell=True)
+            used += int(re.findall('\d+', df)[0])
+
+open("/etc/rhsm/facts/ceph_usage.facts", 'w').write("""
+{
+"band.storage.usage": {used}
+}
+""".format(used=used/(1024*1024*1024)))