mirror of
https://github.com/containers/podman.git
synced 2025-06-27 05:26:50 +08:00
Add information when running podman version on client
* Include service version information and headers Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
@ -10,6 +11,7 @@ import (
|
|||||||
"github.com/containers/buildah/pkg/formats"
|
"github.com/containers/buildah/pkg/formats"
|
||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
|
"github.com/containers/libpod/pkg/adapter"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -38,7 +40,7 @@ func init() {
|
|||||||
|
|
||||||
// versionCmd gets and prints version info for version command
|
// versionCmd gets and prints version info for version command
|
||||||
func versionCmd(c *cliconfig.VersionValues) error {
|
func versionCmd(c *cliconfig.VersionValues) error {
|
||||||
output, err := libpod.GetVersion()
|
clientVersion, err := libpod.GetVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors.Wrapf(err, "unable to determine version")
|
errors.Wrapf(err, "unable to determine version")
|
||||||
}
|
}
|
||||||
@ -51,25 +53,49 @@ func versionCmd(c *cliconfig.VersionValues) error {
|
|||||||
var out formats.Writer
|
var out formats.Writer
|
||||||
switch versionOutputFormat {
|
switch versionOutputFormat {
|
||||||
case formats.JSONString:
|
case formats.JSONString:
|
||||||
out = formats.JSONStruct{Output: output}
|
out = formats.JSONStruct{Output: clientVersion}
|
||||||
default:
|
default:
|
||||||
out = formats.StdoutTemplate{Output: output, Template: versionOutputFormat}
|
out = formats.StdoutTemplate{Output: clientVersion, Template: versionOutputFormat}
|
||||||
}
|
}
|
||||||
return formats.Writer(out).Out()
|
return formats.Writer(out).Out()
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
fmt.Fprintf(w, "Version:\t%s\n", output.Version)
|
|
||||||
fmt.Fprintf(w, "RemoteAPI Version:\t%d\n", output.RemoteAPIVersion)
|
|
||||||
fmt.Fprintf(w, "Go Version:\t%s\n", output.GoVersion)
|
|
||||||
if output.GitCommit != "" {
|
|
||||||
fmt.Fprintf(w, "Git Commit:\t%s\n", output.GitCommit)
|
|
||||||
}
|
|
||||||
// Prints out the build time in readable format
|
|
||||||
if output.Built != 0 {
|
|
||||||
fmt.Fprintf(w, "Built:\t%s\n", time.Unix(output.Built, 0).Format(time.ANSIC))
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(w, "OS/Arch:\t%s\n", output.OsArch)
|
if remote {
|
||||||
|
fmt.Fprintf(w, "Client:\n")
|
||||||
|
}
|
||||||
|
formatVersion(w, clientVersion)
|
||||||
|
|
||||||
|
if remote {
|
||||||
|
fmt.Fprintf(w, "\nService:\n")
|
||||||
|
|
||||||
|
runtime, err := adapter.GetRuntime(getContext(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "could not get runtime")
|
||||||
|
}
|
||||||
|
defer runtime.Shutdown(false)
|
||||||
|
|
||||||
|
serviceVersion, err := runtime.GetVersion()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
formatVersion(w, serviceVersion)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func formatVersion(writer io.Writer, version libpod.Version) {
|
||||||
|
fmt.Fprintf(writer, "Version:\t%s\n", version.Version)
|
||||||
|
fmt.Fprintf(writer, "RemoteAPI Version:\t%d\n", version.RemoteAPIVersion)
|
||||||
|
fmt.Fprintf(writer, "Go Version:\t%s\n", version.GoVersion)
|
||||||
|
if version.GitCommit != "" {
|
||||||
|
fmt.Fprintf(writer, "Git Commit:\t%s\n", version.GitCommit)
|
||||||
|
}
|
||||||
|
// Prints out the build time in readable format
|
||||||
|
if version.Built != 0 {
|
||||||
|
fmt.Fprintf(writer, "Built:\t%s\n", time.Unix(version.Built, 0).Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(writer, "OS/Arch:\t%s\n", version.OsArch)
|
||||||
|
}
|
||||||
|
@ -5,12 +5,13 @@ package adapter
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"github.com/containers/libpod/cmd/podman/shared"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/containers/libpod/cmd/podman/shared"
|
||||||
|
|
||||||
"github.com/containers/buildah"
|
"github.com/containers/buildah"
|
||||||
"github.com/containers/buildah/imagebuildah"
|
"github.com/containers/buildah/imagebuildah"
|
||||||
"github.com/containers/buildah/pkg/parse"
|
"github.com/containers/buildah/pkg/parse"
|
||||||
@ -392,3 +393,8 @@ func (r *LocalRuntime) GetPodsByStatus(statuses []string) ([]*libpod.Pod, error)
|
|||||||
|
|
||||||
return pods, nil
|
return pods, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetVersion is an alias to satisfy interface{}
|
||||||
|
func (r *LocalRuntime) GetVersion() (libpod.Version, error) {
|
||||||
|
return libpod.GetVersion()
|
||||||
|
}
|
||||||
|
@ -9,12 +9,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
v1 "k8s.io/api/core/v1"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
|
|
||||||
"github.com/containers/buildah/imagebuildah"
|
"github.com/containers/buildah/imagebuildah"
|
||||||
"github.com/containers/image/docker/reference"
|
"github.com/containers/image/docker/reference"
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
@ -414,19 +415,19 @@ func (r *LocalRuntime) Build(ctx context.Context, c *cliconfig.BuildValues, opti
|
|||||||
Compression: string(options.Compression),
|
Compression: string(options.Compression),
|
||||||
DefaultsMountFilePath: options.DefaultMountsFilePath,
|
DefaultsMountFilePath: options.DefaultMountsFilePath,
|
||||||
Dockerfiles: dockerfiles,
|
Dockerfiles: dockerfiles,
|
||||||
//Err: string(options.Err),
|
// Err: string(options.Err),
|
||||||
ForceRmIntermediateCtrs: options.ForceRmIntermediateCtrs,
|
ForceRmIntermediateCtrs: options.ForceRmIntermediateCtrs,
|
||||||
Iidfile: options.IIDFile,
|
Iidfile: options.IIDFile,
|
||||||
Label: options.Labels,
|
Label: options.Labels,
|
||||||
Layers: options.Layers,
|
Layers: options.Layers,
|
||||||
Nocache: options.NoCache,
|
Nocache: options.NoCache,
|
||||||
//Out:
|
// Out:
|
||||||
Output: options.Output,
|
Output: options.Output,
|
||||||
OutputFormat: options.OutputFormat,
|
OutputFormat: options.OutputFormat,
|
||||||
PullPolicy: options.PullPolicy.String(),
|
PullPolicy: options.PullPolicy.String(),
|
||||||
Quiet: options.Quiet,
|
Quiet: options.Quiet,
|
||||||
RemoteIntermediateCtrs: options.RemoveIntermediateCtrs,
|
RemoteIntermediateCtrs: options.RemoveIntermediateCtrs,
|
||||||
//ReportWriter:
|
// ReportWriter:
|
||||||
RuntimeArgs: options.RuntimeArgs,
|
RuntimeArgs: options.RuntimeArgs,
|
||||||
SignaturePolicyPath: options.SignaturePolicyPath,
|
SignaturePolicyPath: options.SignaturePolicyPath,
|
||||||
Squash: options.Squash,
|
Squash: options.Squash,
|
||||||
@ -610,7 +611,7 @@ func (r *LocalRuntime) InspectVolumes(ctx context.Context, c *cliconfig.VolumeIn
|
|||||||
return varlinkVolumeToVolume(r, reply), nil
|
return varlinkVolumeToVolume(r, reply), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Volumes returns a slice of adapter.volumes based on information about libpod
|
// Volumes returns a slice of adapter.volumes based on information about libpod
|
||||||
// volumes over a varlink connection
|
// volumes over a varlink connection
|
||||||
func (r *LocalRuntime) Volumes(ctx context.Context) ([]*Volume, error) {
|
func (r *LocalRuntime) Volumes(ctx context.Context) ([]*Volume, error) {
|
||||||
reply, err := iopodman.GetVolumes().Call(r.Conn, []string{}, true)
|
reply, err := iopodman.GetVolumes().Call(r.Conn, []string{}, true)
|
||||||
@ -906,3 +907,29 @@ func (r *LocalRuntime) GetContainersByContext(all bool, latest bool, namesOrIDs
|
|||||||
}
|
}
|
||||||
return containers, nil
|
return containers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetVersion returns version information from service
|
||||||
|
func (r *LocalRuntime) GetVersion() (libpod.Version, error) {
|
||||||
|
version, goVersion, gitCommit, built, osArch, apiVersion, err := iopodman.GetVersion().Call(r.Conn)
|
||||||
|
if err != nil {
|
||||||
|
return libpod.Version{}, errors.Wrapf(err, "Unable to obtain server version information")
|
||||||
|
}
|
||||||
|
|
||||||
|
var buildTime int64
|
||||||
|
if built != "" {
|
||||||
|
t, err := time.Parse(time.RFC3339, built)
|
||||||
|
if err != nil {
|
||||||
|
return libpod.Version{}, nil
|
||||||
|
}
|
||||||
|
buildTime = t.Unix()
|
||||||
|
}
|
||||||
|
|
||||||
|
return libpod.Version{
|
||||||
|
RemoteAPIVersion: apiVersion,
|
||||||
|
Version: version,
|
||||||
|
GoVersion: goVersion,
|
||||||
|
GitCommit: gitCommit,
|
||||||
|
Built: buildTime,
|
||||||
|
OsArch: osArch,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@ var _ = Describe("Podman version", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman version", func() {
|
It("podman version", func() {
|
||||||
|
SkipIfRemote()
|
||||||
session := podmanTest.Podman([]string{"version"})
|
session := podmanTest.Podman([]string{"version"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
@ -38,6 +39,7 @@ var _ = Describe("Podman version", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman version --format json", func() {
|
It("podman version --format json", func() {
|
||||||
|
SkipIfRemote()
|
||||||
session := podmanTest.Podman([]string{"version", "--format", "json"})
|
session := podmanTest.Podman([]string{"version", "--format", "json"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
@ -45,6 +47,7 @@ var _ = Describe("Podman version", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman version --format json", func() {
|
It("podman version --format json", func() {
|
||||||
|
SkipIfRemote()
|
||||||
session := podmanTest.Podman([]string{"version", "--format", "{{ json .}}"})
|
session := podmanTest.Podman([]string{"version", "--format", "{{ json .}}"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
@ -52,6 +55,7 @@ var _ = Describe("Podman version", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman version --format GO template", func() {
|
It("podman version --format GO template", func() {
|
||||||
|
SkipIfRemote()
|
||||||
session := podmanTest.Podman([]string{"version", "--format", "{{ .Version }}"})
|
session := podmanTest.Podman([]string{"version", "--format", "{{ .Version }}"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
Reference in New Issue
Block a user