When creating a VM from the web UI, foreman_hyperv fails when trying to build the network adapters. The following parameters are passed when VM creation is started.
2017-11-28 12:03:21 5e39cbfe [app] [I] Parameters: {"utf8"=>"✓", "authenticity_token"=>"TsTwloaxIZUUpAfVAf1MldD/nXfJxMF7WT0eC4pB/LspRGTJRpM32xm9dcXICH+FjWjcIgQgVQiO5rDy6sxJiA==", "host"=>{"name"=>"test-vm", "hostgroup_id"=>"1", "compute_resource_id"=>"2", "environment_id"=>"1", "puppetclass_ids"=>[""], "managed"=>"true", "progress_report_id"=>"[FILTERED]", "type"=>"Host::Managed", "interfaces_attributes"=>{"0"=>{"_destroy"=>"0", "type"=>"Nic::Managed", "mac"=>"", "identifier"=>"", "name"=>"test-vm", "domain_id"=>"1", "subnet_id"=>"2", "ip"=>"192.168.1.243", "ip6"=>"", "managed"=>"1", "primary"=>"1", "provision"=>"1", "virtual"=>"0", "tag"=>"", "attached_to"=>"", "compute_attributes"=>__{"name"=>"test", "network"=>"PFSense_LAN", "id"=>""}__}}, "compute_attributes"=>{"generation"=>"1", "processor_count"=>"1", "memory_startup"=>"536870912", "memory_maximum"=>"17179869184", "memory_minimum"=>"536870912", "dynamic_memory_enabled"=>"false", "start"=>"1", "notes"=>"", "id"=>""}, "architecture_id"=>"3", "operatingsystem_id"=>"2", "provision_method"=>"build", "build"=>"1", "medium_id"=>"9", "ptable_id"=>"104", "pxe_loader"=>"PXELinux BIOS", "disk"=>"", "root_pass"=>"[FILTERED]", "is_owned_by"=>"3-Users", "enabled"=>"1", "comment"=>"", "overwrite"=>"false"}, "capabilities"=>"build", "provider"=>"Hyperv", "bare_metal_capabilities"=>"build"}
Foreman continues to work correctly until attempting to create the interfaces:
create_interfaces(vm, args[:interfaces_attributes])
def create_interfaces(vm, attrs)
vm.network_adapters.each(&:destroy)
interfaces = nested_attributes_for :interfaces, attrs
client.logger.debug "Building interfaces with: #{interfaces}"
interfaces.each do |iface|
nic = vm.network_adapters.new name: iface[:name], switch_name: iface[:network]
if iface[:mac]
nic.mac = iface[:mac]
nic.dynamic_mac_address_enabled = false
end
nic.save
end
# Populate the MAC addresses
vm.start
vm.stop turn_off: true
vm.network_adapters.reload
vm.network_adapters.each do |nic|
nic.dynamic_mac_address_enabled = false
nic.save if nic.dirty?
end
end
It then explicitly uses the parameters passed by foreman_hyperv-0.0.2/app/views/compute_resources_vms/form/hyperv/_network.html.erb to try and build the interfaces.
Log:
2017-11-29T14:21:26 0f1e160f [hyper-v] [D] PS; <<< OUT=[""] ERR=[""] EXIT=[0]
2017-11-29T14:21:26 0f1e160f [hyper-v] [D] Building interfaces with: [{:network=>"PFSense_LAN", :name=>"test123", :ip=>"192.168.1.22", :ip6=>""}]
2017-11-29T14:21:26 0f1e160f [hyper-v] [D] Executing multi-query for [""]
2017-11-29T14:21:26 0f1e160f [hyper-v] [D] PS; >>> Stop-VM -TurnOff -Name adele-dulatre.cloudapp.net
2017-11-29T14:21:26 0f1e160f [hyper-v] [D] PS; <<< OUT=["Warning: The virtual machine is already in the specified state.\r\n"] ERR=[""] EXIT=[0]
2017-11-29T14:21:26 0f1e160f [app] [W] Failed to create a compute ****** (Hyper-V) instance adele-dulatre.***: computer_name is required for this operation
|
| ArgumentError: computer_name is required for this operation
| /usr/share/foreman/.gem/ruby/gems/fog-core-1.45.0/lib/fog/core/attributes.rb:155:in requires' | /usr/share/foreman/.gem/ruby/gems/fog-hyperv-0.0.5/lib/fog/hyperv/models/compute/network_adapter.rb:61:in
save'
| /usr/share/foreman/.gem/ruby/gems/foreman_hyperv-0.0.2/app/models/foreman_hyperv/hyperv.rb:195:in block in create_interfaces' | /usr/share/foreman/.gem/ruby/gems/foreman_hyperv-0.0.2/app/models/foreman_hyperv/hyperv.rb:189:in
each'
| /usr/share/foreman/.gem/ruby/gems/foreman_hyperv-0.0.2/app/models/foreman_hyperv/hyperv.rb:189:in create_interfaces' | /usr/share/foreman/.gem/ruby/gems/foreman_hyperv-0.0.2/app/models/foreman_hyperv/hyperv.rb:89:in
create_vm'
| /usr/share/foreman/app/models/concerns/orchestration/compute.rb:77:in `setCompute'
Computer_name is required by fog-hyperv-0.0.5/lib/fog/hyperv/models/compute/network_adapter.rb
def connect(switch, options = {})
requires :name, :vm_name
def disconnect(options = {})
requires :name, :computer_name, :vm_name
def save
requires :name, :computer_name, :vm_name
I think the best solution would be to remove the :computer_name requirement from the methods in fog-hyperv-0.0.5/lib/fog/hyperv/models/compute/network_adapter.rb. I think using -computername with the *-vmnetadapter cmdlets is pretty rare, and having it as required doesn't provide any tangible benefit.
Otherwise, computer_name could be passed as a compute_parameter from _network.html.erb, or added to object before create_interfaces is called.
Let me know if I'm off base.
Kevin