sample_data.rake 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # frozen_string_literal: true
  2. require 'yaml'
  3. namespace :sample_data do
  4. sample_data = YAML.load_file(
  5. File.join(File.dirname(File.expand_path(__FILE__)), 'sample_data.yaml')
  6. )
  7. Neo4j::Session.open(:server_db, 'http://localhost:7474')
  8. task :accounts do
  9. puts 'loading accounts'
  10. sample_data['accounts'].each do |account|
  11. next unless AwsAccount.where(name: account[:name]).empty?
  12. acct = AwsAccount.new(
  13. name: account[:name],
  14. account_id: 90000+rand(20),
  15. user_id: account[:name],
  16. key_md5: Digest:: MD5.hexdigest(account[:name]),
  17. secret_md5: Digest:: MD5.hexdigest(account[:name])
  18. )
  19. acct.save
  20. end
  21. end
  22. task :regions do
  23. puts 'loading regions'
  24. sample_data['regions'].each do |reg|
  25. next unless Region.where(region: reg.keys.first).empty?
  26. r = Region.new(region: reg.keys.first)
  27. r.save
  28. reg[reg.keys.first].each do |az|
  29. a = Az.new(az: az)
  30. a.save
  31. AzRegion.create(from_node: a, to_node: Region.where(region: reg.keys.first).first)
  32. end
  33. end
  34. end
  35. task :vpcs do
  36. puts 'loading vpcs'
  37. j = NeoInfra::Vpcs.new
  38. end
  39. task :buckets do
  40. puts 'loading buckets'
  41. j = NeoInfra::Aws.new
  42. end
  43. task :nodes do
  44. puts 'loading nodes'
  45. #j = NeoInfra::Nodes.new
  46. end
  47. desc 'Load Sample Data'
  48. task all: %i[accounts regions vpcs buckets nodes]
  49. end