xml file does virsh create
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
789a5ada40
commit
8ad58db1cf
15
main.go
15
main.go
|
@ -4,6 +4,7 @@ package main
|
|||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
|
@ -52,7 +53,19 @@ func main() {
|
|||
os.Exit(0)
|
||||
}
|
||||
log.Info("start droplet here:", d.Hostname)
|
||||
makeStandardXml(d)
|
||||
domcfg := makeStandardXml(d)
|
||||
|
||||
fmt.Printf("Virt type %s\n", domcfg.Type)
|
||||
fmt.Printf("Virt name %s\n", domcfg.Name)
|
||||
fmt.Printf("Virt UUID %s\n", domcfg.UUID)
|
||||
fmt.Printf("Virt Memory %s\n", domcfg.Memory)
|
||||
|
||||
qcow := "/home/nfs/" + d.Hostname + ".qcow2"
|
||||
setSimpleDisk(domcfg, qcow)
|
||||
// setMacs(domcfg, "33:44:33:11:22:11", "worldbr")
|
||||
setRandomMacs(domcfg)
|
||||
|
||||
writeoutXml(domcfg, "blahcarr")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<domain type='kvm' id='2'>
|
||||
<devices>
|
||||
<graphics type='spice' port='5900' autoport='no' listen='0.0.0.0'>
|
||||
<graphics type='spice' port='5921' autoport='no' listen='0.0.0.0' passwd='deprecatethis'>
|
||||
<listen type='address' address='0.0.0.0'/>
|
||||
<image compression='off'/>
|
||||
</graphics>
|
||||
|
|
|
@ -143,10 +143,6 @@
|
|||
<address type='usb' bus='0' port='1'/>
|
||||
</input>
|
||||
<input type='mouse' bus='ps2'/>
|
||||
<graphics type='spice' autoport='yes'>
|
||||
<listen type='address'/>
|
||||
<image compression='off'/>
|
||||
</graphics>
|
||||
<sound model='ich9'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x1b' function='0x0'/>
|
||||
</sound>
|
||||
|
|
24
xml.go
24
xml.go
|
@ -10,7 +10,7 @@ import (
|
|||
"libvirt.org/go/libvirtxml"
|
||||
)
|
||||
|
||||
func makeStandardXml(d *DropletT) {
|
||||
func makeStandardXml(d *DropletT) *libvirtxml.Domain {
|
||||
log.Info("create new xml file for:", d.Hostname)
|
||||
domcfg := &libvirtxml.Domain{}
|
||||
|
||||
|
@ -21,28 +21,24 @@ func makeStandardXml(d *DropletT) {
|
|||
addDefaults(domcfg, "qcow")
|
||||
addDefaults(domcfg, d.Hostname)
|
||||
|
||||
fmt.Printf("Virt type %s\n", domcfg.Type)
|
||||
fmt.Printf("Virt name %s\n", domcfg.Name)
|
||||
fmt.Printf("Virt UUID %s\n", domcfg.UUID)
|
||||
fmt.Printf("Virt Memory %s\n", domcfg.Memory)
|
||||
|
||||
qcow := "/home/nfs2/" + d.Hostname + ".qcow2"
|
||||
simpleDisk(domcfg, qcow)
|
||||
// setMacs(domcfg, "33:44:33:11:22:11", "worldbr")
|
||||
randomMacs(domcfg)
|
||||
return domcfg
|
||||
}
|
||||
|
||||
func writeoutXml(domcfg *libvirtxml.Domain, filename string) bool {
|
||||
xmldoc, err := domcfg.Marshal()
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("can't make xml file error:\n", err)
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
outfile := "/tmp/" + d.Hostname + ".xml"
|
||||
outfile := "/tmp/" + filename + ".xml"
|
||||
regfile, _ := os.OpenFile(outfile, os.O_RDWR|os.O_CREATE, 0666)
|
||||
fmt.Fprintln(regfile, xmldoc)
|
||||
|
||||
log.Info("File is in", outfile)
|
||||
regfile.Close()
|
||||
return true
|
||||
}
|
||||
|
||||
func setDiskFilename(domcfg *libvirtxml.Domain, filename string) {
|
||||
|
@ -75,7 +71,7 @@ func addDefaults(d *libvirtxml.Domain, filename string) {
|
|||
}
|
||||
}
|
||||
|
||||
func simpleDisk(domcfg *libvirtxml.Domain, filename string) {
|
||||
func setSimpleDisk(domcfg *libvirtxml.Domain, filename string) {
|
||||
// Clear out the existing disks (if any)
|
||||
domcfg.Devices.Disks = nil
|
||||
|
||||
|
@ -133,7 +129,7 @@ func setMacs(domcfg *libvirtxml.Domain, mac string, brname string) {
|
|||
domcfg.Devices.Interfaces = append(domcfg.Devices.Interfaces, newNet)
|
||||
}
|
||||
|
||||
func randomMacs(domcfg *libvirtxml.Domain) {
|
||||
func setRandomMacs(domcfg *libvirtxml.Domain) {
|
||||
for i, x := range domcfg.Devices.Interfaces {
|
||||
// Create a new DomainDiskInterfaces struct
|
||||
newMac := &libvirtxml.DomainInterfaceMAC{
|
||||
|
|
Loading…
Reference in New Issue