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

Explicitly call PowerOnTask to allow DRS to function #232

Open
wants to merge 4 commits 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
4 changes: 3 additions & 1 deletion lib/vSphere/action/clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def call(env)
fail Errors::VSphereError, :'invalid_configuration_linked_clone_with_sdrs' if config.linked_clone && ds.is_a?(RbVmomi::VIM::StoragePod)

location = get_location ds, dc, machine, template
spec = RbVmomi::VIM.VirtualMachineCloneSpec location: location, powerOn: true, template: false
spec = RbVmomi::VIM.VirtualMachineCloneSpec location: location, powerOn: false, template: false
spec[:config] = RbVmomi::VIM.VirtualMachineConfigSpec
customization_info = get_customization_spec_info_by_name connection, machine

Expand Down Expand Up @@ -83,13 +83,15 @@ def call(env)

apply_sr_result = storage_mgr.ApplyStorageDrsRecommendation_Task(key: [key]).wait_for_completion
new_vm = apply_sr_result.vm
new_vm.PowerOnVM_Task().wait_for_completion

else
env[:ui].info I18n.t('vsphere.creating_cloned_vm')
env[:ui].info " -- #{config.clone_from_vm ? 'Source' : 'Template'} VM: #{template.pretty_path}"
env[:ui].info " -- Target VM: #{vm_base_folder.pretty_path}/#{name}"

new_vm = template.CloneVM_Task(folder: vm_base_folder, name: name, spec: spec).wait_for_completion
new_vm.PowerOnVM_Task().wait_for_completion

config.custom_attributes.each do |k, v|
env[:ui].info "Setting custom attribute: #{k}=#{v}"
Expand Down
1 change: 1 addition & 0 deletions lib/vSphere/action/get_ssh_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def filter_guest_nic(vm, machine)
interfaces = vm.guest.net.select { |g| g.deviceConfigId > 0 }
ip_addresses = interfaces.map { |i| i.ipConfig.ipAddress.select { |a| a.state == 'preferred' } }.flatten

return nil if ip_addresses.empty?
fail Errors::VSphereError.new, :'multiple_interface_with_real_nic_ip_set' if ip_addresses.size > 1
ip_addresses.first.ipAddress
end
Expand Down
8 changes: 8 additions & 0 deletions spec/clone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
spec: { location: { pool: @child_resource_pool },
config: RbVmomi::VIM.VirtualMachineConfigSpec }
)
expect(@new_vm).to have_received :PowerOnVM_Task
end

it 'should create a CloneVM task with custom folder when given vm base path' do
Expand All @@ -29,6 +30,7 @@
spec: { location: { pool: @child_resource_pool },
config: RbVmomi::VIM.VirtualMachineConfigSpec }
)
expect(@new_vm).to have_received :PowerOnVM_Task
end

it 'should set the machine id to be the new UUID' do
Expand Down Expand Up @@ -59,6 +61,7 @@
config: expected_config
}
)
expect(@new_vm).to have_received :PowerOnVM_Task
end

it 'should create a CloneVM spec with configured memory_mb' do
Expand All @@ -70,6 +73,7 @@
spec: { location: { pool: @child_resource_pool },
config: RbVmomi::VIM.VirtualMachineConfigSpec(memoryMB: 2048) }
)
expect(@new_vm).to have_received :PowerOnVM_Task
end

it 'should create a CloneVM spec with configured number of cpus' do
Expand All @@ -81,6 +85,7 @@
spec: { location: { pool: @child_resource_pool },
config: RbVmomi::VIM.VirtualMachineConfigSpec(numCPUs: 4) }
)
expect(@new_vm).to have_received :PowerOnVM_Task
end

it 'should set static IP when given config spec' do
Expand All @@ -98,6 +103,7 @@
spec: { location: { pool: @root_resource_pool },
config: RbVmomi::VIM.VirtualMachineConfigSpec }
)
expect(@new_vm).to have_received :PowerOnVM_Task
end

it 'should set extraConfig if specified' do
Expand All @@ -114,6 +120,7 @@
spec: { location: { pool: @child_resource_pool },
config: expected_config }
)
expect(@new_vm).to have_received :PowerOnVM_Task
end

it 'should set custom notes when they are specified' do
Expand All @@ -125,5 +132,6 @@
spec: { location: { pool: @child_resource_pool },
config: RbVmomi::VIM.VirtualMachineConfigSpec(annotation: 'custom_notes') }
)
expect(@new_vm).to have_received :PowerOnVM_Task
end
end
9 changes: 9 additions & 0 deletions spec/get_ssh_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@
expect(@env[:machine_ssh_info][:host]).to eq IP_ADDRESS
end

context 'when the VM networking is uninitialized' do
before do
allow(@vm.guest).to receive(:net) { [] }
end
it 'should set the ssh info to nil if no valid adapters are present' do
call
expect(@env[:machine_ssh_info]).to eq nil
end
end
end
end
end
6 changes: 5 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,15 @@ def call
@template_config = double('template_config',
hardware: @virtual_hardware)

@new_vm = double('new_vm',
config: double('config', uuid: NEW_UUID),
PowerOnVM_Task: double('result', wait_for_completion: nil))

@template = double('template_vm',
parent: @data_center,
pretty_path: "#{@data_center.pretty_path}/template_vm",
CloneVM_Task: double('result',
wait_for_completion: double('new_vm', config: double('config', uuid: NEW_UUID))),
wait_for_completion: @new_vm),
config: @template_config)

@data_center.stub(:find_vm).with(TEMPLATE).and_return(@template)
Expand Down