diff --git a/lib/vSphere/action/clone.rb b/lib/vSphere/action/clone.rb index 00116cf6..0714e7ff 100644 --- a/lib/vSphere/action/clone.rb +++ b/lib/vSphere/action/clone.rb @@ -205,6 +205,7 @@ def get_location(datastore, dc, machine, template) location[:datastore] = datastore unless datastore.nil? end location[:pool] = get_resource_pool(dc, machine) unless machine.provider_config.clone_from_vm + location[:host] = get_host_system(dc,machine) unless machine.provider_config.host_system.nil? location end diff --git a/lib/vSphere/config.rb b/lib/vSphere/config.rb index 19d3efb5..369c534f 100644 --- a/lib/vSphere/config.rb +++ b/lib/vSphere/config.rb @@ -10,6 +10,7 @@ class Config < Vagrant.plugin('2', :config) attr_accessor :password attr_accessor :data_center_name attr_accessor :compute_resource_name + attr_accessor :host_system attr_accessor :resource_pool_name attr_accessor :clone_from_vm attr_accessor :template_name diff --git a/lib/vSphere/util/vim_helpers.rb b/lib/vSphere/util/vim_helpers.rb index d23e3bb4..9f4f7e2a 100644 --- a/lib/vSphere/util/vim_helpers.rb +++ b/lib/vSphere/util/vim_helpers.rb @@ -42,6 +42,12 @@ def get_compute_resource(datacenter, machine) cr end + def get_host_system(datacenter, machine) + cr = find_clustercompute_or_compute_resource(datacenter, machine.provider_config.compute_resource_name) + hs = cr.host.find { |host| host.name == machine.provider_config.host_system } + hs + end + def find_clustercompute_or_compute_resource(datacenter, path) if path.is_a? String es = path.split('/').reject(&:empty?) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b9384370..5d76f239 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -43,6 +43,7 @@ def call password: 'testpassword', data_center_name: nil, compute_resource_name: 'testcomputeresource', + host_system: nil, resource_pool_name: 'testresourcepool', vm_base_path: nil, template_name: TEMPLATE, @@ -122,6 +123,7 @@ def call vmFolder: vm_folder, pretty_path: "data_center/#{vm_folder}", find_compute_resource: @compute_resource, + find_host_system: @host_system, hostFolder: @host_folder) @device = RbVmomi::VIM::VirtualEthernetCard.new