Skip to content
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

allow setting target host for vm #281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/vSphere/action/clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_target_host(dc, machine) unless machine.provider_config.target_host.nil?
location
end

Expand Down
1 change: 1 addition & 0 deletions lib/vSphere/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Config < Vagrant.plugin('2', :config)
attr_accessor :data_center_name
attr_accessor :compute_resource_name
attr_accessor :resource_pool_name
attr_accessor :target_host
attr_accessor :clone_from_vm
attr_accessor :template_name
attr_accessor :name
Expand Down
6 changes: 6 additions & 0 deletions lib/vSphere/util/vim_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def get_compute_resource(datacenter, machine)
cr
end

def get_target_host(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.target_host }
hs
end

def find_clustercompute_or_compute_resource(datacenter, path)
if path.is_a? String
es = path.split('/').reject(&:empty?)
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def call
password: 'testpassword',
data_center_name: nil,
compute_resource_name: 'testcomputeresource',
target_host: nil,
resource_pool_name: 'testresourcepool',
vm_base_path: nil,
template_name: TEMPLATE,
Expand Down Expand Up @@ -122,6 +123,7 @@ def call
vmFolder: vm_folder,
pretty_path: "data_center/#{vm_folder}",
find_compute_resource: @compute_resource,
find_target_host: @target_host,
hostFolder: @host_folder)

@device = RbVmomi::VIM::VirtualEthernetCard.new
Expand Down