mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Reduce object lookups for get_vm
This commit reduces object lookups used for get_vm. Without this change get_vm looks up the VM folder, which is already used and known to find the vm with find_vm.
This commit is contained in:
parent
8be578493a
commit
8840ef4a5c
2 changed files with 18 additions and 22 deletions
|
|
@ -168,18 +168,7 @@ module Vmpooler
|
||||||
vm_object = find_vm(pool_name, vm_name, connection)
|
vm_object = find_vm(pool_name, vm_name, connection)
|
||||||
return vm_hash if vm_object.nil?
|
return vm_hash if vm_object.nil?
|
||||||
|
|
||||||
vm_folder_path = get_vm_folder_path(vm_object)
|
vm_hash = generate_vm_hash(vm_object, pool_name)
|
||||||
# Find the pool name based on the folder path
|
|
||||||
pool_name = nil
|
|
||||||
template_name = nil
|
|
||||||
global_config[:pools].each do |pool|
|
|
||||||
if pool['folder'] == vm_folder_path
|
|
||||||
pool_name = pool['name']
|
|
||||||
template_name = pool['template']
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
vm_hash = generate_vm_hash(vm_object, template_name, pool_name)
|
|
||||||
end
|
end
|
||||||
vm_hash
|
vm_hash
|
||||||
end
|
end
|
||||||
|
|
@ -262,7 +251,7 @@ module Vmpooler
|
||||||
spec: clone_spec
|
spec: clone_spec
|
||||||
).wait_for_completion
|
).wait_for_completion
|
||||||
|
|
||||||
vm_hash = generate_vm_hash(new_vm_object, template_path, pool_name)
|
vm_hash = generate_vm_hash(new_vm_object, pool_name)
|
||||||
end
|
end
|
||||||
vm_hash
|
vm_hash
|
||||||
end
|
end
|
||||||
|
|
@ -365,15 +354,22 @@ module Vmpooler
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_vm_hash(vm_object, template_name, pool_name)
|
def generate_vm_hash(vm_object, pool_name)
|
||||||
hash = { 'name' => nil, 'hostname' => nil, 'template' => nil, 'poolname' => nil, 'boottime' => nil, 'powerstate' => nil }
|
pool_configuration = pool_config(pool_name)
|
||||||
|
return nil if pool_configuration.nil?
|
||||||
|
|
||||||
hash['name'] = vm_object.name
|
hostname = vm_object.summary.guest.hostName if vm_object.summary && vm_object.summary.guest && vm_object.summary.guest.hostName
|
||||||
hash['hostname'] = vm_object.summary.guest.hostName if vm_object.summary && vm_object.summary.guest && vm_object.summary.guest.hostName
|
boottime = vm_object.runtime.bootTime if vm_object.runtime && vm_object.runtime.bootTime
|
||||||
hash['template'] = template_name
|
powerstate = vm_object.runtime.powerState if vm_object.runtime && vm_object.runtime.powerState
|
||||||
hash['poolname'] = pool_name
|
|
||||||
hash['boottime'] = vm_object.runtime.bootTime if vm_object.runtime && vm_object.runtime.bootTime
|
hash = {
|
||||||
hash['powerstate'] = vm_object.runtime.powerState if vm_object.runtime && vm_object.runtime.powerState
|
'name' => vm_object.name,
|
||||||
|
'hostname' => hostname,
|
||||||
|
'template' => pool_configuration['template'],
|
||||||
|
'poolname' => pool_name,
|
||||||
|
'boottime' => boottime,
|
||||||
|
'powerstate' => powerstate,
|
||||||
|
}
|
||||||
|
|
||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ EOT
|
||||||
expect(result['name']).to eq(vmname)
|
expect(result['name']).to eq(vmname)
|
||||||
end
|
end
|
||||||
|
|
||||||
['hostname','template','poolname','boottime','powerstate'].each do |testcase|
|
['hostname','boottime','powerstate'].each do |testcase|
|
||||||
it "should return nil for #{testcase}" do
|
it "should return nil for #{testcase}" do
|
||||||
result = subject.get_vm(poolname,vmname)
|
result = subject.get_vm(poolname,vmname)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue