Revision ca747296
Added by Ohad Levy over 11 years ago
- ID ca74729688fdcc1c488ea3bf7ec2929af0744670
db/migrate/20121118120028_migrate_hypervisors_to_compute_resources.rb | ||
---|---|---|
class MigrateHypervisorsToComputeResources < ActiveRecord::Migration
|
||
class Hypervisor < ActiveRecord::Base; end
|
||
|
||
def self.up
|
||
return unless Hypervisor.table_exists?
|
||
|
||
Hypervisor.all.each do |hypervisor|
|
||
host = Foreman::Model::Libvirt.find_by_url hypervisor.url
|
||
next if host # this host already exits
|
||
host.name = hypervisor.name
|
||
host.description = "Automaticilly migrated from hypervisor #{hypervisor.name} / #{hypervisor.url}"
|
||
say host.description
|
||
host.save
|
||
# check if we have the same compute resource already, if we do, skip it.
|
||
next if Foreman::Model::Libvirt.find_by_url hypervisor.url
|
||
|
||
Foreman::Model::Libvirt.create :name => hypervisor.name,
|
||
:url => hypervisor.url,
|
||
:description => "Automatically migrated from hypervisor #{hypervisor.name} / #{hypervisor.url}"
|
||
end
|
||
drop_table :hypervisors
|
||
end
|
Also available in: Unified diff
fixed wrong old hypervisor migration refs #1957