Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage: Show correct instance root disk size on API #14511

Merged
merged 8 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/rest-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2516,13 +2516,13 @@ definitions:
InstanceStateDisk:
properties:
total:
description: Total size in bytes
description: Total size in bytes. Uses -1 to convey that the instance has access to the entire pool's storage.
example: 502239232
format: int64
type: integer
x-go-name: Total
usage:
description: Disk usage in bytes
description: Disk usage in bytes. Uses -1 to indicate that the storage driver for the instance's pool does not support retrieving the disk usage.
example: 502239232
format: int64
type: integer
Expand Down
24 changes: 18 additions & 6 deletions lxc/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,18 +507,30 @@ func (c *cmdInfo) instanceInfo(d lxd.InstanceServer, name string, showLog bool)
fmt.Printf(" "+i18n.G("Processes: %d")+"\n", inst.State.Processes)

// Disk usage
diskInfo := ""
diskUsage := ""
diskTotal := ""
if inst.State.Disk != nil {
for entry, disk := range inst.State.Disk {
if disk.Usage != 0 {
tomponline marked this conversation as resolved.
Show resolved Hide resolved
diskInfo += fmt.Sprintf(" %s: %s\n", entry, units.GetByteSizeStringIEC(disk.Usage, 2))
// Only show usage when supported.
if disk.Usage != -1 {
diskUsage += fmt.Sprintf(" %s: %s\n", entry, units.GetByteSizeStringIEC(disk.Usage, 2))
}
}

for entry, disk := range inst.State.Disk {
// Only show total for disks that are bounded within the pool.
if disk.Total != -1 {
diskTotal += fmt.Sprintf(" %s: %s\n", entry, units.GetByteSizeStringIEC(disk.Usage, 2))
}
}
}

if diskUsage != "" {
fmt.Printf(" %s\n%s", i18n.G("Disk usage:"), diskUsage)
}

if diskInfo != "" {
fmt.Printf(" %s\n", i18n.G("Disk usage:"))
fmt.Print(diskInfo)
if diskTotal != "" {
fmt.Printf(" %s\n%s", i18n.G("Disk total:"), diskTotal)
}

// CPU usage
Expand Down
14 changes: 12 additions & 2 deletions lxd/storage/backend_lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3261,12 +3261,14 @@ func (b *lxdBackend) GetInstanceUsage(inst instance.Instance) (*VolumeUsage, err
volStorageName := project.Instance(inst.Project().Name, inst.Name())
vol := b.GetVolume(volType, contentType, volStorageName, dbVol.Config)

// Get the usage.
// Get the usage
// If storage driver does not support getting the volume usage, proceed getting the total.
size, err := b.driver.GetVolumeUsage(vol)
if err != nil {
if err != nil && !errors.Is(err, drivers.ErrNotSupported) {
return nil, err
}

// If driver does not support getting volume usage, this value would be -1.
hamistao marked this conversation as resolved.
Show resolved Hide resolved
val.Used = size

// Get the total size.
Expand All @@ -3287,6 +3289,14 @@ func (b *lxdBackend) GetInstanceUsage(inst instance.Instance) (*VolumeUsage, err
}
}

// If the instance volume is neither block based/typed nor bound by the device's size config key,
// this means it is only bound by the pool limits and has access to the entire pool storage.
// So instead of showing the entire pool size for each instance disk, we return -1 to signify the root disk
// is unbounded below the pool level.
if val.Total == 0 {
val.Total = -1
}

return &val, nil
}

Expand Down
64 changes: 34 additions & 30 deletions po/ar.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: lxd\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-12-05 16:02+0000\n"
"POT-Creation-Date: 2024-12-09 03:18-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
Expand Down Expand Up @@ -855,7 +855,7 @@ msgstr ""
msgid "Backup exported successfully!"
msgstr ""

#: lxc/info.go:654 lxc/storage_volume.go:1527
#: lxc/info.go:666 lxc/storage_volume.go:1527
msgid "Backups:"
msgstr ""

Expand Down Expand Up @@ -903,11 +903,11 @@ msgstr ""
msgid "Bridge:"
msgstr ""

#: lxc/info.go:577 lxc/network.go:944
#: lxc/info.go:589 lxc/network.go:944
msgid "Bytes received"
msgstr ""

#: lxc/info.go:578 lxc/network.go:945
#: lxc/info.go:590 lxc/network.go:945
msgid "Bytes sent"
msgstr ""

Expand Down Expand Up @@ -936,11 +936,11 @@ msgstr ""
msgid "CPU USAGE"
msgstr ""

#: lxc/info.go:527
#: lxc/info.go:539
msgid "CPU usage (in seconds)"
msgstr ""

#: lxc/info.go:531
#: lxc/info.go:543
msgid "CPU usage:"
msgstr ""

Expand Down Expand Up @@ -1865,7 +1865,11 @@ msgstr ""
msgid "Disk %d:"
msgstr ""

#: lxc/info.go:520
#: lxc/info.go:533
msgid "Disk total:"
msgstr ""

#: lxc/info.go:529
msgid "Disk usage:"
msgstr ""

Expand Down Expand Up @@ -2138,7 +2142,7 @@ msgid ""
"AND stdout are terminals (stderr is ignored)."
msgstr ""

#: lxc/info.go:640 lxc/info.go:691 lxc/storage_volume.go:1514
#: lxc/info.go:652 lxc/info.go:703 lxc/storage_volume.go:1514
#: lxc/storage_volume.go:1564
msgid "Expires at"
msgstr ""
Expand Down Expand Up @@ -2663,7 +2667,7 @@ msgstr ""
msgid "HOSTNAME"
msgstr ""

#: lxc/info.go:566
#: lxc/info.go:578
msgid "Host interface"
msgstr ""

Expand Down Expand Up @@ -2717,7 +2721,7 @@ msgstr ""
msgid "IP ADDRESS"
msgstr ""

#: lxc/info.go:582
#: lxc/info.go:594
msgid "IP addresses"
msgstr ""

Expand Down Expand Up @@ -2879,7 +2883,7 @@ msgstr ""
msgid "Inspect permissions"
msgstr ""

#: lxc/info.go:692
#: lxc/info.go:704
msgid "Instance Only"
msgstr ""

Expand Down Expand Up @@ -3433,7 +3437,7 @@ msgstr ""
msgid "Log level filtering can only be used with pretty formatting"
msgstr ""

#: lxc/info.go:720
#: lxc/info.go:732
msgid "Log:"
msgstr ""

Expand All @@ -3449,7 +3453,7 @@ msgstr ""
msgid "MAC ADDRESS"
msgstr ""

#: lxc/info.go:570
#: lxc/info.go:582
msgid "MAC address"
msgstr ""

Expand Down Expand Up @@ -3492,7 +3496,7 @@ msgstr ""
msgid "MII state"
msgstr ""

#: lxc/info.go:574
#: lxc/info.go:586
msgid "MTU"
msgstr ""

Expand Down Expand Up @@ -3740,15 +3744,15 @@ msgstr ""
msgid "Member %s renamed to %s"
msgstr ""

#: lxc/info.go:538
#: lxc/info.go:550
msgid "Memory (current)"
msgstr ""

#: lxc/info.go:542
#: lxc/info.go:554
msgid "Memory (peak)"
msgstr ""

#: lxc/info.go:554
#: lxc/info.go:566
msgid "Memory usage:"
msgstr ""

Expand Down Expand Up @@ -4088,7 +4092,7 @@ msgstr ""
msgid "NVRM Version: %v"
msgstr ""

#: lxc/info.go:638 lxc/info.go:689 lxc/storage_volume.go:1512
#: lxc/info.go:650 lxc/info.go:701 lxc/storage_volume.go:1512
#: lxc/storage_volume.go:1562
msgid "Name"
msgstr ""
Expand Down Expand Up @@ -4201,7 +4205,7 @@ msgstr ""
msgid "Network type"
msgstr ""

#: lxc/info.go:595 lxc/network.go:943
#: lxc/info.go:607 lxc/network.go:943
msgid "Network usage:"
msgstr ""

Expand Down Expand Up @@ -4320,7 +4324,7 @@ msgstr ""
msgid "Operation %s deleted"
msgstr ""

#: lxc/info.go:693 lxc/storage_volume.go:1566
#: lxc/info.go:705 lxc/storage_volume.go:1566
msgid "Optimized Storage"
msgstr ""

Expand Down Expand Up @@ -4379,11 +4383,11 @@ msgstr ""
msgid "PUBLIC"
msgstr ""

#: lxc/info.go:579 lxc/network.go:946
#: lxc/info.go:591 lxc/network.go:946
msgid "Packets received"
msgstr ""

#: lxc/info.go:580 lxc/network.go:947
#: lxc/info.go:592 lxc/network.go:947
msgid "Packets sent"
msgstr ""

Expand Down Expand Up @@ -5619,7 +5623,7 @@ msgstr ""
msgid "Snapshots are read-only and can't have their configuration changed"
msgstr ""

#: lxc/info.go:607 lxc/storage_volume.go:1491
#: lxc/info.go:619 lxc/storage_volume.go:1491
msgid "Snapshots:"
msgstr ""

Expand Down Expand Up @@ -5650,7 +5654,7 @@ msgstr ""
msgid "Starting %s"
msgstr ""

#: lxc/info.go:564
#: lxc/info.go:576
msgid "State"
msgstr ""

Expand All @@ -5659,7 +5663,7 @@ msgstr ""
msgid "State: %s"
msgstr ""

#: lxc/info.go:641
#: lxc/info.go:653
msgid "Stateful"
msgstr ""

Expand Down Expand Up @@ -5761,11 +5765,11 @@ msgstr ""
msgid "Supported ports: %s"
msgstr ""

#: lxc/info.go:546
#: lxc/info.go:558
msgid "Swap (current)"
msgstr ""

#: lxc/info.go:550
#: lxc/info.go:562
msgid "Swap (peak)"
msgstr ""

Expand Down Expand Up @@ -5806,7 +5810,7 @@ msgstr ""
msgid "TYPE"
msgstr ""

#: lxc/info.go:639 lxc/info.go:690 lxc/storage_volume.go:1563
#: lxc/info.go:651 lxc/info.go:702 lxc/storage_volume.go:1563
msgid "Taken at"
msgstr ""

Expand Down Expand Up @@ -6130,7 +6134,7 @@ msgstr ""
msgid "Try `lxc info --show-log %s` for more info"
msgstr ""

#: lxc/info.go:563
#: lxc/info.go:575
msgid "Type"
msgstr ""

Expand Down Expand Up @@ -6375,7 +6379,7 @@ msgstr ""
msgid "Unsupported content type for attaching to instances"
msgstr ""

#: lxc/info.go:712
#: lxc/info.go:724
#, c-format
msgid "Unsupported instance type: %s"
msgstr ""
Expand Down
Loading
Loading