This allows us to hide those fields when they are not filled.
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
| ... | ... |
@@ -433,6 +433,12 @@ type MountPoint struct {
|
| 433 | 433 |
Propagation mount.Propagation |
| 434 | 434 |
} |
| 435 | 435 |
|
| 436 |
+// VolumeUsageData holds information regarding the volume usage |
|
| 437 |
+type VolumeUsageData struct {
|
|
| 438 |
+ Size int64 // Size holds how much disk space is used by the (local driver only). Sets to -1 if not provided. |
|
| 439 |
+ RefCount int // RefCount holds the number of containers having this volume attached to them. Sets to -1 if not provided. |
|
| 440 |
+} |
|
| 441 |
+ |
|
| 436 | 442 |
// Volume represents the configuration of a volume for the remote API |
| 437 | 443 |
type Volume struct {
|
| 438 | 444 |
Name string // Name is the name of the volume |
| ... | ... |
@@ -441,8 +447,7 @@ type Volume struct {
|
| 441 | 441 |
Status map[string]interface{} `json:",omitempty"` // Status provides low-level status information about the volume
|
| 442 | 442 |
Labels map[string]string // Labels is metadata specific to the volume |
| 443 | 443 |
Scope string // Scope describes the level at which the volume exists (e.g. `global` for cluster-wide or `local` for machine level) |
| 444 |
- Size int64 // Size holds how much disk space is used by the (local driver only). Sets to -1 if not provided. |
|
| 445 |
- RefCount int // RefCount holds the number of containers having this volume attached to them. Sets to -1 if not provided. |
|
| 444 |
+ UsageData *VolumeUsageData `json:",omitempty"` |
|
| 446 | 445 |
} |
| 447 | 446 |
|
| 448 | 447 |
// VolumesListResponse contains the response for the remote API: |
| ... | ... |
@@ -288,7 +288,7 @@ func (c *diskUsageVolumesContext) Active() string {
|
| 288 | 288 |
|
| 289 | 289 |
used := 0 |
| 290 | 290 |
for _, v := range c.volumes {
|
| 291 |
- if v.RefCount > 0 {
|
|
| 291 |
+ if v.UsageData.RefCount > 0 {
|
|
| 292 | 292 |
used++ |
| 293 | 293 |
} |
| 294 | 294 |
} |
| ... | ... |
@@ -301,8 +301,8 @@ func (c *diskUsageVolumesContext) Size() string {
|
| 301 | 301 |
|
| 302 | 302 |
c.AddHeader(sizeHeader) |
| 303 | 303 |
for _, v := range c.volumes {
|
| 304 |
- if v.Size != -1 {
|
|
| 305 |
- size += v.Size |
|
| 304 |
+ if v.UsageData.Size != -1 {
|
|
| 305 |
+ size += v.UsageData.Size |
|
| 306 | 306 |
} |
| 307 | 307 |
} |
| 308 | 308 |
|
| ... | ... |
@@ -315,11 +315,11 @@ func (c *diskUsageVolumesContext) Reclaimable() string {
|
| 315 | 315 |
|
| 316 | 316 |
c.AddHeader(reclaimableHeader) |
| 317 | 317 |
for _, v := range c.volumes {
|
| 318 |
- if v.Size != -1 {
|
|
| 319 |
- if v.RefCount == 0 {
|
|
| 320 |
- reclaimable += v.Size |
|
| 318 |
+ if v.UsageData.Size != -1 {
|
|
| 319 |
+ if v.UsageData.RefCount == 0 {
|
|
| 320 |
+ reclaimable += v.UsageData.Size |
|
| 321 | 321 |
} |
| 322 |
- totalSize += v.Size |
|
| 322 |
+ totalSize += v.UsageData.Size |
|
| 323 | 323 |
} |
| 324 | 324 |
} |
| 325 | 325 |
|
| ... | ... |
@@ -101,16 +101,16 @@ func (c *volumeContext) Label(name string) string {
|
| 101 | 101 |
|
| 102 | 102 |
func (c *volumeContext) Links() string {
|
| 103 | 103 |
c.AddHeader(linksHeader) |
| 104 |
- if c.v.Size == -1 {
|
|
| 104 |
+ if c.v.UsageData == nil {
|
|
| 105 | 105 |
return "N/A" |
| 106 | 106 |
} |
| 107 |
- return fmt.Sprintf("%d", c.v.RefCount)
|
|
| 107 |
+ return fmt.Sprintf("%d", c.v.UsageData.RefCount)
|
|
| 108 | 108 |
} |
| 109 | 109 |
|
| 110 | 110 |
func (c *volumeContext) Size() string {
|
| 111 | 111 |
c.AddHeader(sizeHeader) |
| 112 |
- if c.v.Size == -1 {
|
|
| 112 |
+ if c.v.UsageData == nil {
|
|
| 113 | 113 |
return "N/A" |
| 114 | 114 |
} |
| 115 |
- return units.HumanSize(float64(c.v.Size)) |
|
| 115 |
+ return units.HumanSize(float64(c.v.UsageData.Size)) |
|
| 116 | 116 |
} |
| ... | ... |
@@ -56,13 +56,12 @@ func (daemon *Daemon) SystemDiskUsage() (*types.DiskUsage, error) {
|
| 56 | 56 |
refs := daemon.volumes.Refs(v) |
| 57 | 57 |
|
| 58 | 58 |
tv := volumeToAPIType(v) |
| 59 |
- tv.RefCount = len(refs) |
|
| 60 | 59 |
sz, err := directory.Size(v.Path()) |
| 61 | 60 |
if err != nil {
|
| 62 | 61 |
logrus.Warnf("failed to determine size of volume %v", name)
|
| 63 | 62 |
sz = -1 |
| 64 | 63 |
} |
| 65 |
- tv.Size = sz |
|
| 64 |
+ tv.UsageData = &types.VolumeUsageData{Size: sz, RefCount: len(refs)}
|
|
| 66 | 65 |
allVolumes = append(allVolumes, tv) |
| 67 | 66 |
|
| 68 | 67 |
return nil |
| ... | ... |
@@ -29,10 +29,8 @@ type mounts []container.Mount |
| 29 | 29 |
// volumeToAPIType converts a volume.Volume to the type used by the remote API |
| 30 | 30 |
func volumeToAPIType(v volume.Volume) *types.Volume {
|
| 31 | 31 |
tv := &types.Volume{
|
| 32 |
- Name: v.Name(), |
|
| 33 |
- Driver: v.DriverName(), |
|
| 34 |
- Size: -1, |
|
| 35 |
- RefCount: -1, |
|
| 32 |
+ Name: v.Name(), |
|
| 33 |
+ Driver: v.DriverName(), |
|
| 36 | 34 |
} |
| 37 | 35 |
if v, ok := v.(volume.LabeledVolume); ok {
|
| 38 | 36 |
tv.Labels = v.Labels() |