示例#1
0
def software_profile_create():
    # if not can_create_user(current_user):
    #    abort(401)

    db_session = DBSession()

    form = SoftwareProfileForm(request.form)
    server_dialog_form = ServerDialogForm(request.form)

    fill_servers(server_dialog_form.server_dialog_server.choices, get_server_list(db_session), False)

    if request.method == 'POST' and form.validate():

        software_profile = get_software_profile(db_session, form.profile_name.data)

        if software_profile is not None:
            return render_template('conformance/profile_edit.html',
                                   form=form, system_option=SystemOption.get(db_session), duplicate_error=True)

        software_profile = SoftwareProfile(
            name=form.profile_name.data,
            description=form.description.data,
            packages=','.join([l for l in form.software_packages.data.splitlines() if l]),
            created_by=current_user.username)

        db_session.add(software_profile)
        db_session.commit()

        return redirect(url_for('conformance.home'))
    else:

        return render_template('conformance/profile_edit.html',
                               form=form, server_dialog_form=server_dialog_form,
                               system_option=SystemOption.get(db_session))
示例#2
0
def software_profile_edit(profile_name):
    db_session = DBSession()

    software_profile = get_software_profile(db_session, profile_name)
    if software_profile is None:
        abort(404)

    form = SoftwareProfileForm(request.form)
    server_dialog_form = ServerDialogForm(request.form)
    fill_servers(server_dialog_form.server_dialog_server.choices, get_server_list(db_session), False)

    if request.method == 'POST' and form.validate():
        if profile_name != form.profile_name.data and \
                        get_software_profile(db_session, form.profile_name.data) is not None:
            return render_template('conformance/profile_edit.html',
                                   form=form, server_dialog_form=server_dialog_form,
                                   system_option=SystemOption.get(db_session), duplicate_error=True)

        software_profile.name = form.profile_name.data
        software_profile.description = form.description.data
        software_profile.packages = ','.join([l for l in form.software_packages.data.splitlines() if l]),

        db_session.commit()

        return redirect(url_for('conformance.home'))
    else:
        form.profile_name.data = software_profile.name
        form.description.data = software_profile.description
        if software_profile.packages is not None:
            form.software_packages.data = '\n'.join(software_profile.packages.split(','))

    return render_template('conformance/profile_edit.html',
                           form=form, server_dialog_form=server_dialog_form,
                           system_option=SystemOption.get(db_session))
示例#3
0
    def create_email_notification(self, db_session, logger, host, install_job):
        try:
            session_log_link = "log/hosts/{}/install_job_history/session_log/{}?file_path={}".format(
                urllib.quote(host.hostname), install_job.id, install_job.session_log)

            message = '<html><head></head><body>'
            if install_job.status == JobStatus.COMPLETED:
                message += 'The scheduled installation for host "' + host.hostname + '" has COMPLETED.<br><br>'
            elif install_job.status == JobStatus.FAILED:
                message += 'The scheduled installation for host "' + host.hostname + '" has FAILED.<br><br>'

            message += 'Scheduled Time: ' + \
                       get_datetime_string(install_job.scheduled_time) + \
                       ' UTC<br>'
            message += 'Start Time: ' + \
                       get_datetime_string(install_job.start_time) + \
                       ' UTC<br>'
            message += 'Install Action: ' + install_job.install_action + '<br><br>'

            message = self.check_command_file_diff(install_job, message)

            session_log_url = SystemOption.get(db_session).base_url + '/' + session_log_link

            message += 'For more information, click the link below<br><br>'
            message += session_log_url + '<br><br>'

            if install_job.packages is not None and len(install_job.packages) > 0:
                message += 'Followings are the software packages: <br><br>' + install_job.packages.replace(',','<br>')

            message += '</body></html>'

            create_email_job(db_session, logger, message, install_job.created_by)

        except Exception:
            logger.exception('create_email_notification() hit exception')
示例#4
0
    def refresh_all(cls):
        """
        Retrieves all the catalog data and SMU XML file data and updates the database.
        """
        db_session = DBSession()
        
        catalog = SMUInfoLoader.get_catalog_from_cco()
        if len(catalog) > 0:
            system_option = SystemOption.get(db_session)
            try:
                # Remove all rows first
                db_session.query(CCOCatalog).delete()
            
                for platform in catalog:
                    releases = catalog[platform]
                    for release in releases:
                        cco_catalog = CCOCatalog(platform=platform,release=release)
                        db_session.add(cco_catalog)

                        SMUInfoLoader(platform, release)
                
                system_option.cco_lookup_time = datetime.datetime.utcnow()
                db_session.commit()
                return True
            except Exception:
                logger.exception('refresh_all() hit exception')
                db_session.rollback()  
            
        return False
示例#5
0
    def refresh_all(cls):
        """
        Retrieves all the catalog data and SMU XML file data and updates the database.
        """
        db_session = DBSession()

        catalog = SMUInfoLoader.get_catalog_from_cco()
        if len(catalog) > 0:
            system_option = SystemOption.get(db_session)
            try:
                # Remove all rows first
                db_session.query(CCOCatalog).delete()

                for platform in catalog:
                    releases = catalog[platform]
                    for release in releases:
                        cco_catalog = CCOCatalog(platform=platform,
                                                 release=release)
                        db_session.add(cco_catalog)

                        # Now, retrieve from SMU XML file
                        SMUInfoLoader(platform, release, refresh=True)

                system_option.cco_lookup_time = datetime.datetime.utcnow()
                db_session.commit()
                return True
            except Exception:
                logger.exception('refresh_all hit exception')
                db_session.rollback()

        return False
示例#6
0
文件: scheduler.py 项目: ommaurya/csm
 def run(self):
     db_session = DBSession()   
     try:         
         system_option = SystemOption.get(db_session)            
         inventory_hour = system_option.inventory_hour
         db_session.close()
                     
         # Build a scheduler object that will look at absolute times
         scheduler = sched.scheduler(time.time, time.sleep)
         current_hour = datetime.datetime.now().hour
 
         # Put task for today at the designated hour.
         daily_time = datetime.time(inventory_hour)
         
         # If the scheduled time already passed, schedule it for tomorrow
         if current_hour > inventory_hour:
             first_time = datetime.datetime.combine(datetime.datetime.now() + datetime.timedelta(days=1), daily_time)
         else:
             first_time = datetime.datetime.combine(datetime.datetime.now(), daily_time)
         
         scheduler.enterabs(time.mktime(first_time.timetuple()), 1,
             self.scheduling, (scheduler, daily_time,))
        
         scheduler.run()
         
     except:
         logger.exception('InventoryManagerScheduler hit exception')
         db_session.close()
示例#7
0
文件: scheduler.py 项目: ommaurya/csm
    def scheduling(self, scheduler, daily_time):

        # First, re-set up the scheduler for the next day the same time. It is important to have
        # this logic on the top so that if any error encountered below, the scheduling still works.
        t = datetime.datetime.combine(
            datetime.datetime.now() + datetime.timedelta(days=1), daily_time)
        scheduler.enterabs(time.mktime(t.timetuple()), 1, self.scheduling, (
            scheduler,
            daily_time,
        ))

        db_session = DBSession()

        try:
            system_option = SystemOption.get(db_session)

            # If software inventory is enabled, submit the inventory jobs
            if system_option.enable_inventory:
                inventory_jobs = db_session.query(InventoryJob).all()

                if len(inventory_jobs) > 0:
                    for inventory_job in inventory_jobs:
                        inventory_job.pending_submit = True
                    db_session.commit()

            #Check if there is any housekeeping work to do
            self.perform_housekeeping_tasks(db_session, system_option)

        except:
            logger.exception('InventoryManagerScheduler hit exception')
        finally:
            db_session.close()
示例#8
0
文件: scheduler.py 项目: ommaurya/csm
    def run(self):
        db_session = DBSession()
        try:
            system_option = SystemOption.get(db_session)
            inventory_hour = system_option.inventory_hour
            db_session.close()

            # Build a scheduler object that will look at absolute times
            scheduler = sched.scheduler(time.time, time.sleep)
            current_hour = datetime.datetime.now().hour

            # Put task for today at the designated hour.
            daily_time = datetime.time(inventory_hour)

            # If the scheduled time already passed, schedule it for tomorrow
            if current_hour > inventory_hour:
                first_time = datetime.datetime.combine(
                    datetime.datetime.now() + datetime.timedelta(days=1),
                    daily_time)
            else:
                first_time = datetime.datetime.combine(datetime.datetime.now(),
                                                       daily_time)

            scheduler.enterabs(time.mktime(first_time.timetuple()), 1,
                               self.scheduling, (
                                   scheduler,
                                   daily_time,
                               ))

            scheduler.run()

        except:
            logger.exception('InventoryManagerScheduler hit exception')
            db_session.close()
