diff options
| author | Ralph Bean <rbean@redhat.com> | 2013-07-30 01:25:09 +0000 |
|---|---|---|
| committer | Ralph Bean <rbean@redhat.com> | 2013-07-30 01:41:13 +0000 |
| commit | ae85cbcaed87c557a86ce8063f4286cdee4e0099 (patch) | |
| tree | 477b756ae0797e91161dae797d5f148591bce1ee /scripts | |
| parent | a50eacb027bcb32008f1a24bca8fc161daf52624 (diff) | |
| download | ansible-ae85cbcaed87c557a86ce8063f4286cdee4e0099.tar.gz ansible-ae85cbcaed87c557a86ce8063f4286cdee4e0099.tar.xz ansible-ae85cbcaed87c557a86ce8063f4286cdee4e0099.zip | |
Make the vhost script report free cpus too.
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/ans-vhost-freemem | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/scripts/ans-vhost-freemem b/scripts/ans-vhost-freemem index 4d1902213..c5c4dd71f 100755 --- a/scripts/ans-vhost-freemem +++ b/scripts/ans-vhost-freemem @@ -58,27 +58,34 @@ errors = [] mem_per_host = {} mem_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) +cpu_per_host = {} +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() for hn in sorted(res['contacted']): if 'failed' in res['contacted'][hn] and res['contacted'][hn]['failed']: continue 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(pattern=hosts, forks=25, transport='paramiko', timeout=10, - module_name='virt', module_args='command=info', remote_user=login) +ans = ansible.runner.Runner( + pattern=hosts, forks=25, transport='paramiko', timeout=10, + module_name='virt', module_args='command=info', remote_user=login) res = ans.run() - for hn in sorted(res['contacted']): mem_used = 0 + cpu_used = 0 if 'failed' in res['contacted'][hn] and res['contacted'][hn]['failed']: errors.append('Failed to contact/run virt lookups on %s' % hn) continue + for vm in sorted(res['contacted'][hn]): info = res['contacted'][hn][vm] @@ -88,15 +95,20 @@ for hn in sorted(res['contacted']): continue elif 'maxMem' not in info: continue + mem_used += int(info['maxMem'])/1024 + cpu_used += info['nrVirtCpu'] mem_used_in_vm[hn] = mem_used + cpu_used_in_vm[hn] = cpu_used for hn in sorted(mem_per_host): 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: - print >> sys.stderr, err
\ No newline at end of file + print >> sys.stderr, err |
