Make the vhost script report free cpus too.
This commit is contained in:
parent
a50eacb027
commit
ae85cbcaed
1 changed files with 20 additions and 8 deletions
|
@ -58,27 +58,34 @@ errors = []
|
||||||
|
|
||||||
mem_per_host = {}
|
mem_per_host = {}
|
||||||
mem_used_in_vm = {}
|
mem_used_in_vm = {}
|
||||||
ans = ansible.runner.Runner(pattern=hosts, forks=25, transport='paramiko', timeout=10,
|
cpu_per_host = {}
|
||||||
module_name='virt', module_args='command=nodeinfo', remote_user=login)
|
cpu_used_in_vm = {}
|
||||||
|
|
||||||
|
ans = ansible.runner.Runner(
|
||||||
|
pattern=hosts, forks=25, transport='paramiko', timeout=10,
|
||||||
|
module_name='virt', module_args='command=nodeinfo', remote_user=login)
|
||||||
res = ans.run()
|
res = ans.run()
|
||||||
|
|
||||||
for hn in sorted(res['contacted']):
|
for hn in sorted(res['contacted']):
|
||||||
if 'failed' in res['contacted'][hn] and res['contacted'][hn]['failed']:
|
if 'failed' in res['contacted'][hn] and res['contacted'][hn]['failed']:
|
||||||
continue
|
continue
|
||||||
mem_per_host[hn] = int(res['contacted'][hn]['phymemory'])
|
mem_per_host[hn] = int(res['contacted'][hn]['phymemory'])
|
||||||
|
cpu_per_host[hn] = int(res['contacted'][hn]['cpus']) * \
|
||||||
|
int(res['contacted'][hn]['cpucores'])
|
||||||
|
|
||||||
|
|
||||||
|
ans = ansible.runner.Runner(
|
||||||
ans = ansible.runner.Runner(pattern=hosts, forks=25, transport='paramiko', timeout=10,
|
pattern=hosts, forks=25, transport='paramiko', timeout=10,
|
||||||
module_name='virt', module_args='command=info', remote_user=login)
|
module_name='virt', module_args='command=info', remote_user=login)
|
||||||
res = ans.run()
|
res = ans.run()
|
||||||
|
|
||||||
|
|
||||||
for hn in sorted(res['contacted']):
|
for hn in sorted(res['contacted']):
|
||||||
mem_used = 0
|
mem_used = 0
|
||||||
|
cpu_used = 0
|
||||||
if 'failed' in res['contacted'][hn] and res['contacted'][hn]['failed']:
|
if 'failed' in res['contacted'][hn] and res['contacted'][hn]['failed']:
|
||||||
errors.append('Failed to contact/run virt lookups on %s' % hn)
|
errors.append('Failed to contact/run virt lookups on %s' % hn)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for vm in sorted(res['contacted'][hn]):
|
for vm in sorted(res['contacted'][hn]):
|
||||||
info = res['contacted'][hn][vm]
|
info = res['contacted'][hn][vm]
|
||||||
|
|
||||||
|
@ -88,15 +95,20 @@ for hn in sorted(res['contacted']):
|
||||||
continue
|
continue
|
||||||
elif 'maxMem' not in info:
|
elif 'maxMem' not in info:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
mem_used += int(info['maxMem'])/1024
|
mem_used += int(info['maxMem'])/1024
|
||||||
|
cpu_used += info['nrVirtCpu']
|
||||||
|
|
||||||
mem_used_in_vm[hn] = mem_used
|
mem_used_in_vm[hn] = mem_used
|
||||||
|
cpu_used_in_vm[hn] = cpu_used
|
||||||
|
|
||||||
|
|
||||||
for hn in sorted(mem_per_host):
|
for hn in sorted(mem_per_host):
|
||||||
freemem = mem_per_host[hn] - mem_used_in_vm[hn]
|
freemem = mem_per_host[hn] - mem_used_in_vm[hn]
|
||||||
print '%s : %s' % (hn, freemem)
|
freecpu = cpu_per_host[hn] - cpu_used_in_vm[hn]
|
||||||
|
print '%s:\t%s mem\t%s/%s cores' % (
|
||||||
|
hn, freemem, freecpu, cpu_per_host[hn])
|
||||||
|
|
||||||
|
|
||||||
for err in errors:
|
for err in errors:
|
||||||
print >> sys.stderr, err
|
print >> sys.stderr, err
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue