%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/salt/modules/win_wua.pyc

�
���^c
@@ssdZddlmZmZmZddlZddlZddlZddl	Zddl
mZddlm
Z
yddlZeZWnek
r�eZnXeje�Zidd6Zd�Zeeeeeeeddd	�	Zeed
�Zeeeeddeed�Zd�Zd
�Zd�Zdddddddd�Z d�Z!d�Z"d�Z#dS(u�	
Module for managing Windows Updates using the Windows Update Agent.

List updates on the system using the following functions:

- :py:func:`win_wua.available <salt.modules.win_wua.available>`
- :py:func:`win_wua.list <salt.modules.win_wua.list_>`

This is an easy way to find additional information about updates available to
to the system, such as the GUID, KB number, or description.

Once you have the GUID or a KB number for the update you can get information
about the update, download, install, or uninstall it using these functions:

- :py:func:`win_wua.get <salt.modules.win_wua.get>`
- :py:func:`win_wua.download <salt.modules.win_wua.download>`
- :py:func:`win_wua.install <salt.modules.win_wua.install>`
- :py:func:`win_wua.uninstall <salt.modules.win_wua.uninstall>`

The get function expects a name in the form of a GUID, KB, or Title and should
return information about a single update. The other functions accept either a
single item or a list of items for downloading/installing/uninstalling a
specific list of items.

The :py:func:`win_wua.list <salt.modules.win_wua.list_>` and
:py:func:`win_wua.get <salt.modules.win_wua.get>` functions are utility
functions. In addition to returning information about updates they can also
download and install updates by setting ``download=True`` or ``install=True``.
So, with py:func:`win_wua.list <salt.modules.win_wua.list_>` for example, you
could run the function with the filters you want to see what is available. Then
just add ``install=True`` to install everything on that list.

If you want to download, install, or uninstall specific updates, use
:py:func:`win_wua.download <salt.modules.win_wua.download>`,
:py:func:`win_wua.install <salt.modules.win_wua.install>`, or
:py:func:`win_wua.uninstall <salt.modules.win_wua.uninstall>`. To update your
system with the latest updates use :py:func:`win_wua.list
<salt.modules.win_wua.list_>` and set ``install=True``

You can also adjust the Windows Update settings using the
:py:func:`win_wua.set_wu_settings <salt.modules.win_wua.set_wu_settings>`
function. This function is only supported on the following operating systems:

- Windows Vista / Server 2008
- Windows 7 / Server 2008R2
- Windows 8 / Server 2012
- Windows 8.1 / Server 2012R2

As of Windows 10 and Windows Server 2016, the ability to modify the Windows
Update settings has been restricted. The settings can be modified in the Local
Group Policy using the ``lgpo`` module.

.. versionadded:: 2015.8.0

