Project

General

Profile

Feature #1923

support converting bare metal hosts to/from VMs on compute resources

Added by Joshua Hoblitt almost 9 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Compute resources
Target version:
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Fixed in Releases:
Found in Releases:

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.

patch patch 2.3 KB Anonymous, 07/19/2013 01:29 AM

Related issues

Related to Foreman - Bug #3795: "Associate VM's" Doesn't Re-associate when compute resource changesClosed2013-12-04
Related to Foreman - Feature #4155: API for CR association and disassociationClosed2014-01-21
Has duplicate Foreman - Feature #1666: Ability to map a vm on an compute ressource with a regular host on ForemanClosed2012-05-31

Associated revisions

Revision 805358df (diff)
Added by Jason Montleon about 8 years ago

fixes #1923 - matches vms on a compute resource to hosts

History

#1 Updated by Oliver Weinmann over 8 years ago

+10 for this feature. ;)

#2 Updated by Ohad Levy over 8 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? :)

#3 Updated by Ohad Levy over 8 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 }

#4 Updated by Anonymous over 8 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.

#5 Updated by Ohad Levy over 8 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!

#6 Updated by Anonymous over 8 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.

#7 Updated by Dominic Cleal about 8 years ago

  • Assignee set to Anonymous
  • Description updated (diff)
  • Category set to Compute resources
  • Status changed from New to Ready For Testing
  • Target version set to 1.3.0

#8 Updated by Anonymous about 8 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#9 Updated by Dominic Cleal about 8 years ago

  • Has duplicate Feature #1666: Ability to map a vm on an compute ressource with a regular host on Foreman added

#10 Updated by Dominic Cleal almost 8 years ago

  • Related to Bug #3795: "Associate VM's" Doesn't Re-associate when compute resource changes added

#11 Updated by Dominic Cleal almost 8 years ago

  • Related to Feature #4155: API for CR association and disassociation added

Also available in: Atom PDF