mirror of https://github.com/containers/podman.git
Merge pull request #14383 from jwhonce/wip/info_todo
Add Authorization field to Plugins for Info
This commit is contained in:
commit
a550af260a
|
@ -14,7 +14,7 @@ type Info struct {
|
||||||
Version Version `json:"version"`
|
Version Version `json:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// HostInfo describes the libpod host
|
// SecurityInfo describes the libpod host
|
||||||
type SecurityInfo struct {
|
type SecurityInfo struct {
|
||||||
AppArmorEnabled bool `json:"apparmorEnabled"`
|
AppArmorEnabled bool `json:"apparmorEnabled"`
|
||||||
DefaultCapabilities string `json:"capabilities"`
|
DefaultCapabilities string `json:"capabilities"`
|
||||||
|
@ -64,8 +64,7 @@ type RemoteSocket struct {
|
||||||
Exists bool `json:"exists,omitempty"`
|
Exists bool `json:"exists,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SlirpInfo describes the slirp executable that
|
// SlirpInfo describes the slirp executable that is being used
|
||||||
// is being being used.
|
|
||||||
type SlirpInfo struct {
|
type SlirpInfo struct {
|
||||||
Executable string `json:"executable"`
|
Executable string `json:"executable"`
|
||||||
Package string `json:"package"`
|
Package string `json:"package"`
|
||||||
|
@ -78,8 +77,7 @@ type IDMappings struct {
|
||||||
UIDMap []idtools.IDMap `json:"uidmap"`
|
UIDMap []idtools.IDMap `json:"uidmap"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DistributionInfo describes the host distribution
|
// DistributionInfo describes the host distribution for libpod
|
||||||
// for libpod
|
|
||||||
type DistributionInfo struct {
|
type DistributionInfo struct {
|
||||||
Distribution string `json:"distribution"`
|
Distribution string `json:"distribution"`
|
||||||
Variant string `json:"variant,omitempty"`
|
Variant string `json:"variant,omitempty"`
|
||||||
|
@ -141,8 +139,8 @@ type Plugins struct {
|
||||||
Volume []string `json:"volume"`
|
Volume []string `json:"volume"`
|
||||||
Network []string `json:"network"`
|
Network []string `json:"network"`
|
||||||
Log []string `json:"log"`
|
Log []string `json:"log"`
|
||||||
// FIXME what should we do with Authorization, docker seems to return nothing by default
|
// Authorization is provided for compatibility, will always be nil as Podman has no daemon
|
||||||
// Authorization []string `json:"authorization"`
|
Authorization []string `json:"authorization"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CPUUsage struct {
|
type CPUUsage struct {
|
||||||
|
|
|
@ -199,50 +199,38 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) {
|
||||||
info.OCIRuntime = ociruntimeInfo
|
info.OCIRuntime = ociruntimeInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
up, err := readUptime()
|
duration, err := procUptime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "error reading up time")
|
return nil, errors.Wrapf(err, "error reading up time")
|
||||||
}
|
}
|
||||||
// Convert uptime in seconds to a human-readable format
|
|
||||||
upSeconds := up + "s"
|
uptime := struct {
|
||||||
upDuration, err := time.ParseDuration(upSeconds)
|
hours float64
|
||||||
if err != nil {
|
minutes float64
|
||||||
return nil, errors.Wrapf(err, "error parsing system uptime")
|
seconds float64
|
||||||
|
}{
|
||||||
|
hours: duration.Truncate(time.Hour).Hours(),
|
||||||
|
minutes: duration.Truncate(time.Minute).Minutes(),
|
||||||
|
seconds: duration.Truncate(time.Second).Seconds(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Isn't there a simple lib for this, something like humantime?
|
// Could not find a humanize-formatter for time.Duration
|
||||||
hoursFound := false
|
var buffer bytes.Buffer
|
||||||
var timeBuffer bytes.Buffer
|
buffer.WriteString(fmt.Sprintf("%.0fh %.0fm %.2fs",
|
||||||
var hoursBuffer bytes.Buffer
|
uptime.hours,
|
||||||
for _, elem := range upDuration.String() {
|
math.Mod(uptime.seconds, 3600)/60,
|
||||||
timeBuffer.WriteRune(elem)
|
math.Mod(uptime.seconds, 60),
|
||||||
if elem == 'h' || elem == 'm' {
|
))
|
||||||
timeBuffer.WriteRune(' ')
|
if int64(uptime.hours) > 0 {
|
||||||
if elem == 'h' {
|
buffer.WriteString(fmt.Sprintf(" (Approximately %.2f days)", uptime.hours/24))
|
||||||
hoursFound = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !hoursFound {
|
|
||||||
hoursBuffer.WriteRune(elem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
info.Uptime = timeBuffer.String()
|
|
||||||
if hoursFound {
|
|
||||||
hours, err := strconv.ParseFloat(hoursBuffer.String(), 64)
|
|
||||||
if err == nil {
|
|
||||||
days := hours / 24
|
|
||||||
info.Uptime = fmt.Sprintf("%s (Approximately %.2f days)", info.Uptime, days)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
info.Uptime = buffer.String()
|
||||||
|
|
||||||
return &info, nil
|
return &info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runtime) getContainerStoreInfo() (define.ContainerStore, error) {
|
func (r *Runtime) getContainerStoreInfo() (define.ContainerStore, error) {
|
||||||
var (
|
var paused, running, stopped int
|
||||||
paused, running, stopped int
|
|
||||||
)
|
|
||||||
cs := define.ContainerStore{}
|
cs := define.ContainerStore{}
|
||||||
cons, err := r.GetAllContainers()
|
cons, err := r.GetAllContainers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -353,16 +341,17 @@ func readKernelVersion() (string, error) {
|
||||||
return string(f[2]), nil
|
return string(f[2]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readUptime() (string, error) {
|
func procUptime() (time.Duration, error) {
|
||||||
|
var zero time.Duration
|
||||||
buf, err := ioutil.ReadFile("/proc/uptime")
|
buf, err := ioutil.ReadFile("/proc/uptime")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return zero, err
|
||||||
}
|
}
|
||||||
f := bytes.Fields(buf)
|
f := bytes.Fields(buf)
|
||||||
if len(f) < 1 {
|
if len(f) < 1 {
|
||||||
return "", fmt.Errorf("invalid uptime")
|
return zero, errors.New("unable to parse uptime from /proc/uptime")
|
||||||
}
|
}
|
||||||
return string(f[0]), nil
|
return time.ParseDuration(string(f[0]) + "s")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHostDistributionInfo returns a map containing the host's distribution and version
|
// GetHostDistributionInfo returns a map containing the host's distribution and version
|
||||||
|
|
Loading…
Reference in New Issue