Exemplo n.º 1
0
Arquivo: sim.py Projeto: 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()       
Exemplo n.º 2
0
Arquivo: sum.py Projeto: ommaurya/csm
 def process(self):
     db_session = DBSession()
     ctx = None
     try:                                  
         install_job = db_session.query(InstallJob).filter(InstallJob.id == self.job_id).first()    
         if install_job is None:
             # This is normal because of race condition. It means the job is already deleted (completed).
             return
          
         if not can_install(db_session):
             # This will halt this host that has already been queued
             return
         
         host = db_session.query(Host).filter(Host.id == self.host_id).first()
         if host is None:
             logger.error('Unable to retrieve host %s', self.host_id)
             return
         
         handler_class = get_install_handler_class(host.platform)
         if handler_class is None:
             logger.error('Unable to get handler for %s, install job %s', host.platform, self.job_id)
     
         install_job.start_time = datetime.datetime.utcnow()
         install_job.set_status(JobStatus.PROCESSING)            
         install_job.session_log = create_log_directory(host.connection_param[0].host_or_ip, install_job.id)
         db_session.commit()
        
         ctx = InstallContext(host, db_session, install_job)
         ctx.operation_id = get_last_operation_id(db_session, install_job)
        
         handler = handler_class()
         handler.execute(ctx)
         
         if ctx.success:    
             # Update the software
             self.get_software(db_session, ctx)                
             archive_install_job(db_session, ctx, install_job, JobStatus.COMPLETED)                
         else:
             archive_install_job(db_session, ctx, install_job, JobStatus.FAILED)
             
         db_session.commit()
         
     except: 
         try:
             logger.exception('InstallManager hit exception - install job =  %s', self.job_id)
             archive_install_job(db_session, ctx, install_job, JobStatus.FAILED, trace=traceback.format_exc())
             db_session.commit()
         except:
             logger.exception('InstallManager hit exception - install job = %s', self.job_id)
     finally:
         # Must remove the host from the in progress list
         remove_host_from_in_progress(self.host_id)
         db_session.close()     
Exemplo n.º 3
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()
Exemplo n.º 4
0
    def start(self, db_session, logger, process_name):
        ctx = None

        try:
            install_job = db_session.query(InstallJob).filter(InstallJob.id == self.job_id).first()

            if install_job is None:
                # This is normal because of race condition. It means the job is already deleted (completed).
                return

            if not db_session.query(SystemOption).first().can_install:
                # This will halt this host that has already been queued
                return

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

            ctx = InstallContext(db_session, host, install_job)

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

            install_job.start_time = datetime.datetime.utcnow()
            install_job.set_status(JobStatus.PROCESSING)
            install_job.session_log = create_log_directory(host.connection_param[0].host_or_ip, install_job.id)

            ctx.operation_id = self.get_last_operation_id(db_session, install_job)

            db_session.commit()

            handler = handler_class()
            handler.execute(ctx)

            if ctx.success:
                # Update the software
                self.get_software(ctx, logger)
                self.archive_install_job(db_session, logger, ctx, host, install_job, JobStatus.COMPLETED, process_name)
            else:
                self.archive_install_job(db_session, logger, ctx, host, install_job, JobStatus.FAILED, process_name)

        except Exception:
            try:
                logger.exception('InstallManager hit exception - install job =  %s', self.job_id)
                self.archive_install_job(db_session, logger, ctx, host, install_job,
                                         JobStatus.FAILED, process_name, trace=traceback.format_exc())
            except Exception:
                logger.exception('InstallManager hit exception - install job = %s', self.job_id)
        finally:
            db_session.close()
Exemplo n.º 5
0
def discover_platform_info(ctx):
    try:
        log_dir = os.path.join(get_log_directory(), create_log_directory(ctx.host.connection_param[0].host_or_ip))
    except Exception:
        log_dir = None

    """Discover platform when added to CSM."""
    conn = condoor.Connection(name=ctx.hostname, urls=ctx.host_urls, log_level=logging.CRITICAL, log_dir=log_dir)
    try:
        conn.connect(force_discovery=True)
        ctx.host.family = conn.family
        ctx.host.platform = conn.platform
        ctx.host.software_platform = get_software_platform(family=conn.family, os_type=conn.os_type)
        ctx.host.software_version = get_software_version(conn.os_version)
        ctx.host.os_type = conn.os_type
        ctx.db_session.commit()
    except condoor.ConnectionError as e:
        logger.error(str(e))
    finally:
        conn.disconnect()
