From 61f591f56ecc957368e9217b7082b2f49e5da3a4 Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Wed, 5 Oct 2016 10:37:53 +1000 Subject: [PATCH] Add latest and currently running os info to 'ros os list' Signed-off-by: Sven Dowideit --- cmd/control/os.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/cmd/control/os.go b/cmd/control/os.go index 992e5d9b..866a7591 100644 --- a/cmd/control/os.go +++ b/cmd/control/os.go @@ -79,6 +79,7 @@ func osSubcommands() []cli.Command { } } +// TODO: this and the getLatestImage should probably move to utils/network and be suitably cached. func getImages() (*Images, error) { upgradeUrl, err := getUpgradeUrl() if err != nil { @@ -128,13 +129,30 @@ func osMetaDataGet(c *cli.Context) error { log.Fatal(err) } - for _, image := range images.Available { + cfg := config.LoadConfig() + runningName := cfg.Rancher.Upgrade.Image + ":" + config.VERSION + + foundRunning := false + for i := len(images.Available) - 1; i >= 0; i-- { + image := images.Available[i] _, _, err := client.ImageInspectWithRaw(context.Background(), image, false) + local := "local" if dockerClient.IsErrImageNotFound(err) { - fmt.Println(image, "remote") - } else { - fmt.Println(image, "local") + local = "remote" } + available := "available" + if image == images.Current { + available = "latest" + } + var running string + if image == runningName { + foundRunning = true + running = "running" + } + fmt.Println(image, local, available, running) + } + if !foundRunning { + fmt.Println(config.VERSION, "running") } return nil