Beispiel #1
0
def set_tape_file_number(drive, num=0):
    if num == 0:
        return rewind_tape(drive)

    current_num = get_tape_file_number(drive)

    if num < current_num:
        op = 'bsfm'
        new_num = current_num - num + 1
    else:
        new_num = num - current_num

        if new_num > 0:
            op = 'fsf'
        elif new_num == 0:
            return

    cmd = 'mt -f %s %s %d' % (drive, op, new_num)
    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    out, err = p.communicate()

    if p.returncode == 1:
        raise MTInvalidOperationOrDeviceNameException(err)

    elif p.returncode == 2:
        raise MTFailedOperationException(err)

    return out
Beispiel #2
0
def set_tape_file_number(drive, num=0):
    if num == 0:
        return rewind_tape(drive)

    current_num = get_tape_file_number(drive)

    new_num, op = get_tape_op_and_count(current_num, num)

    cmd = 'mt -f %s %s %d' % (drive, op, new_num)
    p = Popen(cmd,
              shell=True,
              stdout=PIPE,
              stderr=PIPE,
              universal_newlines=True)
    logger.debug('Setting file number of {drive} to {num}: {cmd}'.format(
        num=num, drive=drive, cmd=cmd))
    out, err = p.communicate()

    if p.returncode:
        logger.error(
            'Failed to set tape file number of {drive} to {num}: {err}'.format(
                drive=drive, num=num, err=err))

    if p.returncode == 1:
        raise MTInvalidOperationOrDeviceNameException(err)
    elif p.returncode == 2:
        raise MTFailedOperationException(err)

    logger.debug('File number of {drive} set to {num}'.format(num=num,
                                                              drive=drive))
    return out
Beispiel #3
0
def rewind_tape(drive):
    """
    Rewinds the tape in the given drive
    """

    cmd = 'mt -f %s rewind' % (drive)
    p = Popen(cmd,
              shell=True,
              stdout=PIPE,
              stderr=PIPE,
              universal_newlines=True)
    logger.debug('Rewinding tape in {drive}: {cmd}'.format(drive=drive,
                                                           cmd=cmd))
    out, err = p.communicate()

    if p.returncode:
        logger.error(
            'Failed to rewind tape in {drive}, err: {err}, returncode: {rcode}'
            .format(drive=drive, err=err, rcode=p.returncode))

    if p.returncode == 1:
        raise MTInvalidOperationOrDeviceNameException(err)
    elif p.returncode == 2:
        raise MTFailedOperationException(err)

    logger.debug('Rewinded tape in {drive}'.format(drive=drive))
    return out
Beispiel #4
0
def set_tape_file_number(drive, num=0):
    if num == 0:
        return rewind_tape(drive)

    current_num = get_tape_file_number(drive)

    if num < current_num:
        op = 'bsfm'
        new_num = current_num - num + 1
    else:
        new_num = num - current_num

        if new_num > 0:
            op = 'fsf'
        elif new_num == 0:
            # We are already on the correct file, ensure we are at the beginning
            op = 'bsfm'
            new_num = 1

    cmd = 'mt -f %s %s %d' % (drive, op, new_num)
    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    logger.debug('Setting file number of {drive} to {num}: {cmd}'.format(num=num, drive=drive, cmd=cmd))
    out, err = p.communicate()

    if p.returncode:
        logger.error('Failed to set tape file number of {drive} to {num}: {err}'.format(drive=drive, num=num, err=err))

    if p.returncode == 1:
        raise MTInvalidOperationOrDeviceNameException(err)
    elif p.returncode == 2:
        raise MTFailedOperationException(err)

    logger.debug('File number of {drive} set to {num}'.format(num=num, drive=drive))
    return out
Beispiel #5
0
def get_tape_file_number(drive):
    cmd = 'mt -f %s status | grep -i "file number"' % drive
    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    out, err = p.communicate()

    if p.returncode == 1:
        raise MTInvalidOperationOrDeviceNameException(err)

    elif p.returncode == 2:
        raise MTFailedOperationException(err)

    return int(out.split(',')[0].split('=')[1])
Beispiel #6
0
def rewind_tape(drive):
    """
    Rewinds the tape in the given drive
    """

    cmd = 'mt -f %s rewind' % (drive)
    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    out, err = p.communicate()

    if p.returncode == 1:
        raise MTInvalidOperationOrDeviceNameException(err)

    elif p.returncode == 2:
        raise MTFailedOperationException(err)

    return out
Beispiel #7
0
def get_tape_file_number(drive):
    cmd = 'mt -f %s status | grep -i "file number"' % drive
    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    logger.debug('Getting tape file number of {drive}: {cmd}'.format(drive=drive, cmd=cmd))
    out, err = p.communicate()

    if p.returncode:
        logger.error('Failed to get tape file number of {drive}'.format(drive=drive))

    if p.returncode == 1:
        raise MTInvalidOperationOrDeviceNameException(err)
    elif p.returncode == 2:
        raise MTFailedOperationException(err)

    file_number = int(out.split(',')[0].split('=')[1])
    logger.debug('Got {num} as file number of {drive}'.format(num=file_number, drive=drive))
    return file_number