示例#9
0
文件: scheduler.py 项目: ommaurya/csm
    def scheduling(self, scheduler, daily_time):
        
        # First, re-set up the scheduler for the next day the same time. It is important to have
        # this logic on the top so that if any error encountered below, the scheduling still works.
        t = datetime.datetime.combine(datetime.datetime.now() + datetime.timedelta(days=1), daily_time)
        scheduler.enterabs(time.mktime(t.timetuple()), 1, self.scheduling, (scheduler, daily_time,))
            
        db_session = DBSession()
        
        try:
            system_option = SystemOption.get(db_session)
            
            # If software inventory is enabled, submit the inventory jobs
            if system_option.enable_inventory:
                inventory_jobs = db_session.query(InventoryJob).all()

                if len(inventory_jobs)> 0:
                    for inventory_job in inventory_jobs:
                        inventory_job.pending_submit = True
                    db_session.commit()
                        
            #Check if there is any housekeeping work to do
            self.perform_housekeeping_tasks(db_session, system_option)
            
        except:
            logger.exception('InventoryManagerScheduler hit exception')
        finally:
            db_session.close()
示例#10
0
def check_host_reachability():
    if not can_check_reachability(current_user):
        abort(401)

    urls = []
    # Below information is directly from the page and
    # may not have been saved yet.
    hostname = request.args.get('hostname')
    platform = request.args.get('platform')
    host_or_ip = request.args.get('host_or_ip')
    username = request.args.get('username')
    password = request.args.get('password')
    enable_password = request.args.get('enable_password')
    connection_type = request.args.get('connection_type')
    port_number = request.args.get('port_number')
    jump_host_id = request.args.get('jump_host')

    # If a jump host exists, create the connection URL
    if int(jump_host_id) > 0:
        db_session = DBSession()
        jump_host = get_jump_host_by_id(db_session=db_session, id=jump_host_id)
        if jump_host is not None:
            url = make_url(connection_type=jump_host.connection_type,
                           host_username=jump_host.username,
                           host_password=jump_host.password,
                           host_or_ip=jump_host.host_or_ip,
                           port_number=jump_host.port_number)
            urls.append(url)

    db_session = DBSession()
    # The form is in the edit mode and the user clicks Validate Reachability
    # If there is no password specified, get it from the database.
    if is_empty(password) or is_empty(enable_password):
        host = get_host(db_session, hostname)
        if host is not None:
            password = host.connection_param[0].password
            enable_password = host.connection_param[0].enable_password

    system_option = SystemOption.get(db_session)
    if system_option.enable_default_host_authentication:
        if not is_empty(system_option.default_host_username) and not is_empty(
                system_option.default_host_password):
            if system_option.default_host_authentication_choice == DefaultHostAuthenticationChoice.ALL_HOSTS or \
                (system_option.default_host_authentication_choice ==
                    DefaultHostAuthenticationChoice.HOSTS_WITH_NO_SPECIFIED_USERNAME_AND_PASSWORD and
                    is_empty(username) and is_empty(password)):
                username = system_option.default_host_username
                password = system_option.default_host_password

    url = make_url(connection_type=connection_type,
                   host_username=username,
                   host_password=password,
                   host_or_ip=host_or_ip,
                   port_number=port_number,
                   enable_password=enable_password)
    urls.append(url)

    return jsonify({'status': 'OK'}) if is_connection_valid(
        hostname, urls) else jsonify({'status': 'Failed'})
示例#11
0
    def __init__(self, name, num_threads=None):
        threading.Thread.__init__(self, name=name)

        if num_threads is None:
            num_threads = SystemOption.get(DBSession()).inventory_threads

        # Set up the thread pool
        self.pool = Pool(num_threads)
示例#12
0
    def host_urls(self):
        system_option = SystemOption.get(self.db_session)
        if system_option.enable_user_credential_for_host:
            user = get_user_by_id(self.db_session, self.install_job.user_id)
            if user is not None:
                return self.make_urls(user.username, user.host_password)

        return self.make_urls()
示例#13
0
文件: sim.py 项目: ommaurya/csm
 def __init__(self, name, num_threads=None):
     threading.Thread.__init__(self, name = name)
     
     if num_threads is None:
         num_threads = SystemOption.get(DBSession()).inventory_threads
     
     # Set up the thread pool
     self.pool = Pool(num_threads)
示例#14
0
文件: cco.py 项目: smjurcak/csm
def optimize_software():
    server_dialog_form = ServerDialogForm(request.form)
    software_profile_form = SoftwareProfileForm(request.form)

    return render_template('cco/optimize_software.html',
                           server_dialog_form=server_dialog_form,
                           software_profile_form=software_profile_form,
                           system_option=SystemOption.get(DBSession()))
示例#15
0
def optimize_software():
    server_dialog_form = ServerDialogForm(request.form)
    software_profile_form = SoftwareProfileForm(request.form)

    return render_template('cco/optimize_software.html',
                           server_dialog_form=server_dialog_form,
                           software_profile_form=software_profile_form,
                           system_option=SystemOption.get(DBSession()))
示例#16
0
文件: sum.py 项目: ommaurya/csm
 def __init__(self, name, num_threads=None):
     threading.Thread.__init__(self, name = name)
     
     db_session = DBSession()
     if num_threads is None:
         num_threads = SystemOption.get(db_session).install_threads
     
     # Set up the thread pool
     self.pool = Pool(num_threads)
示例#17
0
文件: cco.py 项目: smjurcak/csm
def home(platform, release):
    system_option = SystemOption.get(DBSession())
    form = BrowseServerDialogForm(request.form)
    fill_servers(form.dialog_server.choices, get_server_list(DBSession()), False)
    export_software_information_form = ExportSoftwareInformationForm(request.form)

    return render_template('cco/home.html', form=form, platform=platform,
                           release=release, system_option=system_option,
                           export_software_information_form=export_software_information_form)
示例#18
0
    def __init__(self, name, num_threads=None):
        threading.Thread.__init__(self, name=name)

        db_session = DBSession()
        if num_threads is None:
            num_threads = SystemOption.get(db_session).install_threads

        # Set up the thread pool
        self.pool = Pool(num_threads)
示例#19
0
文件: context.py 项目: smjurcak/csm
    def make_urls(self, preferred_host_username=None, preferred_host_password=None):
        urls = []

        if len(self.host.connection_param) > 0:
            connection = self.host.connection_param[0]
            jump_host_url = ''

            # Checks if there is a jump server
            if connection.jump_host_id is not None:
                try:
                    jump_host = self.db_session.query(JumpHost).filter(JumpHost.id == connection.jump_host_id).first()
                    if jump_host is not None:
                        jump_host_url = make_url(
                            connection_type=jump_host.connection_type,
                            host_username=jump_host.username,
                            host_password=jump_host.password,
                            host_or_ip=jump_host.host_or_ip,
                            port_number=jump_host.port_number)
                except:
                    pass

            host_username = connection.username
            host_password = connection.password

            if not is_empty(preferred_host_username) and not is_empty(preferred_host_password):
                host_username = preferred_host_username
                host_password = preferred_host_password
            else:
                system_option = SystemOption.get(self.db_session)
                if system_option.enable_default_host_authentication:
                    if not is_empty(system_option.default_host_username) and not is_empty(system_option.default_host_password):
                        if system_option.default_host_authentication_choice == DefaultHostAuthenticationChoice.ALL_HOSTS or \
                            (system_option.default_host_authentication_choice ==
                                DefaultHostAuthenticationChoice.HOSTS_WITH_NO_SPECIFIED_USERNAME_AND_PASSWORD and
                                is_empty(host_username) and
                                is_empty(host_password)):
                            host_username = system_option.default_host_username
                            host_password = system_option.default_host_password

            for host_or_ip in connection.host_or_ip.split(','):
                for port_number in connection.port_number.split(','):
                    host_urls = []
                    if not is_empty(jump_host_url):
                        host_urls.append(jump_host_url)

                    host_urls.append(make_url(
                        connection_type=connection.connection_type,
                        host_username=host_username,
                        host_password=host_password,
                        host_or_ip=host_or_ip,
                        port_number=port_number,
                        enable_password=connection.enable_password))

                    urls.append(host_urls)

        return urls
示例#20
0
文件: inventory.py 项目: smjurcak/csm
def create_email_job_with_attachment_files(db_session, message, file_paths, recipients):
    system_option = SystemOption.get(db_session)
    if not system_option.enable_email_notify:
        return

    email_job = EmailJob(recipients=recipients, message=message, created_by=current_user.username,
                         attachment_file_paths=file_paths)
    db_session.add(email_job)
    db_session.commit()
    return
