Ejemplo n.º 1
0
 def process(self):
     """
     This is the method that does everything automatically (at least attempts to).
     
     Steps:
         0. Call "before_start" method (which might be implemented by children classes)
         1. Retrieve data from external source
         2. Parse the data
         3. Save the data locally
         4. Call "after_complete" method (which might be implemented by children classes)
     """
     self.before_start()
     self.retrieve_data()
     self.parse()
     
     # TRICK: disable new_nodes_allowed_for_layer validation
     Node._additional_validation.remove('new_nodes_allowed_for_layer')
     # avoid sending zillions of notifications
     pause_disconnectable_signals()
     
     self.save()
     
     # Re-enable new_nodes_allowed_for_layer validation
     Node._additional_validation.insert(0, 'new_nodes_allowed_for_layer')
     # reconnect signals
     resume_disconnectable_signals()
     
     self.after_complete()
     
     # return message as a list because more than one messages might be returned
     return [self.message]
Ejemplo n.º 2
0
    def handle(self, *args, **options):
        """ execute synchronize command """
        self.options = options
        delete = False

        try:
            # blank line
            self.stdout.write('\r\n')
            # store verbosity level in instance attribute for later use
            self.verbosity = int(self.options.get('verbosity'))

            self.verbose(
                'disabling signals (notififcations, websocket alerts)')
            pause_disconnectable_signals()

            self.check_status_mapping()
            self.retrieve_nodes()
            self.extract_users()
            self.import_admins()
            self.import_users()
            self.import_nodes()
            self.check_deleted_nodes()
            self.import_devices()
            self.import_interfaces()
            self.import_links()
            self.check_deleted_links()
            self.import_contacts()

            self.confirm_operation_completed()

            resume_disconnectable_signals()
            self.verbose(
                're-enabling signals (notififcations, websocket alerts)')

        except KeyboardInterrupt:
            self.message('\n\nOperation cancelled...')
            delete = True
        except Exception as e:
            tb = traceback.format_exc()
            delete = True
            # rollback database transaction
            transaction.rollback()
            self.message('Got exception:\n\n%s' % tb)
            error('import_old_nodeshot: %s' % e)

        if delete:
            self.delete_imported_data()
Ejemplo n.º 3
0
    def handle(self, *args, **options):
        """ execute synchronize command """
        self.options = options
        delete = False

        try:
            # blank line
            self.stdout.write('\r\n')
            # store verbosity level in instance attribute for later use
            self.verbosity = int(self.options.get('verbosity'))

            self.verbose('disabling signals (notififcations, websocket alerts)')
            pause_disconnectable_signals()

            self.check_status_mapping()
            self.retrieve_nodes()
            self.extract_users()
            self.import_admins()
            self.import_users()
            self.import_nodes()
            self.check_deleted_nodes()
            self.import_devices()
            self.import_interfaces()
            self.import_links()
            self.check_deleted_links()
            self.import_contacts()

            self.confirm_operation_completed()

            resume_disconnectable_signals()
            self.verbose('re-enabling signals (notififcations, websocket alerts)')

        except KeyboardInterrupt:
            self.message('\n\nOperation cancelled...')
            delete = True
        except Exception as e:
            tb = traceback.format_exc()
            delete = True
            # rollback database transaction
            transaction.rollback()
            self.message('Got exception:\n\n%s' % tb)
            error('import_old_nodeshot: %s' % e)

        if delete:
            self.delete_imported_data()
Ejemplo n.º 4
0
    def sync(self):
        """
        This is the method that does everything automatically (at least attempts to).

        Steps:
            0. Call "before_start" method (which might be implemented by children classes)
            1. Retrieve data from external source
            2. Parse the data
            3. Save the data locally
            4. Call "after_complete" method (which might be implemented by children classes)
        """
        self.before_start()
        self.retrieve_data()
        self.parse()

        # TRICK: disable new_nodes_allowed_for_layer validation
        try:
            Node._additional_validation.remove('new_nodes_allowed_for_layer')
        except ValueError as e:
            print "WARNING! got exception: %s" % e
        # avoid sending zillions of notifications
        pause_disconnectable_signals()

        self.save()

        # Re-enable new_nodes_allowed_for_layer validation
        try:
            Node._additional_validation.insert(0,
                                               'new_nodes_allowed_for_layer')
        except ValueError as e:
            print "WARNING! got exception: %s" % e
        # reconnect signals
        resume_disconnectable_signals()

        self.after_complete()

        # return message as a list because more than one messages might be returned
        return [self.message]