-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce object lookups for finding folders #268
Conversation
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 replaces find_folder to use information already known about folders to determine their location and quickly fail when it does not exist without traversing the hierarchy. Without this change find_folder is very inneficient and can take a long time to return depending on how deep in the folder tree the folder exists.
This commit renames find_folder to find_vm_folder to clarify its intent to retrieve folders from the VM hierarchy. Without this change find_folder implies it may find folders that are not within the VM hierarchy.
This will resolve #204 . |
lib/vmpooler/providers/vsphere.rb
Outdated
@@ -365,15 +353,22 @@ def get_target_datacenter_from_config(pool_name) | |||
nil | |||
end | |||
|
|||
def generate_vm_hash(vm_object, template_name, pool_name) | |||
hash = { 'name' => nil, 'hostname' => nil, 'template' => nil, 'poolname' => nil, 'boottime' => nil, 'powerstate' => nil } | |||
def generate_vm_hash(vm_object, pool_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good opportunity to add documentation to this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some brief documentation to this method. Let me know if you think it doesn't cover what you were hoping to see, it's pretty brief.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good on @Dakta's approval of documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
lib/vmpooler/providers/vsphere.rb
Outdated
@@ -365,15 +353,22 @@ def get_target_datacenter_from_config(pool_name) | |||
nil | |||
end | |||
|
|||
def generate_vm_hash(vm_object, template_name, pool_name) | |||
hash = { 'name' => nil, 'hostname' => nil, 'template' => nil, 'poolname' => nil, 'boottime' => nil, 'powerstate' => nil } | |||
def generate_vm_hash(vm_object, pool_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
These commits reduce the number of objects looked up when finding VM folders. Additionally, object lookup methods that scan for a folder with a matching name are removed in favor of searchIndex with FindByInventoryPath. Without this change the time it takes to find VM folders is much longer and more resource intensive.