示例#21
0
def api_get_install_dashboard_cookie():
    system_option = SystemOption.get(DBSession())

    return jsonify(
        **{
            'data': [{
                'can_schedule': system_option.can_schedule,
                'can_install': system_option.can_install
            }]
        })
示例#22
0
    def make_urls(self, preferred_host_username=None, preferred_host_password=None):
        urls = []

        if len(self.host.connection_param) > 0:
            connection = self.host.connection_param[0]
            jump_host_url = ''

            # Checks if there is a jump server
            if connection.jump_host_id is not None:
                try:
                    jump_host = self.db_session.query(JumpHost).filter(JumpHost.id == connection.jump_host_id).first()
                    if jump_host is not None:
                        jump_host_url = make_url(
                            connection_type=jump_host.connection_type,
                            host_username=jump_host.username,
                            host_password=jump_host.password,
                            host_or_ip=jump_host.host_or_ip,
                            port_number=jump_host.port_number)
                except:
                    pass

            host_username = connection.username
            host_password = connection.password

            if not is_empty(preferred_host_username) and not is_empty(preferred_host_password):
                host_username = preferred_host_username
                host_password = preferred_host_password
            else:
                system_option = SystemOption.get(self.db_session)
                if system_option.enable_default_host_authentication:
                    if not is_empty(system_option.default_host_username) and not is_empty(system_option.default_host_password):
                        if system_option.default_host_authentication_choice == DefaultHostAuthenticationChoice.ALL_HOSTS or \
                            (system_option.default_host_authentication_choice ==
                                DefaultHostAuthenticationChoice.HOSTS_WITH_NO_SPECIFIED_USERNAME_AND_PASSWORD and
                                is_empty(host_username) and
                                is_empty(host_password)):
                            host_username = system_option.default_host_username
                            host_password = system_option.default_host_password

            for host_or_ip in connection.host_or_ip.split(','):
                for port_number in connection.port_number.split(','):
                    host_urls = []
                    if not is_empty(jump_host_url):
                        host_urls.append(jump_host_url)

                    host_urls.append(make_url(
                        connection_type=connection.connection_type,
                        host_username=host_username,
                        host_password=host_password,
                        host_or_ip=host_or_ip,
                        port_number=port_number))

                    urls.append(host_urls)

        return urls
示例#23
0
def home():
    if not can_install(current_user):
        abort(401)

    absolute_path = os.path.abspath('.')
    csm_repository_path = absolute_path.replace(
        NAME_CSM + '/' + NAME_CSMSERVER, NAME_CSM_DATA + '/' + NAME_REPOSITORY)

    return render_template('host/download_dashboard.html',
                           csm_repository_path=csm_repository_path,
                           system_option=SystemOption.get(DBSession()))
示例#24
0
def user_list():
    db_session = DBSession()

    users = get_user_list(db_session)
    if users is None:
        abort(404)

    if current_user.privilege == UserPrivilege.ADMIN:
        return render_template('user/index.html', users=users, system_option=SystemOption.get(db_session))

    return render_template('user/not_authorized.html', user=current_user)
示例#25
0
def api_get_cco_lookup_time():
    system_option = SystemOption.get(DBSession())
    if system_option.cco_lookup_time is not None:
        return jsonify(
            **{
                'data': [{
                    'cco_lookup_time':
                    get_datetime_string(system_option.cco_lookup_time)
                }]
            })
    else:
        return jsonify({'status': 'Failed'})
示例#26
0
def send_install_status_email(install_job):
    db_session = DBSession
    username = install_job.created_by

    system_option = SystemOption.get(db_session)
    if not system_option.enable_email_notify:
        return
    
    smtp_server = get_smtp_server(db_session)
    if smtp_server is None:
        logger.error('mailer: SMTP Server has not been specified')
        return
    
    user = get_user(db_session, username)
    if user is None:
        logger.error('mailer: Unable to locate user "%s"' % username)
        return
    
    host = get_host(db_session, install_job.host_id)
    if host is None:
        logger.error('mailer: Unable to locate host id "%s"' % str(install_job.host_id))
        return
    
    message = '<html><head><body>'
    if install_job.status == JobStatus.COMPLETED:
        message += 'The scheduled installation for host "' + host.hostname + '" has COMPLETED<br><br>'
    elif install_job.status == JobStatus.FAILED:
        message += 'The scheduled installation for host "' + host.hostname + '" has FAILED<br><br>'
    
    message += 'Scheduled Time: ' + get_datetime_string(install_job.scheduled_time) + ' (UTC)<br>'    
    message += 'Start Time: ' + get_datetime_string(install_job.start_time) + ' (UTC)<br>'
    message += 'Install Action: ' + install_job.install_action + '<br><br>'
    
    session_log_url = system_option.base_url + '/' + get_session_log_link(host, install_job)
    
    message += 'For more information, click the link below<br><br>'
    message += session_log_url + '<br><br>'
    
    if install_job.packages is not None and len(install_job.packages) > 0:
        message += 'Followings are the software packages: <br><br>' + install_job.packages.replace(',','<br>')
        
    message += '</body></head></html>'
    
    sendmail(
        server=smtp_server.server, 
        server_port=smtp_server.server_port,
        sender=smtp_server.sender,
        recipient=user.email,
        message=message,
        use_authentication=smtp_server.use_authentication,
        username=smtp_server.username,
        password=smtp_server.password,
        secure_connection=smtp_server.secure_connection)
示例#27
0
def software_profile_edit(profile_name):
    db_session = DBSession()

    software_profile = get_software_profile(db_session, profile_name)
    if software_profile is None:
        abort(404)

    form = SoftwareProfileForm(request.form)
    server_dialog_form = ServerDialogForm(request.form)
    fill_servers(server_dialog_form.server_dialog_server.choices,
                 get_server_list(db_session), False)

    if request.method == 'POST' and form.validate():
        if profile_name != form.profile_name.data and \
                        get_software_profile(db_session, form.profile_name.data) is not None:
            return render_template('conformance/profile_edit.html',
                                   form=form,
                                   server_dialog_form=server_dialog_form,
                                   system_option=SystemOption.get(db_session),
                                   duplicate_error=True)

        software_profile.name = form.profile_name.data
        software_profile.description = form.description.data
        software_profile.packages = ','.join(
            [l for l in form.software_packages.data.splitlines() if l]),

        db_session.commit()

        return redirect(url_for('conformance.home'))
    else:
        form.profile_name.data = software_profile.name
        form.description.data = software_profile.description
        if software_profile.packages is not None:
            form.software_packages.data = '\n'.join(
                software_profile.packages.split(','))

    return render_template('conformance/profile_edit.html',
                           form=form,
                           server_dialog_form=server_dialog_form,
                           system_option=SystemOption.get(db_session))
示例#28
0
def software_profile_create():
    # if not can_create_user(current_user):
    #    abort(401)

    db_session = DBSession()

    form = SoftwareProfileForm(request.form)
    server_dialog_form = ServerDialogForm(request.form)

    fill_servers(server_dialog_form.server_dialog_server.choices,
                 get_server_list(db_session), False)

    if request.method == 'POST' and form.validate():

        software_profile = get_software_profile(db_session,
                                                form.profile_name.data)

        if software_profile is not None:
            return render_template('conformance/profile_edit.html',
                                   form=form,
                                   system_option=SystemOption.get(db_session),
                                   duplicate_error=True)

        software_profile = SoftwareProfile(
            name=form.profile_name.data,
            description=form.description.data,
            packages=','.join(
                [l for l in form.software_packages.data.splitlines() if l]),
            created_by=current_user.username)

        db_session.add(software_profile)
        db_session.commit()

        return redirect(url_for('conformance.home'))
    else:

        return render_template('conformance/profile_edit.html',
                               form=form,
                               server_dialog_form=server_dialog_form,
                               system_option=SystemOption.get(db_session))
示例#29
0
文件: mailer.py 项目: kstaniek/csm
def create_email_job(db_session, logger, message, username):
    system_option = SystemOption.get(db_session)
    if not system_option.enable_email_notify:
        return
    
    user = get_user(db_session, username)
    if user is None:
        logger.error('mailer: Unable to locate user "%s"' % username)
        return

    email_job = EmailJob(recipients=user.email, message=message, created_by=username)
    db_session.add(email_job)
    db_session.commit()
示例#30
0
文件: inventory.py 项目: smjurcak/csm
def create_email_job_with_attachment_files(db_session, message, file_paths,
                                           recipients):
    system_option = SystemOption.get(db_session)
    if not system_option.enable_email_notify:
        return

    email_job = EmailJob(recipients=recipients,
                         message=message,
                         created_by=current_user.username,
                         attachment_file_paths=file_paths)
    db_session.add(email_job)
    db_session.commit()
    return
