summaryrefslogtreecommitdiff
path: root/machine.go
diff options
context:
space:
mode:
Diffstat (limited to 'machine.go')
-rw-r--r--machine.go31
1 files changed, 22 insertions, 9 deletions
diff --git a/machine.go b/machine.go
index 999e31b..a902b7d 100644
--- a/machine.go
+++ b/machine.go
@@ -13,21 +13,34 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)
+func rawGetHostname(data []byte) *zoopb.Machine {
+ newm := new(zoopb.Machine)
+ newm.Unmarshal(data)
+ return newm
+}
+
func handleMachine(w http.ResponseWriter, hostname string, data []byte) {
hostname = strings.TrimSpace(hostname)
+ newm := rawGetHostname(data)
+ if newm == nil {
+ log.Info("unmarshal failed on data len =", len(data))
+ }
+ if hostname == newm.Hostname {
+ log.Info("hostname mismatch", hostname, "vs", newm.Hostname)
+ hostname = newm.Hostname
+ }
+
if hostname == "" {
- log.Info("something went wrong. hostname is blank")
+ log.Info("hostname is blank even after unmarshal. data len =", len(data))
+ return
}
log.Info("lookoing for", hostname)
m := me.machines.FindByHostname(hostname)
if m == nil {
- newm := new(zoopb.Machine)
- err := newm.Unmarshal(data)
- if err != nil {
- log.Info("machine Unmarshal() failed", hostname)
- return
- }
- me.machines.Append(newm)
+ am := new(zoopb.Machine)
+ am.Hostname = newm.Hostname
+ am.Memory = newm.Memory
+ me.machines2.Append(am)
return
}
log.Info("not new machine", hostname)
@@ -44,7 +57,7 @@ func updateMachine(u *zoopb.Machine) string {
log.Info("adding new machine", u.Hostname)
me.machines.Append(u)
log.Info("save machines pb file here...")
- // me.machines.ConfigSave()
+ me.machines2.ConfigSave()
return "new"
}
// log.Info("updating machine", m.Hostname)