forked from antogon/ip-database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
35 lines (32 loc) · 1.54 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
IpDatabase::Application.load_tasks
namespace :db do
desc "Populate DB with Test Data"
task :populate => :environment do
r = Random.new
for i in 1..10
type = DeviceType.new({:name => Faker::Name.title})
type.save
rnum = [true,false].sample
net = Network.new({:name => Faker::Name.first_name + "'s AP", :creator_id => Faker::Internet.user_name, :router_name => "", :is_vrf => false, :is_hsrp => false, :network_no => (rnum) ? Faker::Internet.ip_v6_address : Faker::Internet.ip_v4_address, :netmask => (rnum) ? Faker::Internet.ip_v6_address : Faker::Internet.ip_v4_address})
net.save
dhcp_begin = IP.parse((rnum) ? Faker::Internet.ip_v6_address : Faker::Internet.ip_v4_address)
dhcp = DhcpRange.new({:start_ip => dhcp_begin.to_s, :end_ip => (dhcp_begin+255).to_s, :network_parent => net.id})
dhcp.save
for j in 1..(r.rand(0..200))
ip = IpAddress.new({:contact => Faker::Name.first_name + " " + Faker::Name.last_name, :location => Faker::Address.latitude + " : " + Faker::Address.longitude, :network_parent => net.id, :device_type => type.id})
if ip.network.ip_v4
ip.ip_v4 = Faker::Internet.ip_v4_address
else
ip.ip_v6 = Faker::Internet.ip_v6_address
end
ip.save
#dns = DnsDeviceAssoc.new({:name => Faker::Name.title, :ip_id => ip.id})
#dns.save
end
end
end
end