mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[vsphere|compute] add list_templates function
Templates used to be included in Compute[:vsphere].servers.all, but they've been pruned out for awhile now. This patch adds the functionality back in so that templates may be located for cloning.
This commit is contained in:
parent
3d10f6bb60
commit
9ee029e70a
3 changed files with 57 additions and 1 deletions
lib/fog/vsphere
|
@ -49,6 +49,8 @@ module Fog
|
|||
request :get_network
|
||||
request :list_datastores
|
||||
request :get_datastore
|
||||
request :list_templates
|
||||
request :get_template
|
||||
request :get_folder
|
||||
request :list_folders
|
||||
request :create_vm
|
||||
|
|
50
lib/fog/vsphere/requests/compute/list_templates.rb
Normal file
50
lib/fog/vsphere/requests/compute/list_templates.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Vsphere
|
||||
class Real
|
||||
def list_templates(options = { })
|
||||
|
||||
options[:folder] ||= options['folder']
|
||||
if options[:folder] then
|
||||
list_all_templates_in_folder(options[:folder], options[:datacenter])
|
||||
else
|
||||
list_all_templates(options)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def list_all_templates_in_folder(path, datacenter_name)
|
||||
folder = get_raw_vmfolder(path, datacenter_name)
|
||||
|
||||
vms = folder.children.grep(RbVmomi::VIM::VirtualMachine)
|
||||
# remove all virtual machines that are not template
|
||||
vms.delete_if { |v| not v.config.template }
|
||||
|
||||
vms.map(&method(:convert_vm_mob_ref_to_attr_hash))
|
||||
end
|
||||
|
||||
def list_all_templates(options = {})
|
||||
datacenters = find_datacenters(options[:datacenter])
|
||||
|
||||
vms = datacenters.map do |dc|
|
||||
@connection.serviceContent.viewManager.CreateContainerView({
|
||||
:container => dc.vmFolder,
|
||||
:type => ["VirtualMachine"],
|
||||
:recursive => true
|
||||
}).view
|
||||
end.flatten
|
||||
# remove all virtual machines that are not templates
|
||||
vms.delete_if { |v| not v.config.template }
|
||||
|
||||
vms.map(&method(:convert_vm_mob_ref_to_attr_hash))
|
||||
end
|
||||
|
||||
end
|
||||
class Mock
|
||||
def list_templates(filters = { })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -22,7 +22,11 @@ module Fog
|
|||
def list_all_virtual_machines_in_folder(path, datacenter_name)
|
||||
folder = get_raw_vmfolder(path, datacenter_name)
|
||||
|
||||
folder.children.grep(RbVmomi::VIM::VirtualMachine).map(&method(:convert_vm_mob_ref_to_attr_hash))
|
||||
vms = folder.children.grep(RbVmomi::VIM::VirtualMachine)
|
||||
# remove all template based virtual machines
|
||||
vms.delete_if { |v| v.config.template }
|
||||
|
||||
vms.map(&method(:convert_vm_mob_ref_to_attr_hash))
|
||||
end
|
||||
|
||||
def list_all_virtual_machines(options = { })
|
||||
|
|
Loading…
Add table
Reference in a new issue