mirror of
https://github.com/containers/podman.git
synced 2025-06-20 17:13:43 +08:00
Merge pull request #14805 from jakecorrenti/df-format-output
Podman system df JSON format outputs `Size` and `Reclaimable`
This commit is contained in:
@ -78,11 +78,11 @@ func printSummary(cmd *cobra.Command, reports *entities.SystemDfReport) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
imageSummary := dfSummary{
|
imageSummary := dfSummary{
|
||||||
Type: "Images",
|
Type: "Images",
|
||||||
Total: len(reports.Images),
|
Total: len(reports.Images),
|
||||||
Active: active,
|
Active: active,
|
||||||
size: size,
|
RawSize: size,
|
||||||
reclaimable: reclaimable,
|
RawReclaimable: reclaimable,
|
||||||
}
|
}
|
||||||
dfSummaries = append(dfSummaries, &imageSummary)
|
dfSummaries = append(dfSummaries, &imageSummary)
|
||||||
|
|
||||||
@ -100,11 +100,11 @@ func printSummary(cmd *cobra.Command, reports *entities.SystemDfReport) error {
|
|||||||
conSize += c.RWSize
|
conSize += c.RWSize
|
||||||
}
|
}
|
||||||
containerSummary := dfSummary{
|
containerSummary := dfSummary{
|
||||||
Type: "Containers",
|
Type: "Containers",
|
||||||
Total: len(reports.Containers),
|
Total: len(reports.Containers),
|
||||||
Active: conActive,
|
Active: conActive,
|
||||||
size: conSize,
|
RawSize: conSize,
|
||||||
reclaimable: conReclaimable,
|
RawReclaimable: conReclaimable,
|
||||||
}
|
}
|
||||||
dfSummaries = append(dfSummaries, &containerSummary)
|
dfSummaries = append(dfSummaries, &containerSummary)
|
||||||
|
|
||||||
@ -120,11 +120,11 @@ func printSummary(cmd *cobra.Command, reports *entities.SystemDfReport) error {
|
|||||||
volumesReclaimable += v.ReclaimableSize
|
volumesReclaimable += v.ReclaimableSize
|
||||||
}
|
}
|
||||||
volumeSummary := dfSummary{
|
volumeSummary := dfSummary{
|
||||||
Type: "Local Volumes",
|
Type: "Local Volumes",
|
||||||
Total: len(reports.Volumes),
|
Total: len(reports.Volumes),
|
||||||
Active: activeVolumes,
|
Active: activeVolumes,
|
||||||
size: volumesSize,
|
RawSize: volumesSize,
|
||||||
reclaimable: volumesReclaimable,
|
RawReclaimable: volumesReclaimable,
|
||||||
}
|
}
|
||||||
dfSummaries = append(dfSummaries, &volumeSummary)
|
dfSummaries = append(dfSummaries, &volumeSummary)
|
||||||
|
|
||||||
@ -277,22 +277,22 @@ func (d *dfVolume) Size() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type dfSummary struct {
|
type dfSummary struct {
|
||||||
Type string
|
Type string
|
||||||
Total int
|
Total int
|
||||||
Active int
|
Active int
|
||||||
size int64
|
RawSize int64 `json:"Size"`
|
||||||
reclaimable int64
|
RawReclaimable int64 `json:"Reclaimable"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dfSummary) Size() string {
|
func (d *dfSummary) Size() string {
|
||||||
return units.HumanSize(float64(d.size))
|
return units.HumanSize(float64(d.RawSize))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dfSummary) Reclaimable() string {
|
func (d *dfSummary) Reclaimable() string {
|
||||||
percent := 0
|
percent := 0
|
||||||
// make sure to check this to prevent div by zero problems
|
// make sure to check this to prevent div by zero problems
|
||||||
if d.size > 0 {
|
if d.RawSize > 0 {
|
||||||
percent = int(math.Round(float64(d.reclaimable) / float64(d.size) * float64(100)))
|
percent = int(math.Round(float64(d.RawReclaimable) / float64(d.RawSize) * float64(100)))
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s (%d%%)", units.HumanSize(float64(d.reclaimable)), percent)
|
return fmt.Sprintf("%s (%d%%)", units.HumanSize(float64(d.RawReclaimable)), percent)
|
||||||
}
|
}
|
||||||
|
@ -97,4 +97,17 @@ var _ = Describe("podman system df", func() {
|
|||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
Expect(session).Should(Exit(0))
|
Expect(session).Should(Exit(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman system df --format \"{{ json . }}\"", func() {
|
||||||
|
session := podmanTest.Podman([]string{"create", ALPINE})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"system", "df", "--format", "{{ json . }}"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
Expect(session.LineInOutputContains("Size"))
|
||||||
|
Expect(session.LineInOutputContains("Reclaimable"))
|
||||||
|
Expect(session.IsJSONOutputValid())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user