-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the speed of finding an individual VM (#422)
* Improve the speed of finding an individual VM This PR makes use of the [ContainerView](https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.view.ViewManager.html) to retrieve a cut down list of servers from which the desired object can be found, after which the object itself can be downloaded. Previously, we'd download each VM (about 3.5K and several round trips to the server) to find the VM we want. From ``` sean~/play/knife-vsphere (find_speed %)$ time knife vsphere vm disk list myserver 0 Hard disk 1 nosnapshots_ds4 64.00 GiB real 1m56.153s user 0m9.536s sys 0m1.713s ``` to ``` sean~/play/knife-vsphere (find_speed *%)$ time be knife vsphere vm disk list myserver /Users/sean/.gem/ruby/2.4.1/gems/builder-3.2.2/lib/builder/xchar.rb:111: warning: constant ::Fixnum is deprecated 0 Hard disk 1 nosnapshots_ds4 64.00 GiB real 0m2.929s user 0m1.038s sys 0m0.236s ``` This'll have to be retrofitted to the other commands, which we can do over time. See vmware-archive/rbvmomi#117 for some more context * Use the new finding on property set * Add this to vm state, too * Add same thing to vm config * Add vm lookup to snapshot
- Loading branch information
Showing
6 changed files
with
58 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Some helpers for faster searching of the inventory | ||
module SearchHelper | ||
# Retrieves all the VM objects and returns their ObjectContents | ||
# Note that since it's a ObjectContent coming back, the individual | ||
# object's [] will return only the properties you asked for | ||
# and `#obj` will return the actual object (but make a call to the server) | ||
# param [Array<String>] properties to retrieve | ||
# @return [Array<RbVmomi::VIM::ObjectContent>] | ||
def get_all_vm_objects(properties = ['name']) | ||
pc = vim_connection.serviceInstance.content.propertyCollector | ||
viewmgr = vim_connection.serviceInstance.content.viewManager | ||
root_folder = vim_connection.serviceInstance.content.rootFolder | ||
vmview = viewmgr.CreateContainerView(container: root_folder, | ||
type: ['VirtualMachine'], | ||
recursive: true) | ||
|
||
filter_spec = RbVmomi::VIM.PropertyFilterSpec( | ||
objectSet: [ | ||
obj: vmview, | ||
skip: true, | ||
selectSet: [ | ||
RbVmomi::VIM.TraversalSpec( | ||
name: 'traverseEntities', | ||
type: 'ContainerView', | ||
path: 'view', | ||
skip: false | ||
) | ||
] | ||
], | ||
propSet: [ | ||
{ type: 'VirtualMachine', pathSet: properties } | ||
] | ||
) | ||
pc.RetrieveProperties(specSet: [filter_spec]) | ||
end | ||
|
||
def get_vm_by_name(vmname) | ||
vm = get_all_vm_objects.detect { |r| r['name'] == vmname } | ||
vm ? vm.obj : nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters