Browse Source

vpcs are unhappy

Chris Mague 7 years ago
parent
commit
3b914d3014
5 changed files with 44 additions and 6 deletions
  1. 8 0
      lib/neoinfra/aws.rb
  2. 11 3
      lib/neoinfra/vpcs.rb
  3. 7 1
      web/controllers.rb
  4. 17 1
      web/controllers/dataloader.rb
  5. 1 1
      web/views/load_all.html.erb

+ 8 - 0
lib/neoinfra/aws.rb

@@ -25,6 +25,14 @@ module NeoInfra
       conn.describe_regions.data[:body]['regionInfo'].collect { |x| x['regionName'] }
     end
 
+    def region_count
+      Region.all.length
+    end
+
+    def az_count
+      Az.all.length
+    end
+
     def azs(region)
       @cfg = NeoInfra::Config.new
       account = @cfg.accounts.first

+ 11 - 3
lib/neoinfra/vpcs.rb

@@ -1,16 +1,24 @@
 # frozen_string_literal: true
 
+require 'neoinfra'
 require 'vpc'
 require 'accounts'
 require 'fog'
 require 'neo4j'
-require 'neoinfra/aws'
-require 'neoinfra/config'
 
 # NeoInfra Account information
 module NeoInfra
   # Provide informations about the accounts available
   class Vpcs
+    def non_default_vpc_count
+      p Vpc.all
+      21
+    end
+
+    def default_vpc_count
+      22
+    end
+
     def load
       aws = NeoInfra::Aws.new
       @cfg = NeoInfra::Config.new
@@ -32,7 +40,7 @@ module NeoInfra
             next unless Vpc.where(vpc_id: vpc.id).empty?
             vpc_name = if vpc.tags.empty?
                          vpc.id
-                       elsif vpc.tags.key? 'Name'
+                       elsif vpc.tags.has_key? 'Name'
                          vpc.tags['Name']
                        else
                          vpc.id

+ 7 - 1
web/controllers.rb

@@ -1,4 +1,10 @@
 # Dynamically pick up all of the controllers
+
+
 Dir.glob(File.join(File.dirname(__FILE__), 'controllers', '*.rb')).select{|c| File.basename(c) != 'controllers.rb' }.each do |x|
-  require x
+  begin
+    require x
+  rescue
+    puts "unable to load: #{x}"
+  end
 end

+ 17 - 1
web/controllers/dataloader.rb

@@ -20,9 +20,25 @@ class Dataloader < Sinatra::Base
 
   get '/accounts' do
     j = NeoInfra::Accounts.new
-    #j.load
+    j.load
     status 200
     "Loaded Accounts: #{j.list_names.sort.join(' ')}"
   end
 
+  get '/regions' do
+    j = NeoInfra::Aws.new
+    j.load_regions
+    status 200
+    #{}"Loaded #{j.region_count} regions, #{j.az_count} availablity zones"
+    "suck"
+  end
+
+  get '/vpcs' do
+    j = NeoInfra::Vpcs.new
+    #j.load_vpcs
+    status 200
+    "Loaded #{j.default_vpc_count} default vpcs, #{j.non_default_vpc_count} non-default vpcs"
+
+  end
+
 end

+ 1 - 1
web/views/load_all.html.erb

@@ -1,6 +1,6 @@
 <h2 class="title"><br><br><center>Loading Data</center></h2>
 
-<% ['accounts'].each do |ep| %>
+<% ['accounts', 'regions', 'vpcs'].each do |ep| %>
 
 <script>
 $.get( "/load/<%= ep %>", function( data ) {