:depends: salt.utils.win_update
i(tabsolute_importtunicode_literalstprint_functionN(tCommandExecutionError(tsixulistulist_cC@sItjjj�stdfSts,tdfStjjjsEtdfStS(u4
    Only works on Windows systems with PyWin32
    u%WUA: Only available on Window systemsuWUA: Requires PyWin32 librariesu8WUA: Missing Libraries required by salt.utils.win_update(tsalttutilstplatformt
is_windowstFalsetHAS_PYWIN32t
win_updatetTrue(((s8/usr/lib/python2.7/site-packages/salt/modules/win_wua.pyt__virtual__Ss


c	C@shtjjj�}	|	jd|d|d|d|d|d|d|d|�}
|r^|
j�S|
j�S(	ut
    .. versionadded:: 2017.7.0

    List updates that match the passed criteria. This allows for more filter
    options than :func:`list`. Good for finding a specific GUID or KB.

    Args:

        software (bool):
            Include software updates in the results (default is True)

        drivers (bool):
            Include driver updates in the results (default is True)

        summary (bool):
            - True: Return a summary of updates available for each category.
            - False (default): Return a detailed list of available updates.

        skip_installed (bool):
            Skip updates that are already installed. Default is False.

        skip_hidden (bool):
            Skip updates that have been hidden. Default is True.

        skip_mandatory (bool):
            Skip mandatory updates. Default is False.

        skip_reboot (bool):
            Skip updates that require a reboot. Default is False.

        categories (list):
            Specify the categories to list. Must be passed as a list. All
            categories returned by default.

            Categories include the following:

            * Critical Updates
            * Definition Updates
            * Drivers (make sure you set drivers=True)
            * Feature Packs
            * Security Updates
            * Update Rollups
            * Updates
            * Update Rollups
            * Windows 7
            * Windows 8.1
            * Windows 8.1 drivers
            * Windows 8.1 and later drivers
            * Windows Defender

        severities (list):
            Specify the severities to include. Must be passed as a list. All
            severities returned by default.

            Severities include the following:

            * Critical
            * Important

    Returns:

        dict: Returns a dict containing either a summary or a list of updates:

        .. code-block:: cfg

            List of Updates:
            {'<GUID>': {'Title': <title>,
                        'KB': <KB>,
                        'GUID': <the globally unique identifier for the update>
                        'Description': <description>,
                        'Downloaded': <has the update been downloaded>,
                        'Installed': <has the update been installed>,
                        'Mandatory': <is the update mandatory>,
                        'UserInput': <is user input required>,
                        'EULAAccepted': <has the EULA been accepted>,
                        'Severity': <update severity>,
                        'NeedsReboot': <is the update installed and awaiting reboot>,
                        'RebootBehavior': <will the update require a reboot>,
                        'Categories': [ '<category 1>',
                                        '<category 2>',
                                        ...]
                        }
            }

            Summary of Updates:
            {'Total': <total number of updates returned>,
             'Available': <updates that are not downloaded or installed>,
             'Downloaded': <updates that are downloaded but not installed>,
             'Installed': <updates installed (usually 0 unless installed=True)>,
             'Categories': { <category 1>: <total for that category>,
                             <category 2>: <total for category 2>,
                             ... }
            }

    CLI Examples:

    .. code-block:: bash

        # Normal Usage (list all software updates)
        salt '*' win_wua.available

        # List all updates with categories of Critical Updates and Drivers
        salt '*' win_wua.available categories=["Critical Updates","Drivers"]

        # List all Critical Security Updates
        salt '*' win_wua.available categories=["Security Updates"] severities=["Critical"]

        # List all updates with a severity of Critical
        salt '*' win_wua.available severities=["Critical"]

        # A summary of all available updates
        salt '*' win_wua.available summary=True

        # A summary of all Feature Packs and Windows 8.1 Updates
        salt '*' win_wua.available categories=["Feature Packs","Windows 8.1"] summary=True
    tskip_hiddentskip_installedtskip_mandatorytskip_reboottsoftwaretdriverst
categoriest
severities(RRRtWindowsUpdateAgentt	availabletsummarytlist(RRRRRRRRRtwuatupdates((s8/usr/lib/python2.7/site-packages/salt/modules/win_wua.pyRcs		cC@sytjjj�}|j|�}i}|s3|rI|j|�|d<n|re|j|�|d<n|ro|S|j�S(u�

    .. versionadded:: 2017.7.0

    Returns details for the named update

    Args:

        name (str):
            The name of the update you're searching for. This can be the GUID, a
            KB number, or any part of the name of the update. GUIDs and KBs are
            preferred. Run ``list`` to get the GUID for the update you're
            looking for.

        download (bool):
            Download the update returned by this function. Run this function
            first to see if the update exists, then set ``download=True`` to
            download the update.

        install (bool):
            Install the update returned by this function. Run this function
            first to see if the update exists, then set ``install=True`` to
            install the update.

    Returns:

        dict: Returns a dict containing a list of updates that match the name if
        download and install are both set to False. Should usually be a single
        update, but can return multiple if a partial name is given.

        If download or install is set to true it will return the results of the
        operation.

        .. code-block:: cfg

            List of Updates:
            {'<GUID>': {'Title': <title>,
                        'KB': <KB>,
                        'GUID': <the globally unique identifier for the update>
                        'Description': <description>,
                        'Downloaded': <has the update been downloaded>,
                        'Installed': <has the update been installed>,
                        'Mandatory': <is the update mandatory>,
                        'UserInput': <is user input required>,
                        'EULAAccepted': <has the EULA been accepted>,
                        'Severity': <update severity>,
                        'NeedsReboot': <is the update installed and awaiting reboot>,
                        'RebootBehavior': <will the update require a reboot>,
                        'Categories': [ '<category 1>',
                                        '<category 2>',
                                        ...]
                        }
            }

    CLI Examples:

    .. code-block:: bash

        # Recommended Usage using GUID without braces
        # Use this to find the status of a specific update
        salt '*' win_wua.get 12345678-abcd-1234-abcd-1234567890ab

        # Use the following if you don't know the GUID:

        # Using a KB number
        # Not all updates have an associated KB
        salt '*' win_wua.get KB3030298

        # Using part or all of the name of the update
        # Could possibly return multiple results
        # Not all updates have an associated KB
        salt '*' win_wua.get 'Microsoft Camera Codec Pack'
    uDownloaduInstall(RRRRtsearchtdownloadtinstallR(tnameRRRRtret((s8/usr/lib/python2.7/site-packages/salt/modules/win_wua.pytget�sJcC@s�tjjj�}|jd|d|d|d|d|�}	i}
|sN|rd|j|	�|
d<n|r�|j|	�|
d<n|
s�|r�|	j�S|	j�S|
S(u�
    .. versionadded:: 2017.7.0

    Returns a detailed list of available updates or a summary. If download or
    install is True the same list will be downloaded and/or installed.

    Args:

        software (bool):
            Include software updates in the results (default is True)

        drivers (bool):
            Include driver updates in the results (default is False)

        summary (bool):
            - True: Return a summary of updates available for each category.
            - False (default): Return a detailed list of available updates.

        skip_installed (bool):
            Skip installed updates in the results (default is False)

        download (bool):
            (Overrides reporting functionality) Download the list of updates
            returned by this function. Run this function first with
            ``download=False`` to see what will be downloaded, then set
            ``download=True`` to download the updates.

        install (bool):
            (Overrides reporting functionality) Install the list of updates
            returned by this function. Run this function first with
            ``install=False`` to see what will be installed, then set
            ``install=True`` to install the updates.

        categories (list):
            Specify the categories to list. Must be passed as a list. All
            categories returned by default.

            Categories include the following:

            * Critical Updates
            * Definition Updates
            * Drivers (make sure you set drivers=True)
            * Feature Packs
            * Security Updates
            * Update Rollups
            * Updates
            * Update Rollups
            * Windows 7
            * Windows 8.1
            * Windows 8.1 drivers
            * Windows 8.1 and later drivers
            * Windows Defender

        severities (list):
            Specify the severities to include. Must be passed as a list. All
            severities returned by default.

            Severities include the following:

            * Critical
            * Important

    Returns:

        dict: Returns a dict containing either a summary or a list of updates:

        .. code-block:: cfg

            List of Updates:
            {'<GUID>': {'Title': <title>,
                        'KB': <KB>,
                        'GUID': <the globally unique identifier for the update>
                        'Description': <description>,
                        'Downloaded': <has the update been downloaded>,
                        'Installed': <has the update been installed>,
                        'Mandatory': <is the update mandatory>,
                        'UserInput': <is user input required>,
                        'EULAAccepted': <has the EULA been accepted>,
                        'Severity': <update severity>,
                        'NeedsReboot': <is the update installed and awaiting reboot>,
                        'RebootBehavior': <will the update require a reboot>,
                        'Categories': [ '<category 1>',
                                        '<category 2>',
                                        ...]
                        }
            }

            Summary of Updates:
            {'Total': <total number of updates returned>,
             'Available': <updates that are not downloaded or installed>,
             'Downloaded': <updates that are downloaded but not installed>,
             'Installed': <updates installed (usually 0 unless installed=True)>,
             'Categories': { <category 1>: <total for that category>,
                             <category 2>: <total for category 2>,
                             ... }
            }

    CLI Examples:

    .. code-block:: bash

        # Normal Usage (list all software updates)
        salt '*' win_wua.list

        # List all updates with categories of Critical Updates and Drivers
        salt '*' win_wua.list categories=['Critical Updates','Drivers']

        # List all Critical Security Updates
        salt '*' win_wua.list categories=['Security Updates'] severities=['Critical']

        # List all updates with a severity of Critical
        salt '*' win_wua.list severities=['Critical']

        # A summary of all available updates
        salt '*' win_wua.list summary=True

        # A summary of all Feature Packs and Windows 8.1 Updates
        salt '*' win_wua.list categories=['Feature Packs','Windows 8.1'] summary=True
    RRRRRuDownloaduInstall(	RRRRRRRRR(RRRRRRRRRRR ((s8/usr/lib/python2.7/site-packages/salt/modules/win_wua.pyRKs�	cC@s�tjjj�}|j|�}|j�dkrBtd��nt|tj	�r`|g}nt|tj
�r�tj|�g}n|j�t|�kr�td��n|j
|�S(u
    .. versionadded:: 2017.7.0

    Downloads updates that match the list of passed identifiers. It's easier to
    use this function by using list_updates and setting install=True.

    Args:

        names (str, list):
            A single update or a list of updates to download. This can be any
            combination of GUIDs, KB numbers, or names. GUIDs or KBs are
            preferred.

    .. note::
        An error will be raised if there are more results than there are items
        in the names parameter

    Returns:

        dict: A dictionary containing the details about the downloaded updates

    CLI Examples:

    .. code-block:: bash

        # Normal Usage
        salt '*' win_wua.download names=['12345678-abcd-1234-abcd-1234567890ab', 'KB2131233']
    iuNo updates foundu6Multiple updates found, names need to be more specific(RRRRRtcountRt
isinstanceRtstring_typest
integer_typest	text_typetlenR(tnamesRR((s8/usr/lib/python2.7/site-packages/salt/modules/win_wua.pyR�scC@s�tjjj�}|j|�}|j�dkrBtd��nt|tj	�r`|g}nt|tj
�r�tj|�g}n|j�t|�kr�td��n|j
|�S(u�
    .. versionadded:: 2017.7.0

    Installs updates that match the list of identifiers. It may be easier to use
    the list_updates function and set install=True.

    Args:

        names (str, list):
            A single update or a list of updates to install. This can be any
            combination of GUIDs, KB numbers, or names. GUIDs or KBs are
            preferred.

    .. note::
        An error will be raised if there are more results than there are items
        in the names parameter

    Returns:

        dict: A dictionary containing the details about the installed updates

    CLI Examples:

    .. code-block:: bash

        # Normal Usage
        salt '*' win_wua.install KB12323211
    iuNo updates foundu6Multiple updates found, names need to be more specific(RRRRRR"RR#RR$R%R&R'R(R(RR((s8/usr/lib/python2.7/site-packages/salt/modules/win_wua.pyRscC@sOtjjj�}|j|�}|j�dkrBtd��n|j|�S(uV
    .. versionadded:: 2017.7.0

    Uninstall updates.

    Args:

        names (str, list):
            A single update or a list of updates to uninstall. This can be any
            combination of GUIDs, KB numbers, or names. GUIDs or KBs are
            preferred.

    Returns:

        dict: A dictionary containing the details about the uninstalled updates

    CLI Examples:

    .. code-block:: bash

        # Normal Usage
        salt '*' win_wua.uninstall KB3121212

        # As a list
        salt '*' win_wua.uninstall guid=['12345678-abcd-1234-abcd-1234567890ab', 'KB1231231']
    iuNo updates found(RRRRRR"Rt	uninstall(R(RR((s8/usr/lib/python2.7/site-packages/salt/modules/win_wua.pyR)Js
cC@sJitd6}tjjj��tjjd�}WdQX|j}	|dk	r�t
|�|	_|	j�}
|
dkr�||d<q�d|d<t
|d<n|dk	r�||	_|	j�}
|
dkr�||d<q�d|d<t
|d<n|dk	r:||	_|	j�}
|
dkr#||d<q:d|d<t
|d<n|dk	r�||	_|	j�}
|
dkrt||d	<q�d|d<t
|d<n|dk	rAid
d6dd
6dd6dd6dd6dd6dd6dd6}||kr�d|d<t
|d<qA|||	_|	j�}
|
dkr*||d<qAd|d<t
|d<n|dk	rt|tj�sdj|�|d<t
|d<qd|kr�dj|�|d<t
|d<q|jd�}|d
|	_|	j�}
|
dkr�||d<qd|d<t
|d<n|dk	r9tjjj��tjjd �}
WdQXd!|
_|r�y!|
jd"dd#�||d$<Wq6tk
r�}|j\}}}}d%j|d�|d<t
|d<q6Xq9t�r,y|
jd"�||d$<Wq6tk
r(}|j\}}}}d%j|d�|d<t
|d<q6Xq9||d$<nt�|d&<|S('uH	
    Change Windows Update settings. If no parameters are passed, the current
    value will be returned.

    Supported:
        - Windows Vista / Server 2008
        - Windows 7 / Server 2008R2
        - Windows 8 / Server 2012
        - Windows 8.1 / Server 2012R2

    .. note:
        Microsoft began using the Unified Update Platform (UUP) starting with
        Windows 10 / Server 2016. The Windows Update settings have changed and
        the ability to 'Save' Windows Update settings has been removed. Windows
        Update settings are read-only. See MSDN documentation:
        https://msdn.microsoft.com/en-us/library/aa385829(v=vs.85).aspx

    Args:

        level (int):
            Number from 1 to 4 indicating the update level:

            1. Never check for updates
            2. Check for updates but let me choose whether to download and install them
            3. Download updates but let me choose whether to install them
            4. Install updates automatically

        recommended (bool):
            Boolean value that indicates whether to include optional or
            recommended updates when a search for updates and installation of
            updates is performed.

        featured (bool):
            Boolean value that indicates whether to display notifications for
            featured updates.

        elevated (bool):
            Boolean value that indicates whether non-administrators can perform
            some update-related actions without administrator approval.

        msupdate (bool):
            Boolean value that indicates whether to turn on Microsoft Update for
            other Microsoft products

        day (str):
            Days of the week on which Automatic Updates installs or uninstalls
            updates. Accepted values:

            - Everyday
            - Monday
            - Tuesday
            - Wednesday
            - Thursday
            - Friday
            - Saturday

        time (str):
            Time at which Automatic Updates installs or uninstalls updates. Must
            be in the ##:## 24hr format, eg. 3:00 PM would be 15:00. Must be in
            1 hour increments.

    Returns:

        dict: Returns a dictionary containing the results.

    CLI Examples:

    .. code-block:: bash

        salt '*' win_wua.set_wu_settings level=4 recommended=True featured=False
    uSuccessuMicrosoft.Update.AutoUpdateNuLevelu+Settings failed to save. Check permissions.uCommentuRecommendeduFeatureduElevatediuEverydayiuSundayiuMondayiuTuesdayiu	WednesdayiuThursdayiuFridayiuSaturdayueDay needs to be one of the following: Everyday,Monday, Tuesday, Wednesday, Thursday, Friday, SaturdayuDayuVTime argument needs to be a string; it may need tobe quoted. Passed {0}. Time not set.u:uDTime argument needs to be in 00:00 format. Passed {0}. Time not set.uTimeuMicrosoft.Update.ServiceManageruMy Appu$7971f918-a847-4430-9279-4a52d1efe18duumsupdateuFailed with failure code: {0}uReboot(RRRtwinapitComtwin32comtclienttDispatchtSettingstNonetinttNotificationLeveltSaveR	tIncludeRecommendedUpdatestFeaturedUpdatesEnabledtNonAdministratorsElevatedtScheduledInstallationDayR#RR$tformattsplittClientApplicationIDtAddService2t	Exceptiontargst_get_msupdate_statust
RemoveServicetget_needs_reboot(tleveltrecommendedtfeaturedtelevatedtmsupdatetdayttimeR tobj_autobj_au_settingstresulttdaystttobj_smterrorthrtmsgtexctarg((s8/usr/lib/python2.7/site-packages/salt/modules/win_wua.pytset_wu_settingsqs�d
	


	


	


	


















		


cC@si}ddddddddg}tjjj��tjjd	�}Wd
QX|j}|j|d<|j	|d<t
�|d
<t�|d<|j|d<|j
|d<|j|d<|j|d<||j|d<|jdkr�dj|j�|d<ndj|j�|d<|S(uZ
    Get current Windows Update settings.

    Returns:

        dict: A dictionary of Windows Update settings:

        Featured Updates:
            Boolean value that indicates whether to display notifications for
            featured updates.
        Group Policy Required (Read-only):
            Boolean value that indicates whether Group Policy requires the
            Automatic Updates service.
        Microsoft Update:
            Boolean value that indicates whether to turn on Microsoft Update for
            other Microsoft Products
        Needs Reboot:
            Boolean value that indicates whether the machine is in a reboot
            pending state.
        Non Admins Elevated:
            Boolean value that indicates whether non-administrators can perform
            some update-related actions without administrator approval.
        Notification Level:
            Number 1 to 4 indicating the update level:
                1. Never check for updates
                2. Check for updates but let me choose whether to download and
                   install them
                3. Download updates but let me choose whether to install them
                4. Install updates automatically
        Read Only (Read-only):
            Boolean value that indicates whether the Automatic Update
            settings are read-only.
        Recommended Updates:
            Boolean value that indicates whether to include optional or
            recommended updates when a search for updates and installation of
            updates is performed.
        Scheduled Day:
            Days of the week on which Automatic Updates installs or uninstalls
            updates.
        Scheduled Time:
            Time at which Automatic Updates installs or uninstalls updates.

    CLI Examples:

    .. code-block:: bash

        salt '*' win_wua.get_wu_settings
    u	Every DayuSundayuMondayuTuesdayu	WednesdayuThursdayuFridayuSaturdayuMicrosoft.Update.AutoUpdateNuFeatured UpdatesuGroup Policy RequireduMicrosoft UpdateuNeeds RebootuNon Admins ElevateduNotification Levelu	Read OnlyuRecommended Updatesu
Scheduled Dayi
u0{0}:00uScheduled Timeu{0}:00(RRR*R+R,R-R.R/R5tRequiredR>R@R6R2tReadOnlyR4R7tScheduledInstallationTimeR8(R RFRHRI((s8/usr/lib/python2.7/site-packages/salt/modules/win_wua.pytget_wu_settingsbs61		







cC@s\tjjj��tjjd�}WdQX|j}x!|D]}|jdkr;t	Sq;Wt
S(uH
    Check to see if Microsoft Update is Enabled
    Return Boolean
    uMicrosoft.Update.ServiceManagerNuMicrosoft Update(RRR*R+R,R-R.tServicesRRR	(RMtcol_servicestservice((s8/usr/lib/python2.7/site-packages/salt/modules/win_wua.pyR>�s	
cC@stjjj�S(u�
    Determines if the system needs to be rebooted.

    Returns:

        bool: True if the system requires a reboot, otherwise False

    CLI Examples:

    .. code-block:: bash

        salt '*' win_wua.get_needs_reboot
    (RRRtneeds_reboot(((s8/usr/lib/python2.7/site-packages/salt/modules/win_wua.pyR@�s($t__doc__t
__future__RRRtloggingtsalt.utils.platformRtsalt.utils.win_updatetsalt.utils.winapitsalt.exceptionsRtsalt.extRtwin32com.clientR,RR
tImportErrorR	t	getLoggert__name__tlogt__func_alias__R
R0RR!RRRR)RSRWR>R@(((s8/usr/lib/python2.7/site-packages/salt/modules/win_wua.pyt<module>9s^



	�\�	4	4	'�	Z	

Zerion Mini Shell 1.0