Example #1
0
    def get_inventory(self, ctx, logger):
        handler_class = get_inventory_handler_class(ctx)
        if handler_class is None:
            logger.error('SoftwareManager: Unable to get handler for %s', ctx.host.software_platform)

        handler = handler_class()
        if handler.get_inventory(ctx):
            # Update the time stamp
            ctx.host.inventory_job[0].set_status(JobStatus.COMPLETED)
Example #2
0
File: sum.py Project: ommaurya/csm
    def get_software(self, db_session, ctx):
        handler_class = get_inventory_handler_class(ctx.host.platform)
        if handler_class is None:
            logger.error('SoftwareManager: Unable to get handler for %s', ctx.host.platform)

        handler = handler_class()
        if handler.get_software(ctx.host, ctx.inactive_cli, ctx.active_cli, ctx.committed_cli):  
            # Update the time stamp
            ctx.host.inventory_job[0].set_status(JobStatus.COMPLETED)
Example #3
0
File: sim.py Project: ommaurya/csm
    def process(self):
        
        db_session = DBSession()
        host_id = None
        inventory_job = None
        ctx = None
        try:
            
            inventory_job = db_session.query(InventoryJob).filter(InventoryJob.id == self.job_id).first()    
            if inventory_job is None:
                logger.error('Unable to retrieve inventory job: %s' % self.job_id)
                return
            
            host_id = inventory_job.host_id
            host = db_session.query(Host).filter(Host.id == host_id).first()
            if host is None:
                logger.error('Unable to retrieve host: %s' % host_id)
            
            handler_class = get_inventory_handler_class(host.platform)
            if handler_class is None:
                logger.error('Unable to get handler for %s, inventory job %s', host.platform, self.job_id)
            
            inventory_job.set_status(JobStatus.PROCESSING)
            inventory_job.session_log = create_log_directory(host.connection_param[0].host_or_ip, inventory_job.id)
            db_session.commit()         
            
            # Delegates the get_software logic to the handler
            ctx = InventoryContext(host, db_session, inventory_job)

            handler = handler_class()
            handler.execute(ctx)
            
            if ctx.success:
                archive_inventory_job(db_session, inventory_job, JobStatus.COMPLETED)
            else:
                # removes the host object as host.packages may have been modified.
                db_session.expunge(host)
                archive_inventory_job(db_session, inventory_job, JobStatus.FAILED)
            
            # Reset the pending retrieval flag
            inventory_job.pending_submit = False
            db_session.commit()

        except:
            try:
                logger.exception('InventoryManager hit exception - inventory job = %s', self.job_id)
                archive_inventory_job(db_session, inventory_job, JobStatus.FAILED, trace=sys.exc_info)
                # Reset the pending retrieval flag
                inventory_job.pending_submit = False
                db_session.commit()
            except:
                logger.exception('InventoryManager hit exception - inventory job = %s', self.job_id)
        finally:
            with lock:
                if self.job_id is not None and self.job_id in in_progress_jobs: del in_progress_jobs[self.job_id]
            db_session.close()       
Example #4
0
    def get_software(self, ctx, logger):
        handler_class = get_inventory_handler_class(ctx)
        if handler_class is None:
            logger.error('SoftwareManager: Unable to get handler for %s',
                         ctx.host.software_platform)

        handler = handler_class()
        if handler.get_software(ctx):
            # Update the time stamp
            ctx.host.inventory_job[0].set_status(JobStatus.COMPLETED)
Example #5
0
    def get_software(self, db_session, ctx):
        handler_class = get_inventory_handler_class(ctx.host.platform)
        if handler_class is None:
            logger.error('SoftwareManager: Unable to get handler for %s',
                         ctx.host.platform)

        handler = handler_class()
        if handler.get_software(ctx.host, ctx.inactive_cli, ctx.active_cli,
                                ctx.committed_cli):
            # Update the time stamp
            ctx.host.inventory_job[0].set_status(JobStatus.COMPLETED)
