]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: get cephadm version information from zipapp module
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 27 Apr 2023 17:36:51 +0000 (13:36 -0400)
committerAdam King <adking@redhat.com>
Thu, 31 Aug 2023 17:35:12 +0000 (13:35 -0400)
Use the `_version.py` module that gets embedded into the zipapp at build
time to print cephadm's own version information.
The version string printed is basically copied from the one printed by
the `ceph` command.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit cfa2d0de77b71a6b61b75cd0ea408065aa9fbd45)

src/cephadm/cephadm.py

index 20ed47ef3c006091940d51aca6799704306cccc6..e6575edbd1b45bd141ddec33dc1bd01d2f465eab 100755 (executable)
@@ -4845,15 +4845,23 @@ def command_agent(ctx: CephadmContext) -> None:
 
 ##################################
 
-
-@infer_image
 def command_version(ctx):
     # type: (CephadmContext) -> int
-    c = CephContainer(ctx, ctx.image, 'ceph', ['--version'])
-    out, err, ret = call(ctx, c.run_cmd(), desc=c.entrypoint)
-    if not ret:
-        print(out.strip())
-    return ret
+    import importlib
+
+    try:
+        vmod = importlib.import_module('_version')
+    except ImportError:
+        print('cephadm version UNKNOWN')
+        return 1
+    _unset = '<UNSET>'
+    print('cephadm version {0} ({1}) {2} ({3})'.format(
+        getattr(vmod, 'CEPH_GIT_NICE_VER', _unset),
+        getattr(vmod, 'CEPH_GIT_VER', _unset),
+        getattr(vmod, 'CEPH_RELEASE_NAME', _unset),
+        getattr(vmod, 'CEPH_RELEASE_TYPE', _unset),
+    ))
+    return 0
 
 ##################################
 
@@ -9433,7 +9441,7 @@ def _get_parser():
     subparsers = parser.add_subparsers(help='sub-command')
 
     parser_version = subparsers.add_parser(
-        'version', help='get ceph version from container')
+        'version', help='get cephadm version')
     parser_version.set_defaults(func=command_version)
 
     parser_pull = subparsers.add_parser(