Some enhancements, simplifications to that vhost script.
This commit is contained in:
parent
3e43c3f30a
commit
35ab4759e1
1 changed files with 16 additions and 10 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue