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 (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -52,7 +53,19 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
log.Info("start droplet here:", d.Hostname)
|
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)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<domain type='kvm' id='2'>
|
<domain type='kvm' id='2'>
|
||||||
<devices>
|
<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'/>
|
<listen type='address' address='0.0.0.0'/>
|
||||||
<image compression='off'/>
|
<image compression='off'/>
|
||||||
</graphics>
|
</graphics>
|
||||||
|
|
|
@ -143,10 +143,6 @@
|
||||||
<address type='usb' bus='0' port='1'/>
|
<address type='usb' bus='0' port='1'/>
|
||||||
</input>
|
</input>
|
||||||
<input type='mouse' bus='ps2'/>
|
<input type='mouse' bus='ps2'/>
|
||||||
<graphics type='spice' autoport='yes'>
|
|
||||||
<listen type='address'/>
|
|
||||||
<image compression='off'/>
|
|
||||||
</graphics>
|
|
||||||
<sound model='ich9'>
|
<sound model='ich9'>
|
||||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x1b' function='0x0'/>
|
<address type='pci' domain='0x0000' bus='0x00' slot='0x1b' function='0x0'/>
|
||||||
</sound>
|
</sound>
|
||||||
|
|
24
xml.go
24
xml.go
|
@ -10,7 +10,7 @@ import (
|
||||||
"libvirt.org/go/libvirtxml"
|
"libvirt.org/go/libvirtxml"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeStandardXml(d *DropletT) {
|
func makeStandardXml(d *DropletT) *libvirtxml.Domain {
|
||||||
log.Info("create new xml file for:", d.Hostname)
|
log.Info("create new xml file for:", d.Hostname)
|
||||||
domcfg := &libvirtxml.Domain{}
|
domcfg := &libvirtxml.Domain{}
|
||||||
|
|
||||||
|
@ -21,28 +21,24 @@ func makeStandardXml(d *DropletT) {
|
||||||
addDefaults(domcfg, "qcow")
|
addDefaults(domcfg, "qcow")
|
||||||
addDefaults(domcfg, d.Hostname)
|
addDefaults(domcfg, d.Hostname)
|
||||||
|
|
||||||
fmt.Printf("Virt type %s\n", domcfg.Type)
|
return domcfg
|
||||||
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)
|
|
||||||
|
|
||||||
|
func writeoutXml(domcfg *libvirtxml.Domain, filename string) bool {
|
||||||
xmldoc, err := domcfg.Marshal()
|
xmldoc, err := domcfg.Marshal()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("can't make xml file error:\n", err)
|
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)
|
regfile, _ := os.OpenFile(outfile, os.O_RDWR|os.O_CREATE, 0666)
|
||||||
fmt.Fprintln(regfile, xmldoc)
|
fmt.Fprintln(regfile, xmldoc)
|
||||||
|
|
||||||
log.Info("File is in", outfile)
|
log.Info("File is in", outfile)
|
||||||
|
regfile.Close()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func setDiskFilename(domcfg *libvirtxml.Domain, filename string) {
|
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)
|
// Clear out the existing disks (if any)
|
||||||
domcfg.Devices.Disks = nil
|
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)
|
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 {
|
for i, x := range domcfg.Devices.Interfaces {
|
||||||
// Create a new DomainDiskInterfaces struct
|
// Create a new DomainDiskInterfaces struct
|
||||||
newMac := &libvirtxml.DomainInterfaceMAC{
|
newMac := &libvirtxml.DomainInterfaceMAC{
|
||||||
|
|
Loading…
Reference in New Issue