I am trying to patch a foreman bug where they don't disable network boot after build and turn it back on when you want to rebuild a host. It looks like I just need to add some code to the "built" method in:
./app/controllers/unattended_controller.rb
def built
logger.info "#{controller_name}: #{@host.name} is Built!"
update_ip if Setting[:update_ip_from_built_request]
head(@host.built ? :created : :conflict)
end
and the "setBuild" method in:
./app/models/host/managed.rb
def setBuild
self.build = true
self.save
errors.empty?
end
Borrowing from line 79 of foreman_bootdisk.rb and modify_vm_cdrom.rb for inspiration, I have come up with something along the lines of:
def setBuild
load '/usr/share/foreman/app/models/compute_resources/foreman/model/vmware.rb'
if ComputeResources::Foreman::Model::Vmware.available?
vm_reconfig_hardware('instance_uuid' => params[:token], 'hardware_spec' => {'bootOptions'=>['network', 'disk']})
end
self.build = true
self.save
errors.empty?
end
The problem is that I get the error,
Oops, we're sorry but something went wrong Circular dependency detected while autoloading constant ComputeResources::Foreman::Model::Vmware
I have done some reading on this and hear that the problem is probably with rail's autoload, but I have tried fixing this with load and require (I was trying to avoid the autoload function which I hear is deprecated), but despite having tried both, I continue to get this error and I am unsure why. What am i doing differently than the coders of foreman_bootdisk.rb to get this error that they aren't? Whey doesn't vmware.rb seem to want to load?
def setBuild
vm_reconfig_hardware(
'instance_uuid' => params[:token],
'hardware_spec' => {'bootOptions'=>['network', 'disk']}
) if Fog::Compute.providers.include?(:vsphere)
self.build = true
self.save
errors.empty?
end