Installs the given image on the device. After the installation is complete\
     the device is rebooted,
    if reboot=True is given as a keyworded argument.

    path (required)
        Path where the image file is present on the proxy minion

    remote_path :
        If the value of path  is a file path on the local
        (Salt host's) filesystem, then the image is copied from the local
        filesystem to the :remote_path: directory on the target Junos
        device. The default is ``/var/tmp``. If the value of :path: or
        is a URL, then the value of :remote_path: is unused.

    dev_timeout : 30
        The NETCONF RPC timeout (in seconds). This argument was added since most of
        the time the "package add" RPC takes a significant amount of time.  The default
        RPC timeout is 30 seconds.  So this :timeout: value will be
        used in the context of the SW installation process.  Defaults to
        30 minutes (30*60=1800)

    reboot : False
        Whether to reboot after installation

    no_copy : False
        If ``True`` the software package will not be SCP’d to the device

    bool validate:
        When ``True`` this method will perform a config validation against
        the new image

    bool issu:
        When ``True`` allows unified in-service software upgrade
        (ISSU) feature enables you to upgrade between two different Junos OS
        releases with no disruption on the control plane and with minimal
        disruption of traffic.

    bool nssu:
        When ``True`` allows nonstop software upgrade (NSSU)
        enables you to upgrade the software running on a Juniper Networks
        EX Series Virtual Chassis or a Juniper Networks EX Series Ethernet
        Switch with redundant Routing Engines with a single command and
        minimal disruption to network traffic.

    CLI Examples:

    .. code-block:: bash

        salt 'device_name' junos.install_os 'salt://images/junos_image.tgz' reboot=True
        salt 'device_name' junos.install_os 'salt://junos_16_1.tgz' dev_timeout=300

def install_os(path=None, **kwargs):
    '''
    Installs the given image on the device. After the installation is complete\
     the device is rebooted,
    if reboot=True is given as a keyworded argument.

    path (required)
        Path where the image file is present on the proxy minion

    remote_path :
        If the value of path  is a file path on the local
        (Salt host's) filesystem, then the image is copied from the local
        filesystem to the :remote_path: directory on the target Junos
        device. The default is ``/var/tmp``. If the value of :path: or
        is a URL, then the value of :remote_path: is unused.

    dev_timeout : 30
        The NETCONF RPC timeout (in seconds). This argument was added since most of
        the time the "package add" RPC takes a significant amount of time.  The default
        RPC timeout is 30 seconds.  So this :timeout: value will be
        used in the context of the SW installation process.  Defaults to
        30 minutes (30*60=1800)

    reboot : False
        Whether to reboot after installation

    no_copy : False
        If ``True`` the software package will not be SCP’d to the device

    bool validate:
        When ``True`` this method will perform a config validation against
        the new image

    bool issu:
        When ``True`` allows unified in-service software upgrade
        (ISSU) feature enables you to upgrade between two different Junos OS
        releases with no disruption on the control plane and with minimal
        disruption of traffic.

    bool nssu:
        When ``True`` allows nonstop software upgrade (NSSU)
        enables you to upgrade the software running on a Juniper Networks
        EX Series Virtual Chassis or a Juniper Networks EX Series Ethernet
        Switch with redundant Routing Engines with a single command and
        minimal disruption to network traffic.

    CLI Examples:

    .. code-block:: bash

        salt 'device_name' junos.install_os 'salt://images/junos_image.tgz' reboot=True
        salt 'device_name' junos.install_os 'salt://junos_16_1.tgz' dev_timeout=300
    '''
    conn = __proxy__['junos.conn']()
    ret = {}
    ret['out'] = True

    op = {}
    if '__pub_arg' in kwargs:
        if kwargs['__pub_arg']:
            if isinstance(kwargs['__pub_arg'][-1], dict):
                op.update(kwargs['__pub_arg'][-1])
    else:
        op.update(kwargs)

    no_copy_ = op.get('no_copy', False)

    if path is None:
        ret['message'] = \
            'Please provide the salt path where the junos image is present.'
        ret['out'] = False
        return ret

    if not no_copy_:
        image_cached_path = salt.utils.files.mkstemp()
        __salt__['cp.get_file'](path, image_cached_path)

        if not os.path.isfile(image_cached_path):
            ret['message'] = 'Invalid image path.'
            ret['out'] = False
            return ret

        if os.path.getsize(image_cached_path) == 0:
            ret['message'] = 'Failed to copy image'
            ret['out'] = False
            return ret
        path = image_cached_path

    try:
        conn.sw.install(path, progress=True, **op)
        ret['message'] = 'Installed the os.'
    except Exception as exception:
        ret['message'] = 'Installation failed due to: "{0}"'.format(exception)
        ret['out'] = False
        return ret
    finally:
        if not no_copy_:
            salt.utils.files.safe_rm(image_cached_path)

    if 'reboot' in op and op['reboot'] is True:
        try:
            conn.sw.reboot()
        except Exception as exception:
            ret['message'] = \
                'Installation successful but reboot failed due to : "{0}"' \
                .format(exception)
            ret['out'] = False
            return ret
        ret['message'] = 'Successfully installed and rebooted!'

    return ret