示例#31
0
    def __init__(self, platform, release, refresh=False):
        self.platform = self.get_cco_supported_platform(platform)
        self.release = self.get_cco_supported_release(release)
        self.smu_meta = None
        self.smus = {}
        self.service_packs = {}
        self.in_transit_smus = {}
        self.software = {}

        if SystemOption.get(DBSession()).enable_cco_lookup or refresh:
            self.get_smu_info_from_cco(platform, release)
        else:
            self.get_smu_info_from_db(platform, release)
示例#32
0
def user_list():
    db_session = DBSession()

    users = get_user_list(db_session)
    if users is None:
        abort(404)

    if current_user.privilege == UserPrivilege.ADMIN:
        return render_template('user/index.html',
                               users=users,
                               system_option=SystemOption.get(db_session))

    return render_template('user/not_authorized.html', user=current_user)
示例#33
0
    def __init__(self, platform, release, refresh=False):
        self.platform = self.get_cco_supported_platform(platform)
        self.release = self.get_cco_supported_release(release)
        self.smu_meta = None
        self.smus = {}
        self.service_packs = {}
        self.in_transit_smus = {}
        self.software = {}

        if SystemOption.get(DBSession()).enable_cco_lookup or refresh:
            self.get_smu_info_from_cco(platform, release)
        else:
            self.get_smu_info_from_db(platform, release)
示例#34
0
文件: mailer.py 项目: ommaurya/csm
def send_install_status_email(install_job):
    db_session = DBSession
    username = install_job.created_by

    system_option = SystemOption.get(db_session)
    if not system_option.enable_email_notify:
        return

    smtp_server = get_smtp_server(db_session)
    if smtp_server is None:
        logger.error('mailer: SMTP Server has not been specified')
        return

    user = get_user(db_session, username)
    if user is None:
        logger.error('mailer: Unable to locate user "%s"' % username)
        return

    host = get_host(db_session, install_job.host_id)
    if host is None:
        logger.error('mailer: Unable to locate host id "%s"' %
                     str(install_job.host_id))
        return

    message = '<html><head><body>'
    if install_job.status == JobStatus.COMPLETED:
        message += 'The scheduled installation for host "' + host.hostname + '" has COMPLETED<br><br>'
    elif install_job.status == JobStatus.FAILED:
        message += 'The scheduled installation for host "' + host.hostname + '" has FAILED<br><br>'

    message += 'Scheduled Time: ' + get_datetime_string(
        install_job.scheduled_time) + ' (UTC)<br>'
    message += 'Start Time: ' + get_datetime_string(
        install_job.start_time) + ' (UTC)<br>'
    message += 'Install Action: ' + install_job.install_action + '<br><br>'

    if install_job.packages is not None and len(install_job.packages) > 0:
        message += 'Following are the software packages: <br>' + install_job.packages.replace(
            '\n', '<br>')

    message += '</body></head></html>'

    sendmail(server=smtp_server.server,
             server_port=smtp_server.server_port,
             sender=smtp_server.sender,
             recipient=user.email,
             message=message,
             use_authentication=smtp_server.use_authentication,
             username=smtp_server.username,
             password=smtp_server.password,
             secure_connection=smtp_server.secure_connection)
示例#35
0
def home(hostname):
    db_session = DBSession()

    host = get_host(db_session, hostname)
    if host is None:
        abort(404)

    return render_template('host/host_dashboard.html', host=host,
                           form=get_host_schedule_install_form(request),
                           system_option=SystemOption.get(db_session),
                           package_states=[PackageState.ACTIVE_COMMITTED,
                                           PackageState.ACTIVE,
                                           PackageState.INACTIVE_COMMITTED,
                                           PackageState.INACTIVE])
示例#36
0
文件: mailer.py 项目: smjurcak/csm
def create_email_job(db_session, logger, message, username):
    system_option = SystemOption.get(db_session)
    if not system_option.enable_email_notify:
        return

    user = get_user(db_session, username)
    if user is None:
        logger.error('mailer: Unable to locate user "%s"' % username)
        return

    email_job = EmailJob(recipients=user.email,
                         message=message,
                         created_by=username)
    db_session.add(email_job)
    db_session.commit()
示例#37
0
def home(platform, release):
    system_option = SystemOption.get(DBSession())
    form = BrowseServerDialogForm(request.form)
    fill_servers(form.dialog_server.choices, get_server_list(DBSession()),
                 False)
    export_software_information_form = ExportSoftwareInformationForm(
        request.form)

    return render_template(
        'cco/home.html',
        form=form,
        platform=platform,
        release=release,
        system_option=system_option,
        export_software_information_form=export_software_information_form)
示例#38
0
def home(hostname):
    db_session = DBSession()

    host = get_host(db_session, hostname)
    if host is None:
        abort(404)

    return render_template('host/host_dashboard.html',
                           host=host,
                           form=get_host_schedule_install_form(request),
                           system_option=SystemOption.get(db_session),
                           package_states=[
                               PackageState.ACTIVE_COMMITTED,
                               PackageState.ACTIVE,
                               PackageState.INACTIVE_COMMITTED,
                               PackageState.INACTIVE
                           ])
示例#39
0
def login():

    form = LoginForm(request.form)
    error_message = None

    if request.method == 'POST' and form.validate():
        username = form.username.data.strip()
        password = form.password.data.strip()

        db_session = DBSession()

        user, authenticated = \
            User.authenticate(db_session.query, username, password)

        if authenticated:
            login_user(user)

            # record the base URL
            try:
                system_option = SystemOption.get(db_session)
                system_option.base_url = get_base_url(request.url)
                db_session.commit()
            except:
                logger.exception('login() hit exception')

            # Certain admin features (Admin Console/Create or Edit User require
            # re-authentication. The return_url indicates which admin feature the
            # user wants to access.
            return_url = get_return_url(request)
            if return_url is None:
                return redirect(request.args.get("next") or url_for('home'))
            else:
                return redirect(url_for(return_url))
        else:
            error_message = 'Your user name or password is incorrect.  \
                             Re-enter them again or contact your system administrator.'

    # Fill the username if the user is still logged in.
    username = get_username(current_user)
    if username is not None:
        form.username.data = username

    return render_template('user/login.html',
                           form=form,
                           error_message=error_message,
                           username=username)
示例#40
0
def login():

    form = LoginForm(request.form)
    error_message = None

    if request.method == 'POST' and form.validate():
        username = form.username.data.strip()
        password = form.password.data.strip()

        db_session = DBSession()

        user, authenticated = \
            User.authenticate(db_session.query, username, password)

        if authenticated:
            login_user(user)

            # record the base URL
            try:
                system_option = SystemOption.get(db_session)
                system_option.base_url = get_base_url(request.url)
                db_session.commit()
            except:
                logger.exception('login() hit exception')

            # Certain admin features (Admin Console/Create or Edit User require
            # re-authentication. The return_url indicates which admin feature the
            # user wants to access.
            return_url = get_return_url(request)
            if return_url is None:
                return redirect(request.args.get("next") or url_for('home'))
            else:
                return redirect(url_for(return_url))
        else:
            error_message = 'Your user name or password is incorrect.  \
                             Re-enter them again or contact your system administrator.'

    # Fill the username if the user is still logged in.
    username = get_username(current_user)
    if username is not None:
        form.username.data = username

    return render_template('user/login.html', form=form, error_message=error_message, username=username)
示例#41
0
def dashboard():
    db_session = DBSession()

    jump_hosts = get_jump_host_list(db_session)
    regions = get_region_list(db_session)
    servers = get_server_list(db_session)

    form = BrowseServerDialogForm(request.form)
    fill_servers(form.dialog_server.choices, get_server_list(DBSession()),
                 False)

    return render_template('host/home.html',
                           form=form,
                           jump_hosts=jump_hosts,
                           regions=regions,
                           servers=servers,
                           system_option=SystemOption.get(db_session),
                           build_date=get_build_date(),
                           current_user=current_user)
示例#42
0
def dispatch():
    db_session = DBSession
    system_option = SystemOption.get(db_session)

    inventory_manager = InventoryManager(system_option.inventory_threads, 'Inventory-Manager')
    inventory_manager.start()
 
    software_manager = SoftwareManager(system_option.install_threads, 'Software-Manager')
    software_manager.start()
    
    download_manager = DownloadManager(system_option.download_threads, 'Download-Manager')
    download_manager.start()

    generic_job_manager = GenericJobManager(2, 'Generic-Job')
    generic_job_manager.start()

    scheduler = Scheduler('Scheduler')
    scheduler.start()

    print('csmdispatcher started')
示例#43
0
def home():
    conformance_form = ConformanceForm(request.form)
    conformance_report_dialog_form = ConformanceReportDialogForm(request.form)
    make_conform_dialog_form = MakeConformDialogForm(request.form)
    fill_custom_command_profiles(make_conform_dialog_form.custom_command_profile.choices)
    select_server_form = SelectServerForm(request.form)

    export_conformance_report_form = ExportConformanceReportForm(request.form)
    export_conformance_report_form.include_host_packages.data = True

    return render_template('conformance/index.html',
                           conformance_form=conformance_form,
                           conformance_report_dialog_form=conformance_report_dialog_form,
                           install_actions=[InstallAction.PRE_UPGRADE, InstallAction.INSTALL_ADD,
                                            InstallAction.INSTALL_ACTIVATE, InstallAction.POST_UPGRADE,
                                            InstallAction.INSTALL_COMMIT, InstallAction.ALL],
                           make_conform_dialog_form=make_conform_dialog_form,
                           export_conformance_report_form=export_conformance_report_form,
                           select_server_form=select_server_form,
                           system_option=SystemOption.get(DBSession()))
示例#44
0
 def get_catalog(cls):
     db_session = DBSession()        
     system_option = SystemOption.get(db_session)
     
     if system_option.enable_cco_lookup:
         return SMUInfoLoader.get_catalog_from_cco()
     else:
         catalog = {}
         # Retrieve from the database
         db_catalog = db_session.query(CCOCatalog).all()
         if len(db_catalog) > 0:
             for entry in db_catalog:
                 if entry.platform in catalog:
                     release_list = catalog[entry.platform]
                 else:
                     release_list = []
                     catalog[entry.platform] = release_list
                 
                 # Inserts release in reverse order (latest release first)
                 release_list.insert(0, entry.release)
                 
         return OrderedDict(sorted(catalog.items()))           
示例#45
0
    def get_catalog(cls):
        db_session = DBSession()
        system_option = SystemOption.get(db_session)

        if system_option.enable_cco_lookup:
            return SMUInfoLoader.get_catalog_from_cco()
        else:
            catalog = {}
            # Retrieve from the database
            db_catalog = db_session.query(CCOCatalog).all()
            if len(db_catalog) > 0:
                for entry in db_catalog:
                    if entry.platform in catalog:
                        release_list = catalog[entry.platform]
                    else:
                        release_list = []
                        catalog[entry.platform] = release_list

                    # Inserts release in reverse order (latest release first)
                    release_list.insert(0, entry.release)

            return OrderedDict(sorted(catalog.items()))
示例#46
0
def api_get_host_dashboard_cookie(hostname):
    db_session = DBSession()
    host = get_host(db_session, hostname)

    rows = []
    if host is not None:
        software_profile = get_software_profile_by_id(db_session,
                                                      host.software_profile_id)
        system_option = SystemOption.get(db_session)
        row = {}
        connection_param = host.connection_param[0]
        row['hostname'] = host.hostname
        row['region'] = host.region.name if host.region is not None else UNKNOWN
        row['location'] = host.location
        row['roles'] = host.roles
        row['platform'] = host.platform
        row['software_platform'] = host.software_platform
        row['software_version'] = host.software_version
        row['host_or_ip'] = connection_param.host_or_ip
        row['username'] = connection_param.username
        row['connection'] = connection_param.connection_type
        row['port_number'] = connection_param.port_number
        row['created_by'] = host.created_by
        row['software_profile_name'] = '' if software_profile is None else software_profile.name

        if connection_param.jump_host is not None:
            row['jump_host'] = connection_param.jump_host.hostname

        # Last inventory successful time
        inventory_job = host.inventory_job[0]
        row['last_successful_inventory_elapsed_time'] = get_last_successful_inventory_elapsed_time(
            host)
        row['last_successful_inventory_time'] = inventory_job.last_successful_time
        row['status'] = inventory_job.status
        row['can_schedule'] = system_option.can_schedule
        rows.append(row)

    return jsonify(**{'data': rows})
示例#47
0
def dispatch():
    db_session = DBSession
    system_option = SystemOption.get(db_session)

    inventory_manager = InventoryManager(system_option.inventory_threads,
                                         'Inventory-Manager')
    inventory_manager.start()

    software_manager = SoftwareManager(system_option.install_threads,
                                       'Software-Manager')
    software_manager.start()

    download_manager = DownloadManager(system_option.download_threads,
                                       'Download-Manager')
    download_manager.start()

    generic_job_manager = GenericJobManager(2, 'Generic-Job')
    generic_job_manager.start()

    scheduler = Scheduler('Scheduler')
    scheduler.start()

    print('csmdispatcher started')
示例#48
0
    def create_email_notification(self, db_session, logger, host, install_job):
        try:
            session_log_link = "hosts/{}/install_job_history/session_log/{}?file_path={}".format(
                urllib.quote(host.hostname), install_job.id,
                install_job.session_log)

            message = '<html><head><body>'
            if install_job.status == JobStatus.COMPLETED:
                message += 'The scheduled installation for host "' + host.hostname + '" has COMPLETED<br><br>'
            elif install_job.status == JobStatus.FAILED:
                message += 'The scheduled installation for host "' + host.hostname + '" has FAILED<br><br>'

            message += 'Scheduled Time: ' + get_datetime_string(
                install_job.scheduled_time) + ' (UTC)<br>'
            message += 'Start Time: ' + get_datetime_string(
                install_job.start_time) + ' (UTC)<br>'
            message += 'Install Action: ' + install_job.install_action + '<br><br>'

            session_log_url = SystemOption.get(
                db_session).base_url + '/' + session_log_link

            message += 'For more information, click the link below<br><br>'
            message += session_log_url + '<br><br>'

            if install_job.packages is not None and len(
                    install_job.packages) > 0:
                message += 'Followings are the software packages: <br><br>' + install_job.packages.replace(
                    ',', '<br>')

            message += '</body></head></html>'

            create_email_job(db_session, logger, message,
                             install_job.created_by)

        except Exception:
            logger.exception('create_email_notification hit exception')
示例#49
0
def home():
    conformance_form = ConformanceForm(request.form)
    conformance_report_dialog_form = ConformanceReportDialogForm(request.form)
    make_conform_dialog_form = MakeConformDialogForm(request.form)
    fill_custom_command_profiles(
        make_conform_dialog_form.custom_command_profile.choices)
    select_server_form = SelectServerForm(request.form)

    export_conformance_report_form = ExportConformanceReportForm(request.form)
    export_conformance_report_form.include_host_packages.data = True

    return render_template(
        'conformance/index.html',
        conformance_form=conformance_form,
        conformance_report_dialog_form=conformance_report_dialog_form,
        install_actions=[
            InstallAction.PRE_UPGRADE, InstallAction.INSTALL_ADD,
            InstallAction.INSTALL_ACTIVATE, InstallAction.POST_UPGRADE,
            InstallAction.INSTALL_COMMIT, InstallAction.ALL
        ],
        make_conform_dialog_form=make_conform_dialog_form,
        export_conformance_report_form=export_conformance_report_form,
        select_server_form=select_server_form,
        system_option=SystemOption.get(DBSession()))
示例#50
0
def api_get_host_dashboard_cookie(hostname):
    db_session = DBSession()
    host = get_host(db_session, hostname)

    rows = []
    if host is not None:
        software_profile = get_software_profile_by_id(db_session, host.software_profile_id)
        system_option = SystemOption.get(db_session)
        row = {}
        connection_param = host.connection_param[0]
        row['hostname'] = host.hostname
        row['region'] = host.region.name if host.region is not None else UNKNOWN
        row['location'] = host.location
        row['roles'] = host.roles
        row['platform'] = host.platform
        row['software_platform'] = host.software_platform
        row['software_version'] = host.software_version
        row['host_or_ip'] = connection_param.host_or_ip
        row['username'] = connection_param.username
        row['connection'] = connection_param.connection_type
        row['port_number'] = connection_param.port_number
        row['created_by'] = host.created_by
        row['software_profile_name'] = '' if software_profile is None else software_profile.name

        if connection_param.jump_host is not None:
            row['jump_host'] = connection_param.jump_host.hostname

        # Last inventory successful time
        inventory_job = host.inventory_job[0]
        row['last_successful_inventory_elapsed_time'] = get_last_successful_inventory_elapsed_time(host)
        row['last_successful_inventory_time'] = inventory_job.last_successful_time
        row['status'] = inventory_job.status
        row['can_schedule'] = system_option.can_schedule
        rows.append(row)

    return jsonify(**{'data': rows})
