provider/vsphere/vsphere_discover.go
func virtualMachinesForTag(ctx context.Context, client *vSphereClient, id string) ([]*object.VirtualMachine, error) {
	logger.Printf("[DEBUG] Locating all virtual machines under tag ID %q", id)

	var vms []*object.VirtualMachine

	objs, err := client.TagsClient.ListAttachedObjects(ctx, id)
	if err != nil {
		return nil, err
	}
	for i, obj := range objs {
		switch {
		case obj.Type == nil || obj.ID == nil:
			logger.Printf("[WARN] Discovered object at index %d has either no ID or type", i)
			continue
		case *obj.Type != "VirtualMachine":
			logger.Printf("[DEBUG] Discovered object ID %q is not a virutal machine", *obj.ID)
			continue
		}
		vm, err := virtualMachineFromMOID(ctx, client.VimClient, *obj.ID)
		if err != nil {
			return nil, fmt.Errorf("error locating virtual machine with ID %q: %s", *obj.ID, err)
		}
		vms = append(vms, vm)
	}

	logger.Printf("[DEBUG] Discovered virtual machines: %s", virtualMachineNames(vms))
	return vms, nil
}
func virtualMachinesForTag(ctx context.Context, client *vSphereClient, id string) ([]*object.VirtualMachine, error) {
	logger.Printf("[DEBUG] Locating all virtual machines under tag ID %q", id)

	var vms []*object.VirtualMachine

	objs, err := client.TagsClient.ListAttachedObjects(ctx, id)
	if err != nil {
		return nil, err
	}
	for i, obj := range objs {
		switch {
		case obj.Type == nil || obj.ID == nil:
			logger.Printf("[WARN] Discovered object at index %d has either no ID or type", i)
			continue
		case *obj.Type != "VirtualMachine":
			logger.Printf("[DEBUG] Discovered object ID %q is not a virutal machine", *obj.ID)
			continue
		}
		vm, err := virtualMachineFromMOID(ctx, client.VimClient, *obj.ID)
		if err != nil {
			return nil, fmt.Errorf("error locating virtual machine with ID %q: %s", *obj.ID, err)
		}
		vms = append(vms, vm)
	}

	logger.Printf("[DEBUG] Discovered virtual machines: %s", virtualMachineNames(vms))
	return vms, nil
}
func virtualMachinesForTag ( ctx context . Context , client * vSphereClient , id string ) ( [ ] * object . VirtualMachine , error ) { logger . Printf ( " " , id ) var vms [ ] * object . VirtualMachine objs , err := client . TagsClient . ListAttachedObjects ( ctx , id ) if err != nil { return nil , err } for i , obj := range objs { switch { case obj . Type == nil || obj . ID == nil : logger . Printf ( " " , i ) continue case * obj . Type != " " : logger . Printf ( " " , * obj . ID ) continue } vm , err := virtualMachineFromMOID ( ctx , client . VimClient , * obj . ID ) if err != nil { return nil , fmt . Errorf ( " " , * obj . ID , err ) } vms = append ( vms , vm ) } logger . Printf ( " " , virtualMachineNames ( vms ) ) return vms , nil }
// virtualMachinesForTag discovers all of the virtual machines that match a
// specific tag ID and returns their higher level helper objects.
virtualMachinesForTag discovers all of the virtual machines that match a specific tag ID and returns their higher level helper objects .