engine: resources: virt: Clean up virt resource for lang

This commit is contained in:
James Shubin
2019-02-01 07:02:06 -05:00
parent b5e29771ab
commit 35c26f9ee5

View File

@@ -71,24 +71,24 @@ type VirtRes struct {
init *engine.Init init *engine.Init
URI string `yaml:"uri"` // connection uri, eg: qemu:///session URI string `lang:"uri" yaml:"uri"` // connection uri, eg: qemu:///session
State string `yaml:"state"` // running, paused, shutoff State string `lang:"state" yaml:"state"` // running, paused, shutoff
Transient bool `yaml:"transient"` // defined (false) or undefined (true) Transient bool `lang:"transient" yaml:"transient"` // defined (false) or undefined (true)
CPUs uint `yaml:"cpus"` CPUs uint `lang:"cpus" yaml:"cpus"`
MaxCPUs uint `yaml:"maxcpus"` MaxCPUs uint `lang:"maxcpus" yaml:"maxcpus"`
Memory uint64 `yaml:"memory"` // in KBytes Memory uint64 `lang:"memory" yaml:"memory"` // in KBytes
OSInit string `yaml:"osinit"` // init used by lxc OSInit string `lang:"osinit" yaml:"osinit"` // init used by lxc
Boot []string `yaml:"boot"` // boot order. values: fd, hd, cdrom, network Boot []string `lang:"boot" yaml:"boot"` // boot order. values: fd, hd, cdrom, network
Disk []diskDevice `yaml:"disk"` Disk []DiskDevice `lang:"disk" yaml:"disk"`
CDRom []cdRomDevice `yaml:"cdrom"` CDRom []CDRomDevice `lang:"cdrom" yaml:"cdrom"`
Network []networkDevice `yaml:"network"` Network []NetworkDevice `lang:"network" yaml:"network"`
Filesystem []filesystemDevice `yaml:"filesystem"` Filesystem []FilesystemDevice `lang:"filesystem" yaml:"filesystem"`
Auth *VirtAuth `yaml:"auth"` Auth *VirtAuth `lang:"auth" yaml:"auth"`
HotCPUs bool `yaml:"hotcpus"` // allow hotplug of cpus? HotCPUs bool `lang:"hotcpus" yaml:"hotcpus"` // allow hotplug of cpus?
// FIXME: values here should be enum's! // FIXME: values here should be enum's!
RestartOnDiverge string `yaml:"restartondiverge"` // restart policy: "ignore", "ifneeded", "error" RestartOnDiverge string `lang:"restartondiverge" yaml:"restartondiverge"` // restart policy: "ignore", "ifneeded", "error"
RestartOnRefresh bool `yaml:"restartonrefresh"` // restart on refresh? RestartOnRefresh bool `lang:"restartonrefresh" yaml:"restartonrefresh"` // restart on refresh?
wg *sync.WaitGroup wg *sync.WaitGroup
conn *libvirt.Connect conn *libvirt.Connect
@@ -103,8 +103,8 @@ type VirtRes struct {
// VirtAuth is used to pass credentials to libvirt. // VirtAuth is used to pass credentials to libvirt.
type VirtAuth struct { type VirtAuth struct {
Username string `yaml:"username"` Username string `lang:"username" yaml:"username"`
Password string `yaml:"password"` Password string `lang:"password" yaml:"password"`
} }
// Default returns some sensible defaults for this resource. // Default returns some sensible defaults for this resource.
@@ -970,44 +970,51 @@ type virtDevice interface {
GetXML(idx int) string GetXML(idx int) string
} }
type diskDevice struct { // DiskDevice represents a disk that is attached to the virt machine.
Source string `yaml:"source"` type DiskDevice struct {
Type string `yaml:"type"` Source string `lang:"source" yaml:"source"`
Type string `lang:"type" yaml:"type"`
} }
type cdRomDevice struct { // CDRomDevice represents a CDRom device that is attached to the virt machine.
Source string `yaml:"source"` type CDRomDevice struct {
Type string `yaml:"type"` Source string `lang:"source" yaml:"source"`
Type string `lang:"type" yaml:"type"`
} }
type networkDevice struct { // NetworkDevice represents a network card that is attached to the virt machine.
Name string `yaml:"name"` type NetworkDevice struct {
MAC string `yaml:"mac"` Name string `lang:"name" yaml:"name"`
MAC string `lang:"mac" yaml:"mac"`
} }
type filesystemDevice struct { // FilesystemDevice represents a filesystem that is attached to the virt
Access string `yaml:"access"` // machine.
Source string `yaml:"source"` type FilesystemDevice struct {
Target string `yaml:"target"` Access string `lang:"access" yaml:"access"`
ReadOnly bool `yaml:"read_only"` Source string `lang:"source" yaml:"source"`
Target string `lang:"target" yaml:"target"`
ReadOnly bool `lang:"read_only" yaml:"read_only"`
} }
func (d *diskDevice) GetXML(idx int) string { // GetXML returns the XML representation of this device.
source, _ := util.ExpandHome(d.Source) // TODO: should we handle errors? func (obj *DiskDevice) GetXML(idx int) string {
source, _ := util.ExpandHome(obj.Source) // TODO: should we handle errors?
var b string var b string
b += "<disk type='file' device='disk'>" b += "<disk type='file' device='disk'>"
b += fmt.Sprintf("<driver name='qemu' type='%s'/>", d.Type) b += fmt.Sprintf("<driver name='qemu' type='%s'/>", obj.Type)
b += fmt.Sprintf("<source file='%s'/>", source) b += fmt.Sprintf("<source file='%s'/>", source)
b += fmt.Sprintf("<target dev='vd%s' bus='virtio'/>", util.NumToAlpha(idx)) b += fmt.Sprintf("<target dev='vd%s' bus='virtio'/>", util.NumToAlpha(idx))
b += "</disk>" b += "</disk>"
return b return b
} }
func (d *cdRomDevice) GetXML(idx int) string { // GetXML returns the XML representation of this device.
source, _ := util.ExpandHome(d.Source) // TODO: should we handle errors? func (obj *CDRomDevice) GetXML(idx int) string {
source, _ := util.ExpandHome(obj.Source) // TODO: should we handle errors?
var b string var b string
b += "<disk type='file' device='cdrom'>" b += "<disk type='file' device='cdrom'>"
b += fmt.Sprintf("<driver name='qemu' type='%s'/>", d.Type) b += fmt.Sprintf("<driver name='qemu' type='%s'/>", obj.Type)
b += fmt.Sprintf("<source file='%s'/>", source) b += fmt.Sprintf("<source file='%s'/>", source)
b += fmt.Sprintf("<target dev='hd%s' bus='ide'/>", util.NumToAlpha(idx)) b += fmt.Sprintf("<target dev='hd%s' bus='ide'/>", util.NumToAlpha(idx))
b += "<readonly/>" b += "<readonly/>"
@@ -1015,29 +1022,31 @@ func (d *cdRomDevice) GetXML(idx int) string {
return b return b
} }
func (d *networkDevice) GetXML(idx int) string { // GetXML returns the XML representation of this device.
if d.MAC == "" { func (obj *NetworkDevice) GetXML(idx int) string {
d.MAC = randMAC() if obj.MAC == "" {
obj.MAC = randMAC()
} }
var b string var b string
b += "<interface type='network'>" b += "<interface type='network'>"
b += fmt.Sprintf("<mac address='%s'/>", d.MAC) b += fmt.Sprintf("<mac address='%s'/>", obj.MAC)
b += fmt.Sprintf("<source network='%s'/>", d.Name) b += fmt.Sprintf("<source network='%s'/>", obj.Name)
b += "</interface>" b += "</interface>"
return b return b
} }
func (d *filesystemDevice) GetXML(idx int) string { // GetXML returns the XML representation of this device.
source, _ := util.ExpandHome(d.Source) // TODO: should we handle errors? func (obj *FilesystemDevice) GetXML(idx int) string {
source, _ := util.ExpandHome(obj.Source) // TODO: should we handle errors?
var b string var b string
b += "<filesystem" // open b += "<filesystem" // open
if d.Access != "" { if obj.Access != "" {
b += fmt.Sprintf(" accessmode='%s'", d.Access) b += fmt.Sprintf(" accessmode='%s'", obj.Access)
} }
b += ">" // close b += ">" // close
b += fmt.Sprintf("<source dir='%s'/>", source) b += fmt.Sprintf("<source dir='%s'/>", source)
b += fmt.Sprintf("<target dir='%s'/>", d.Target) b += fmt.Sprintf("<target dir='%s'/>", obj.Target)
if d.ReadOnly { if obj.ReadOnly {
b += "<readonly/>" b += "<readonly/>"
} }
b += "</filesystem>" b += "</filesystem>"