test unmarshal configspec
This commit is contained in:
@@ -24,6 +24,8 @@ func (h *Handler) VmModify(w http.ResponseWriter, r *http.Request) {
|
|||||||
params := queries.CreateUpdateParams{}
|
params := queries.CreateUpdateParams{}
|
||||||
var unixTimestamp int64
|
var unixTimestamp int64
|
||||||
|
|
||||||
|
//re := regexp.MustCompile(`/([^/]+)/[^/]+\.vmdk$`)
|
||||||
|
|
||||||
reqBody, err := io.ReadAll(r.Body)
|
reqBody, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Logger.Error("Invalid data received", "error", err)
|
h.Logger.Error("Invalid data received", "error", err)
|
||||||
@@ -52,7 +54,17 @@ func (h *Handler) VmModify(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusAccepted)
|
w.WriteHeader(http.StatusAccepted)
|
||||||
fmt.Fprintf(w, "Processed update event but no config changes were found\n")
|
fmt.Fprintf(w, "Processed update event but no config changes were found\n")
|
||||||
} else {
|
} else {
|
||||||
h.Logger.Debug("Received event contains config change info", "source", event.CloudEvent.Source, "vm", event.CloudEvent.Data.VM.Name)
|
h.Logger.Debug("Received event contains config change info", "source", event.CloudEvent.Source,
|
||||||
|
"vm", event.CloudEvent.Data.VM.Name, "user_name", event.CloudEvent.Data.UserName)
|
||||||
|
|
||||||
|
// Try to decode the config changes data
|
||||||
|
var testConfig models.ConfigSpec
|
||||||
|
if err := json.Unmarshal(*event.CloudEvent.Data.ConfigSpec, &testConfig); err != nil {
|
||||||
|
h.Logger.Warn("unable to decode ConfigSpec json", "error", err)
|
||||||
|
} else {
|
||||||
|
h.Logger.Debug("successfully decoded ConfigSpec JSON")
|
||||||
|
}
|
||||||
|
|
||||||
configChanges = h.processConfigChanges(event.CloudEvent.Data.ConfigChanges.Modified)
|
configChanges = h.processConfigChanges(event.CloudEvent.Data.ConfigChanges.Modified)
|
||||||
//prettyPrint(configChanges)
|
//prettyPrint(configChanges)
|
||||||
|
|
||||||
@@ -85,6 +97,15 @@ func (h *Handler) VmModify(w http.ResponseWriter, r *http.Request) {
|
|||||||
if strings.Contains(change["type"], "config.hardware.device") &&
|
if strings.Contains(change["type"], "config.hardware.device") &&
|
||||||
strings.Contains(event.CloudEvent.Data.FullFormattedMessage, ".vmdk") {
|
strings.Contains(event.CloudEvent.Data.FullFormattedMessage, ".vmdk") {
|
||||||
|
|
||||||
|
// TODO - query current disk size from Inventory table and only create an update if the size is now changed
|
||||||
|
if testConfig.DeviceChange != nil {
|
||||||
|
for i := range testConfig.DeviceChange {
|
||||||
|
if testConfig.DeviceChange[i].Device.Backing != nil {
|
||||||
|
h.Logger.Debug("Found backing in configspec", "backing", testConfig.DeviceChange[i].Device.Backing)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO - recalculate total disk size
|
// TODO - recalculate total disk size
|
||||||
h.Logger.Debug("Detected config change for VM disk")
|
h.Logger.Debug("Detected config change for VM disk")
|
||||||
found = true
|
found = true
|
||||||
|
@@ -101,37 +101,9 @@ type ConfigSpec struct {
|
|||||||
DeviceChange []struct {
|
DeviceChange []struct {
|
||||||
Backing any `json:"Backing"`
|
Backing any `json:"Backing"`
|
||||||
Device struct {
|
Device struct {
|
||||||
Backing struct {
|
Backing *BackingSpec `json:"Backing,omitempty"`
|
||||||
Port struct {
|
CapacityInBytes int `json:"CapacityInBytes"`
|
||||||
ConnectionCookie int `json:"ConnectionCookie"`
|
CapacityInKB int `json:"CapacityInKB"`
|
||||||
PortKey string `json:"PortKey"`
|
|
||||||
PortgroupKey string `json:"PortgroupKey"`
|
|
||||||
SwitchUUID string `json:"SwitchUuid"`
|
|
||||||
} `json:"Port"`
|
|
||||||
BackingObjectID string `json:"BackingObjectId"`
|
|
||||||
ChangeID string `json:"ChangeId"`
|
|
||||||
ContentID string `json:"ContentId"`
|
|
||||||
Datastore struct {
|
|
||||||
Type string `json:"Type"`
|
|
||||||
Value string `json:"Value"`
|
|
||||||
} `json:"Datastore"`
|
|
||||||
DeltaDiskFormat string `json:"DeltaDiskFormat"`
|
|
||||||
DeltaDiskFormatVariant string `json:"DeltaDiskFormatVariant"`
|
|
||||||
DeltaGrainSize int `json:"DeltaGrainSize"`
|
|
||||||
DigestEnabled any `json:"DigestEnabled"`
|
|
||||||
DiskMode string `json:"DiskMode"`
|
|
||||||
EagerlyScrub bool `json:"EagerlyScrub"`
|
|
||||||
FileName string `json:"FileName"`
|
|
||||||
KeyID any `json:"KeyId"`
|
|
||||||
Parent any `json:"Parent"`
|
|
||||||
Sharing string `json:"Sharing"`
|
|
||||||
Split any `json:"Split"`
|
|
||||||
ThinProvisioned bool `json:"ThinProvisioned"`
|
|
||||||
UUID string `json:"Uuid"`
|
|
||||||
WriteThrough any `json:"WriteThrough"`
|
|
||||||
} `json:"Backing"`
|
|
||||||
CapacityInBytes int `json:"CapacityInBytes"`
|
|
||||||
CapacityInKB int `json:"CapacityInKB"`
|
|
||||||
Connectable struct {
|
Connectable struct {
|
||||||
AllowGuestControl bool `json:"AllowGuestControl"`
|
AllowGuestControl bool `json:"AllowGuestControl"`
|
||||||
Connected bool `json:"Connected"`
|
Connected bool `json:"Connected"`
|
||||||
@@ -173,7 +145,7 @@ type ConfigSpec struct {
|
|||||||
} `json:"StorageIOAllocation"`
|
} `json:"StorageIOAllocation"`
|
||||||
VDiskID any `json:"VDiskId"`
|
VDiskID any `json:"VDiskId"`
|
||||||
VFlashCacheConfigInfo any `json:"VFlashCacheConfigInfo"`
|
VFlashCacheConfigInfo any `json:"VFlashCacheConfigInfo"`
|
||||||
} `json:"Device"`
|
} `json:"Device,omitempty"`
|
||||||
FileOperation string `json:"FileOperation"`
|
FileOperation string `json:"FileOperation"`
|
||||||
Operation string `json:"Operation"`
|
Operation string `json:"Operation"`
|
||||||
Profile []struct {
|
Profile []struct {
|
||||||
@@ -243,3 +215,33 @@ type ConfigSpec struct {
|
|||||||
VirtualSMCPresent any `json:"VirtualSMCPresent"`
|
VirtualSMCPresent any `json:"VirtualSMCPresent"`
|
||||||
VMProfile any `json:"VmProfile"`
|
VMProfile any `json:"VmProfile"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BackingSpec struct {
|
||||||
|
Port struct {
|
||||||
|
ConnectionCookie int `json:"ConnectionCookie"`
|
||||||
|
PortKey string `json:"PortKey"`
|
||||||
|
PortgroupKey string `json:"PortgroupKey"`
|
||||||
|
SwitchUUID string `json:"SwitchUuid"`
|
||||||
|
} `json:"Port"`
|
||||||
|
BackingObjectID string `json:"BackingObjectId"`
|
||||||
|
ChangeID string `json:"ChangeId"`
|
||||||
|
ContentID string `json:"ContentId"`
|
||||||
|
Datastore struct {
|
||||||
|
Type string `json:"Type"`
|
||||||
|
Value string `json:"Value"`
|
||||||
|
} `json:"Datastore"`
|
||||||
|
DeltaDiskFormat string `json:"DeltaDiskFormat"`
|
||||||
|
DeltaDiskFormatVariant string `json:"DeltaDiskFormatVariant"`
|
||||||
|
DeltaGrainSize int `json:"DeltaGrainSize"`
|
||||||
|
DigestEnabled any `json:"DigestEnabled"`
|
||||||
|
DiskMode string `json:"DiskMode"`
|
||||||
|
EagerlyScrub bool `json:"EagerlyScrub"`
|
||||||
|
FileName string `json:"FileName"`
|
||||||
|
KeyID any `json:"KeyId"`
|
||||||
|
Parent any `json:"Parent"`
|
||||||
|
Sharing string `json:"Sharing"`
|
||||||
|
Split any `json:"Split"`
|
||||||
|
ThinProvisioned bool `json:"ThinProvisioned"`
|
||||||
|
UUID string `json:"Uuid"`
|
||||||
|
WriteThrough any `json:"WriteThrough"`
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user