From 3b3c70c64bfaaeccaae0ed3d4ea00ceae3e07dcc Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Mon, 9 Mar 2020 18:13:41 +0000 Subject: [PATCH] cephadm: Infer ceph image Fixes: https://tracker.ceph.com/issues/44440 Signed-off-by: Ricardo Marques --- src/cephadm/cephadm | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index b55e123adaf..8bc0b110262 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -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) -- 2.39.5