<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_source_ip_for_interface(source_ip_address, desired_source_ip_address, device_num=0):
 """Configures the source IP address for a Linux interface :param source_ip_address: (str) Source IP address to change :param desired_source_ip_address: (str) IP address to configure as the source in outgoing packets :param device_num: (int) Integer interface device number to configure :return: None :raises: TypeError, ValueError, OSError """

    log = logging.getLogger(mod_logger + '.set_source_ip_for_interface')
    if not isinstance(source_ip_address, basestring):
        msg = 'arg source_ip_address must be a string'
        log.error(msg)
        raise TypeError(msg)
    if not isinstance(desired_source_ip_address, basestring):
        msg = 'arg desired_source_ip_address must be a string'
        log.error(msg)
        raise TypeError(msg)
    if not validate_ip_address(ip_address=source_ip_address):
        msg = 'The arg source_ip_address was found to be an invalid IP address.  Please pass a valid IP address'
        log.error(msg)
        raise ValueError(msg)
    if not validate_ip_address(ip_address=desired_source_ip_address):
        msg = 'The arg desired_source_ip_address was found to be an invalid IP address.  Please pass a valid IP address'
        log.error(msg)
        raise ValueError(msg)

    # Determine the device name based on the device_num
    log.debug('Attempting to determine the device name based on the device_num arg...')
    try:
        int(device_num)
    except ValueError:
        if isinstance(device_num, basestring):
            device_name = device_num
            log.info('Provided device_num is not an int, assuming it is the full device name: {d}'.format(
                d=device_name))
        else:
            raise TypeError('device_num arg must be a string or int')
    else:
        device_name = 'eth{n}'.format(n=str(device_num))
        log.info('Provided device_num is an int, assuming device name is: {d}'.format(d=device_name))

    # Build the command
    # iptables -t nat -I POSTROUTING -o eth0 -s ${RA_ORIGINAL_IP} -j SNAT --to-source

    command = ['iptables', '-t', 'nat', '-I', 'POSTROUTING', '-o', device_name, '-s',
               source_ip_address, '-j', 'SNAT', '--to-source', desired_source_ip_address]
    log.info('Running command: {c}'.format(c=command))
    try:
        result = run_command(command, timeout_sec=20)
    except CommandError:
        _, ex, trace = sys.exc_info()
        msg = 'There was a problem running iptables command: {c}\n{e}'.format(c=' '.join(command), e=str(ex))
        log.error(msg)
        raise OSError, msg, trace

    if int(result['code']) != 0:
        msg = 'The iptables command produced an error with exit code: {c}, and output:\n{o}'.format(
            c=result['code'], o=result['output'])
        log.error(msg)
        raise OSError(msg)
    log.info('Successfully configured the source IP for {d} to be: {i}'.format(
        d=device_name, i=desired_source_ip_address))