Bläddra i källkod

Merge branch 'master' of ssh://gogs.mague.com:7022/Shokunin/neo-infra

Chris Mague 7 år sedan
förälder
incheckning
b1e9a63111

+ 1 - 0
.gitignore

@@ -5,3 +5,4 @@ data/*
 vendor/*
 .bundle
 tmp_notes
+tmp/*

+ 3 - 2
Gemfile

@@ -2,13 +2,14 @@
 
 source 'http://rubygems.org'
 
-gem 'fog-aws', :git => 'https://github.com/maguec/fog-aws.git', :branch => 'fix_vpc_parser_issue_387'
+gem 'fog-aws'
 gem 'mime-types'
 gem 'neo4j', '7.2.0'
+gem 'rake'
 gem 'rspec'
 gem 'rubytree'
 gem 'sinatra'
-gem 'sinatra-respond_to'
+gem 'sinatra-contrib'
 
 group :development do
   gem 'rubocop', require: false

+ 1 - 1
lib/neoinfra/audit.rb

@@ -26,7 +26,7 @@ module NeoInfra
           new_conn = Fog::Compute.new(region_conf.merge(base_conf))
           new_conn.servers.all.each do |ec2|
             %i[required recommended].each do |a|
-              next unless @cfg.tag_policy.has_key? a
+              next unless @cfg.tag_policy.key? a
               next if (ec2.tags.keys.sort & @cfg.tag_policy[a].sort) == @cfg.tag_policy[a].sort
               results[ec2.id].merge!("#{a}_missing_tags" => @cfg.tag_policy[a].sort - ec2.tags.keys.sort,
                                      'tags' => ec2.tags.keys.sort,

+ 118 - 99
lib/neoinfra/aws.rb

@@ -16,14 +16,13 @@ require 'neoinfra/cloudwatch'
 RFC_1918 = [
   IPAddr.new('10.0.0.0/8'),
   IPAddr.new('172.16.0.0/12'),
-  IPAddr.new('192.168.0.0/16'),
+  IPAddr.new('192.168.0.0/16')
 ].freeze
 
 # NeoInfra Account information
 module NeoInfra
   # Provide informations about the accounts available
   class Aws
-
     def initialize
       @cfg = NeoInfra::Config.new
       neo4j_url = "http://#{@cfg.neo4j[:host]}:#{@cfg.neo4j[:port]}"
@@ -84,7 +83,7 @@ module NeoInfra
     def list_buckets
       buckets = []
       Bucket.all.order('n.size DESC').each do |b|
-        buckets <<  {
+        buckets << {
           'name'       => b.name,
           'size'       => b.size,
           'versioning' => b.versioning,
@@ -93,7 +92,7 @@ module NeoInfra
           'owner'      => b.owner.name
         }
       end
-      return buckets
+      buckets
     end
 
     def load_buckets
@@ -109,10 +108,10 @@ module NeoInfra
           next unless Bucket.where(name: bucket.key).empty?
           begin
             vers = bucket.versioning?.to_s
-            crea =  bucket.creation_date.to_s
-          rescue
-            vers = "unknown"
-            crea = "unknown"
+            crea = bucket.creation_date.to_s
+          rescue StandardError
+            vers = 'unknown'
+            crea = 'unknown'
           end
           b = Bucket.new(
             name: bucket.key,
@@ -134,11 +133,11 @@ module NeoInfra
           aws_access_key_id: account[:key],
           aws_secret_access_key: account[:secret]
         }
-        self.regions.each do |region|
+        regions.each do |region|
           region_conf = { region: region }
           begin
             conn = Fog::Compute.new(region_conf.merge(base_conf))
-          rescue
+          rescue StandardError
             puts "Error loading security groups for region #{region}"
             next
           end
@@ -147,58 +146,56 @@ module NeoInfra
               g = SecurityGroup.new(
                 sg_id: grp.group_id,
                 name: grp.name,
-                description: grp.description,
+                description: grp.description
               )
               g.save
-              SecurityGroupOwner.create(from_node: g, to_node:  AwsAccount.where(account_id: grp.owner_id).first)
-              SecurityGroupVpc.create(from_node: g, to_node:  Vpc.where(vpc_id: grp.vpc_id).first)
+              SecurityGroupOwner.create(from_node: g, to_node: AwsAccount.where(account_id: grp.owner_id).first)
+              SecurityGroupVpc.create(from_node: g, to_node: Vpc.where(vpc_id: grp.vpc_id).first)
             end
             grp.ip_permissions.each do |iprule|
-                  if iprule['ipProtocol'] != "-1"
-                  iprule['ipRanges'].each do |r|
-                    if iprule['toPort'] == -1
-                      to_port = 65535
-                    else
-                      to_port = iprule['toPort']
-                    end
-                    if iprule['fromPort'] == -1
-                      from_port = 0
-                    else
-                      from_port = iprule['fromPort']
-                    end
-                    if IpRules.where(
-                      cidr_block: r['cidrIp'],
-                      direction: 'ingress',
-                      proto: iprule['ipProtocol'],
-                      to_port: to_port,
-                      from_port: from_port,
-                    ).empty?
-                      rl = IpRules.new(
-                        cidr_block: r['cidrIp'],
-                        direction: 'ingress',
-                        proto: iprule['ipProtocol'],
-                        to_port: to_port,
-                        from_port: from_port,
-                        private: RFC_1918.any? { |rfc| rfc.include?(IPAddr.new(r['cidrIp']))}
-                      )
-                      rl.save
-                    end
-                    # TODO: remove duplicate Relationships
-                    SecurityGroupsIpRules.create(
-                      from_node: SecurityGroup.where(sg_id: grp.group_id).first,
-                      to_node: IpRules.where(
-                        cidr_block: r['cidrIp'],
-                        direction: 'ingress',
-                        proto: iprule['ipProtocol'],
-                        to_port: to_port,
-                        from_port: from_port,
-                        private: RFC_1918.any? { |rfc| rfc.include?(IPAddr.new(r['cidrIp']))}
-                      ).first
-                    )
-                  end
+              next unless iprule['ipProtocol'] != '-1'
+              iprule['ipRanges'].each do |r|
+                to_port = if iprule['toPort'] == -1
+                            65_535
+                          else
+                            iprule['toPort']
+                          end
+                from_port = if iprule['fromPort'] == -1
+                              0
+                            else
+                              iprule['fromPort']
+                            end
+                if IpRules.where(
+                  cidr_block: r['cidrIp'],
+                  direction: 'ingress',
+                  proto: iprule['ipProtocol'],
+                  to_port: to_port,
+                  from_port: from_port
+                ).empty?
+                  rl = IpRules.new(
+                    cidr_block: r['cidrIp'],
+                    direction: 'ingress',
+                    proto: iprule['ipProtocol'],
+                    to_port: to_port,
+                    from_port: from_port,
+                    private: RFC_1918.any? { |rfc| rfc.include?(IPAddr.new(r['cidrIp'])) }
+                  )
+                  rl.save
                 end
+                # TODO: remove duplicate Relationships
+                SecurityGroupsIpRules.create(
+                  from_node: SecurityGroup.where(sg_id: grp.group_id).first,
+                  to_node: IpRules.where(
+                    cidr_block: r['cidrIp'],
+                    direction: 'ingress',
+                    proto: iprule['ipProtocol'],
+                    to_port: to_port,
+                    from_port: from_port,
+                    private: RFC_1918.any? { |rfc| rfc.include?(IPAddr.new(r['cidrIp'])) }
+                  ).first
+                )
               end
-              #
+            end
           end
         end
       end
@@ -207,7 +204,7 @@ module NeoInfra
     def list_lambdas
       lambdas = []
       Lambda.all.each do |l|
-        lambdas <<  {
+        lambdas << {
           'name'           => l.name,
           'runtime'        => l.runtime,
           'handler'        => l.handler,
@@ -218,7 +215,26 @@ module NeoInfra
           'owner'          => l.owner.name
         }
       end
-      return lambdas
+      lambdas
+    end
+
+    def list_rds
+      rds = []
+      Rds.all.each do |r|
+        rds << {
+          'name'              => r.name,
+          'size'              => r.size,
+          'engine'            => r.engine,
+          'engine_version'    => r.engine_version,
+          'multi_az'          => r.multi_az,
+          'endpoint'          => r.endpoint,
+          'port'              => r.port,
+          'allocated_storage' => r.allocated_storage,
+          'owner'             => r.owner.name,
+          'az'                => r.az.az,
+        }
+      end
+      rds
     end
 
     def load_lambda
@@ -227,21 +243,21 @@ module NeoInfra
           aws_access_key_id: account[:key],
           aws_secret_access_key: account[:secret]
         }
-        self.regions.each do |region|
+        regions.each do |region|
           region_conf = { region: region }
           begin
             lambdas = Fog::AWS::Lambda.new(region_conf.merge(base_conf))
             lambdas.list_functions.data[:body]['Functions'].each do |f|
               next unless Lambda.where(name: f['FunctionArn']).empty?
               l = Lambda.new(
-                  name:             f['FunctionName'],
-                  runtime:          f['Runtime'],
-                  lambda_timeout:   f['Timeout'],
-                  handler:          f['Handler'],
-                  memorysize:       f['MemorySize'],
-                  arn:              f['FunctionArn'],
-                  codesize:         f['CodeSize'],
-                  last_modified:    f['LastModified'],
+                name:             f['FunctionName'],
+                runtime:          f['Runtime'],
+                lambda_timeout:   f['Timeout'],
+                handler:          f['Handler'],
+                memorysize:       f['MemorySize'],
+                arn:              f['FunctionArn'],
+                codesize:         f['CodeSize'],
+                last_modified:    f['LastModified']
               )
               l.save
               LambdaAccount.create(from_node: l, to_node: AwsAccount.where(name: account[:name]).first)
@@ -258,7 +274,7 @@ module NeoInfra
     def list_dynamos
       dynamos = []
       Dynamo.all.order('n.sizebytes DESC').each do |d|
-        dynamos <<  {
+        dynamos << {
           'name'       => d.name,
           'size'       => d.sizebytes,
           'itemcount'  => d.itemcount,
@@ -268,7 +284,7 @@ module NeoInfra
           'owner'      => d.owner.name
         }
       end
-      return dynamos
+      dynamos
     end
 
     def load_dynamo
@@ -277,24 +293,24 @@ module NeoInfra
           aws_access_key_id: account[:key],
           aws_secret_access_key: account[:secret]
         }
-        self.regions.each do |region|
+        regions.each do |region|
           region_conf = { region: region }
           begin
             dyns = Fog::AWS::DynamoDB.new(region_conf.merge(base_conf))
-            dyns.list_tables.data[:body]["TableNames"].each do |table|
+            dyns.list_tables.data[:body]['TableNames'].each do |table|
               tb = dyns.describe_table(table).data[:body]['Table']
               next unless Dynamo.where(name: table['TableId']).empty?
               d = Dynamo.new(
-                  tableid: 	tb['TableId'],
-                  name: 	tb['TableName'],
-                  creation: Time.at(tb['CreationDateTime']).to_datetime.strftime("%F %H:%M:%S %Z"),
-                  arn: 		tb['TableArn'],
-                  itemcount: 	tb['ItemCount'],
-                  sizebytes: 	tb['TableSizeBytes'],
-                  status: 	tb['TableStatus'],
-                  readcap: 	tb['ProvisionedThroughput']['ReadCapacityUnits'],
-                  writecap: 	tb['ProvisionedThroughput']['WriteCapacityUnits'],
-                  capdecreases: tb['ProvisionedThroughput']['NumberOfDecreasesToday'],
+                tableid:   tb['TableId'],
+                name:   tb['TableName'],
+                creation: Time.at(tb['CreationDateTime']).to_datetime.strftime('%F %H:%M:%S %Z'),
+                arn:     tb['TableArn'],
+                itemcount:   tb['ItemCount'],
+                sizebytes:   tb['TableSizeBytes'],
+                status:   tb['TableStatus'],
+                readcap:   tb['ProvisionedThroughput']['ReadCapacityUnits'],
+                writecap:   tb['ProvisionedThroughput']['WriteCapacityUnits'],
+                capdecreases: tb['ProvisionedThroughput']['NumberOfDecreasesToday']
               )
               d.save
               DynamoAccount.create(from_node: d, to_node: AwsAccount.where(name: account[:name]).first)
@@ -305,9 +321,9 @@ module NeoInfra
             next
           end
         end
-        #dyns.list_tables.each do |table|
+        # dyns.list_tables.each do |table|
         #  p table
-        #end
+        # end
       end
     end
 
@@ -317,22 +333,25 @@ module NeoInfra
           aws_access_key_id: account[:key],
           aws_secret_access_key: account[:secret]
         }
-        s = Fog::AWS::RDS.new(base_conf)
-        s.servers.each do |rds|
-          next unless Rds.where(name: rds.id).empty?
-          r = Rds.new(
-            name: rds.id,
-            size: rds.flavor_id,
-            engine: rds.engine,
-            engine_version: rds.engine_version,
-            multi_az: rds.multi_az.to_s,
-            endpoint: rds.endpoint['Address'],
-            port: rds.endpoint['Port'],
-            allocated_storage: rds.allocated_storage,
-          )
-          r.save
-          RdsAz.create(from_node: r, to_node: Az.where(az: rds.availability_zone).first)
-          RdsAccount.create(from_node: r, to_node: AwsAccount.where(name: account[:name]).first)
+        regions.each do |region|
+          region_conf = { region: region }
+          s = Fog::AWS::RDS.new(region_conf.merge(base_conf))
+          s.servers.each do |rds|
+            next unless Rds.where(name: rds.id).empty?
+            r = Rds.new(
+              name: rds.id,
+              size: rds.flavor_id,
+              engine: rds.engine,
+              engine_version: rds.engine_version,
+              multi_az: rds.multi_az.to_s,
+              endpoint: rds.endpoint['Address'],
+              port: rds.endpoint['Port'],
+              allocated_storage: rds.allocated_storage
+            )
+            r.save
+            RdsAz.create(from_node: r, to_node: Az.where(az: rds.availability_zone).first)
+            RdsAccount.create(from_node: r, to_node: AwsAccount.where(name: account[:name]).first)
+          end
         end
       end
     end

+ 11 - 11
lib/neoinfra/cloudwatch.rb

@@ -15,17 +15,17 @@ module NeoInfra
       }
       cwstats = Fog::AWS::CloudWatch.new(conf)
       begin
-      cwstats.get_metric_statistics('Statistics' => ['Maximum'],
-                                    'StartTime'  => DateTime.now - 7,
-                                    'EndTime'    => DateTime.now,
-                                    'Period'     => 3600,
-                                    'MetricName' => 'BucketSizeBytes',
-                                    'Namespace'  => 'AWS/S3',
-                                    'Dimensions' => [
-                                      { 'Name' => 'BucketName', 'Value' => bucket },
-                                      { 'Name' => 'StorageType', 'Value' => 'StandardStorage' }
-                                    ]).data[:body]['GetMetricStatisticsResult']['Datapoints'].last['Maximum']
-      rescue
+        cwstats.get_metric_statistics('Statistics' => ['Maximum'],
+                                      'StartTime'  => DateTime.now - 7,
+                                      'EndTime'    => DateTime.now,
+                                      'Period'     => 3600,
+                                      'MetricName' => 'BucketSizeBytes',
+                                      'Namespace'  => 'AWS/S3',
+                                      'Dimensions' => [
+                                        { 'Name' => 'BucketName', 'Value' => bucket },
+                                        { 'Name' => 'StorageType', 'Value' => 'StandardStorage' }
+                                      ]).data[:body]['GetMetricStatisticsResult']['Datapoints'].last['Maximum']
+      rescue StandardError
         puts "Unable to get stats for #{bucket} returning -1"
         return -1
       end

+ 40 - 29
lib/neoinfra/nodes.rb

@@ -6,12 +6,10 @@ require 'nodes'
 require 'accounts'
 require 'fog-aws'
 
-
 # NeoInfra Account information
 module NeoInfra
   # Provide informations about the accounts available
   class Nodes
-
     def initialize
       @cfg = NeoInfra::Config.new
       neo4j_url = "http://#{@cfg.neo4j[:host]}:#{@cfg.neo4j[:port]}"
@@ -20,27 +18,39 @@ module NeoInfra
 
     def display_node(node_id)
       n = Node.where(node_id: node_id).first
-      return {
-        "Name"          => n.name,
-        "IP"            => n.ip,
-        "State"         => n.state,
-        "AMI"           => n.ami,
-        "Public_IP"     => n.public_ip,
-        "AZ"            => n.az.az,
-        "Account"       => n.account.name,
-        "Size"          => n.size,
-        "Subnet"        => n.subnet.name,
-        "VPC"           => n.subnet.subnet.name,
-        "SSH-Key"       => n.sshkey.name,
-        "SecurityGroup" => n.node_sg.name,
+      {
+        'Name'          => n.name,
+        'IP'            => n.ip,
+        'State'         => n.state,
+        'AMI'           => n.ami,
+        'Public_IP'     => n.public_ip,
+        'AZ'            => n.az.az,
+        'Account'       => n.account.name,
+        'Size'          => n.size,
+        'Subnet'        => n.subnet.name,
+        'VPC'           => n.subnet.subnet.name,
+        'SSH-Key'       => n.sshkey.name,
+        'SecurityGroup' => n.node_sg.name
       }
     end
 
+    def search_nodes_by_name(name)
+      results = {:nodes => [], :errors => []}
+      if !Node.where(name: name).empty?
+        Node.where(name: name).each do |k|
+          results[:nodes] << display_node(k.node_id)
+        end
+      else
+        results[:errors] << "Could not find a node with name: #{name}"
+      end
+      return results
+    end
+
     def search_nodes_by_ip(ip)
-      if Node.where(ip: ip).length > 0
-	display_node(Node.where(ip: ip).first.node_id)
+      if !Node.where(ip: ip).empty?
+        display_node(Node.where(ip: ip).first.node_id)
       else
-	display_node(Node.where(public_ip: ip).first.node_id)
+        display_node(Node.where(public_ip: ip).first.node_id)
       end
     end
 
@@ -61,11 +71,12 @@ module NeoInfra
           region_conf = { region: region }
           begin
             new_conn = Fog::Compute.new(region_conf.merge(base_conf))
-          rescue
+          rescue StandardError
             puts "Error loading nodes in region: #{region}"
             next
           end
           new_conn.servers.all.each do |ec2|
+            next if ec2.state == 'terminated'
             if SshKey.where(name: ec2.key_name).empty?
               s = SshKey.new(
                 name: ec2.key_name,
@@ -95,18 +106,18 @@ module NeoInfra
             n.save
             NodeAccount.create(from_node: n, to_node: AwsAccount.where(name: account[:name]).first)
             NodeSubnet.create(from_node: n, to_node: Subnet.where(subnet_id: ec2.subnet_id).first)
+
             NodeAz.create(from_node: n, to_node: Az.where(az: ec2.availability_zone).first)
             NodeSshKey.create(from_node: n, to_node: SshKey.where(name: ec2.key_name).first)
-            ec2.network_interfaces.select{|x| x.length > 0 }.each do |i|
-              if i.has_key? 'groupIds'
-                i['groupIds'].each do |g|
-                  begin
-                    NodeSecurityGroup.create(from_node: n, to_node: SecurityGroup.where(sg_id: g).first)
-                  rescue
-                    puts "Security Groups: #{account[:name]}/#{region} couldn't get the following to work:"
-                    p ec2
-                    p g
-                  end
+            ec2.network_interfaces.reject(&:empty?).each do |i|
+              next unless i.key? 'groupIds'
+              i['groupIds'].each do |g|
+                begin
+                  NodeSecurityGroup.create(from_node: n, to_node: SecurityGroup.where(sg_id: g).first)
+                rescue StandardError
+                  puts "Security Groups: #{account[:name]}/#{region} couldn't get the following to work:"
+                  p ec2
+                  p g
                 end
               end
             end

+ 6 - 7
lib/neoinfra/vpcs.rb

@@ -10,7 +10,6 @@ require 'neo4j'
 module NeoInfra
   # Provide informations about the accounts available
   class Vpcs
-
     def initialize
       @cfg = NeoInfra::Config.new
       neo4j_url = "http://#{@cfg.neo4j[:host]}:#{@cfg.neo4j[:port]}"
@@ -18,17 +17,17 @@ module NeoInfra
     end
 
     def non_default_vpc_count
-      Vpc.all.collect{|x| x.default}.select{|y| y == "false"}.length
+      Vpc.all.collect(&:default).select { |y| y == 'false' }.length
     end
 
     def default_vpc_count
-      Vpc.all.collect{|x| x.default}.select{|y| y == "true"}.length
+      Vpc.all.collect(&:default).select { |y| y == 'true' }.length
     end
 
     def list_vpcs
       node_counts = Hash.new(0)
-      Node.all.each{|x| node_counts[x.subnet.subnet.name]+=1}
-      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
+      Node.all.each { |x| node_counts[x.subnet.subnet.name] += 1 }
+      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
 
     def load
@@ -43,7 +42,7 @@ module NeoInfra
           region_conf = { region: region }
           begin
             new_conn = Fog::Compute.new(region_conf.merge(base_conf))
-          rescue
+          rescue StandardError
             puts "Error loading VPCs in region: #{region}"
             next
           end
@@ -89,7 +88,7 @@ module NeoInfra
             VpcSubnet.create(from_node: sn, to_node: Vpc.where(vpc_id: subnet.vpc_id).first)
             begin
               SubnetAz.create(from_node: sn, to_node: Az.where(az: subnet.availability_zone).first)
-            rescue
+            rescue StandardError
               #  Handle the case of hanging subnets
               puts "Account #{account[:name]} couldn't load the following subnet:"
               p subnet

+ 1 - 1
models/nodes.rb

@@ -27,7 +27,7 @@ class SecurityGroup
   has_one  :out, :sg_owner, rel_class: :SecurityGroupOwner
   has_one  :out, :sg_vpc, rel_class: :SecurityGroupVpc
   has_many :out, :ip_rules, rel_class: :SecurityGroupsIpRules
-#  has_many :out, :sg_rules, rel_class: :SecurityGroupsSgRules
+  #  has_many :out, :sg_rules, rel_class: :SecurityGroupsSgRules
 end
 
 class NodeSecurityGroup

+ 0 - 1
models/rds.rb

@@ -61,4 +61,3 @@ class DynamoRegion
   to_class :Region
   type :region
 end
-

+ 0 - 1
tasks/load_data.rake

@@ -57,7 +57,6 @@ namespace :load_data do
     j.load_dynamo
   end
 
-
   desc 'Load Lambdas'
   task :lambda do
     puts 'loading Lambdas'

+ 18 - 20
tasks/sample_data.rake

@@ -4,7 +4,6 @@ require 'yaml'
 require 'pp'
 
 namespace :sample_data do
-
   sample_data = YAML.load_file(
     File.join(File.dirname(File.expand_path(__FILE__)), 'sample_data.yaml')
   )
@@ -13,22 +12,22 @@ namespace :sample_data do
   task :accounts do
     puts 'loading accounts'
     sample_data['accounts'].each do |account|
-    	next unless AwsAccount.where(name: account[:name]).empty?
-    	acct = AwsAccount.new(
-    	  name:       account[:name],
-    	  account_id: 90000+rand(20),
-    	  user_id:    account[:name],
-    	  key_md5:    Digest:: MD5.hexdigest(account[:name]),
-    	  secret_md5: Digest:: MD5.hexdigest(account[:name])
-    	)
-    acct.save
+      next unless AwsAccount.where(name: account[:name]).empty?
+      acct = AwsAccount.new(
+        name:       account[:name],
+        account_id: rand(90_000..90_019),
+        user_id:    account[:name],
+        key_md5:    Digest:: MD5.hexdigest(account[:name]),
+        secret_md5: Digest:: MD5.hexdigest(account[:name])
+      )
+      acct.save
     end
   end
 
   task :regions do
     puts 'loading regions'
     sample_data['regions'].each do |reg|
-    	next unless Region.where(region: reg.keys.first).empty?
+      next unless Region.where(region: reg.keys.first).empty?
       r = Region.new(region: reg.keys.first)
       r.save
       reg[reg.keys.first].each do |az|
@@ -42,7 +41,7 @@ namespace :sample_data do
   task :vpcs do
     puts 'loading vpcs'
     sample_data['vpcs'].each do |v|
-    	next unless Vpc.where(vpc_id: v['vpc_id']).empty?
+      next unless Vpc.where(vpc_id: v['vpc_id']).empty?
       vp = Vpc.new(
         vpc_id: v['vpc_id'],
         name: v['name'],
@@ -59,7 +58,7 @@ namespace :sample_data do
   task :subnets do
     puts 'loading subnets'
     sample_data['subnets'].each do |s|
-    	next unless Subnet.where(subnet_id: s['subnet_id']).empty?
+      next unless Subnet.where(subnet_id: s['subnet_id']).empty?
       sn = Subnet.new(
         subnet_id: s['subnet_id'],
         cidr: s['cidr'],
@@ -75,10 +74,10 @@ namespace :sample_data do
   task :buckets do
     puts 'loading buckets'
     sample_data['buckets'].each do |b|
-    	next unless Bucket.where(name: b['name']).empty?
+      next unless Bucket.where(name: b['name']).empty?
       s = Bucket.new(
         name: b['name'],
-        size: b['size'],
+        size: b['size']
       )
       s.save
       BucketRegion.create(from_node: s, to_node: Region.where(region: b['region']).first)
@@ -89,21 +88,20 @@ namespace :sample_data do
   task :ssh_keys do
     puts 'loading ssh_keys'
     sample_data['ssh_keys'].each do |k|
-    	next unless SshKey.where(name: k['name']).empty?
+      next unless SshKey.where(name: k['name']).empty?
       s = SshKey.new(
         name: k['name'],
-        account: k['account'],
+        account: k['account']
       )
       s.save
       SshKeyAccount.create(from_node: s, to_node: AwsAccount.where(name: k['account']).first)
     end
-
   end
 
   task :nodes do
     puts 'loading nodes'
     sample_data['nodes'].each do |n|
-    	next unless Node.where(node_id: n['node_id']).empty?
+      next unless Node.where(node_id: n['node_id']).empty?
       node = Node.new(
         node_id: n['node_id'],
         name:  n['name'],
@@ -111,7 +109,7 @@ namespace :sample_data do
         public_ip: n['public_ip'],
         size: n['size'],
         state: 'running',
-        ami: n['ami'],
+        ami: n['ami']
       )
       node.save
       NodeAccount.create(from_node: node, to_node: AwsAccount.where(name: n['account']).first)

+ 1 - 1
web/controllers.rb

@@ -9,7 +9,7 @@ Dir.glob(
 ).reject { |c| File.basename(c) == 'controllers.rb' }.each do |x|
   begin
     require x
-  rescue
+  rescue StandardError
     puts "unable to load: #{x}"
   end
 end

+ 2 - 2
web/controllers/dataloader.rb

@@ -7,11 +7,11 @@ $LOAD_PATH.unshift(lib_dir) unless
 require 'neoinfra'
 require 'sinatra'
 require 'sinatra/base'
-require 'sinatra/respond_to'
+require 'sinatra/contrib'
 
 # Handle loading data into the graph db
 class Dataloader < Sinatra::Base
-  register Sinatra::RespondTo
+  register Sinatra::RespondWith
   set :views, File.join(File.dirname(__FILE__), '..', '/views')
 
   get '/all' do

+ 21 - 12
web/controllers/search.rb

@@ -8,32 +8,41 @@ require 'json'
 require 'neoinfra'
 require 'sinatra'
 require 'sinatra/base'
-require 'sinatra/respond_to'
+require 'sinatra/contrib'
 
 # Handle loading data into the graph db
 class Search < Sinatra::Base
-  register Sinatra::RespondTo
+  register Sinatra::RespondWith
   set :views, File.join(File.dirname(__FILE__), '..', '/views')
 
   post '/all' do
     if params['search'] =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/
       n = NeoInfra::Nodes.new
       respond_to do |wants|
-        wants.html {
+        wants.html do
           erb :view_node,
-          :layout => :base_layout,
-          :locals => {:node => n.search_nodes_by_ip(params['search'])}
-        }
-    end
+              layout: :base_layout,
+              locals: { node: n.search_nodes_by_ip(params['search']) }
+        end
+      end
     elsif params['search'] =~ /i-[a-f0-9]{6,20}/
       n = NeoInfra::Nodes.new
       respond_to do |wants|
-        wants.html {
+        wants.html do
           erb :view_node,
-          :layout => :base_layout,
-          :locals => {:node => n.search_nodes_by_node_id(params['search'])}
-        }
-    end
+              layout: :base_layout,
+              locals: { node: n.search_nodes_by_node_id(params['search']) }
+        end
+      end
+    else
+      n = NeoInfra::Nodes.new
+      respond_to do |wants|
+        wants.html do
+          erb :view_nodes,
+              layout: :base_layout,
+              locals: { nodes: n.search_nodes_by_name(params['search']) }
+        end
+      end
     end
   end
 end

+ 2 - 2
web/controllers/toppage.rb

@@ -2,11 +2,11 @@
 
 require 'sinatra'
 require 'sinatra/base'
-require 'sinatra/respond_to'
+require 'sinatra/contrib'
 
 # Display the Top level Web page
 class Toppage < Sinatra::Base
-  register Sinatra::RespondTo
+  register Sinatra::RespondWith
   set :public_folder, File.join(File.dirname(__FILE__), '..', '/static')
   set :views, File.join(File.dirname(__FILE__), '..', '/views')
 

+ 28 - 19
web/controllers/views.rb

@@ -8,56 +8,65 @@ require 'json'
 require 'neoinfra'
 require 'sinatra'
 require 'sinatra/base'
-require 'sinatra/respond_to'
+require 'sinatra/contrib'
 
 # Handle loading data into the graph db
 class Views < Sinatra::Base
-  register Sinatra::RespondTo
+  register Sinatra::RespondWith
   set :views, File.join(File.dirname(__FILE__), '..', '/views')
 
   get '/vpcs' do
     w = NeoInfra::Vpcs.new
     respond_to do |wants|
-      wants.html {
+      wants.html do
         erb :view_vpcs,
-        :layout => :base_layout,
-        :locals => {:vpcs => w.list_vpcs}
-      }
+            layout: :base_layout,
+            locals: { vpcs: w.list_vpcs }
+      end
     end
   end
 
   get '/buckets' do
     j = NeoInfra::Aws.new
     respond_to do |wants|
-      wants.html {
+      wants.html do
         erb :view_buckets,
-        :layout => :base_layout,
-        :locals => {:buckets => j.list_buckets}
-      }
+            layout: :base_layout,
+            locals: { buckets: j.list_buckets }
+      end
     end
   end
 
   get '/dynamos' do
     j = NeoInfra::Aws.new
     respond_to do |wants|
-      wants.html {
+      wants.html do
         erb :view_dynamos,
-        :layout => :base_layout,
-        :locals => {:dynamos => j.list_dynamos}
-      }
+            layout: :base_layout,
+            locals: { dynamos: j.list_dynamos }
+      end
     end
   end
 
   get '/lambdas' do
     j = NeoInfra::Aws.new
     respond_to do |wants|
-      wants.html {
+      wants.html do
         erb :view_lambdas,
-        :layout => :base_layout,
-        :locals => {:lambdas => j.list_lambdas}
-      }
+            layout: :base_layout,
+            locals: { lambdas: j.list_lambdas }
+      end
     end
   end
 
-
+  get '/rds' do
+    j = NeoInfra::Aws.new
+    respond_to do |wants|
+      wants.html do
+        erb :view_rds,
+            layout: :base_layout,
+            locals: { rds: j.list_rds }
+      end
+    end
+  end
 end

+ 0 - 0
web/views/base_layout.html.erb → web/views/base_layout.erb


+ 0 - 0
web/views/index.html.erb → web/views/index.erb


+ 0 - 0
web/views/load_all.html.erb → web/views/load_all.erb


+ 0 - 0
web/views/view_buckets.html.erb → web/views/view_buckets.erb


+ 0 - 0
web/views/view_dynamos.html.erb → web/views/view_dynamos.erb


+ 0 - 0
web/views/view_lambdas.html.erb → web/views/view_lambdas.erb


+ 0 - 0
web/views/view_node.html.erb → web/views/view_node.erb


+ 44 - 0
web/views/view_nodes.erb

@@ -0,0 +1,44 @@
+<h2 class="title"><br><br><center>Node Information</center><br><br></h2>
+<div class="container">
+
+<% if nodes[:errors].length > 0 %>
+<% nodes[:errors].each do |e| %>
+	<br><%= e %>
+<% end %>
+<% else %>
+
+<table class="table table-hover">
+<tbody>
+<tr> <th>Name</th>
+<th>IP</th>
+<th>Public IP</th>
+<th>Account</th>
+<th>Size</th>
+<th>Subnet</th>
+<th>AZ</th>
+<th>VPC</th>
+<th>AMI</th>
+<th>State</th>
+<th>Security Group</th>
+<tr>
+<% nodes[:nodes].each do |n| %>
+<tr>
+	<td><%= n['Name'] %></td>
+	<td><%= n['IP'] %></td>
+	<td><%= n['Public_IP'] %></td>
+	<td><%= n['Account'] %></td>
+	<td><%= n['Size'] %></td>
+	<td><%= n['Subnet'] %></td>
+	<td><%= n['AZ'] %></td>
+	<td><%= n['VPC'] %></td>
+	<td><%= n['AMI'] %></td>
+	<td><%= n['State'] %></td>
+	<td><%= n['SecurityGroup'] %></td>
+</tr>
+<% end %>
+</tbody>
+</table>
+
+<% end %>
+
+</div>

+ 30 - 0
web/views/view_rds.erb

@@ -0,0 +1,30 @@
+<h2 class="title"><br><br><center>RDS Intances</center></h2>
+
+<div class="container">
+  <table class="table table-hover">
+    <thead>
+      <tr>
+        <th>Name</th>
+        <th>Owner</th>
+        <th>AZ</th>
+        <th>Engine</th>
+        <th>Engine Version</th>
+        <th>Endpoint</th>
+        <th>Port</th>
+      </tr>
+    </thead>
+    <tbody>
+<% rds.each do |r| %>
+<tr>
+<td><%= r['name'] %></td>
+<td><%= r['owner'] %></td>
+<td><%= r['az'] %></td>
+<td><%= r['engine'] %></td>
+<td><%= r['engine_version'] %></td>
+<td><%= r['endpoint'] %></td>
+<td><%= r['port'] %></td>
+</tr>
+<% end %>
+    </tbody>
+  </table>
+</div>

+ 0 - 0
web/views/view_vpcs.html.erb → web/views/view_vpcs.erb