示例#51
0
def home():
    if current_user.privilege != UserPrivilege.ADMIN:
        abort(401)

    db_session = DBSession()

    smtp_form = SMTPForm(request.form)
    admin_console_form = AdminConsoleForm(request.form)

    smtp_server = get_smtp_server(db_session)
    system_option = SystemOption.get(db_session)

    fill_user_privileges(admin_console_form.ldap_default_user_privilege.choices)

    if request.method == 'POST' and \
        smtp_form.validate() and \
        admin_console_form.validate():

        if smtp_server is None:
            smtp_server = SMTPServer()
            db_session.add(smtp_server)

        smtp_server.server = smtp_form.server.data
        smtp_server.server_port = smtp_form.server_port.data if len(smtp_form.server_port.data) > 0 else None
        smtp_server.sender = smtp_form.sender.data
        smtp_server.use_authentication = smtp_form.use_authentication.data
        smtp_server.username = smtp_form.username.data
        if len(smtp_form.password.data) > 0:
            smtp_server.password = smtp_form.password.data
        smtp_server.secure_connection = smtp_form.secure_connection.data

        system_option.inventory_threads = admin_console_form.num_inventory_threads.data
        system_option.install_threads = admin_console_form.num_install_threads.data
        system_option.download_threads = admin_console_form.num_download_threads.data
        system_option.can_schedule = admin_console_form.can_schedule.data
        system_option.can_install = admin_console_form.can_install.data
        system_option.enable_email_notify = admin_console_form.enable_email_notify.data
        system_option.enable_inventory = admin_console_form.enable_inventory.data

        # The LDAP UI may be hidden if it is not supported.
        # In this case, the flag is not set.
        if not is_empty(admin_console_form.enable_ldap_auth.data):
            system_option.enable_ldap_auth = admin_console_form.enable_ldap_auth.data
            system_option.ldap_server_url = admin_console_form.ldap_server_url.data
            system_option.ldap_default_user_privilege = admin_console_form.ldap_default_user_privilege.data
            system_option.ldap_server_distinguished_names = admin_console_form.ldap_server_distinguished_names.data.strip()

        system_option.inventory_hour = admin_console_form.inventory_hour.data
        system_option.inventory_history_per_host = admin_console_form.inventory_history_per_host.data
        system_option.download_history_per_user = admin_console_form.download_history_per_user.data
        system_option.install_history_per_host = admin_console_form.install_history_per_host.data
        system_option.total_system_logs = admin_console_form.total_system_logs.data
        system_option.enable_default_host_authentication = admin_console_form.enable_default_host_authentication.data
        system_option.default_host_authentication_choice = admin_console_form.default_host_authentication_choice.data
        system_option.enable_cco_lookup = admin_console_form.enable_cco_lookup.data
        system_option.use_utc_timezone = admin_console_form.use_utc_timezone.data
        system_option.default_host_username = admin_console_form.default_host_username.data

        if len(admin_console_form.default_host_password.data) > 0:
            system_option.default_host_password = admin_console_form.default_host_password.data

        system_option.enable_user_credential_for_host = admin_console_form.enable_user_credential_for_host.data

        db_session.commit()

        return redirect(url_for('home'))
    else:

        admin_console_form.num_inventory_threads.data = system_option.inventory_threads
        admin_console_form.num_install_threads.data = system_option.install_threads
        admin_console_form.num_download_threads.data = system_option.download_threads
        admin_console_form.can_schedule.data = system_option.can_schedule
        admin_console_form.can_install.data = system_option.can_install
        admin_console_form.enable_email_notify.data = system_option.enable_email_notify
        admin_console_form.enable_ldap_auth.data = system_option.enable_ldap_auth
        admin_console_form.ldap_server_url.data = system_option.ldap_server_url
        admin_console_form.ldap_default_user_privilege.data = system_option.ldap_default_user_privilege
        admin_console_form.ldap_server_distinguished_names.data = system_option.ldap_server_distinguished_names
        admin_console_form.enable_inventory.data = system_option.enable_inventory
        admin_console_form.inventory_hour.data = system_option.inventory_hour
        admin_console_form.inventory_history_per_host.data = system_option.inventory_history_per_host
        admin_console_form.download_history_per_user.data = system_option.download_history_per_user
        admin_console_form.install_history_per_host.data = system_option.install_history_per_host
        admin_console_form.total_system_logs.data = system_option.total_system_logs
        admin_console_form.enable_default_host_authentication.data = system_option.enable_default_host_authentication
        admin_console_form.default_host_authentication_choice.data = system_option.default_host_authentication_choice
        admin_console_form.default_host_username.data = system_option.default_host_username
        admin_console_form.enable_cco_lookup.data = system_option.enable_cco_lookup
        admin_console_form.use_utc_timezone.data = system_option.use_utc_timezone
        admin_console_form.cco_lookup_time.data = get_datetime_string(system_option.cco_lookup_time)
        admin_console_form.enable_user_credential_for_host.data = system_option.enable_user_credential_for_host

        if not is_empty(system_option.default_host_password):
            admin_console_form.default_host_password_placeholder = 'Use Password on File'
        else:
            admin_console_form.default_host_password_placeholder = 'No Password Specified'

        if smtp_server is not None:
            smtp_form.server.data = smtp_server.server
            smtp_form.server_port.data = smtp_server.server_port
            smtp_form.sender.data = smtp_server.sender
            smtp_form.use_authentication.data = smtp_server.use_authentication
            smtp_form.username.data = smtp_server.username
            smtp_form.secure_connection.data = smtp_server.secure_connection
            if not is_empty(smtp_server.password):
                smtp_form.password_placeholder = 'Use Password on File'
            else:
                smtp_form.password_placeholder = 'No Password Specified'

        return render_template('admin/index.html',
                               admin_console_form=admin_console_form,
                               smtp_form=smtp_form,
                               system_option=SystemOption.get(db_session),
                               is_ldap_supported=is_ldap_supported())
示例#52
0
def api_get_install_dashboard_cookie():
    system_option = SystemOption.get(DBSession())

    return jsonify(**{'data': [{'can_schedule': system_option.can_schedule, 'can_install': system_option.can_install}]})
示例#53
0
def can_install(db_session):
    # Check if scheduled jobs are allowed to run
    return SystemOption.get(db_session).can_install
示例#54
0
def handle_schedule_install_form(request, db_session, hostname, install_job=None):
    host = get_host(db_session, hostname)
    if host is None:
        abort(404)

    return_url = get_return_url(request, 'host_dashboard.home')

    schedule_form = ScheduleMigrationForm(request.form)

    # Fills the selections
    fill_servers(schedule_form.server_dialog_server.choices, host.region.servers, include_local=False)
    fill_custom_command_profiles(db_session, schedule_form.custom_command_profile.choices)
    fill_hardware_audit_version(schedule_form.hardware_audit_version.choices)

    if request.method == 'POST':
        if install_job is not None:
            # In Edit mode, the install_action UI on HostScheduleForm is disabled (not allowed to change).
            # Thus, there will be no value returned by form.install_action.data.  So, re-use the existing ones.
            install_action = [ install_job.install_action ]
        else:
            install_action = schedule_form.install_action.data

        scheduled_time = schedule_form.scheduled_time_UTC.data
        software_packages = schedule_form.hidden_software_packages.data.split()
        server_id = schedule_form.hidden_server.data
        server_directory = schedule_form.hidden_server_directory.data
        custom_command_profile_ids = [str(i) for i in schedule_form.custom_command_profile.data]

        if InstallAction.MIGRATION_AUDIT in install_action:
            host.context[0].data['hardware_audit_version'] = \
                schedule_form.hidden_hardware_audit_version.data

        if InstallAction.PRE_MIGRATE in install_action:
            host.context[0].data['config_filename'] = schedule_form.hidden_config_filename.data
            host.context[0].data['override_hw_req'] = schedule_form.hidden_override_hw_req.data

        # install_action is a list object which can only contain one install action
        # at this editing time, accept the selected dependency if any

        dependency = int(schedule_form.hidden_dependency.data)
        create_or_update_install_job(db_session=db_session, host_id=host.id, install_action=install_action[0],
                                     scheduled_time=scheduled_time, software_packages=software_packages,
                                     server_id=server_id, server_directory=server_directory,
                                     custom_command_profile_ids=custom_command_profile_ids, dependency=dependency,
                                     install_job=install_job)

        return redirect(url_for(return_url, hostname=hostname))

    elif request.method == 'GET':
        # Initialize the hidden fields
        schedule_form.hidden_server.data = -1
        schedule_form.hidden_server_name.data = ''
        schedule_form.hidden_server_directory.data = ''
        schedule_form.hidden_pending_downloads.data = ''
        schedule_form.hidden_edit.data = install_job is not None

        schedule_form.hidden_region.data = str(host.region.name)
        fill_default_region(schedule_form.region.choices, host.region)
        schedule_form.hidden_hosts.data = hostname
        schedule_form.hidden_dependency.data = ''

        # In Edit mode
        if install_job is not None:
            schedule_form.install_action.data = install_job.install_action

            if install_job.custom_command_profile_ids:
                ids = [str(id) for id in install_job.custom_command_profile_ids.split(',')]
                schedule_form.custom_command_profile.data = ids

            schedule_form.hidden_override_hw_req.data = host.context[0].data.get('override_hw_req')
            schedule_form.hidden_config_filename.data = host.context[0].data.get('config_filename')
            schedule_form.hidden_hardware_audit_version.data = host.context[0].data.get('hardware_audit_version')

            if install_job.server_id is not None:
                schedule_form.hidden_server.data = install_job.server_id
                server = get_server_by_id(db_session, install_job.server_id)
                if server is not None:
                    schedule_form.hidden_server_name.data = server.hostname

                schedule_form.hidden_server_directory.data = '' if install_job.server_directory is None \
                    else install_job.server_directory

            schedule_form.hidden_pending_downloads.data = '' if install_job.pending_downloads is None \
                else install_job.pending_downloads

            # Form a line separated list for the textarea
            if install_job.packages is not None:

                schedule_form.hidden_software_packages.data = install_job.packages

            if install_job.dependency is not None:
                schedule_form.hidden_dependency.data = str(install_job.dependency)
            else:
                schedule_form.hidden_dependency.data = '-1'

            if install_job.scheduled_time is not None:
                schedule_form.scheduled_time_UTC.data = get_datetime_string(install_job.scheduled_time)

    return render_template('asr9k_64_migrate/migration.html', schedule_form=schedule_form, system_option=SystemOption.get(db_session),
                           host=host, server_time=datetime.datetime.utcnow(), install_job=install_job,
                           return_url=return_url, install_action=get_install_migrations_dict(), input_filename="",
                           err_msg="")
