Example #1
0
def update_repo(file_paths):
    '''This function accept a directory path or csv format and run createrepo_c on it'''
    if len(file_paths) > 0:
        for f_path in set(file_paths.split(',')):
            try:
                # All repodata we have is under 'RPMS' directory
                # let's do a check on this first
                basepath = os.path.dirname(f_path)
                if os.path.exists(basepath) and os.path.basename(basepath) == 'RPMS':
                    pkgutils.updaterepos([basepath], action_logger)
                else:
                    raise PkgeventError('[ERROR] %s does not exist or not conform to rpm repo directory format') 
            except:
                status="FAIL"
                action_logger.info("[FAIL] update_repo %s" % f_path)
            else:
                status="SUCCESS"
                action_logger.info("[SUCCESS] update_repo %s" % f_path)

    # Log and send the response
    log_and_format_response_msg("update_repo", file_paths, status)
Example #2
0
def rsync_file(files):
    '''
    Support for both individual file input or csv format
    These files are to be rsynced over from the yum-master
    '''
    rsync = '/usr/bin/rsync'
    rsync_user = '******'
    rsync_args = [
        '-qaplH', '--password-file=/root/rsync_yum_password', '--delete-delay',
        '--delay-updates'
    ]
    to_update_list = []

    if len(files) > 0:
        rpms = files.split(',')
        for rpm in rpms:
            remote_file = rpm[
                1:]  #remove the '/' at the start, data0 is the rsync exposed module
            rsync_url = "%s@%s::%s" % (rsync_user, yum_master,
                                       remote_file.strip())
            local_file = rpm

            #flatten out the command to run, sum() expects all args to be lists,
            cmd = sum([[rsync], rsync_args, [rsync_url], [local_file]], [])

            if pkgutils.run_cmd(cmd, action_logger) == True:
                status = "SUCCESS"
                #rsync completed successfully, we add this to our updaterepo list
                if os.path.dirname(local_file) not in to_update_list:
                    if os.path.basename(os.path.dirname(local_file)) == 'RPMS':
                        to_update_list.append(os.path.dirname(local_file))
            else:
                status = "FAIL"

    #append to our to_update_list we run createrepo on this list
    if len(to_update_list) > 0:
        pkgutils.updaterepos(to_update_list, action_logger)

    # Log and send the response
    log_and_format_response_msg("rsync", files, status)
Example #3
0
def rsync_file(files):
    '''
    Support for both individual file input or csv format
    These files are to be rsynced over from the yum-master
    '''
    rsync      = '/usr/bin/rsync'
    rsync_user = '******'
    rsync_args = [ '-qaplH',
                   '--password-file=/root/rsync_yum_password',
                   '--delete-delay',
                   '--delay-updates'
                 ]
    to_update_list=[]

    if len(files) > 0:
        rpms = files.split(',')
        for rpm in rpms:
            remote_file = rpm[1:]  #remove the '/' at the start, data0 is the rsync exposed module
            rsync_url   = "%s@%s::%s" % (rsync_user, yum_master, remote_file.strip())
            local_file  = rpm

            #flatten out the command to run, sum() expects all args to be lists,
            cmd = sum([ [rsync], rsync_args, [rsync_url], [local_file] ], [])

            if pkgutils.run_cmd(cmd, action_logger) == True :
                status="SUCCESS"
                #rsync completed successfully, we add this to our updaterepo list
                if os.path.dirname(local_file) not in to_update_list:
                    if os.path.basename(os.path.dirname(local_file)) == 'RPMS':
                        to_update_list.append(os.path.dirname(local_file))
            else:
                status="FAIL"

    #append to our to_update_list we run createrepo on this list
    if len(to_update_list) > 0:
        pkgutils.updaterepos(to_update_list, action_logger)
    
    # Log and send the response 
    log_and_format_response_msg("rsync", files, status)
Example #4
0
def delete_file(files):
    to_update_list = []
    if len(files) > 0:
        rpms = files.split(',')
        for rpm in rpms:
            try:
                os.remove(rpm)
            except:
                status="FAIL"
                action_logger.info("[FAIL] delete %s" % rpm)
            else:
                status="SUCCESS"
                action_logger.info("[SUCCESS] delete %s" % rpm)
                # Only updaterepo if the dir path is with "RPMS"
                if os.path.dirname(rpm) not in to_update_list:
                    if os.path.basename(os.path.dirname(rpm)) == 'RPMS':
                        to_update_list.append(os.path.dirname(rpm))

    if len(to_update_list) > 0:
        pkgutils.updaterepos(to_update_list, action_logger)

    # Log and send the response
    log_and_format_response_msg("delete", files, status)
Example #5
0
def delete_file(files):
    to_update_list = []
    if len(files) > 0:
        rpms = files.split(',')
        for rpm in rpms:
            try:
                os.remove(rpm)
            except:
                status = "FAIL"
                action_logger.info("[FAIL] delete %s" % rpm)
            else:
                status = "SUCCESS"
                action_logger.info("[SUCCESS] delete %s" % rpm)
                # Only updaterepo if the dir path is with "RPMS"
                if os.path.dirname(rpm) not in to_update_list:
                    if os.path.basename(os.path.dirname(rpm)) == 'RPMS':
                        to_update_list.append(os.path.dirname(rpm))

    if len(to_update_list) > 0:
        pkgutils.updaterepos(to_update_list, action_logger)

    # Log and send the response
    log_and_format_response_msg("delete", files, status)
Example #6
0
def update_repo(file_paths):
    '''This function accept a directory path or csv format and run createrepo_c on it'''
    if len(file_paths) > 0:
        for f_path in set(file_paths.split(',')):
            try:
                # All repodata we have is under 'RPMS' directory
                # let's do a check on this first
                basepath = os.path.dirname(f_path)
                if os.path.exists(basepath) and os.path.basename(
                        basepath) == 'RPMS':
                    pkgutils.updaterepos([basepath], action_logger)
                else:
                    raise PkgeventError(
                        '[ERROR] %s does not exist or not conform to rpm repo directory format'
                    )
            except:
                status = "FAIL"
                action_logger.info("[FAIL] update_repo %s" % f_path)
            else:
                status = "SUCCESS"
                action_logger.info("[SUCCESS] update_repo %s" % f_path)

    # Log and send the response
    log_and_format_response_msg("update_repo", file_paths, status)