Skip to content

Instantly share code, notes, and snippets.

@NickLaMuro
Last active November 15, 2018 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickLaMuro/225833358423723ed17ff294415fa6b4 to your computer and use it in GitHub Desktop.
Save NickLaMuro/225833358423723ed17ff294415fa6b4 to your computer and use it in GitHub Desktop.
Database replication script for BZ 1580569 - https://bugzilla.redhat.com/show_bug.cgi?id=1580569
# Create Zone
Zone.first || Zone.seed
zone = Zone.first
# Create EMS records
ems_records = []
if ExtManagementSystem.count.positive?
ems_records = ExtManagementSystem.all
else
6.times do |i|
id = i + 1
ems_data = {
:name => "ems_#{'%03d' % id}",
:hostname => "ems-#{'%03d' % id}",
:ipaddress => "10.#{'%03d' % id}.0.0",
:guid => SecureRandom.uuid,
:zone => zone,
:storage_profiles => []
}
ems_records << ManageIQ::Providers::Vmware::InfraManager.create(ems_data)
end
end
# Create Tags
tag_records = []
if Tag.count.positive?
tag_records = Tag.all
else
600.times do |i|
id = i + 1
tag_data = { :name => "/namespace/cat/tag_#{'%03d' % id}" }
tag_records << Tag.create(tag_data)
end
end
# Create Host Records
host_records = []
if Host.count.positive?
host_records = Host.all
else
250.times do |i|
id = i + 1
ems = ems_records.sample
host_data = {
:name => "host_#{'%03d' % id}",
:hostname => "host-#{'%03d' % id}",
:vmm_vendor => "vmware",
:ipaddress => ems.ipaddress.sub(/\.0$/, '%03d' % id),
:user_assigned_os => "linux_generic",
:power_state => "on",
:ext_management_system => ems_records.sample,
:tags => tag_records.sample(75)
}
host_records << ManageIQ::Providers::Vmware::InfraManager::Host.create(host_data)
end
end
# Garbage Collect ems_records, tags, and hosts
ems_records = nil
tags = nil
hosts = nil
zone = nil
GC.start
# Apply host related records to hosts in batches
compliance_vals = [true, true, true, true, true, true, true, false]
auth_status_vals = [nil, "Valid", "None", "Incomplete", "ERROR", "Unreachable", "Invalid"]
Host.find_each(:batch_size => 25) do |host|
compliance_num = rand(5) == 0 ? rand(1500) : 3
# compliances
compliance_num.times do
Compliance.create(
:resource => host,
:compliant => compliance_vals.sample,
:timestamp => DateTime.current - rand(120).days,
:updated_on => DateTime.current,
:event_type => 'string',
:compliance_details => [],
)
end
# VMs
(50 + rand(700)).times do |i|
id = i + 1
vm_data = {
:name => "vm_#{'%05d' % id}",
:location => "[storage] vm_#{'%05d' % id}/vm_#{'%05d' % id}.vmx",
:uid_ems => SecureRandom.uuid,
:vendor => "vmware",
:raw_power_state => "poweredOn",
:host => host,
:template => [true, false, false, false, false].sample
}
vm = ManageIQ::Providers::Vmware::InfraManager::Vm.create(vm_data)
hw = Hardware.create(:vm => vm)
end
# Authentications
rand(4).times do |i|
id = i + 1
Authentication.create(
:resource => host,
:authtype => "default",
:userid => "user_#{id}",
:password => SecureRandom.hex,
:status => auth_status_vals.sample
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment