pretty good XML handling at this point
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
cf79357bba
commit
15f48a01ab
|
@ -20,24 +20,23 @@ func addDomainDroplet(domcfg *libvirtxml.Domain) (*DropletT, error) {
|
|||
}
|
||||
|
||||
d, _ := findDomain(domcfg)
|
||||
if d != nil {
|
||||
return d, errors.New(d.pb.Hostname + " droplet exists. need to update instead")
|
||||
if d == nil {
|
||||
// this is a new unknown droplet (not in the config file)
|
||||
d = new(DropletT)
|
||||
|
||||
d.pb = me.cluster.AddDroplet(domcfg.UUID, domcfg.Name, 2, 2*1024*1024)
|
||||
d.pb.StartState = pb.DropletState_OFF
|
||||
d.CurrentState = pb.DropletState_UNKNOWN
|
||||
|
||||
// if the domcfg doesn't have a uuid, make a new one here
|
||||
if d.pb.Uuid == "" {
|
||||
u := uuid.New()
|
||||
d.pb.Uuid = u.String()
|
||||
}
|
||||
|
||||
me.droplets = append(me.droplets, d)
|
||||
me.changed = true
|
||||
}
|
||||
// this is a new unknown droplet (not in the config file)
|
||||
d = new(DropletT)
|
||||
|
||||
d.pb = me.cluster.AddDroplet(domcfg.UUID, domcfg.Name, 2, 2*1024*1024)
|
||||
d.pb.StartState = pb.DropletState_OFF
|
||||
d.CurrentState = pb.DropletState_UNKNOWN
|
||||
|
||||
// if the domcfg doesn't have a uuid, make a new one here
|
||||
if d.pb.Uuid == "" {
|
||||
u := uuid.New()
|
||||
d.pb.Uuid = u.String()
|
||||
}
|
||||
|
||||
me.droplets = append(me.droplets, d)
|
||||
me.changed = true
|
||||
|
||||
err := updateDroplet(d, domcfg)
|
||||
if err != nil {
|
||||
|
|
|
@ -331,10 +331,9 @@ func dumpNonStandardXML(domcfg *libvirtxml.Domain) (string, error) {
|
|||
domcfg.CPU = nil
|
||||
case "custom":
|
||||
updatedXML, _ := xml.MarshalIndent(domcfg.CPU, "", " ")
|
||||
log.Info("Ignore custom CPU Start")
|
||||
log.Info("Ignoring custom CPU Start")
|
||||
fmt.Println(string(updatedXML))
|
||||
log.Info("Ignore custom CPU End")
|
||||
log.Info("Add --xml-ignore-cpu to ignore this")
|
||||
log.Info("Ignoring custom CPU End (--xml-ignore-cpu=true)")
|
||||
if argv.IgnoreCpu {
|
||||
domcfg.CPU = nil
|
||||
}
|
||||
|
|
60
main.go
60
main.go
|
@ -52,84 +52,42 @@ func main() {
|
|||
// sanity check the droplets
|
||||
checkDroplets(false)
|
||||
|
||||
// ok tracks if all the libvirt xml files imported ok
|
||||
var ok bool = true
|
||||
for _, filename := range argv.Xml {
|
||||
domcfg, err := readXml(filename)
|
||||
if err != nil {
|
||||
// parsing the libvirt xml file failed
|
||||
log.Info("error:", filename, err)
|
||||
ok = false
|
||||
log.Info("readXml() error", filename)
|
||||
log.Info("readXml() error", err)
|
||||
log.Info("libvirt XML will have to be fixed by hand")
|
||||
os.Exit(-1)
|
||||
continue
|
||||
}
|
||||
// see if the libvirt xml droplet is already here
|
||||
d, err := findDomain(domcfg)
|
||||
// this is a new droplet. add it to the cluster
|
||||
log.Info("Add XML Droplet here", domcfg.Name)
|
||||
_, err = addDomainDroplet(domcfg)
|
||||
if err != nil {
|
||||
// some error. probably UUID mismatch or hostname duplication
|
||||
// this has to be fixed by hand
|
||||
ok = false
|
||||
log.Info("findDomain() error", filename)
|
||||
log.Info("findDomain() error", err)
|
||||
log.Info("addDomainDroplet() error", filename)
|
||||
log.Info("addDomainDroplet() error", err)
|
||||
log.Info("libvirt XML will have to be fixed by hand")
|
||||
os.Exit(-1)
|
||||
continue
|
||||
}
|
||||
if d == nil {
|
||||
// this is a new droplet. add it to the cluster
|
||||
log.Info("Add New Droplet here", domcfg.Name)
|
||||
_, err := addDomainDroplet(domcfg)
|
||||
if err != nil {
|
||||
ok = false
|
||||
log.Info("addDomainDroplet() error", filename)
|
||||
log.Info("addDomainDroplet() error", err)
|
||||
log.Info("libvirt XML will have to be fixed by hand")
|
||||
os.Exit(-1)
|
||||
}
|
||||
} else {
|
||||
// this droplet is already here
|
||||
err := updateDroplet(d, domcfg)
|
||||
if err != nil {
|
||||
log.Info("updateDroplet() error", filename)
|
||||
log.Info("updateDroplet() error", d.pb.Hostname, err)
|
||||
log.Info("libvirt XML will have to be fixed by hand")
|
||||
ok = false
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(argv.Xml) != 0 {
|
||||
if !ok {
|
||||
log.Info("importing xml files had errors")
|
||||
os.Exit(-1)
|
||||
}
|
||||
if me.changed {
|
||||
if argv.Save {
|
||||
writeConfigFile()
|
||||
writeConfigFileDroplets()
|
||||
log.Info("XML changes saved in protobuf config")
|
||||
os.Exit(0)
|
||||
} else {
|
||||
log.Info("Not saving changes (use --save to save)")
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
log.Info("No XML changes found")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
/*
|
||||
log.Info("command line hypervisors:", argv.Hosts)
|
||||
for _, name := range argv.Hosts {
|
||||
h := findHypervisor(name)
|
||||
if h != nil {
|
||||
log.Info("command line hypervisor", name, "already in config file")
|
||||
continue
|
||||
}
|
||||
h = addHypervisor(name)
|
||||
h.pb.Active = true
|
||||
}
|
||||
*/
|
||||
|
||||
// start the watchdog polling for each hypervisor
|
||||
for _, h := range me.hypers {
|
||||
log.Info("starting polling on", h.pb.Hostname)
|
||||
|
|
Loading…
Reference in New Issue