forked from machine-drivers/docker-machine-kvm
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use libvirt-go-xml struct instead of a string template for domain
- Loading branch information
1 parent
71ac779
commit 92225c6
Showing
4 changed files
with
171 additions
and
124 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package libvirt | ||
|
||
import ( | ||
libvirtxml "github.com/libvirt/libvirt-go-xml" | ||
) | ||
|
||
func domainXML(d *Driver) (string, error) { | ||
domain := libvirtxml.Domain{ | ||
Type: "kvm", | ||
Name: d.MachineName, | ||
Memory: &libvirtxml.DomainMemory{ | ||
Value: uint(d.Memory), | ||
Unit: "MB", | ||
}, | ||
VCPU: &libvirtxml.DomainVCPU{ | ||
Placement: "static", | ||
Value: uint(d.CPU), | ||
}, | ||
Features: &libvirtxml.DomainFeatureList{ | ||
ACPI: &libvirtxml.DomainFeature{}, | ||
APIC: &libvirtxml.DomainFeatureAPIC{}, | ||
PAE: &libvirtxml.DomainFeature{}, | ||
}, | ||
CPU: &libvirtxml.DomainCPU{ | ||
Mode: "host-passthrough", | ||
Features: []libvirtxml.DomainCPUFeature{ | ||
{ | ||
Policy: "disable", | ||
Name: "rdrand", | ||
}, | ||
}, | ||
}, | ||
OS: &libvirtxml.DomainOS{ | ||
Type: &libvirtxml.DomainOSType{ | ||
Arch: "x86_64", | ||
Type: "hvm", | ||
}, | ||
BootDevices: []libvirtxml.DomainBootDevice{ | ||
{ | ||
Dev: "hd", | ||
}, | ||
}, | ||
BootMenu: &libvirtxml.DomainBootMenu{ | ||
Enable: "no", | ||
}, | ||
}, | ||
Clock: &libvirtxml.DomainClock{ | ||
Offset: "utc", | ||
}, | ||
Devices: &libvirtxml.DomainDeviceList{ | ||
Disks: []libvirtxml.DomainDisk{ | ||
{ | ||
Device: "disk", | ||
Driver: &libvirtxml.DomainDiskDriver{ | ||
Name: "qemu", | ||
Type: "qcow2", | ||
Cache: d.CacheMode, | ||
IO: d.IOMode, | ||
}, | ||
Source: &libvirtxml.DomainDiskSource{ | ||
File: &libvirtxml.DomainDiskSourceFile{ | ||
File: d.getDiskImagePath(), | ||
}, | ||
}, | ||
Target: &libvirtxml.DomainDiskTarget{ | ||
Dev: "vda", | ||
Bus: "virtio", | ||
}, | ||
}, | ||
}, | ||
Graphics: []libvirtxml.DomainGraphic{ | ||
{ | ||
VNC: &libvirtxml.DomainGraphicVNC{ | ||
AutoPort: "yes", | ||
Listen: "127.0.0.1", | ||
Listeners: []libvirtxml.DomainGraphicListener{ | ||
{ | ||
Address: &libvirtxml.DomainGraphicListenerAddress{ | ||
Address: "127.0.0.1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Consoles: []libvirtxml.DomainConsole{ | ||
{}, | ||
}, | ||
Channels: []libvirtxml.DomainChannel{ | ||
{ | ||
Target: &libvirtxml.DomainChannelTarget{ | ||
VirtIO: &libvirtxml.DomainChannelTargetVirtIO{ | ||
Name: "org.qemu.guest_agent.0", | ||
}, | ||
}, | ||
}, | ||
}, | ||
RNGs: []libvirtxml.DomainRNG{ | ||
{ | ||
Model: "virtio", | ||
Backend: &libvirtxml.DomainRNGBackend{ | ||
Random: &libvirtxml.DomainRNGBackendRandom{ | ||
Device: "/dev/urandom", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
if d.Network != "" { | ||
domain.Devices.Interfaces = []libvirtxml.DomainInterface{ | ||
{ | ||
MAC: &libvirtxml.DomainInterfaceMAC{ | ||
Address: "52:fd:fc:07:21:82", | ||
}, | ||
Source: &libvirtxml.DomainInterfaceSource{ | ||
Network: &libvirtxml.DomainInterfaceSourceNetwork{ | ||
Network: d.Network, | ||
}, | ||
}, | ||
Model: &libvirtxml.DomainInterfaceModel{ | ||
Type: "virtio", | ||
}, | ||
}, | ||
} | ||
} | ||
if d.VSock { | ||
domain.Devices.VSock = &libvirtxml.DomainVSock{ | ||
Model: "virtio", | ||
CID: &libvirtxml.DomainVSockCID{ | ||
Auto: "yes", | ||
}, | ||
} | ||
} | ||
return domain.Marshal() | ||
} |
This file contains 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
This file contains 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