Skip to content

Instantly share code, notes, and snippets.

@Maka7veli
Created April 19, 2018 15:28
Show Gist options
  • Save Maka7veli/c31b11d8bbb1f2876ff7a4c0a99d9eda to your computer and use it in GitHub Desktop.
Save Maka7veli/c31b11d8bbb1f2876ff7a4c0a99d9eda to your computer and use it in GitHub Desktop.
$sql = "select abc.vm_name as vm_name, abc.vm_dns_name as vm_dns_name, abc.ip_addresses as ip_address, abc.dns_ip_address as dns_ip_address, abc.network_address as network_address, group_concat(vlan SEPARATOR ' ; ') as vlan, group_concat(mac_address SEPARATOR ' ; ') as mac_address, group_concat(hdd SEPARATOR ' ; ') as hdd, cpu, memory, os, owner, vcenter_name, datastore_name, cluster_name, hypervisor_name
from (
SELECT distinct group_concat(b.ip_address SEPARATOR ' ; ') as ip_addresses,
group_concat(b.vm_dnsname_ip SEPARATOR ' ;') as dns_ip_address,
a.vm_name, a.id ,a.vm_serial, a.vm_dns_name, a.vcenter_id, a.datastore_id, a.cluster_id, a.hypervisor_id,
group_concat(b.network_address SEPARATOR ' ;') as network_address
FROM vm a, ip_address b , vcenter h
WHERE a.vcenter_id = h.id
and a.id = b.vm_id
and h.vcenter_name = '$vcenter'
group by a.vm_name, a.id ,a.vm_serial, a.vm_dns_name, a.vcenter_id, a.datastore_id, a.cluster_id, a.hypervisor_id
) as abc
left join cluster
on abc.cluster_id = cluster.id
inner join vcenter
on abc.vcenter_id = vcenter.id
inner join datastore
on abc.datastore_id = datastore.id
inner join hypervisor
on abc.hypervisor_id = hypervisor.id
inner join os
on abc.id = os.vm_id
inner join memory
on abc.id = memory.vm_id
inner join owner
on abc.id = owner.vm_id
inner join cpu
on abc.id = cpu.vm_id
inner join mac_address
on abc.id = mac_address.vm_id
inner join hdd
on hdd.vm_id = abc.id
inner join network
on network.vm_id = abc.id
group by abc.vm_name, abc.vm_dns_name, abc.ip_addresses, abc.dns_ip_address, abc.network_address, cpu, memory, os, owner, vcenter_name, datastore_name, cluster_name, hypervisor_name";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment