summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-25 16:08:55 -0500
committerJeff Carr <[email protected]>2024-10-25 16:08:55 -0500
commit15f48a01ab043a996b72460358ffca2e47b3d88f (patch)
tree209ac91813d3f74e21913af6754f665cf44883de
parentcf79357bbab75b356ba3cc77f2c7f7e7c86d3bbd (diff)
pretty good XML handling at this pointv0.1
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--addDroplet.go29
-rw-r--r--libvirtxml.go5
-rw-r--r--main.go60
3 files changed, 25 insertions, 69 deletions
diff --git a/addDroplet.go b/addDroplet.go
index 305e45b..4a1f314 100644
--- a/addDroplet.go
+++ b/addDroplet.go
@@ -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")
- }
- // this is a new unknown droplet (not in the config file)
- d = new(DropletT)
+ 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
+ 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()
- }
+ // 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
+ me.droplets = append(me.droplets, d)
+ me.changed = true
+ }
err := updateDroplet(d, domcfg)
if err != nil {
diff --git a/libvirtxml.go b/libvirtxml.go
index 64b6814..f872c75 100644
--- a/libvirtxml.go
+++ b/libvirtxml.go
@@ -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
}
diff --git a/main.go b/main.go
index f38dded..fb26ee6 100644
--- a/main.go
+++ b/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)