// ListVM returns a list of virtual machines
ListVM returns a list of virtual machines
// ListVM returns a list of virtual machines
func (m *Manager) ListVM() ([]*VirtualMachine, error) {
	fields := []string{}
	qParams := []wmi.Query{
		&wmi.AndQuery{
			wmi.QueryFields{
				Key:   "VirtualSystemType",
				Value: VirtualSystemTypeRealized,
				Type:  wmi.Equals},
		},
	}
	result, err := m.con.Gwmi(VirtualSystemSettingDataClass, fields, qParams)
	if err != nil {
		return nil, errors.Wrap(err, "VirtualSystemSettingDataClass")
	}
	elements, err := result.Elements()
	if err != nil {
		return nil, errors.Wrap(err, "Elements")
	}
	vms := make([]*VirtualMachine, len(elements))
	for idx, val := range elements {
		cs, err := val.Get("associators_", nil, ComputerSystemClass)
		if err != nil {
			return nil, errors.Wrap(err, "getting ComputerSystemClass")
		}
		elem, err := cs.Elements()
		if err != nil || len(elem) == 0 {
			return nil, errors.Wrap(err, "getting elements")
		}
		vms[idx] = &VirtualMachine{
			mgr:                m,
			activeSettingsData: val,
			computerSystem:     elem[0],
		}
	}
	return vms, nil
}
func ( m * Manager ) ListVM ( ) ( [ ] * VirtualMachine , error ) { fields := [ ] string { } qParams := [ ] wmi . Query { & wmi . AndQuery { wmi . QueryFields { Key : " " , Value : VirtualSystemTypeRealized , Type : wmi . Equals } , } , } result , err := m . con . Gwmi ( VirtualSystemSettingDataClass , fields , qParams ) if err != nil { return nil , errors . Wrap ( err , " " ) } elements , err := result . Elements ( ) if err != nil { return nil , errors . Wrap ( err , " " ) } vms := make ( [ ] * VirtualMachine , len ( elements ) ) for idx , val := range elements { cs , err := val . Get ( " " , nil , ComputerSystemClass ) if err != nil { return nil , errors . Wrap ( err , " " ) } elem , err := cs . Elements ( ) if err != nil || len ( elem ) == 0 { return nil , errors . Wrap ( err , " " ) } vms [ idx ] = & VirtualMachine { mgr : m , activeSettingsData : val , computerSystem : elem [ 0 ] , } } return vms , nil }
ListVM returns a list of virtual machines
ListVM returns a list of virtual machines