Exemplo n.º 6
0
    def start(self, db_session, logger, process_name):
        ctx = None

        try:
            install_job = db_session.query(InstallJob).filter(
                InstallJob.id == self.job_id).first()

            if install_job is None:
                # This is normal because of race condition. It means the job is already deleted (completed).
                return

            if not db_session.query(SystemOption).first().can_install:
                # This will halt this host that has already been queued
                return

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

            ctx = InstallContext(db_session, host, install_job)

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

            install_job.start_time = datetime.datetime.utcnow()
            install_job.set_status(JobStatus.PROCESSING)
            install_job.session_log = create_log_directory(
                host.connection_param[0].host_or_ip, install_job.id)

            ctx.operation_id = self.get_last_operation_id(
                db_session, install_job)

            db_session.commit()

            handler = handler_class()
            handler.execute(ctx)

            if ctx.success:
                # Update the software
                self.get_software(ctx, logger)
                self.archive_install_job(db_session, logger, ctx, host,
                                         install_job, JobStatus.COMPLETED,
                                         process_name)
            else:
                self.archive_install_job(db_session, logger, ctx, host,
                                         install_job, JobStatus.FAILED,
                                         process_name)

        except Exception:
            try:
                logger.exception(
                    'InstallManager hit exception - install job =  %s',
                    self.job_id)
                self.archive_install_job(db_session,
                                         logger,
                                         ctx,
                                         host,
                                         install_job,
                                         JobStatus.FAILED,
                                         process_name,
                                         trace=traceback.format_exc())
            except Exception:
                logger.exception(
                    'InstallManager hit exception - install job = %s',
                    self.job_id)
        finally:
            db_session.close()
Exemplo n.º 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()
Exemplo n.º 8
0
    def process(self):
        db_session = DBSession()
        ctx = None
        try:
            install_job = db_session.query(InstallJob).filter(
                InstallJob.id == self.job_id).first()
            if install_job is None:
                # This is normal because of race condition. It means the job is already deleted (completed).
                return

            if not can_install(db_session):
                # This will halt this host that has already been queued
                return

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

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

            install_job.start_time = datetime.datetime.utcnow()
            install_job.set_status(JobStatus.PROCESSING)
            install_job.session_log = create_log_directory(
                host.connection_param[0].host_or_ip, install_job.id)
            db_session.commit()

            ctx = InstallContext(host, db_session, install_job)
            ctx.operation_id = get_last_operation_id(db_session, install_job)

            handler = handler_class()
            handler.execute(ctx)

            if ctx.success:
                # Update the software
                self.get_software(db_session, ctx)
                archive_install_job(db_session, ctx, install_job,
                                    JobStatus.COMPLETED)
            else:
                archive_install_job(db_session, ctx, install_job,
                                    JobStatus.FAILED)

            db_session.commit()

        except:
            try:
                logger.exception(
                    'InstallManager hit exception - install job =  %s',
                    self.job_id)
                archive_install_job(db_session,
                                    ctx,
                                    install_job,
                                    JobStatus.FAILED,
                                    trace=traceback.format_exc())
                db_session.commit()
            except:
                logger.exception(
                    'InstallManager hit exception - install job = %s',
                    self.job_id)
        finally:
            # Must remove the host from the in progress list
            remove_host_from_in_progress(self.host_id)
            db_session.close()
Exemplo n.º 9
0
    def start(self, db_session, logger, process_name):
        ctx = None
        host = None
        try:
            install_job = db_session.query(InstallJob).filter(InstallJob.id == self.job_id).first()

            if install_job is None:
                # This is normal because of race condition. It means the job is already deleted (completed).
                return

            if not db_session.query(SystemOption).first().can_install:
                # This will halt this host that has already been queued
                return

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

            ctx = InstallContext(db_session, host, install_job)

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

            install_job.start_time = datetime.datetime.utcnow()
            install_job.set_status(JobStatus.IN_PROGRESS)
            install_job.session_log = create_log_directory(host.connection_param[0].host_or_ip, install_job.id)

            ctx.operation_id = self.get_last_operation_id(db_session, install_job)

            db_session.commit()

            handler = handler_class()
            handler.execute(ctx)

            if ctx.success:
                try:
                    # Update the software
                    self.get_inventory(ctx, logger)
                except Exception:
                    pass

                # Support Doc Central feature for SIT team
                if install_job.install_action == InstallAction.PRE_UPGRADE or \
                        install_job.install_action == InstallAction.INSTALL_ADD:
                    install_job.save_data("from_release", ctx.host.software_version)

                self.archive_install_job(db_session, logger, ctx, host, install_job, JobStatus.COMPLETED, process_name)

                # Support Doc Central feature for SIT team - must be done after archive_install_job.
                handle_doc_central_logging(ctx, logger)
            else:
                self.archive_install_job(db_session, logger, ctx, host, install_job, JobStatus.FAILED, process_name)

        except Exception:
            try:
                self.log_exception(logger, host)
                self.archive_install_job(db_session, logger, ctx, host, install_job,
                                         JobStatus.FAILED, process_name, trace=traceback.format_exc())
            except Exception:
                self.log_exception(logger, host)
        finally:
            db_session.close()
Exemplo n.º 10
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()