add vm name and placeholder change to updates table
Some checks are pending
CI / Lint (push) Waiting to run
CI / Test (push) Waiting to run
CI / End-to-End (push) Waiting to run
CI / Publish Docker (push) Blocked by required conditions
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-10-02 13:14:09 +10:00
parent b9c1f65971
commit f80dfe9027
6 changed files with 28 additions and 10 deletions

View File

@@ -104,8 +104,17 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
params.NewRam = sql.NullInt64{Int64: i, Valid: i > 0}
params.UpdateType = "reconfigure"
}
case "config.managedBy":
// This changes when a VM becomes a placeholder or vice versa
case "config.managedBy": // This changes when a VM becomes a placeholder or vice versa
found = true
params.UpdateType = "srm"
if change["newValue"] == "(extensionKey = \"com.vmware.vcDr\", type = \"placeholderVm\")" {
params.PlaceholderChange = sql.NullString{String: "placeholderVm", Valid: true}
} else if change["newValue"] == "<unset>" {
params.PlaceholderChange = sql.NullString{String: "Vm", Valid: true}
} else {
h.Logger.Error("Unexpected value for managedBy configuration", "new_value", change["newValue"])
}
// map[newValue:(extensionKey = \"com.vmware.vcDr\", type = \"placeholderVm\") type:config.managedBy]
// map[newValue:\"testVm\" type:config.managedBy.type]
@@ -187,12 +196,14 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
}
// populate other parameters for the Update database record
params.Name = sql.NullString{String: event.CloudEvent.Data.VM.Name, Valid: event.CloudEvent.Data.VM.Name != ""}
params.EventId = sql.NullString{String: event.CloudEvent.ID, Valid: event.CloudEvent.ID != ""}
params.EventKey = sql.NullString{String: strconv.Itoa(event.CloudEvent.Data.Key), Valid: event.CloudEvent.Data.Key > 0}
params.UpdateTime = sql.NullInt64{Int64: unixTimestamp, Valid: unixTimestamp > 0}
params.UserName = sql.NullString{String: event.CloudEvent.Data.UserName, Valid: event.CloudEvent.Data.UserName != ""}
// Create the Update database record
h.Logger.Debug("Adding Update record", "params", params)
result, err := h.Database.Queries().CreateUpdate(ctx, params)
if err != nil {
h.Logger.Error("unable to perform database insert", "error", err)