Has anyone found a way to query / list virtual machines by the resource pool?
Here is an example that list all VMs in a pool. Note that in ESX 2.5 all VMs will end up in the pool called "resources".
select
e2.name as datacenter_name,
e.name as vm_name,
e3.name as resource_pool_name,
vm.guest_os,
vm.mem_size_mb,
vm.num_vcpu
from
vpx_vm vm
inner join vpx_entity e on vm.id = e.id
inner join vpx_datacenter d on d.id = vm.datacenter_id
inner join vpx_entity e2 on d.id = e2.id
left outer join vpx_resource_pool rp on vm.resource_group_id = rp.id
inner join vpx_entity e3 on rp.id = e3.id
where
is_template = 0
order by
e3.name, e2.name, e.name
Here is another query that will give you some details about each pool (in ESX 3.0) and their current resource usage. rp.* returns all info but you can select the colums you want like rp.allocated_mem etc.
select
e.name as pool_name,
cast(rp.allocated_cpu as int) + cast(rp.available_pool_cpu as int) as pool_max_cpu,
rp.*
from
vpx_resource_pool rp
inner join vpx_entity e on rp.id = e.id
inner join vpx_entity e2 on e.parent_id = e2.id
where
e2.name = 'Resources'
order by
e2.name, e.name
You can remove the where filter (e2.name = 'Resources') and add e2.name in the column list to see what it looks like on ESX 2.5.
I imagine its only possible using the virtualcenter SDK... and probably best done there, as someone could easily move a VM from one resource pool... is this out of your reach you could look at the vmish command which is run at the service console...
This tool has been quite well documented at:
Regards
Mike
I would have thought that this is also possible by writing a query to interrogate the VC Database also.
Simon
Yes, that's true - didn't think of that...
Might be much easier to do than console commands or SDK...
Regards
Mike
Hello,
I had a quick look at this will get you started:
SELECT vm.DNS_NAME, rg.ID
FROM VPX_VM vm RIGHT OUTER JOIN
VPX_RESOURCE_POOL rg ON vm.RESOURCE_GROUP_ID = rg.ID
ORDER BY rg.ID
If I have time I will spend a little more time to get it right. I don't do resource pools so my environment is not an ideal test bed for this script. right now it lists virtual machines by the id of the resources pool. The next step would be to get the resource pool by name and included in the results.
Edit:
Funky, my post was under a different user name.
Here is an example that list all VMs in a pool. Note that in ESX 2.5 all VMs will end up in the pool called "resources".
select
e2.name as datacenter_name,
e.name as vm_name,
e3.name as resource_pool_name,
vm.guest_os,
vm.mem_size_mb,
vm.num_vcpu
from
vpx_vm vm
inner join vpx_entity e on vm.id = e.id
inner join vpx_datacenter d on d.id = vm.datacenter_id
inner join vpx_entity e2 on d.id = e2.id
left outer join vpx_resource_pool rp on vm.resource_group_id = rp.id
inner join vpx_entity e3 on rp.id = e3.id
where
is_template = 0
order by
e3.name, e2.name, e.name
Here is another query that will give you some details about each pool (in ESX 3.0) and their current resource usage. rp.* returns all info but you can select the colums you want like rp.allocated_mem etc.
select
e.name as pool_name,
cast(rp.allocated_cpu as int) + cast(rp.available_pool_cpu as int) as pool_max_cpu,
rp.*
from
vpx_resource_pool rp
inner join vpx_entity e on rp.id = e.id
inner join vpx_entity e2 on e.parent_id = e2.id
where
e2.name = 'Resources'
order by
e2.name, e.name
You can remove the where filter (e2.name = 'Resources') and add e2.name in the column list to see what it looks like on ESX 2.5.
Argyle,
Man I'm not sure my schema looks anything like yours. Can you elaborate?
(VC 3.0.1)
The SDK is EASY!!! Really, it's easy! I am not a programmer...especially not in perl - but the vi-perl toolkit makes life easy.
Give it a go.
Dave
Your SQL Server schema should be identical. We use ESX 3.01, VC 2.01 here. You need to open SQL Server Enterprise Manager and run the query in the "Query analyzer" tool.
or perhaps strait forward like this
TestsRUs:/usr/local/lib/vmware-viperl/apps/vm# ./vminfo.pl --server <esx> --pool <pool name>