def attack_scenario(self):
        if not self.failed:
            # topology
            try:
                scenario_topology = models.Topology(
                    id_topology_type=self.id_topology_type,
                    topology=(self.scenario_name + ' - ' +
                              self.topology_base)[:50],
                    description=self.scenario_description)
                self.dbsession.add(scenario_topology)
                self.dbsession.flush()
            except Exception as error:
                self.dbsession.rollback()
                print(error)
                return

            # scenario
            try:
                self.dbsession.add(
                    models.Scenario(
                        id_scenario_attack_type=self.id_scenario_attack_type,
                        id_topology=scenario_topology.id))
                self.dbsession.flush()
            except Exception as error:
                self.dbsession.rollback()
                print(error)
                return

            self.id_scenario = self.dbsession.query(models.Scenario.id).\
                filter_by(id_scenario_attack_type=self.id_scenario_attack_type).\
                filter_by(id_topology=scenario_topology.id).first()

            return self.attacker_list, self.affected_area_list, self.target_list, self.scenario_attack_type
 def topology(self, dbsession):
     topology = models.Topology(
         topology=self.topology_name,
         description='CAIDA AS-Relationship - %s' % self.file,
         id_topology_type=dbsession.query(models.TopologyType.id).filter(
             func.lower(models.TopologyType.topology_type) ==
             'caida as-relationship'))
     dbsession.add(topology)
    def duplicate_topology(dbsession, old_id_topology, new_topology_name):
        try:

            # Topology
            old_topology = dbsession.query(models.Topology).\
                filter_by(id=old_id_topology).first()
            new_topology = models.Topology(topology=new_topology_name,
                                           id_topology_type=old_topology.id_topology_type,
                                           description=old_topology.description)
            dbsession.add(new_topology)

            dbsession.flush()

            return new_topology.id

        except Exception as error:
            print('Error -------- 1 -------- : ', error)
            dbsession.rollback()
    def attack_scenario(self):
        print('estou no attack_scenario')
        if not self.failed:
            # topology
            try:
                self.dbsession.add(
                    models.Topology(id_topology_type=self.id_topology_type,
                                    topology=(self.scenario_name + ' - ' +
                                              self.topology_base)[:50],
                                    description=self.scenario_description))
                self.dbsession.flush()
            except Exception as error:
                self.dbsession.rollback()
                print(error)
                return

            scenario_topology = self.dbsession.query(models.Topology).\
                filter_by(topology=(self.scenario_name + ' - ' + self.topology_base)[:50]).first()

            # scenario
            try:
                self.dbsession.add(
                    models.Scenario(
                        id_scenario_attack_type=self.id_scenario_attack_type,
                        id_topology=scenario_topology.id))
                self.dbsession.flush()
            except Exception as error:
                self.dbsession.rollback()
                print(error)
                return

            # scenario_item / path / path_item
            if self.attacker and self.affected and self.target:
                if self.scenario_attack_type == 'attraction':
                    self.attraction_attack_type()
                elif self.scenario_attack_type == 'interception':
                    self.interception_attack_type()
                else:
                    print('attack type unknown')
                    return