示例#55
0
文件: install.py 项目: smjurcak/csm
def batch_schedule_install():
    """
    For batch scheduled installation.
    """
    if not can_install(current_user):
        abort(401)

    db_session = DBSession()
    form = ScheduleInstallForm(request.form)

    # Fills the selections
    fill_regions(db_session, form.region.choices)
    fill_dependencies(form.dependency.choices)
    fill_custom_command_profiles(db_session, form.custom_command_profile.choices)

    return_url = get_return_url(request, 'home')

    if request.method == 'POST':  # and form.validate():
        """
        f = request.form
        for key in f.keys():
            for value in f.getlist(key):
               print(key,":",value)
        """
        # Retrieves from the multi-select box
        hostnames = form.hidden_selected_hosts.data.split(',')
        install_action = form.install_action.data

        custom_command_profile_ids = [str(i) for i in form.custom_command_profile.data]

        if hostnames is not None:

            for hostname in hostnames:
                host = get_host(db_session, hostname)
                if host is not None:
                    db_session = DBSession()
                    scheduled_time = form.scheduled_time_UTC.data
                    software_packages = form.software_packages.data.split()
                    server_id = form.hidden_server.data
                    server_directory = form.hidden_server_directory.data
                    pending_downloads = form.hidden_pending_downloads.data.split()

                    # If only one install_action, accept the selected dependency if any
                    dependency = 0
                    if len(install_action) == 1:
                        # No dependency when it is 0 (a digit)
                        if not form.dependency.data.isdigit():
                            prerequisite_install_job = get_last_install_action(db_session,
                                                                               form.dependency.data, host.id)
                            if prerequisite_install_job is not None:
                                dependency = prerequisite_install_job.id

                        create_or_update_install_job(db_session=db_session, host_id=host.id,
                                                     install_action=install_action[0],
                                                     custom_command_profile_ids=custom_command_profile_ids,
                                                     scheduled_time=scheduled_time, software_packages=software_packages,
                                                     server_id=server_id, server_directory=server_directory,
                                                     pending_downloads=pending_downloads, dependency=dependency,
                                                     created_by=current_user.username)
                    else:
                        # The dependency on each install action is already indicated in the implicit ordering
                        # in the selector.  If the user selected Pre-Upgrade and Install Add, Install Add (successor)
                        # will have Pre-Upgrade (predecessor) as the dependency.
                        dependency = 0
                        for one_install_action in install_action:
                            new_install_job = create_or_update_install_job(db_session=db_session, host_id=host.id,
                                                                           install_action=one_install_action,
                                                                           scheduled_time=scheduled_time,
                                                                           custom_command_profile_ids=custom_command_profile_ids,
                                                                           software_packages=software_packages,
                                                                           server_id=server_id,
                                                                           server_directory=server_directory,
                                                                           pending_downloads=pending_downloads,
                                                                           dependency=dependency,
                                                                           created_by=current_user.username)
                            dependency = new_install_job.id

        return redirect(url_for(return_url))
    else:
        # Initialize the hidden fields
        form.hidden_server.data = -1
        form.hidden_server_name.data = ''
        form.hidden_server_directory.data = ''
        form.hidden_pending_downloads.data = ''

        return render_template('schedule_install.html', form=form, system_option=SystemOption.get(db_session),
                               server_time=datetime.datetime.utcnow(), return_url=return_url)
示例#56
0
文件: install.py 项目: smjurcak/csm
def handle_schedule_install_form(request, db_session, hostname, install_job=None):
    host = get_host(db_session, hostname)
    if host is None:
        abort(404)

    return_url = get_return_url(request, 'host_dashboard.home')

    form = HostScheduleInstallForm(request.form)

    # Retrieves all the install jobs for this host.  This will allow
    # the user to select which install job this install job can depend on.
    install_jobs = db_session.query(InstallJob).filter(
        InstallJob.host_id == host.id).order_by(InstallJob.scheduled_time.asc()).all()

    region_servers = host.region.servers
    # Returns all server repositories if the region does not have any server repository designated.
    if is_empty(region_servers):
        region_servers = get_server_list(db_session)

    # Fills the selections
    fill_servers(form.server_dialog_server.choices, region_servers)
    fill_servers(form.server_modal_dialog_server.choices, region_servers)
    fill_servers(form.cisco_dialog_server.choices, region_servers, False)
    fill_dependency_from_host_install_jobs(form.dependency.choices, install_jobs,
                                           (-1 if install_job is None else install_job.id))
    fill_custom_command_profiles(db_session, form.custom_command_profile.choices)

    if request.method == 'POST':
        if install_job is not None:
            # In Edit mode, the install_action UI on HostScheduleForm is disabled (not allow to change).
            # Thus, there will be no value returned by form.install_action.data.  So, re-use the existing ones.
            install_action = [install_job.install_action]
        else:
            install_action = form.install_action.data

        scheduled_time = form.scheduled_time_UTC.data
        software_packages = form.software_packages.data.split()
        server_id = form.hidden_server.data
        server_directory = form.hidden_server_directory.data
        pending_downloads = form.hidden_pending_downloads.data.split()
        custom_command_profile_ids = [str(i) for i in form.custom_command_profile.data]

        # install_action is a list object which may contain multiple install actions.
        # If only one install_action, accept the selected dependency if any
        if len(install_action) == 1:
            dependency = int(form.dependency.data)
            create_or_update_install_job(db_session=db_session, host_id=host.id, install_action=install_action[0],
                                         scheduled_time=scheduled_time, software_packages=software_packages,
                                         server_id=server_id, server_directory=server_directory,
                                         pending_downloads=pending_downloads,
                                         custom_command_profile_ids=custom_command_profile_ids, dependency=dependency,
                                         created_by=current_user.username, install_job=install_job)
        else:
            # The dependency on each install action is already indicated in the implicit ordering in the selector.
            # If the user selected Pre-Upgrade and Install Add, Install Add (successor) will
            # have Pre-Upgrade (predecessor) as the dependency.
            dependency = 0
            for one_install_action in install_action:
                new_install_job = create_or_update_install_job(db_session=db_session,
                                                               host_id=host.id,
                                                               install_action=one_install_action,
                                                               scheduled_time=scheduled_time,
                                                               software_packages=software_packages, server_id=server_id,
                                                               server_directory=server_directory,
                                                               pending_downloads=pending_downloads,
                                                               custom_command_profile_ids=custom_command_profile_ids,
                                                               dependency=dependency, created_by=current_user.username,
                                                               install_job=install_job)
                dependency = new_install_job.id

        return redirect(url_for(return_url, hostname=hostname))

    elif request.method == 'GET':
        # Initialize the hidden fields
        form.hidden_server.data = -1
        form.hidden_selected_hosts.data = ''
        form.hidden_server_name.data = ''
        form.hidden_server_directory.data = ''
        form.hidden_pending_downloads.data = ''
        form.hidden_edit.data = install_job is not None

        # In Edit mode
        if install_job is not None:
            form.install_action.data = install_job.install_action

            if install_job.server_id is not None:
                form.hidden_server.data = install_job.server_id
                server = get_server_by_id(db_session, install_job.server_id)
                if server is not None:
                    form.hidden_server_name.data = server.hostname

                form.hidden_server_directory.data = '' if install_job.server_directory is None else install_job.server_directory

            form.hidden_pending_downloads.data = '' if install_job.pending_downloads is None else install_job.pending_downloads

            # Form a line separated list for the textarea
            if install_job.packages is not None:
                form.software_packages.data = '\n'.join(install_job.packages.split(','))

            form.dependency.data = str(install_job.dependency)

            if install_job.scheduled_time is not None:
                form.scheduled_time_UTC.data = get_datetime_string(install_job.scheduled_time)

            if install_job.custom_command_profile_ids:
                ids = [int(id) for id in install_job.custom_command_profile_ids.split(',')]
                form.custom_command_profile.data = ids

    return render_template('host/schedule_install.html', form=form, system_option=SystemOption.get(db_session),
                           host=host, server_time=datetime.datetime.utcnow(), install_job=install_job,
                           return_url=return_url)
