graph.rb 954 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # frozen_string_literal: true
  2. require 'neoinfra'
  3. require 'vpc'
  4. require 'accounts'
  5. require 'fog-aws'
  6. require 'neo4j'
  7. # NeoInfra Account information
  8. module NeoInfra
  9. # Provide informations about the accounts available
  10. class Graph
  11. def initialize
  12. @cfg = NeoInfra::Config.new
  13. neo4j_url = "http://#{@cfg.neo4j[:host]}:#{@cfg.neo4j[:port]}"
  14. Neo4j::Session.open(:server_db, neo4j_url)
  15. end
  16. def graph_vpcs
  17. nodes = []
  18. rels = []
  19. i = 0
  20. @cfg = NeoInfra::Config.new
  21. @cfg.accounts.each do |account|
  22. nodes << {title: account[:name], label: 'account'}
  23. i +=1
  24. Vpc.where(default: "false").each do |vpc|
  25. if vpc.owned.name == account[:name]
  26. source = i
  27. nodes << {title: vpc.name, label: 'vpc'}
  28. i +=1
  29. rels << {source: source, target: i}
  30. end
  31. end
  32. end
  33. return {nodes: nodes, links: rels}
  34. end
  35. end
  36. end