]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
[RM-11115] initial take on a Ceph package object
authorAlfredo Deza <adeza@redhat.com>
Tue, 11 Aug 2015 17:58:36 +0000 (13:58 -0400)
committerAlfredo Deza <adeza@redhat.com>
Wed, 12 Aug 2015 12:50:43 +0000 (08:50 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
ceph_deploy/util/packages.py [new file with mode: 0644]

diff --git a/ceph_deploy/util/packages.py b/ceph_deploy/util/packages.py
new file mode 100644 (file)
index 0000000..3a1bea6
--- /dev/null
@@ -0,0 +1,59 @@
+from ceph_deploy.exc import ExecutableNotFound
+from ceph_deploy.util import system, versions
+from ceph_deploy.lib import remoto
+
+
+class Ceph(object):
+    """
+    Determine different aspects of the Ceph package, like ``version`` and path
+    ``executable``. Although mostly provide a version object that helps for
+    parsing and comparing.
+    """
+
+    def __init__(self, conn, _check=None):
+        self.conn = conn
+        self._check = _check or remoto.process.check
+
+    @property
+    def installed(self):
+        """
+        If the ``ceph`` executable exists, then Ceph is installed. Should
+        probably be revisited if different components do not have the ``ceph``
+        executable (this is currently provided by ``ceph-common``).
+        """
+        return bool(self.executable)
+
+    @property
+    def executable(self):
+        try:
+            return system.executable_path(self.conn, 'ceph')
+        except ExecutableNotFound:
+            return None
+
+    def _get_version_output(self):
+        """
+        Ignoring errors, call `ceph --version` and return only the version
+        portion of the output. For example, output like::
+
+            ceph version 9.0.1-1234kjd (asdflkj2k3jh234jhg)
+
+        Would return::
+
+            9.0.1-1234kjd
+        """
+        if not self.executable:
+            return ''
+        command = [self.executable, '--version']
+        out, _, _ = self._check(self.conn, command)
+        try:
+            return out.split()[2]
+        except IndexError:
+            return ''
+
+    @property
+    def version(self):
+        """
+        Return a version object (see
+        :mod:``ceph_deploy.util.versions.NormalizedVersion``)
+        """
+        return versions.parse_version(self._get_version_output)