Implement complete support for disks - #199
Open
davispuh wants to merge 7 commits into
Open
Conversation
Needed for backward compatibility since Hash#except needs Ruby 3.0+
There was a problem hiding this comment.
Pull request overview
This PR extends fog-libvirt’s Server disk handling to support a wider range of libvirt disk configurations (multiple disks, CD-ROMs, NVMe/network-backed sources, and richer disk XML), by introducing a structured Disk model hierarchy, updating domain listing to parse disks, and adding test coverage.
Changes:
- Added a full set of
Server::Disk(and nested) models to parse/build libvirt disk XML with many optional sub-elements. - Updated domain listing to parse disks from domain XML and expose them on server attributes.
- Refactored server XML generation to emit disks from explicit
:disksplus derived volume/ISO disks, and added comprehensive disk minitests.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| minitests/server/disks_test.rb | Adds end-to-end coverage for disk JSON/XML roundtrips, mirrors, block disks, and Ceph disk XML. |
| lib/fog/libvirt/requests/compute/list_domains.rb | Parses <devices><disk> elements into disk attribute hashes for server listings. |
| lib/fog/libvirt/models/compute/util/util.rb | Adds XML attribute/value helpers and assignment casting helpers used by new models. |
| lib/fog/libvirt/models/compute/server/seclabel.rb | Implements a Seclabel model for disk/source security labels. |
| lib/fog/libvirt/models/compute/server/encryption.rb | Implements an Encryption model for disk/source encryption XML. |
| lib/fog/libvirt/models/compute/server/driver/virtio.rb | Adds Virtio driver feature attributes (iommu/ats/packed/page_per_vq). |
| lib/fog/libvirt/models/compute/server/driver/statistics.rb | Adds Driver statistics model with intervals and latency histograms. |
| lib/fog/libvirt/models/compute/server/driver/latency_histogram.rb | Adds latency histogram model for driver statistics XML. |
| lib/fog/libvirt/models/compute/server/driver/iothread.rb | Adds IOThread model for driver iothreads XML. |
| lib/fog/libvirt/models/compute/server/disk/target.rb | Adds Disk::Target model for target device/bus/tray/etc. |
| lib/fog/libvirt/models/compute/server/disk/source/reservations.rb | Adds Source reservations model for reservation XML. |
| lib/fog/libvirt/models/compute/server/disk/source/data_store.rb | Adds Source DataStore support (network datastore XML). |
| lib/fog/libvirt/models/compute/server/disk/source.rb | Adds Disk::Source model with many libvirt source options and nested elements. |
| lib/fog/libvirt/models/compute/server/disk/mirror.rb | Adds Disk::Mirror parsing model for mirror XML. |
| lib/fog/libvirt/models/compute/server/disk/metadata_cache.rb | Adds MetadataCache model used by format/driver. |
| lib/fog/libvirt/models/compute/server/disk/format.rb | Adds Disk::Format model (type + metadata cache). |
| lib/fog/libvirt/models/compute/server/disk/driver.rb | Adds Disk::Driver model with virtio fields, statistics, iothreads, metadata cache. |
| lib/fog/libvirt/models/compute/server/disk/backing_store.rb | Adds BackingStore model with nested backing stores, format, and source. |
| lib/fog/libvirt/models/compute/server/disk.rb | Adds the top-level Disk model with parse/build logic and nested components. |
| lib/fog/libvirt/models/compute/server.rb | Switches domain XML disk emission to new disk models and adds derived volume/ISO disk handling. |
| lib/fog/libvirt/models/compute/common/pci_address.rb | Adds PCI address subtype for Address. |
| lib/fog/libvirt/models/compute/common/drive_address.rb | Adds Drive address subtype for Address. |
| lib/fog/libvirt/models/compute/common/clonable_model.rb | Adds deep-clone/deep-dup support for attribute-backed models. |
| lib/fog/libvirt/models/compute/common/attribute_model.rb | Introduces a Fog::Model subclass tailored to attribute-only models (no service identity assumptions). |
| lib/fog/libvirt/models/compute/common/address.rb | Adds Address base class with subtype dispatch and XML parsing/building. |
Suppressed comments (3)
lib/fog/libvirt/models/compute/server.rb:511
volume_diskscallsdisks.any?, which raises whendisksis nil. Since callers can create servers without:disks, this should be nil-safe (e.g., by usingdisks.to_a).
def volume_disks
used_names = disk_device_names
@volumes.to_a.filter_map do |volume|
next if disks.any? { |disk| disk_source_path(disk) == volume.path }
lib/fog/libvirt/models/compute/server.rb:565
iso_diskchecksdisks.any?, which raises whendisksis nil. Usedisks.to_a.any?to handle servers created without:disks.
return nil if disks.any? { |disk| disk_source_path(disk) == source }
lib/fog/libvirt/models/compute/server.rb:580
disk_device_namesassumesdisksis always an Array, but it can be nil. This will raise when building volume/ISO disks for servers created without:disks.
def disk_device_names
disks.filter_map do |disk|
target = model_cast(disk, Disk).target
target&.dev
end
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
davispuh
force-pushed
the
disks
branch
2 times, most recently
from
August 16, 2026 22:19
db98b9d to
4d7f180
Compare
Contributor
Author
|
Use this functionality like: server = compute.servers.create(
disks: [
{
type: :file,
device: :cdrom,
source: { file: iso_path },
target: { dev: :sda, bus: :scsi }
},
{
type: :nvme,
device: :disk,
source: {
type: :pci,
managed: true,
namespace: 1,
address: { bus: '0x30', slot: '0x00' }
},
target: { dev: :nvme0n1, bus: :virtio }
}
]
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently it's not possible to configure libvirt disks like adding multiple cdrom's or NVMe's.
This PR implements complete support for disks so all disk configurations that are supported by libvirt can be achieved.