Merge pull request #27294 from mlaventure/hide-unused-volume-fields

Move types.Volumes optional fields under a new type
This commit is contained in:
Sebastiaan van Stijn 2016-10-11 23:55:25 +02:00 committed by GitHub
commit a7db0a8402
5 changed files with 21 additions and 19 deletions

View file

@ -433,6 +433,12 @@ type MountPoint struct {
Propagation mount.Propagation
}
// VolumeUsageData holds information regarding the volume usage
type VolumeUsageData struct {
Size int64 // Size holds how much disk space is used by the (local driver only). Sets to -1 if not provided.
RefCount int // RefCount holds the number of containers having this volume attached to them. Sets to -1 if not provided.
}
// Volume represents the configuration of a volume for the remote API
type Volume struct {
Name string // Name is the name of the volume
@ -441,8 +447,7 @@ type Volume struct {
Status map[string]interface{} `json:",omitempty"` // Status provides low-level status information about the volume
Labels map[string]string // Labels is metadata specific to the volume
Scope string // Scope describes the level at which the volume exists (e.g. `global` for cluster-wide or `local` for machine level)
Size int64 // Size holds how much disk space is used by the (local driver only). Sets to -1 if not provided.
RefCount int // RefCount holds the number of containers having this volume attached to them. Sets to -1 if not provided.
UsageData *VolumeUsageData `json:",omitempty"`
}
// VolumesListResponse contains the response for the remote API:

View file

@ -288,7 +288,7 @@ func (c *diskUsageVolumesContext) Active() string {
used := 0
for _, v := range c.volumes {
if v.RefCount > 0 {
if v.UsageData.RefCount > 0 {
used++
}
}
@ -301,8 +301,8 @@ func (c *diskUsageVolumesContext) Size() string {
c.AddHeader(sizeHeader)
for _, v := range c.volumes {
if v.Size != -1 {
size += v.Size
if v.UsageData.Size != -1 {
size += v.UsageData.Size
}
}
@ -315,11 +315,11 @@ func (c *diskUsageVolumesContext) Reclaimable() string {
c.AddHeader(reclaimableHeader)
for _, v := range c.volumes {
if v.Size != -1 {
if v.RefCount == 0 {
reclaimable += v.Size
if v.UsageData.Size != -1 {
if v.UsageData.RefCount == 0 {
reclaimable += v.UsageData.Size
}
totalSize += v.Size
totalSize += v.UsageData.Size
}
}

View file

@ -101,16 +101,16 @@ func (c *volumeContext) Label(name string) string {
func (c *volumeContext) Links() string {
c.AddHeader(linksHeader)
if c.v.Size == -1 {
if c.v.UsageData == nil {
return "N/A"
}
return fmt.Sprintf("%d", c.v.RefCount)
return fmt.Sprintf("%d", c.v.UsageData.RefCount)
}
func (c *volumeContext) Size() string {
c.AddHeader(sizeHeader)
if c.v.Size == -1 {
if c.v.UsageData == nil {
return "N/A"
}
return units.HumanSize(float64(c.v.Size))
return units.HumanSize(float64(c.v.UsageData.Size))
}

View file

@ -56,13 +56,12 @@ func (daemon *Daemon) SystemDiskUsage() (*types.DiskUsage, error) {
refs := daemon.volumes.Refs(v)
tv := volumeToAPIType(v)
tv.RefCount = len(refs)
sz, err := directory.Size(v.Path())
if err != nil {
logrus.Warnf("failed to determine size of volume %v", name)
sz = -1
}
tv.Size = sz
tv.UsageData = &types.VolumeUsageData{Size: sz, RefCount: len(refs)}
allVolumes = append(allVolumes, tv)
return nil

View file

@ -29,10 +29,8 @@ type mounts []container.Mount
// volumeToAPIType converts a volume.Volume to the type used by the remote API
func volumeToAPIType(v volume.Volume) *types.Volume {
tv := &types.Volume{
Name: v.Name(),
Driver: v.DriverName(),
Size: -1,
RefCount: -1,
Name: v.Name(),
Driver: v.DriverName(),
}
if v, ok := v.(volume.LabeledVolume); ok {
tv.Labels = v.Labels()