]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: Infer ceph image
authorRicardo Marques <rimarques@suse.com>
Mon, 9 Mar 2020 18:13:41 +0000 (18:13 +0000)
committerSage Weil <sage@redhat.com>
Thu, 12 Mar 2020 12:38:11 +0000 (07:38 -0500)
Fixes: https://tracker.ceph.com/issues/44440
Signed-off-by: Ricardo Marques <rimarques@suse.com>
src/cephadm/cephadm

index b55e123adaf4a1765b7b1f53f988653ac890a7c2..8bc0b110262af094dd6c37d31b0e24d20c9dccdd 100755 (executable)
@@ -761,6 +761,24 @@ def infer_fsid(func):
 
     return _infer_fsid
 
+def get_last_local_ceph_image():
+    """
+    :return: The most recent local ceph image (already pulled)
+    """
+    out, _, _ = call_throws(
+        [container_path, 'images', '--format', '{{ .ID }} {{.Repository}} {{.Tag}}'])
+    out_lines = out.splitlines()
+    for out_line in out_lines:
+        id, repository, tag = out_line.split()
+        out, _, _ = call_throws([container_path, 'inspect', str(id)])
+        images_details = json.loads(out)
+        for image_details in images_details:
+            image_labels = image_details['Labels']
+            git_repo = image_labels.get('GIT_REPO', "")
+            if git_repo.endswith("/ceph-container.git"):
+                return '{}:{}'.format(repository, tag)
+    return None
+
 def write_tmp(s, uid, gid):
     tmp_f = tempfile.NamedTemporaryFile(mode='w',
                                         prefix='ceph-tmp')
@@ -2153,7 +2171,7 @@ def command_deploy():
             daemon_ports = Monitoring.port_map[daemon_type]  # type: List[int]
             if any([port_in_use(port) for port in daemon_ports]):
                 raise Error("TCP Port(s) '{}' required for {} is already in use".format(",".join(map(str, daemon_ports)), daemon_type))
-            elif args.image == DEFAULT_IMAGE:
+            elif args.image == DEFAULT_IMAGE or args.image == inferred_image:
                 raise Error("--image parameter must be supplied for {}".format(daemon_type))
 
         # make sure provided config-json is sufficient
@@ -3699,10 +3717,19 @@ def _parse_args(av):
             if type_ in Monitoring.components:
                 args.image = Monitoring.components[type_]['image']
         if not args.image:
-            args.image = os.environ.get('CEPHADM_IMAGE', DEFAULT_IMAGE)
+            args.image = os.environ.get('CEPHADM_IMAGE')
 
     return args
 
+def _infer_image():
+    inferred = None
+    if not args.image:
+        inferred = get_last_local_ceph_image()
+        args.image = inferred
+    if not args.image:
+        args.image = DEFAULT_IMAGE
+    return inferred
+
 if __name__ == "__main__":
     # allow argv to be injected
     try:
@@ -3736,6 +3763,8 @@ if __name__ == "__main__":
             sys.stderr.write('Unable to locate any of %s\n' % CONTAINER_PREFERENCE)
             sys.exit(1)
 
+    inferred_image = _infer_image()
+
     if 'func' not in args:
         sys.stderr.write('No command specified; pass -h or --help for usage\n')
         sys.exit(1)