Feature #1923
closedsupport converting bare metal hosts to/from VMs on compute resources
Description
There is presently now way to convert a host in foreman from bare metal to a VM (or vise versa). This is needed for p2v and v2p. At my site we also have some older VMs managed by foreman that were provisioned as if they were bare metal. In order to convert these existing hosts we need a new mechanism for telling foreman which compute resource the VMs are already on. I don't believe it's possible to add a virtual host to foreman for a preexisting VM at all as it will automatically try to provision it.
Perhaps one way of addressing this would be to add a dialog for creating a foreman host for an unmanaged VM that's visible to foreman on an already managed compute resource.
Files
Updated by Ohad Levy over 11 years ago
it should actually not be that hard, it could start as a rake task to compare MAC addresses, and later on with a UI.. any takers? :)
Updated by Ohad Levy over 11 years ago
here is an example patch, it does not include UI nor rake task, but gives an example:
diff --git a/app/models/compute_resource.rb b/app/models/compute_resource.rb
index 7da5982..3c4dea2 100644
--- a/app/models/compute_resource.rb
+++ b/app/models/compute_resource.rb
@@ -176,6 +176,25 @@ class ComputeResource < ActiveRecord::Base
[]
end
+ def import hosts
+ #fetch all vms
+
+ logger.debug 'fetching all vms'
+ vms = self.vms
+ hosts.where(:compute_resource_id => nil).each do |host|
+ # find host based on mac
+ logger.debug "searching vms that match #{host}"
+ vm = vms.detect {|vm| vm.mac == host.mac if vm.respond_to?(:mac)}
+ if vm.present?
+ logger.debug "found match Host:#{host}, VM: #{vm}"
+ host.compute_resource_id = self.id
+ host.uuid = vm.identity
+ host.save(:validate => false) # don't want to trigger callbacks
+ end
+ end
+ true
+ end
+
it currently assume there is a mac address (so both facts already exists on foreman and fog knows how to respond to mac).
to use within the console:
ComputeResource.all.each {|cr| cr.import Host }
Updated by Anonymous over 11 years ago
This would do similar in the UI.
Navigate to More>Provisioning>Compute Resources
Select a compute resource
Click on the Virtual Machines tab
If you click on a virtual machine whose identity is not store in the uuid for any host AND there is a host with the same mac address you will get a 'Manage' button
Click on it and it should tie the VM to your host.
Tested against RHEV and it worked for me. Would be interested to know if it works for anyone else on vmware, etc.
Updated by Ohad Levy over 11 years ago
Jason, would you mind sending this as a PR?
I would assume we need both levels (on the CR level as a whole, and per VM).
thanks!
Updated by Anonymous over 11 years ago
https://github.com/theforeman/foreman/pull/803
I change the patch a bit and made it so you can do all at once at the CR level or individual at the CR_VM level, as you suggested.
I can 'update hosts set uuid=NULL where id=*; update hosts set compute_resource_id=NULL;' in mysql and see all my hosts pretty much looking like bare metal, without a vm page, and without console/power management capabilities, etc. I can then either one by one or all at once reassign the CRID/VMUUID back and get all that stuff back.
Updated by Dominic Cleal over 11 years ago
- Description updated (diff)
- Category set to Compute resources
- Status changed from New to Ready For Testing
- Target version set to 1.3.0
- Assignee set to Anonymous
Updated by Anonymous over 11 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 805358dfbc08bf97d2743396572fe92207ba75a7.
Updated by Dominic Cleal about 11 years ago
- Has duplicate Feature #1666: Ability to map a vm on an compute ressource with a regular host on Foreman added
Updated by Dominic Cleal almost 11 years ago
- Related to Bug #3795: "Associate VM's" Doesn't Re-associate when compute resource changes added
Updated by Dominic Cleal almost 11 years ago
- Related to Feature #4155: API for CR association and disassociation added