theforeman / foreman_fog_proxmox

Foreman plugin to add Proxmox compute resource based on fog-proxmox gem
GNU General Public License v3.0
106 stars 31 forks source link

Overwrite persisted? method of compute object #9

Closed tristanrobert closed 6 years ago

tristanrobert commented 6 years ago

To create a vm, foreman uses vm_exists? from app/models/concerns/orchestration/compute.rb which uses persisted? from app/models/concerns/fog_extensions/model.rb which uses !!identity from fog model. The issue is that proxmox requires vmid to be submitted by the client in order to create a new vm. vmid is the identity attribute. So it is always persisted to foreman. To resolve it, it is necessary to overwrite persisted? method.

tristanrobert commented 6 years ago

@timogoebel I confirm you that persisted? method from app/models/concerns/fog_extensions/model.rb is used by foreman and not the one from fog/core/attributes.rb. I have tested it in debug mode and step by step with an IDE. The reason may be that fog-proxmox is not included in fog library. I will try the solution with a concern.

timogoebel commented 6 years ago

@tristanrobert: Yeah, makes sense. The fog extensions are loaded here: https://github.com/theforeman/foreman/blob/389649737a0dcc5d2a2e6bed99199bb8bbd33b53/app/models/concerns/fog_extensions.rb#L4. But it should be possible to overwrite them with a concern, e.g. using Module.prepend.

tristanrobert commented 6 years ago

thanks @timogoebel it works with a concern. I will then commit it and close this issue.