From 1e00aed248e7b529d6152b70cb195ae098fa37f1 Mon Sep 17 00:00:00 2001 From: Dan Walsh Date: Wed, 28 Jan 2015 16:36:55 -0500 Subject: [PATCH] Ignore stderr output, add atomic info --- atomic | 28 +++++++++++++++++++++------- docs/atomic-info.1.md | 20 ++++++++++++++++++++ docs/atomic.1.md | 5 ++++- 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 docs/atomic-info.1.md diff --git a/atomic b/atomic index 24bfbb7..0e46e70 100755 --- a/atomic +++ b/atomic @@ -1,5 +1,5 @@ -#!/bin/python -Es -# Copyright (C) 2014 Red Hat +#!/usr/bin/python -Es +# Copyright (C) 2014-2015 Red Hat # AUTHOR: Dan Walsh # see file 'COPYING' for use and warranty information # @@ -68,7 +68,6 @@ class Atomic: SPC_ARGS = ["/usr/bin/docker", "run", "-t", "-i", - "--rm", "--privileged", "-v", "/:/host", "-v", "/run:/run", @@ -84,7 +83,6 @@ class Atomic: RUN_ARGS = ["/usr/bin/docker", "run", "-t", "-i", - "--rm", "--name", "NAME", "IMAGE" ] @@ -153,10 +151,10 @@ class Atomic: try: self.d.inspect_container(self.name) try: - return subprocess.check_call(["/usr/bin/docker", "exec", "-t", "-i", self.name] + self.command) + return subprocess.check_call(["/usr/bin/docker", "exec", "-t", "-i", self.name] + self.command, stderr=subprocess.PIPE) except subprocess.CalledProcessError: try: - subprocess.check_call(["/usr/bin/docker", "start", self.name]) + subprocess.check_call(["/usr/bin/docker", "start", self.name], stderr=subprocess.PIPE) return subprocess.check_call(["/usr/bin/docker", "exec", "-t", "-i", self.name] + self.command) except subprocess.CalledProcessError: pass @@ -188,7 +186,7 @@ class Atomic: return (subprocess.check_call(cmd, env={ "CONFDIR": "/etc/%s" % self.name, "LOGDIR": "/var/log/%s" % self.name, - "DATADIR":"/var/lib/%s" % self.name}, shell=True)) + "DATADIR":"/var/lib/%s" % self.name}, shell=True, stderr=subprocess.PIPE)) def _rpmostree(self, *args): os.execl("/usr/bin/rpm-ostree", "rpm-ostree", *args) @@ -250,6 +248,15 @@ class Atomic: args.append(c) return " ".join(args) + def info(self): + try: + labels = self.d.inspect_image(self.image)["Config"]["Labels"] + except docker.errors.APIError: + self.update() + labels = self.d.inspect_image(self.image)["Config"]["Labels"] + for label in labels: + print ("%-13s: %s" % (label, labels[label])) + def install(self): try: inspect = self.d.inspect_image(self.image)["Config"] @@ -337,6 +344,12 @@ if __name__ == '__main__': action="store_true", help=_("If an upgrade is available, reboot after deployment is complete")) + infop = subparser.add_parser("info", + help=_("dispaly label information about an image"), + epilog="atomic info attempts to read and display the LABEL information about an image") + infop.set_defaults(func=atomic.info) + infop.add_argument("image", help=_("container image")) + installp = subparser.add_parser("install", help=_("execute container image install method"), epilog="atomic install attempts to read the LABEL INSTALL field in the image, if it does not exist atomic will just pull the image on to your machine. You could add a LABEL INSTALL command to your Dockerfile like: 'LABEL INSTALL %s'" % atomic.print_install() ) @@ -390,6 +403,7 @@ if __name__ == '__main__': except KeyboardInterrupt: sys.exit(0) except subprocess.CalledProcessError as e: + print "" sys.exit(e.returncode) except docker.errors.DockerException as e: sys.stderr.write("%s\n" % str(e)) diff --git a/docs/atomic-info.1.md b/docs/atomic-info.1.md new file mode 100644 index 0000000..c88db13 --- /dev/null +++ b/docs/atomic-info.1.md @@ -0,0 +1,20 @@ +% ATOMIC(1) Atomic Man Pages +% Dan Walsh +% January 2015 +# NAME +atomic-info - Display LABEL information about an image + +# SYNOPSIS +**atomic info** +[**-h**] +IMAGE + +# DESCRIPTION +**atomic info** displays the LABEL fields within an image + +# OPTIONS: +**--help** + Print usage statement + +# HISTORY +January 2015, Originally compiled by Daniel Walsh (dwalsh at redhat dot com) diff --git a/docs/atomic.1.md b/docs/atomic.1.md index ff71945..ebff663 100644 --- a/docs/atomic.1.md +++ b/docs/atomic.1.md @@ -6,7 +6,7 @@ atomic \- Atomic Management Tool # SYNOPSIS **atomic** [OPTIONS] COMMAND [arg...] - {defaults,host,install,run,uninstall,update} + {defaults,host,info,install,run,uninstall,update} # DESCRIPTION Atomic Management Tool @@ -22,6 +22,9 @@ list Default RUN/INSTALL/UNINSTALL Values **atomic-host(1)** execute Atomic commands +**atomic-info(1)** +execute Atomic commands + **atomic-install(1)** execute image install method