simpleDisk() to add qcow2 file

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-18 08:18:11 -05:00
parent c9ccf688c2
commit bffee3265e
1 changed files with 26 additions and 0 deletions

26
xml.go
View File

@ -76,3 +76,29 @@ func addDefaults(d *libvirtxml.Domain, filename string) {
return return
} }
} }
func simpleDisk(domcfg *libvirtxml.Domain, filename string) {
// Clear out the existing disks (if any)
domcfg.Devices.Disks = nil
// Define a new disk with "mynew.qcow2"
newDisk := libvirtxml.DomainDisk{
Device: "disk",
Driver: &libvirtxml.DomainDiskDriver{
Name: "qemu",
Type: "qcow2",
},
Source: &libvirtxml.DomainDiskSource{
File: &libvirtxml.DomainDiskSourceFile{
File: filename,
},
},
Target: &libvirtxml.DomainDiskTarget{
Dev: "vda",
Bus: "virtio",
},
}
// Add the new disk to the domain configuration
domcfg.Devices.Disks = append(domcfg.Devices.Disks, newDisk)
}