Add UUID to VMs in vSphere input (#4769)
This commit is contained in:
parent
5ec50b28ed
commit
797fbf7215
|
@ -60,6 +60,7 @@ type objectMap map[string]objectRef
|
||||||
|
|
||||||
type objectRef struct {
|
type objectRef struct {
|
||||||
name string
|
name string
|
||||||
|
altID string
|
||||||
ref types.ManagedObjectReference
|
ref types.ManagedObjectReference
|
||||||
parentRef *types.ManagedObjectReference //Pointer because it must be nillable
|
parentRef *types.ManagedObjectReference //Pointer because it must be nillable
|
||||||
guest string
|
guest string
|
||||||
|
@ -470,22 +471,22 @@ func getHosts(ctx context.Context, root *view.ContainerView) (objectMap, error)
|
||||||
|
|
||||||
func getVMs(ctx context.Context, root *view.ContainerView) (objectMap, error) {
|
func getVMs(ctx context.Context, root *view.ContainerView) (objectMap, error) {
|
||||||
var resources []mo.VirtualMachine
|
var resources []mo.VirtualMachine
|
||||||
err := root.Retrieve(ctx, []string{"VirtualMachine"}, []string{"name", "runtime.host", "config.guestId"}, &resources)
|
err := root.Retrieve(ctx, []string{"VirtualMachine"}, []string{"name", "runtime.host", "config.guestId", "config.uuid"}, &resources)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m := make(objectMap)
|
m := make(objectMap)
|
||||||
for _, r := range resources {
|
for _, r := range resources {
|
||||||
var guest string
|
guest := "unknown"
|
||||||
|
uuid := ""
|
||||||
// Sometimes Config is unknown and returns a nil pointer
|
// Sometimes Config is unknown and returns a nil pointer
|
||||||
//
|
//
|
||||||
if r.Config != nil {
|
if r.Config != nil {
|
||||||
guest = cleanGuestID(r.Config.GuestId)
|
guest = cleanGuestID(r.Config.GuestId)
|
||||||
} else {
|
uuid = r.Config.Uuid
|
||||||
guest = "unknown"
|
|
||||||
}
|
}
|
||||||
m[r.ExtensibleManagedObject.Reference().Value] = objectRef{
|
m[r.ExtensibleManagedObject.Reference().Value] = objectRef{
|
||||||
name: r.Name, ref: r.ExtensibleManagedObject.Reference(), parentRef: r.Runtime.Host, guest: guest}
|
name: r.Name, ref: r.ExtensibleManagedObject.Reference(), parentRef: r.Runtime.Host, guest: guest, altID: uuid}
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
@ -785,6 +786,10 @@ func (e *Endpoint) populateTags(objectRef *objectRef, resourceType string, resou
|
||||||
t[resource.pKey] = objectRef.name
|
t[resource.pKey] = objectRef.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resourceType == "vm" && objectRef.altID != "" {
|
||||||
|
t["uuid"] = objectRef.altID
|
||||||
|
}
|
||||||
|
|
||||||
// Map parent reference
|
// Map parent reference
|
||||||
parent, found := e.instanceInfo[objectRef.parentRef.Value]
|
parent, found := e.instanceInfo[objectRef.parentRef.Value]
|
||||||
if found {
|
if found {
|
||||||
|
|
Loading…
Reference in New Issue