Using Foreman to provision VMs with multiple network interfaces fail in an XCP-NG environment

Problem:
When provisioning a VM with multiple network interfaces, Foreman fails with the error:

  • Failed to create a compute {compute node} (Xenserver) instance {FQDN}: VIF.create: [“DEVICE_ALREADY_EXISTS”, “0”]

Expected outcome:
Foreman should provision a VM with the specified interfaces.

Foreman and Proxy versions:
2.1.2

Foreman and Proxy plugin versions:

Distribution and version:
CentOS 7.8.2003

Other relevant data:
http://debugs.theforeman.org/foreman-debug-DNSAi.tar.xz

Based on the error, it appears that the mechanism for incrementing interface indexes are not functioning as expected.

Additional log info:
Fog::XenServer::RequestFailed VIF.create: [“DEVICE_ALREADY_EXISTS”, “0”]
/opt/theforeman/tfm/root/usr/share/gems/gems/fog-xenserver-1.0.0/lib/fog/xenserver/connection.rb:55:in request' /opt/theforeman/tfm/root/usr/share/gems/gems/fog-xenserver-1.0.0/lib/fog/xenserver/compute/requests/create_vif.rb:6:in create_vif’
/opt/theforeman/tfm/root/usr/share/gems/gems/fog-xenserver-1.0.0/lib/fog/xenserver/compute/models/instance_methods.rb:25:in save' /opt/theforeman/tfm/root/usr/share/gems/gems/fog-core-2.1.0/lib/fog/core/collection.rb:50:in create’
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_xen-1.0.1/app/models/foreman_xen/xenserver.rb:466:in create_interface' /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_xen-1.0.1/app/models/foreman_xen/xenserver.rb:310:in block in create_vm’
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_xen-1.0.1/app/models/foreman_xen/xenserver.rb:309:in each' /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_xen-1.0.1/app/models/foreman_xen/xenserver.rb:309:in map’
/opt/theforeman/tfm/root/usr/share/gems/gems/foreman_xen-1.0.1/app/models/foreman_xen/xenserver.rb:309:in create_vm' /usr/share/foreman/app/models/concerns/orchestration/compute.rb:91:in setCompute’
/usr/share/foreman/app/models/concerns/orchestration.rb:220:in execute' /usr/share/foreman/app/models/concerns/orchestration.rb:145:in block in process’
/usr/share/foreman/app/models/concerns/orchestration.rb:137:in each' /usr/share/foreman/app/models/concerns/orchestration.rb:137:in process’
/usr/share/foreman/app/models/concerns/orchestration.rb:44:in around_save_orchestration' /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:121:in block in run_callbacks’
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:139:in run_callbacks' /opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:825:in _run_save_callbacks’
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.1/lib/active_record/callbacks.rb:327:in `create_or_update’