示例#57
0
def home():
    if not can_install(current_user):
        abort(401)

    msg = ''
    # Software Profile import
    if request.method == 'POST':
        file = request.files['file']
        if file:
            if not allowed_file(file.filename):
                msg = "Incorrect file format -- " + file.filename + " must be .json"
            else:
                file_path = os.path.join(get_temp_directory(), "software_profiles.json")
                file.save(file_path)
                failed = ""

                with open(file_path, 'r') as f:
                    try:
                        s = json.load(f)
                    except:
                        msg = "Incorrect file format -- " + file.filename + " must be a valid JSON file."
                        flash(msg, 'import_feedback')
                        return redirect(url_for(".home"))

                    if "CSM Server:Software Profile" not in s.keys():
                        msg = file.filename + " is not in the correct Software Profile format."
                    else:
                        db_session = DBSession
                        profiles = [p for (p,) in DBSession().query(SoftwareProfile.name).all()]
                        d = s["CSM Server:Software Profile"]

                        for software_profile_name in d.keys():
                            name = ''
                            if software_profile_name in profiles:
                                name = software_profile_name
                                # Will keep appending ' - copy' until it hits a unique name
                                while name in profiles:
                                    name += " - copy"
                                msg += software_profile_name + ' -> ' + name + '\n'
                                profiles.append(name)

                            if len(name) < 100 and len(software_profile_name) < 100:
                                try:
                                    profile = SoftwareProfile(
                                        name=name if name else software_profile_name,
                                        packages=d[software_profile_name],
                                        created_by=current_user.username
                                    )
                                    db_session.add(profile)
                                    db_session.commit()
                                except:
                                    failed += software_profile_name + '\n'
                            else:
                                failed += software_profile_name + ' (name too long)\n'

                        if msg:
                            msg = "The following profiles already exist and will try to be imported under modified " \
                                  "names:\n\n" + msg + '\n'
                            if failed:
                                msg += 'The following profiles failed to import:\n\n' + failed
                        elif failed:
                            msg = 'The following profiles failed to import:\n\n' + failed
                        else:
                            msg = "Software Profile import was successful!"

                # delete file
                os.remove(file_path)

            flash(msg, 'import_feedback')
            return redirect(url_for(".home"))

    db_session = DBSession()
    conformance_form = ConformanceForm(request.form)
    assign_software_profile_to_hosts_form = AssignSoftwareProfileToHostsForm(request.form)
    view_host_software_profile_form = ViewHostSoftwareProfileForm(request.form)
    conformance_report_dialog_form = ConformanceReportDialogForm(request.form)
    make_conform_dialog_form = MakeConformDialogForm(request.form)
    fill_custom_command_profiles(db_session, make_conform_dialog_form.custom_command_profile.choices)
    select_server_form = SelectServerForm(request.form)

    export_conformance_report_form = ExportConformanceReportForm(request.form)
    export_conformance_report_form.include_host_packages.data = True
    export_conformance_report_form.exclude_conforming_hosts.data = True

    return render_template('conformance/index.html',
                           conformance_form=conformance_form,
                           assign_software_profile_to_hosts_form=assign_software_profile_to_hosts_form,
                           view_host_software_profile_form=view_host_software_profile_form,
                           conformance_report_dialog_form=conformance_report_dialog_form,
                           install_actions=[InstallAction.PRE_UPGRADE, InstallAction.INSTALL_ADD,
                                            InstallAction.INSTALL_ACTIVATE, InstallAction.POST_UPGRADE,
                                            InstallAction.INSTALL_COMMIT, InstallAction.ALL],
                           make_conform_dialog_form=make_conform_dialog_form,
                           export_conformance_report_form=export_conformance_report_form,
                           select_server_form=select_server_form,
                           server_time=datetime.datetime.utcnow(),
                           system_option=SystemOption.get(DBSession()))
示例#58
0
def batch_schedule_install():
    """
    For batch scheduled installation.
    """
    if not can_install(current_user):
        abort(401)

    db_session = DBSession()
    form = ScheduleInstallForm(request.form)

    # Fills the selections
    fill_regions(db_session, form.region.choices)
    fill_dependencies(form.dependency.choices)
    fill_custom_command_profiles(db_session,
                                 form.custom_command_profile.choices)

    return_url = get_return_url(request, 'home')

    if request.method == 'POST':  # and form.validate():
        """
        f = request.form
        for key in f.keys():
            for value in f.getlist(key):
               print(key,":",value)
        """
        # Retrieves from the multi-select box
        hostnames = form.hidden_selected_hosts.data.split(',')
        install_action = form.install_action.data

        custom_command_profile_ids = [
            str(i) for i in form.custom_command_profile.data
        ]

        if hostnames is not None:

            for hostname in hostnames:
                host = get_host(db_session, hostname)
                if host is not None:
                    db_session = DBSession()
                    scheduled_time = form.scheduled_time_UTC.data
                    software_packages = form.software_packages.data.split()
                    server_id = form.hidden_server.data
                    server_directory = form.hidden_server_directory.data
                    pending_downloads = form.hidden_pending_downloads.data.split(
                    )

                    # If only one install_action, accept the selected dependency if any
                    dependency = 0
                    if len(install_action) == 1:
                        # No dependency when it is 0 (a digit)
                        if not form.dependency.data.isdigit():
                            prerequisite_install_job = get_last_install_action(
                                db_session, form.dependency.data, host.id)
                            if prerequisite_install_job is not None:
                                dependency = prerequisite_install_job.id

                        create_or_update_install_job(
                            db_session=db_session,
                            host_id=host.id,
                            install_action=install_action[0],
                            custom_command_profile_ids=
                            custom_command_profile_ids,
                            scheduled_time=scheduled_time,
                            software_packages=software_packages,
                            server_id=server_id,
                            server_directory=server_directory,
                            pending_downloads=pending_downloads,
                            dependency=dependency,
                            created_by=current_user.username)
                    else:
                        # The dependency on each install action is already indicated in the implicit ordering
                        # in the selector.  If the user selected Pre-Upgrade and Install Add, Install Add (successor)
                        # will have Pre-Upgrade (predecessor) as the dependency.
                        dependency = 0
                        for one_install_action in install_action:
                            new_install_job = create_or_update_install_job(
                                db_session=db_session,
                                host_id=host.id,
                                install_action=one_install_action,
                                scheduled_time=scheduled_time,
                                custom_command_profile_ids=
                                custom_command_profile_ids,
                                software_packages=software_packages,
                                server_id=server_id,
                                server_directory=server_directory,
                                pending_downloads=pending_downloads,
                                dependency=dependency,
                                created_by=current_user.username)
                            dependency = new_install_job.id

        return redirect(url_for(return_url))
    else:
        # Initialize the hidden fields
        form.hidden_server.data = -1
        form.hidden_server_name.data = ''
        form.hidden_server_directory.data = ''
        form.hidden_pending_downloads.data = ''

        return render_template('schedule_install.html',
                               form=form,
                               system_option=SystemOption.get(db_session),
                               server_time=datetime.datetime.utcnow(),
                               return_url=return_url)
示例#59
0
def home():
    return render_template('host/install_dashboard.html', system_option=SystemOption.get(DBSession()))