|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
require 'neoinfra'
|
|
require 'neoinfra'
|
|
require 'vpc'
|
|
require 'vpc'
|
|
|
|
+require 'peers'
|
|
require 'accounts'
|
|
require 'accounts'
|
|
require 'fog-aws'
|
|
require 'fog-aws'
|
|
require 'neo4j'
|
|
require 'neo4j'
|
|
@@ -35,6 +36,50 @@ module NeoInfra
|
|
end
|
|
end
|
|
Vpc.all.collect { |x| { 'nodes' => node_counts[x.name], 'vpc_id' => x.vpc_id, 'name' => x.name, 'region' => x.region.region, 'owner' => x.owned.name, 'cidr' => x.cidr, 'default' => x.default } }.select { |y| y['default'] == 'false' }.sort_by { |h| h['nodes'] }.reverse
|
|
Vpc.all.collect { |x| { 'nodes' => node_counts[x.name], 'vpc_id' => x.vpc_id, 'name' => x.name, 'region' => x.region.region, 'owner' => x.owned.name, 'cidr' => x.cidr, 'default' => x.default } }.select { |y| y['default'] == 'false' }.sort_by { |h| h['nodes'] }.reverse
|
|
end
|
|
end
|
|
|
|
+
|
|
|
|
+ def load_peers
|
|
|
|
+ aws = NeoInfra::Aws.new
|
|
|
|
+ @cfg.accounts.each do |account|
|
|
|
|
+ base_conf = {
|
|
|
|
+ provider: 'AWS',
|
|
|
|
+ aws_access_key_id: account[:key],
|
|
|
|
+ aws_secret_access_key: account[:secret]
|
|
|
|
+ }
|
|
|
|
+ aws.regions.each do |region|
|
|
|
|
+ region_conf = { region: region }
|
|
|
|
+ begin
|
|
|
|
+ new_conn = Fog::Compute.new(region_conf.merge(base_conf))
|
|
|
|
+ rescue StandardError
|
|
|
|
+ puts "Error loading Peering in region: #{region}"
|
|
|
|
+ next
|
|
|
|
+ end
|
|
|
|
+ new_conn.route_tables.each do |rt|
|
|
|
|
+ rt.routes.select{ |x| not x["vpcPeeringConnectionId"].nil? }.each do |r|
|
|
|
|
+ if Peer.where(peer_id: r["vpcPeeringConnectionId"]).empty?
|
|
|
|
+ mypeer = Peer.new(
|
|
|
|
+ peer_id: r['vpcPeeringConnectionId']
|
|
|
|
+ )
|
|
|
|
+ mypeer.save
|
|
|
|
+ else
|
|
|
|
+ mypeer = Peer.where(peer_id: r["vpcPeeringConnectionId"]).first
|
|
|
|
+ end
|
|
|
|
+ puts r["vpcPeeringConnectionId"]
|
|
|
|
+ ### TODO: make this more efficient
|
|
|
|
+ match_count = 0
|
|
|
|
+ PeerVpc.all.each do |x|
|
|
|
|
+ if x.from_node.peer_id == r["vpcPeeringConnectionId"] and x.to_node.vpc_id == rt.vpc_id
|
|
|
|
+ puts "matched #{x.from_node.peer_id} and #{x.to_node.vpc_id}"
|
|
|
|
+ match_count += 1
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+ if match_count < 1
|
|
|
|
+ PeerVpc.create(from_node: mypeer, to_node: Vpc.where(vpc_id: rt.vpc_id).first)
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
+ end
|
|
|
|
|
|
def load
|
|
def load
|
|
aws = NeoInfra::Aws.new
|
|
aws = NeoInfra::Aws.new
|