summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorRalph Bean <rbean@redhat.com>2013-07-30 02:00:21 +0000
committerRalph Bean <rbean@redhat.com>2013-07-30 02:00:21 +0000
commit35ab4759e1d8a29ad2bb9d789f0bd1eb8d104b34 (patch)
treecb2218c4fd202c0b9b7d300b80e1010bcd23f2bf /scripts
parent3e43c3f30a685893f0499c3732249d8fbbbcdb59 (diff)
Some enhancements, simplifications to that vhost script.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/ans-vhost-freemem26
1 files changed, 16 insertions, 10 deletions
diff --git a/scripts/ans-vhost-freemem b/scripts/ans-vhost-freemem
index 7fd014717..b350f27df 100755
--- a/scripts/ans-vhost-freemem
+++ b/scripts/ans-vhost-freemem
@@ -56,14 +56,24 @@ else:
errors = []
+# Setup some dictionaries for storing intermediate results
mem_per_host = {}
mem_used_in_vm = {}
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)
+# We end up running ansible twice here. These are the common arguments.
+# We'll use two different commands of the 'virt' ansible module.
+ansible_args = dict(
+ pattern=hosts,
+ module_name='virt',
+ forks=25,
+ transport='paramiko',
+ timeout=10,
+ remote_user=login,
+)
+
+ans = ansible.runner.Runner(module_args='command=nodeinfo', **ansible_args)
res = ans.run()
for hn in sorted(res['contacted']):
@@ -73,9 +83,7 @@ for hn in sorted(res['contacted']):
cpu_per_host[hn] = int(res['contacted'][hn]['cpus'])
-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(module_args='command=info', **ansible_args)
res = ans.run()
for hn in sorted(res['contacted']):
@@ -92,11 +100,9 @@ for hn in sorted(res['contacted']):
continue
elif type(info) != dict:
continue
- elif 'maxMem' not in info:
- continue
- mem_used += int(info['maxMem'])/1024
- cpu_used += info['nrVirtCpu']
+ mem_used += int(info.get('maxMem', 0))/1024
+ cpu_used += info.get('nrVirtCpu', 0)
mem_used_in_vm[hn] = mem_used
cpu_used_in_vm[hn] = cpu_used