Example #6
0
    def start(self, db_session, logger, process_name):
        host = None
        inventory_job = None

        try:
            inventory_job = db_session.query(InventoryJob).filter(InventoryJob.id == self.job_id).first()
            if inventory_job is None:
                logger.error('Unable to retrieve inventory job: %s' % self.job_id)
                return

            host_id = inventory_job.host_id
            host = db_session.query(Host).filter(Host.id == host_id).first()
            if host is None:
                logger.error('Unable to retrieve host: %s' % host_id)

            ctx = InventoryContext(db_session, host, inventory_job)

            handler_class = get_inventory_handler_class(ctx)
            if handler_class is None:
                logger.error('Unable to get handler for %s, inventory job %s', host.software_platform, self.job_id)

            inventory_job.set_status(JobStatus.IN_PROGRESS)
            inventory_job.session_log = create_log_directory(host.connection_param[0].host_or_ip, inventory_job.id)
            db_session.commit()

            handler = handler_class()
            handler.execute(ctx)

            if ctx.success:
                self.archive_inventory_job(db_session, inventory_job, JobStatus.COMPLETED)
            else:
                # removes the host object as host.packages may have been modified.
                db_session.expunge(host)
                self.archive_inventory_job(db_session, inventory_job, JobStatus.FAILED)

            # Reset the pending retrieval flag
            inventory_job.request_update = False
            db_session.commit()

        except Exception:
            try:
                self.log_exception(logger, host)

                self.archive_inventory_job(db_session, inventory_job, JobStatus.FAILED, trace=sys.exc_info)

                # Reset the pending retrieval flag
                inventory_job.request_update = False
                db_session.commit()
            except Exception:
                self.log_exception(logger, host)
        finally:
            db_session.close()
Example #7
0
    def start(self, db_session, logger, process_name):
        host = None
        inventory_job = None

        try:
            inventory_job = db_session.query(InventoryJob).filter(
                InventoryJob.id == self.job_id).first()
            if inventory_job is None:
                logger.error('Unable to retrieve inventory job: %s' %
                             self.job_id)
                return

            host_id = inventory_job.host_id
            host = db_session.query(Host).filter(Host.id == host_id).first()
            if host is None:
                logger.error('Unable to retrieve host: %s' % host_id)

            ctx = InventoryContext(db_session, host, inventory_job)

            handler_class = get_inventory_handler_class(ctx)
            if handler_class is None:
                logger.error('Unable to get handler for %s, inventory job %s',
                             host.software_platform, self.job_id)

            inventory_job.set_status(JobStatus.IN_PROGRESS)
            inventory_job.session_log = create_log_directory(
                host.connection_param[0].host_or_ip, inventory_job.id)
            db_session.commit()

            handler = handler_class()
            handler.execute(ctx)

            if ctx.success:
                self.archive_inventory_job(db_session, inventory_job,
                                           JobStatus.COMPLETED)
            else:
                # removes the host object as host.packages may have been modified.
                db_session.expunge(host)
                self.archive_inventory_job(db_session, inventory_job,
                                           JobStatus.FAILED)

            # Reset the pending retrieval flag
            inventory_job.request_update = False
            db_session.commit()

        except Exception:
            try:
                self.log_exception(logger, host)

                self.archive_inventory_job(db_session,
                                           inventory_job,
                                           JobStatus.FAILED,
                                           trace=sys.exc_info)

                # Reset the pending retrieval flag
                inventory_job.request_update = False
                db_session.commit()
            except Exception:
                self.log_exception(logger, host)
        finally:
            db_session.close()
Example #8
0
    def process(self):

        db_session = DBSession()
        host_id = None
        inventory_job = None
        ctx = None
        try:

            inventory_job = db_session.query(InventoryJob).filter(
                InventoryJob.id == self.job_id).first()
            if inventory_job is None:
                logger.error('Unable to retrieve inventory job: %s' %
                             self.job_id)
                return

            host_id = inventory_job.host_id
            host = db_session.query(Host).filter(Host.id == host_id).first()
            if host is None:
                logger.error('Unable to retrieve host: %s' % host_id)

            handler_class = get_inventory_handler_class(host.platform)
            if handler_class is None:
                logger.error('Unable to get handler for %s, inventory job %s',
                             host.platform, self.job_id)

            inventory_job.set_status(JobStatus.PROCESSING)
            inventory_job.session_log = create_log_directory(
                host.connection_param[0].host_or_ip, inventory_job.id)
            db_session.commit()

            # Delegates the get_software logic to the handler
            ctx = InventoryContext(host, db_session, inventory_job)

            handler = handler_class()
            handler.execute(ctx)

            if ctx.success:
                archive_inventory_job(db_session, inventory_job,
                                      JobStatus.COMPLETED)
            else:
                # removes the host object as host.packages may have been modified.
                db_session.expunge(host)
                archive_inventory_job(db_session, inventory_job,
                                      JobStatus.FAILED)

            # Reset the pending retrieval flag
            inventory_job.pending_submit = False
            db_session.commit()

        except:
            try:
                logger.exception(
                    'InventoryManager hit exception - inventory job = %s',
                    self.job_id)
                archive_inventory_job(db_session,
                                      inventory_job,
                                      JobStatus.FAILED,
                                      trace=sys.exc_info)
                # Reset the pending retrieval flag
                inventory_job.pending_submit = False
                db_session.commit()
            except:
                logger.exception(
                    'InventoryManager hit exception - inventory job = %s',
                    self.job_id)
        finally:
            with lock:
                if self.job_id is not None and self.job_id in in_progress_jobs:
                    del in_progress_jobs[self.job_id]
            db_session.close()