Beispiel #1
0
def api_get_reload_list():
    """
    Given a software package/SMU/SP list, return those
    that require router reload.
    """
    # The software packages/SMUs/SPs selected by the user to install
    package_list = request.args.get('package_list').split()

    rows = []
    if not is_empty(package_list):
        # Identify the platform and release
        platform, release = SMUInfoLoader.get_platform_and_release(package_list)
        if platform != UNKNOWN and release != UNKNOWN:
            smu_loader = SMUInfoLoader(platform, release)
            if smu_loader.is_valid:
                for package_name in package_list:
                    if 'mini' in package_name:
                        rows.append({'entry': package_name, 'description': ''})
                    else:
                        # Strip the suffix
                        smu_info = smu_loader.get_smu_info(package_name.replace('.' + smu_loader.file_suffix, ''))
                        if smu_info is not None:
                            if "Reload" in smu_info.impact or "Reboot" in smu_info.impact:
                                rows.append({'entry': package_name, 'description': smu_info.description})

    return jsonify(**{'data': rows})
Beispiel #2
0
def api_get_reload_list():
    """
    Given a software package/SMU/SP list, return those
    that require router reload.
    """
    # The software packages/SMUs/SPs selected by the user to install
    package_list = request.args.get('package_list').split()

    rows = []
    if not is_empty(package_list):
        # Identify the platform and release
        platform, release = SMUInfoLoader.get_platform_and_release(
            package_list)
        if platform != UNKNOWN and release != UNKNOWN:
            smu_loader = SMUInfoLoader(platform, release)
            if smu_loader.is_valid:
                for package_name in package_list:
                    if 'mini' in package_name:
                        rows.append({'entry': package_name, 'description': ''})
                    else:
                        # Strip the suffix
                        smu_info = smu_loader.get_smu_info(
                            package_name.replace('.' + smu_loader.file_suffix,
                                                 ''))
                        if smu_info is not None:
                            if "Reload" in smu_info.impact or "Reboot" in smu_info.impact:
                                rows.append({
                                    'entry': package_name,
                                    'description': smu_info.description
                                })

    return jsonify(**{'data': rows})
Beispiel #3
0
def api_get_missing_prerequisite_list():
    """
    Given a SMU list, return any missing pre-requisites.  The
    SMU entries returned also have the file extension appended.
    """
    hostname = request.args.get('hostname')
    # The SMUs selected by the user to install
    smu_list = request.args.get('smu_list').split()

    rows = []
    platform, release = SMUInfoLoader.get_platform_and_release(smu_list)
    if platform != UNKNOWN and release != UNKNOWN:
        smu_loader = SMUInfoLoader(platform, release)

        prerequisite_list = get_missing_prerequisite_list(smu_list)
        host_packages = get_host_active_packages(hostname)

        for smu_name in prerequisite_list:
            # If the missing pre-requisites have not been installed
            # (i.e. not in the Active/Active-Committed), include them.
            if not host_packages_contains(host_packages, smu_name):
                smu_info = smu_loader.get_smu_info(smu_name.replace('.' + smu_loader.file_suffix, ''))
                description = '' if smu_info is None else smu_info.description
                rows.append({'smu_entry': smu_name, 'description': description})

    return jsonify(**{'data': rows})
Beispiel #4
0
def api_get_conformance_report_software_profile_packages(id):
    rows = []
    db_session = DBSession()

    conformance_report = get_conformance_report_by_id(db_session, id)
    if conformance_report is not None:
        software_profile_packages = conformance_report.software_profile_packages.split(
            ',')

        smu_loader = None
        platform, release = SMUInfoLoader.get_platform_and_release(
            software_profile_packages)
        if platform != UNKNOWN and release != UNKNOWN:
            smu_loader = SMUInfoLoader(platform, release)

        for software_profile_package in software_profile_packages:
            description = ''
            if smu_loader is not None and smu_loader.is_valid:
                smu_info = smu_loader.get_smu_info(
                    software_profile_package.replace(
                        '.' + smu_loader.file_suffix, ''))
                if smu_info is not None:
                    description = smu_info.description

            rows.append({
                'software_profile_package': software_profile_package,
                'description': description
            })

    return jsonify(**{'data': rows})
Beispiel #5
0
def api_get_missing_prerequisite_list():
    """
    Given a SMU list, return any missing pre-requisites.  The
    SMU entries returned also have the file extension appended.
    """
    hostname = request.args.get('hostname')
    # The SMUs selected by the user to install
    smu_list = request.args.get('smu_list').split()

    rows = []
    platform, release = SMUInfoLoader.get_platform_and_release(smu_list)
    if platform != UNKNOWN and release != UNKNOWN:
        smu_loader = SMUInfoLoader(platform, release)

        prerequisite_list = get_missing_prerequisite_list(smu_list)
        host_packages = get_host_active_packages(hostname)

        for smu_name in prerequisite_list:
            # If the missing pre-requisites have not been installed
            # (i.e. not in the Active/Active-Committed), include them.
            if not host_packages_contains(host_packages, smu_name):
                smu_info = smu_loader.get_smu_info(
                    smu_name.replace('.' + smu_loader.file_suffix, ''))
                description = '' if smu_info is None else smu_info.description
                rows.append({
                    'smu_entry': smu_name,
                    'description': description
                })

    return jsonify(**{'data': rows})
Beispiel #6
0
def get_missing_prerequisite_list(smu_list):
    result_list = []   
    platform, release = SMUInfoLoader.get_platform_and_release(smu_list)
    
    if platform == UNKNOWN or release == UNKNOWN:
        return result_list
    
    # Load the SMU information
    smu_loader = SMUInfoLoader(platform, release)
    smu_info_list= []
    smu_name_set = set()
    
    for line in smu_list:
        smu_name = get_smu_lookup_name(line)
        smu_info = smu_loader.get_smu_info(smu_name)
        
        if smu_info is None or smu_name in smu_name_set:  
            continue

        smu_name_set.add(smu_name)
        smu_info_list.append(smu_info)
        
    if len(smu_info_list) > 0:
        # Exclude all the superseded SMUs in smu_info_list
        excluded_supersede_list = get_excluded_supersede_list(smu_info_list)
       
        missing_required_prerequisite_dict = \
            get_missing_required_prerequisites(smu_loader, excluded_supersede_list)
        
        missing_required_prerequisite_set = get_unique_set_from_dict(missing_required_prerequisite_dict)
        for pre_requisite_smu in missing_required_prerequisite_set:
            result_list.append(pre_requisite_smu + '.' + smu_loader.file_suffix)
                
    return result_list
Beispiel #7
0
def api_create_download_jobs():
    try:
        server_id = request.form.get("server_id")
        server_directory = request.form.get("server_directory")
        smu_list = request.form.get("smu_list").split()
        pending_downloads = request.form.get("pending_downloads").split()

        # Derives the platform and release using the first SMU name.
        if len(smu_list) > 0 and len(pending_downloads) > 0:
            platform, release = SMUInfoLoader.get_platform_and_release(smu_list)

            create_download_jobs(DBSession(), platform, release, pending_downloads, server_id, server_directory, current_user.username)
        return jsonify({'status': 'OK'})
    except:
        logger.exception('api_create_download_jobs() hit exception')
        return jsonify({'status': 'Failed'})
Beispiel #8
0
def api_create_download_jobs():
    try:
        server_id = request.form.get("server_id")
        server_directory = request.form.get("server_directory")
        smu_list = request.form.get("smu_list").split()
        pending_downloads = request.form.get("pending_downloads").split()

        # Derives the platform and release using the first SMU name.
        if len(smu_list) > 0 and len(pending_downloads) > 0:
            platform, release = SMUInfoLoader.get_platform_and_release(
                smu_list)

            create_download_jobs(DBSession(), platform, release,
                                 pending_downloads, server_id,
                                 server_directory, current_user.username)
        return jsonify({'status': 'OK'})
    except:
        logger.exception('api_create_download_jobs() hit exception')
        return jsonify({'status': 'Failed'})
Beispiel #9
0
 def write_software_profile_info(self):
     self.ws.write(self.row, 0, 'Software Profile: ' + self.conformance_report.software_profile, self.style_bold)
     self.row += 2
 
     software_profile_packages = self.conformance_report.software_profile_packages.split(',')
     
     smu_loader = None
     platform, release = SMUInfoLoader.get_platform_and_release(software_profile_packages)
     if platform != UNKNOWN and release != UNKNOWN:
         smu_loader = SMUInfoLoader(platform, release)
     
     for software_profile_package in software_profile_packages:
         self.ws.write(self.row, 0, software_profile_package)
         if smu_loader is not None and smu_loader.is_valid:
             smu_info = smu_loader.get_smu_info(software_profile_package.replace('.' + smu_loader.file_suffix,''))
             if smu_info is not None:
                 self.ws.write(self.row, 1, smu_info.description)
         
         self.row += 1  
     
     self.row += 1
Beispiel #10
0
def api_get_conformance_report_software_profile_packages(id):
    rows = []
    db_session = DBSession()

    conformance_report = get_conformance_report_by_id(db_session, id)
    if conformance_report is not None:
        software_profile_packages = conformance_report.software_profile_packages.split(',')

        smu_loader = None
        platform, release = SMUInfoLoader.get_platform_and_release(software_profile_packages)
        if platform != UNKNOWN and release != UNKNOWN:
            smu_loader = SMUInfoLoader(platform, release)

        for software_profile_package in software_profile_packages:
            description = ''
            if smu_loader is not None and smu_loader.is_valid:
                smu_info = smu_loader.get_smu_info(software_profile_package.replace('.' + smu_loader.file_suffix,''))
                if smu_info is not None:
                    description = smu_info.description

            rows.append({'software_profile_package': software_profile_package,
                         'description': description})

    return jsonify(**{'data': rows})
Beispiel #11
0
def get_download_info_dict(smu_list):
    """
    Given a SMU list, return a dictionary which contains
    key: smu name in smu_list
    value: cco filename  (can be None if smu_name is not in the XML file)
    """
    download_info_dict = {}
    platform, release = SMUInfoLoader.get_platform_and_release(smu_list)
    
    if platform == UNKNOWN or release == UNKNOWN:
        return download_info_dict, None
    
    # Load the SMU information
    smu_loader = SMUInfoLoader(platform, release)
    for smu_name in smu_list:
        lookup_name = get_smu_lookup_name(smu_name)
        smu_info = smu_loader.get_smu_info(lookup_name)
        if smu_info is not None:
            # Return back the same name (i.e. smu_name)
            download_info_dict[smu_name] = smu_info.cco_filename
        else:
            download_info_dict[smu_name] = None
            
    return download_info_dict, smu_loader
Beispiel #12
0
def create_or_update_install_job(db_session,
                                 host_id,
                                 install_action,
                                 scheduled_time,
                                 software_packages=[],
                                 server_id=-1,
                                 server_directory='',
                                 custom_command_profile_ids=[],
                                 dependency=0,
                                 pending_downloads=[],
                                 created_by=None,
                                 install_job=None):

    if not type(software_packages) is list:
        raise ValueError('software_packages must be a list type')

    if not type(custom_command_profile_ids) is list:
        raise ValueError('custom_command_profile_ids must be a list type')

    if not type(pending_downloads) is list:
        raise ValueError('pending_downloads must be a list type')

    # This is a new install_job
    if install_job is None:
        install_job = InstallJob()
        install_job.host_id = host_id
        db_session.add(install_job)

    install_job.install_action = install_action

    if install_job.install_action == InstallAction.INSTALL_ADD and not is_empty(
            pending_downloads):
        install_job.pending_downloads = ','.join(pending_downloads)
    else:
        install_job.pending_downloads = ''

    install_job.scheduled_time = get_datetime(scheduled_time)

    # Only Install Add and Pre-Migrate should have server_id and server_directory
    if install_action == InstallAction.INSTALL_ADD or install_action == InstallAction.PRE_MIGRATE:
        install_job.server_id = int(server_id) if int(server_id) > 0 else None
        install_job.server_directory = server_directory
    else:
        install_job.server_id = None
        install_job.server_directory = ''

    install_job_packages = []

    # Only the following install actions should have software packages
    if install_action == InstallAction.INSTALL_ADD or \
        install_action == InstallAction.INSTALL_ACTIVATE or \
        install_action == InstallAction.INSTALL_REMOVE or \
        install_action == InstallAction.INSTALL_DEACTIVATE or \
        install_action == InstallAction.PRE_MIGRATE:

        for software_package in software_packages:
            if install_action == InstallAction.INSTALL_ADD:
                if is_file_acceptable_for_install_add(software_package):
                    install_job_packages.append(software_package)
            else:
                # Install Activate can have external or internal package names
                install_job_packages.append(software_package)

    install_job.packages = ','.join(install_job_packages)
    install_job.dependency = dependency if dependency > 0 else None

    user = get_user(db_session, created_by)
    install_job.created_by = created_by
    install_job.user_id = None if user is None else user.id

    if install_action == InstallAction.PRE_UPGRADE or install_action == InstallAction.POST_UPGRADE or \
       install_action == InstallAction.PRE_MIGRATE or install_action == InstallAction.MIGRATE_SYSTEM or \
       install_action == InstallAction.POST_MIGRATE:
        install_job.custom_command_profile_ids = ','.join(
            custom_command_profile_ids) if custom_command_profile_ids else None

    # Resets the following fields
    install_job.status = None
    install_job.status_time = None
    install_job.session_log = None
    install_job.trace = None

    if install_job.install_action != InstallAction.UNKNOWN:
        db_session.commit()

    # Creates download jobs if needed
    if install_job.install_action == InstallAction.INSTALL_ADD and \
        len(install_job.packages) > 0 and \
        len(install_job.pending_downloads) > 0:

        # Use the SMU name to derive the platform and release strings
        smu_list = install_job.packages.split(',')
        pending_downloads = install_job.pending_downloads.split(',')

        # Derives the platform and release using the first SMU name.
        platform, release = SMUInfoLoader.get_platform_and_release(smu_list)

        create_download_jobs(db_session, platform, release, pending_downloads,
                             install_job.server_id,
                             install_job.server_directory, created_by)

    return install_job
Beispiel #13
0
def create_or_update_install_job(db_session, host_id, install_action, scheduled_time, software_packages=[],
                                 server_id=-1, server_directory='', custom_command_profile_ids=[], dependency=0,
                                 pending_downloads=[], created_by=None, install_job=None):

    if not type(software_packages) is list:
        raise ValueError('software_packages must be a list type')

    if not type(custom_command_profile_ids) is list:
        raise ValueError('custom_command_profile_ids must be a list type')

    if not type(pending_downloads) is list:
        raise ValueError('pending_downloads must be a list type')

    # This is a new install_job
    if install_job is None:
        install_job = InstallJob()
        install_job.host_id = host_id
        db_session.add(install_job)

    install_job.install_action = install_action

    if install_job.install_action == InstallAction.INSTALL_ADD and not is_empty(pending_downloads):
        install_job.pending_downloads = ','.join(pending_downloads)
    else:
        install_job.pending_downloads = ''

    install_job.scheduled_time = get_datetime(scheduled_time)

    # Only Install Add and Pre-Migrate should have server_id and server_directory
    if install_action == InstallAction.INSTALL_ADD or install_action == InstallAction.PRE_MIGRATE:
        install_job.server_id = int(server_id) if int(server_id) > 0 else None
        install_job.server_directory = server_directory
    else:
        install_job.server_id = None
        install_job.server_directory = ''

    install_job_packages = []

    # Only the following install actions should have software packages
    if install_action == InstallAction.INSTALL_ADD or \
        install_action == InstallAction.INSTALL_ACTIVATE or \
        install_action == InstallAction.INSTALL_REMOVE or \
        install_action == InstallAction.INSTALL_DEACTIVATE or \
        install_action == InstallAction.PRE_MIGRATE:

        for software_package in software_packages:
            if install_action == InstallAction.INSTALL_ADD:
                if is_file_acceptable_for_install_add(software_package):
                    install_job_packages.append(software_package)
            else:
                # Install Activate can have external or internal package names
                install_job_packages.append(software_package)

    install_job.packages = ','.join(install_job_packages)
    install_job.dependency = dependency if dependency > 0 else None

    user = get_user(db_session, created_by)
    install_job.created_by = created_by
    install_job.user_id = None if user is None else user.id

    if install_action == InstallAction.PRE_UPGRADE or install_action == InstallAction.POST_UPGRADE or \
       install_action == InstallAction.PRE_MIGRATE or install_action == InstallAction.MIGRATE_SYSTEM or \
       install_action == InstallAction.POST_MIGRATE:
        install_job.custom_command_profile_ids = ','.join(custom_command_profile_ids) if custom_command_profile_ids else None

    # Resets the following fields
    install_job.status = None
    install_job.status_time = None
    install_job.session_log = None
    install_job.trace = None

    if install_job.install_action != InstallAction.UNKNOWN:
        db_session.commit()

    # Creates download jobs if needed
    if install_job.install_action == InstallAction.INSTALL_ADD and \
        len(install_job.packages) > 0 and \
        len(install_job.pending_downloads) > 0:

        # Use the SMU name to derive the platform and release strings
        smu_list = install_job.packages.split(',')
        pending_downloads = install_job.pending_downloads.split(',')

        # Derives the platform and release using the first SMU name.
        platform, release = SMUInfoLoader.get_platform_and_release(smu_list)

        create_download_jobs(db_session, platform, release, pending_downloads,
                             install_job.server_id, install_job.server_directory, created_by)

    return install_job
Beispiel #14
0
def get_optimized_list(smu_list):
    """
    Returns the validated list given the SMU/SP list.
    A smu_list may contain packages, SMUs, SPs, or junk texts.
    """
    unrecognized_list = []
    package_list = []
    result_list = []
    
    # Identify the platform and release
    platform, release = SMUInfoLoader.get_platform_and_release(smu_list)
    
    if platform == UNKNOWN or release == UNKNOWN:
        for line in smu_list:
            result_list.append({'smu_entry': line, 'is': 'Unrecognized', 'description': ''})
        return result_list
    
    # Load the SMU information
    smu_loader = SMUInfoLoader(platform, release)
    
    file_suffix = smu_loader.file_suffix
    smu_info_list = []
    smu_name_set = set()
    
    for line in smu_list:
        smu_name = get_smu_lookup_name(line)
        smu_info = smu_loader.get_smu_info(smu_name)
        
        if smu_info is None:
            # Check if the entry is a package type
            platform, release = SMUInfoLoader.get_platform_and_release(smu_name)
            if platform == UNKNOWN:
                unrecognized_list.append(smu_name)
            else:
                package_list.append(smu_name)
            continue
        
        if smu_name in smu_name_set:
            continue
    
        smu_name_set.add(smu_name)
        smu_info_list.append(smu_info)
        
    if len(smu_info_list) > 0:
        # Exclude all the superseded SMUs in smu_info_list
        excluded_supersede_list = get_excluded_supersede_list(smu_info_list)
       
        missing_required_prerequisite_dict = \
            get_missing_required_prerequisites(smu_loader, excluded_supersede_list)
        
        missing_required_prerequisite_set = get_unique_set_from_dict(missing_required_prerequisite_dict)
        for pre_requisite_smu in missing_required_prerequisite_set:
            pre_requisite_smu_info = smu_loader.get_smu_info(pre_requisite_smu)
            description = pre_requisite_smu_info.description if pre_requisite_smu_info is not None else ''
            result_list.append({'smu_entry': pre_requisite_smu + '.' + file_suffix,
                                'is': 'Pre-requisite', 'description':description})
                
        excluded_supersede_dict = get_dict_from_list(excluded_supersede_list)
        
        for smu_info in smu_info_list:
            if smu_info.name not in excluded_supersede_dict:
                result_list.append({'smu_entry': smu_info.name + '.' + file_suffix,
                                    'is': 'Superseded', 'description': smu_info.description})
            else:
                result_list.append({'smu_entry': smu_info.name + '.' + file_suffix,
                                    'is': 'SMU/SP', 'description': smu_info.description})
    
    if len(package_list) > 0:
        for entry in package_list:
            result_list.append({'smu_entry': entry, 'is': 'Package', 'description': ''})
            
    if len(unrecognized_list) > 0:
        for entry in unrecognized_list:
            result_list.append({'smu_entry': entry, 'is': 'Unrecognized', 'description': ''})

    return result_list