def _find_existing_default_route()

in source/state_machine_handler.py [0:0]


    def _find_existing_default_route(self, existing_routes, destination_route):
        try:
            self.logger.info("Executing: " + self.__class__.__name__ + "/" + inspect.stack()[0][3])
            gateway_id = None
            # set default flags
            self.event.update({'DefaultRouteToTgwExists': 'no'})
            self.event.update({'DestinationRouteExists': 'no'})
            for route in existing_routes:
                if route.get('DestinationCidrBlock') == destination_route:
                    # if destination route already exists in the route table - set flag
                    self.event.update({'DestinationRouteExists': 'yes'})
                    self.logger.info('Found route: {} in the route table.'.format(destination_route))
                    # Check if default route has Transit gateway as the target
                    if route.get('TransitGatewayId') is not None:
                        comment = "Found Transit Gateway as a target to the default route: {}" \
                            .format(destination_route)
                        self.event.update({'DefaultRouteToTgwExists': 'yes'})
                        self.logger.info(comment)
                        gateway_id = route.get('TransitGatewayId')
                        self._print('Transit Gateway Id', gateway_id)

                    # Check if default route has Internet gateway as the target
                    elif route.get('GatewayId') is not None:
                        comment = "Found existing gateway as a target to the default route: {}" \
                            .format(destination_route)
                        self.logger.info(comment)
                        gateway_id = route.get('GatewayId')
                        self._print('Gateway Id', gateway_id)

                    # Check if default route has NAT gateway as the target
                    elif route.get('NatGatewayId') is not None:
                        comment = "Found NAT Gateway as a target to the default route: {}" \
                            .format(destination_route)
                        self.logger.info(comment)
                        gateway_id = route.get('NatGatewayId')
                        self._print('NAT Gateway Id', gateway_id)
                    elif route.get('VpcPeeringConnectionId') is not None:
                        comment = "Found VPC Peering Connection as a target to the default route: {}" \
                            .format(destination_route)
                        self.logger.info(comment)
                        gateway_id = route.get('VpcPeeringConnectionId')
                        self._print('Peering Connection Id', gateway_id)
                    else:
                        self.logger.info("Found an existing target for the default route.")
                        gateway_id = 'custom-target'
                        self._print('Route', route)
            # update event with gateway id
            self.event.update({'GatewayId': gateway_id})
        except Exception as e:
            message = self._message(inspect.stack()[0][3], e)
            self.logger.exception(message)
            self._update_ddb_failed(e)
            raise