Selaa lähdekoodia

handle case where errors occur in from/to relationships

Chris Mague 6 vuotta sitten
vanhempi
commit
db69c2bb01
3 muutettua tiedostoa jossa 28 lisäystä ja 10 poistoa
  1. 17 4
      lib/neoinfra/aws.rb
  2. 9 4
      lib/neoinfra/nodes.rb
  3. 2 2
      lib/neoinfra/vpcs.rb

+ 17 - 4
lib/neoinfra/aws.rb

@@ -149,8 +149,15 @@ module NeoInfra
                 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)
+              begin
+                SecurityGroupOwner.create(from_node: g, to_node: AwsAccount.where(account_id: grp.owner_id).first)
+                unless grp.vpc_id.nil?
+                  SecurityGroupVpc.create(from_node: g, to_node: Vpc.where(vpc_id: grp.vpc_id).first)
+                end
+              rescue
+                puts "Account #{account[:name]} couldn't load the following security group:"
+                p grp
+              end
             end
             grp.ip_permissions.each do |iprule|
               next unless iprule['ipProtocol'] != '-1'
@@ -349,8 +356,14 @@ module NeoInfra
               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)
+            begin
+              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)
+            rescue Exception => e
+              puts "Account #{account[:name]} couldn't load the following rds: #{e.message}"
+              p r
+              next
+            end
           end
         end
       end

+ 9 - 4
lib/neoinfra/nodes.rb

@@ -104,11 +104,16 @@ module NeoInfra
               ami: ec2.image_id
             )
             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)
+            begin
+              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)
+            rescue Exception => e
+              puts "Account #{account[:name]} couldn't load the following node: #{e.message}"
+              p n
+            end
 
-            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.reject(&:empty?).each do |i|
               next unless i.key? 'groupIds'
               i['groupIds'].each do |g|

+ 2 - 2
lib/neoinfra/vpcs.rb

@@ -88,9 +88,9 @@ 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 StandardError
+            rescue Exception => e 
               #  Handle the case of hanging subnets
-              puts "Account #{account[:name]} couldn't load the following subnet:"
+              puts "Account #{account[:name]} couldn't load the following subnet: #{e.message}"
               p subnet
             end
           end