fog / fog-xenserver

Module for the 'fog' gem to support XENSERVER
MIT License
16 stars 22 forks source link

Fog::XenServer::RequestFailed VIF.create: ["DEVICE_ALREADY_EXISTS", "0"] #77

Closed whipplekm closed 3 years ago

whipplekm commented 3 years ago

This error occurs when attempting to use Foreman to provision a VM with multiple network interfaces in an XCP-NG compute environment. Provisioning VMs with a single network interface works flawlessly.

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'
plribeiro3000 commented 3 years ago

It seems like it is setting all of them as number 0. Can you elaborate on what is being done on foreman to achieve this?

In fog-xenserver it does pass on the data of the attributes of the model to the request as you can see here.

The device definition can be found here and its value is defined in this method.

Can you confirm which values is it defining at the creation time?

I believe that the device definition code needs some patch but we need to figure out whats it going on in your scenario before we find a solution.

whipplekm commented 3 years ago

EDIT My mistake. I must have bumped a backspace while trying to format for visual aesthetics. The JSON actually appears to be properly formatted and the interface indexes appear to have incremented as expected.

ORIGINAL Thank you for the information. This prompted me to look at the JSON request being submitted. It looks like the interface section is malformed.

interfaces_attributes should be a proper array, but it looks like it's missing the definition

"interfaces_attributes"=>{"0"=>{ "_destroy"=>"0", "type"=>"Nic::Managed", "identifier"=>"eth0", "name"=>"olive-hermance", "domain_id"=>"1", "subnet_id"=>"3", "ip"=>"redacted", "ip6"=>"", "managed"=>"1", "primary"=>"1", "provision"=>"1", "execution"=>"1", "virtual"=>"0", "tag"=>"", "attached_to"=>"", "compute_attributes"=>{ "network"=>"redacted" } }, "1"=>{ "_destroy"=>"0", "type"=>"Nic::Managed", "identifier"=>"eth1", "name"=>"", "domain_id"=>"", "subnet_id"=>"4", "ip"=>"redacted", "ip6"=>"", "managed"=>"1", "primary"=>"0", "provision"=>"0", "execution"=>"0", "virtual"=>"0", "tag"=>"", "attached_to"=>"", "compute_attributes"=>{ "network"=>"redacted" } }

plribeiro3000 commented 3 years ago

Hmmmm. It is defined as a Hash. HMMMMMMMMM

plribeiro3000 commented 3 years ago

Where is this json being defined?

I could not find an _destroy definition from within here. Maybe it is foreman's fault?

whipplekm commented 3 years ago

I am severely weak when it comes to Ruby, so I apologize if I'm running you around. With that being said, the linked file is from Foreman's source and appears to define the parameters for the NICs https://github.com/theforeman/foreman/blob/develop/app/controllers/api/v2/interfaces_controller.rb

This file also appears to require https://github.com/theforeman/foreman/blob/develop/app/models/nic/base.rb which I believe defined the _destroy method you inquired about.

This is the host controller which I believe controls the creation of the host; but again, my Ruby knowledge is near nonexistent. https://github.com/theforeman/foreman/blob/develop/app/controllers/hosts_controller.rb

plribeiro3000 commented 3 years ago

@whipplekm It seems that foreman is not using fog-xenserver models at all but rather going straight to the request and defining the parameters itself.

Could you push this issue in foreman as well to see what the folks there have to say about it?

I'm feeling the code that generates the hash of data has a bug.

whipplekm commented 3 years ago

I have a report in with Foreman. Thank you for your help.

plribeiro3000 commented 3 years ago

Sure. Let me know if i can help again!

plribeiro3000 commented 3 years ago

Feel free to reopen in case something else needs to be fixed!