dataloader.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. lib_dir = File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'lib')
  3. $LOAD_PATH.unshift(lib_dir) unless
  4. $LOAD_PATH.include?(lib_dir) || $LOAD_PATH.include?(lib_dir)
  5. require 'neoinfra'
  6. require 'sinatra'
  7. require 'sinatra/base'
  8. require 'sinatra/contrib'
  9. # Handle loading data into the graph db
  10. class Dataloader < Sinatra::Base
  11. register Sinatra::RespondWith
  12. set :views, File.join(File.dirname(__FILE__), '..', '/views')
  13. get '/all' do
  14. respond_to do |wants|
  15. wants.html do
  16. erb :load_all,
  17. layout: :base_layout
  18. end
  19. end
  20. end
  21. get '/accounts' do
  22. j = NeoInfra::Accounts.new
  23. j.load
  24. status 200
  25. "Loaded Accounts: #{j.list_names.sort.join(' ')}"
  26. end
  27. get '/regions' do
  28. j = NeoInfra::Aws.new
  29. j.load_regions
  30. status 200
  31. "Loaded #{j.region_count} regions, #{j.az_count} availablity zones"
  32. end
  33. get '/vpcs' do
  34. j = NeoInfra::Vpcs.new
  35. # j.load_vpcs
  36. status 200
  37. "Loaded #{j.default_vpc_count} default vpcs, #{j.non_default_vpc_count} non-default vpcs"
  38. end
  39. end