Skip to content

Instantly share code, notes, and snippets.

@codegold79
Created October 2, 2020 02:45
Show Gist options
  • Select an option

  • Save codegold79/a3ec782b0644185fc096349aa6e6c900 to your computer and use it in GitHub Desktop.

Select an option

Save codegold79/a3ec782b0644185fc096349aa6e6c900 to your computer and use it in GitHub Desktop.
func eventVmMOR(req []byte) (*types.ManagedObjectReference, error) {
var ce cloudEvent
var mor types.ManagedObjectReference
err := json.Unmarshal(req, &ce)
if err != nil {
return nil, fmt.Errorf("parse request: %w", err)
}
if ce.Data.Vm == nil || ce.Data.Vm.Vm.Value == "" {
return nil, errors.New("event is not of type VmEvent")
}
// Fill information in the request into a govmomi type.
mor.Type = ce.Data.Vm.Vm.Type
mor.Value = ce.Data.Vm.Vm.Value
if debug {
log.Println("Cloud event parsed and validated.")
}
return &mor, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment