Sha256: 2a0aa4b08446b80a47d003f83b1e9f7d572c4dca70f97d5b62daa376cddd42ff

Contents?: true

Size: 728 Bytes

Versions: 11

Compression:

Stored size: 728 Bytes

Contents

class FakeDiscoveredHost < ActiveRecord::Base
  self.table_name = 'hosts'
end

class FillDiscoveryAttributeSetsForExistingHosts < ActiveRecord::Migration
  def up
    FakeDiscoveredHost.where(:type => "Host::Discovered").all.each do |host|
      begin
        say "Populating attribute set for discovered host #{host.name}"
        host.discovery_attribute_set = DiscoveryAttributeSet.where(:host_id => host.id).first_or_create
        host.discovery_attribute_set.update_attributes(host.import_from_facts)
        host.save!
      rescue Exception => e
        say "Error while populating host #{host.name}, deleting: #{e.message}:\n" + e.backtrace.join("\n")
        host.destroy
      end
    end
  end

  def down
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
foreman_discovery-9.1.5 db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb
foreman_discovery-9.1.4 db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb
foreman_discovery-9.1.3 db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb
foreman_discovery-9.1.2 db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb
foreman_discovery-9.1.1 db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb
foreman_discovery-9.0.0 db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb
foreman_discovery-8.0.1 db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb
foreman_discovery-8.0.0 db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb
foreman_discovery-7.0.1 db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb
foreman_discovery-7.0.0 db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb
foreman_discovery-6.0.0 db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb