Beispiel #1
0
def get_platform_and_release(package_list):
    platform = UNKNOWN
    release = UNKNOWN
    
    # Identify the platform and release
    for line in package_list:
        platform = get_platform(line)
        release = get_release(line)
        
        if platform != UNKNOWN and release != UNKNOWN:
            break
        
    return platform, release
Beispiel #2
0
def get_platform_and_release(package_list):
    platform = UNKNOWN
    release = UNKNOWN
    
    # Identify the platform and release
    for line in package_list:
        platform = get_platform(line)
        release = get_release(line)
        
        if platform != UNKNOWN and release != UNKNOWN:
            break
        
    return platform, release
Beispiel #3
0
def get_platform_and_release(package_list):
    """
    Given a package list (SMU/SP/Pacages), return the platform and release.
    """
    platform = UNKNOWN
    release = UNKNOWN
    
    # Identify the platform and release
    for line in package_list:
        platform = get_platform(line)
        release = get_release(line)
        
        if platform != UNKNOWN and release != UNKNOWN:
            break
        
    return platform, release
Beispiel #4
0
def get_platform_and_release(package_list):
    """
    Given a package list (SMU/SP/Pacages), return the platform and release.
    """
    platform = UNKNOWN
    release = UNKNOWN

    # Identify the platform and release
    for line in package_list:
        platform = get_platform(line)
        release = get_release(line)

        if platform != UNKNOWN and release != UNKNOWN:
            break

    return platform, release
Beispiel #5
0
def get_validated_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 = 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
            if get_platform(smu_name) == 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
Beispiel #6
0
def create_or_update_install_job(
    db_session, host_id, install_action, scheduled_time, software_packages=None,
    server=-1, server_directory='', custom_command_profile=-1, dependency=0, pending_downloads=None, install_job=None):

    # 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.split())
    else:
        install_job.pending_downloads = ''

    install_job.scheduled_time = get_datetime(scheduled_time, "%m/%d/%Y %I:%M %p")

    # Only Install Add should have server_id and server_directory
    if install_action == InstallAction.INSTALL_ADD:
        install_job.server_id = int(server) if int(server) > 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:

        software_packages = software_packages.split() if software_packages is not None else []
        for software_package in software_packages:
            if install_action == InstallAction.INSTALL_ADD:
                # Install Add only accepts external package names with the following suffix
                if '.pie' in software_package or \
                    '.tar' in software_package or \
                    '.rpm' in 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
    install_job.created_by = current_user.username
    install_job.user_id = current_user.id

    if install_action == InstallAction.PRE_UPGRADE or install_action == InstallAction.POST_UPGRADE:
        install_job.custom_command_profile_id = custom_command_profile if custom_command_profile 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 = get_platform(smu_list[0])
        release = get_release(smu_list[0])

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

    return install_job
Beispiel #7
0
def create_or_update_install_job(
    db_session, host_id, install_action, scheduled_time, software_packages=None,
    server=-1, server_directory='', custom_command_profile=-1, dependency=0, pending_downloads=None, install_job=None):

    # 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.split())
    else:
        install_job.pending_downloads = ''

    install_job.scheduled_time = get_datetime(scheduled_time, "%m/%d/%Y %I:%M %p")

    # Only Install Add should have server_id and server_directory
    if install_action == InstallAction.INSTALL_ADD:
        install_job.server_id = int(server) if int(server) > 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:

        software_packages = software_packages.split() if software_packages is not None else []
        for software_package in software_packages:
            if install_action == InstallAction.INSTALL_ADD:
                # Install Add only accepts external package names with the following suffix
                if '.pie' in software_package or \
                    '.tar' in software_package or \
                    '.rpm' in 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
    install_job.created_by = current_user.username
    install_job.user_id = current_user.id

    if install_action == InstallAction.PRE_UPGRADE or install_action == InstallAction.POST_UPGRADE:
        install_job.custom_command_profile_id = custom_command_profile if custom_command_profile 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 = get_platform(smu_list[0])
        release = get_release(smu_list[0])

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

    return install_job
Beispiel #8
0
def get_validated_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 = 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'})
        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
            if get_platform(smu_name) == 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