Ensures that a software version is downloaded.

    name: The name of the module function to execute.

    version(str): The software version to check. If this version is not already downloaded, it will attempt to download
    the file from Palo Alto.

    synch(bool): If true, after downloading the file it will be synched to its peer.

    check(bool): If true, the PANOS device will first attempt to pull the most recent software inventory list from Palo
    Alto.

    SLS Example:

    .. code-block:: yaml

        panos/version8.0.0:
            panos.download_software:
              - version: 8.0.0
              - synch: False
              - check: True

def download_software(name, version=None, synch=False, check=False):
    '''
    Ensures that a software version is downloaded.

    name: The name of the module function to execute.

    version(str): The software version to check. If this version is not already downloaded, it will attempt to download
    the file from Palo Alto.

    synch(bool): If true, after downloading the file it will be synched to its peer.

    check(bool): If true, the PANOS device will first attempt to pull the most recent software inventory list from Palo
    Alto.

    SLS Example:

    .. code-block:: yaml

        panos/version8.0.0:
            panos.download_software:
              - version: 8.0.0
              - synch: False
              - check: True

    '''
    ret = _default_ret(name)

    if check is True:
        __salt__['panos.check_software']()

    versions = __salt__['panos.get_software_info']()['result']

    if 'sw-updates' not in versions \
        or 'versions' not in versions['sw-updates'] \
        or 'entry' not in versions['sw-updates']['versions']:
        ret.update({
            'comment': 'Software version is not found in the local software list.',
            'result': False
        })
        return ret

    for entry in versions['sw-updates']['versions']['entry']:
        if entry['version'] == version and entry['downloaded'] == "yes":
            ret.update({
                'comment': 'Software version is already downloaded.',
                'result': True
            })
        return ret

    ret.update({
        'changes': __salt__['panos.download_software_version'](version=version, synch=synch)
    })

    versions = __salt__['panos.get_software_info']()['result']

    if 'sw-updates' not in versions \
        or 'versions' not in versions['sw-updates'] \
        or 'entry' not in versions['sw-updates']['versions']:
        ret.update({
            'result': False
        })
        return ret

    for entry in versions['sw-updates']['versions']['entry']:
        if entry['version'] == version and entry['downloaded'] == "yes":
            ret.update({
                'result': True
            })
        return ret

    return ret