Foreman-xen: create_vm_from_builtin: <NoMethodError> undefined method `name' for nil:NilClass

Problem:

I’m trying to provision a VM via API with foreman-xen. I tried v0.6.1 and v0.7.0 of foreman-xen. But it always fails with: undefined method `name’ for nil:NilClass

The line of code seems to be:

logger.info "create_vm_from_builtin: host : #{host.name}"

Is this an issue with the parameters that I use to call the API with?

Expected outcome:

A VM is created.

Foreman and Proxy versions:

foreman                         1.18.0-1  
foreman-cli                     1.18.0-1  
foreman-debug                   1.18.0-1  
foreman-installer               1.18.0-1  
foreman-postgresql              1.18.0-1  
foreman-proxy                   1.18.0-1  

Foreman and Proxy plugin versions:

ruby-foreman-deface             1.2.0-1   
ruby-foreman-dhcp-browser       0.0.8-1   
ruby-foreman-discovery          12.0.2-1  
ruby-foreman-tasks              0.13.2-1  
ruby-foreman-tasks-core         0.2.5-1   
ruby-foreman-templates          6.0.3-1   
ruby-hammer-cli-foreman         0.13.0-1  

foreman_xen                     0.7.0

Other relevant data:

root@foreman-1 [~]# grep e897b /var/log/foreman/production.log
2018-11-14T12:35:39 [I|app|e897b] Processing by Api::V2::HostsController#create as JSON
2018-11-14T12:35:39 [I|app|e897b]   Parameters: {"host"=>{"comment"=>"", "managed"=>true, "ip"=>"10.1.2.240", "provision_method"=>"build", "interfaces_attributes"=>{"0"=>{"managed"=>false, "name"=>"testvm001", "ip"=>"10.1.2.141", "primary
"=>true, "netmask"=>"255.255.255.0", "domain_name"=>"nbg.example.com", "mac"=>"02:40:a7:23:01:fa", "gateway"=>"10.1.2.1", "type"=>"interface", "mtu"=>1500, "provision"=>true, "domain_id"=>1}}, "operatingsystem_name"=>"Debian 9", "disk"=>"", "domain_id"=>1, "compute_profile_name"=>"2-Medium", "subnet_id"=>1, "architecture_name"=>"x86_64", "domain_name"=>"nbg.example.com", "name"=>"testvm001.nbg.example.com", "architecture_id"=>1, "build"=>true, "hostgroup_title"=>"xen-vm/debian9", "subnet_name"=>"NBG LAN", "medium_name"=>"Debian 9 mirror extern", "operatingsystem_id"=>2, "certname"=>"testvm001.nbg.example.com", "compute_resource_name"=>"nix.nbg.example.com", "mac"=>"02:40:a7:23:01:fa", "compute_resource_id"=>2, "ptable_name"=>"ACME Preseed default", "medium_id"=>14, "enabled"=>true, "hostgroup_id"=>9, "compute_attributes"=>{"compute_resource_id"=>2, "compute_resource_name"=>"nix.nbg.example.com", "vcpus_max"=>2, "vcpus_min"=>2, "builtin_template_name"=>"Debian Jessie 8.0", "memory_min"=>2147483648, "VBDs"=>{"physical_size"=>25, "sr_uuid"=>"0a78580b-5d10-9acb-b6af-e643eae405fa", "name"=>"disk0"}, "memory_max"=>2147483648, "compute_profile_id"=>2, "compute_profile_name"=>"2-Medium"}, "hostgroup_name"=>"xen-vm/debian9", "ptable_id"=>111, "pxe_loader"=>"PXELinux BIOS", "compute_profile_id"=>2}, "apiv"=>"v2"}
2018-11-14T12:35:39 [I|app|e897b] Current user: foreman_admin (administrator) 
2018-11-14T12:35:39 [I|app|e897b] Authorized user admin(Admin User)
2018-11-14T12:35:39 [I|app|e897b] Current user: admin (administrator)
2018-11-14T12:35:41 [I|app|e897b] Adding Compute instance for testvm001.nbg.example.com
2018-11-14T12:35:41 [I|app|e897b] create_vm(): custom_template_name:
2018-11-14T12:35:41 [I|app|e897b] create_vm(): builtin_template_name: Debian Jessie 8.0
2018-11-14T12:35:41 [I|app|e897b] <NoMethodError> undefined method `name' for nil:NilClass
2018-11-14T12:35:41 [I|app|e897b] /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman_xen-0.7.0/app/models/foreman_xen/xenserver.rb:283:in `create_vm_from_builtin'
2018-11-14T12:35:41 [W|app|e897b] Rolling back due to a problem: [#<Orchestration::Task:0x0055cab7e46f88 @name="Set up compute instance testvm001.nbg.example.com", @id="Set up compute instance testvm001.nbg.example.com", @status="failed", @priority=2, @action=[#<Host::Managed id: nil, name: "testvm001.nbg.example.com", last_compile: nil, last_report: nil, updated_at: nil, created_at: nil, root_pass: "$5$4wP3JwoN$5IjJdWDJ3kHf0x3wE4zmWqhF.ufVq1oo2fHICN...", architecture_id: 1, operatingsystem_id: 2, environment_id: nil, ptable_id: 111, medium_id: 14, build: true, comment: "", disk: "", installed_at: nil, model_id: nil, hostgroup_id: 9, owner_id: 4, owner_type: "User", enabled: true, puppet_ca_proxy_id: nil, managed: true, use_image: nil, image_file: nil, uuid: nil, compute_resource_id: 6, puppet_proxy_id: nil, certname: "testvm001.nbg.example.com", image_id: nil, organization_id: nil, location_id: nil, type: "Host::Managed", otp: nil, realm_id: nil, compute_profile_id: 2, provision_method: "build", grub_pass: "$5$4wP3JwoN$5IjJdWDJ3kHf0x3wE4zmWqhF.ufVq1oo2fHICN...", global_status: 0, lookup_value_matcher: "fqdn=testvm001.nbg.example.com", pxe_loader: "PXELinux BIOS", discovery_rule_id: nil>, :setCompute], @created=1542195340.972112, @timestamp=2018-11-14 11:35:41 UTC>]
2018-11-14T12:35:41 [I|app|e897b] Processed 1 tasks from queue 'Host::Managed Main', completed 0/2
2018-11-14T12:35:41 [E|app|e897b] Task 'Set up compute instance testvm001.nbg.example.com' *failed*
2018-11-14T12:35:41 [E|app|e897b] Task 'Query instance details for testvm001.nbg.example.com' *canceled*
2018-11-14T12:35:41 [W|app|e897b] Action failed
2018-11-14T12:35:41 [I|app|e897b]   Rendering api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout
2018-11-14T12:35:41 [I|app|e897b]   Rendered api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout (1.1ms)
2018-11-14T12:35:41 [I|app|e897b] Completed 500 Internal Server Error in 1759ms (Views: 4.1ms | ActiveRecord: 115.2ms)
root@foreman-1 [~]#