%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@sNdZddlmZmZmZddlZddlZddlZddlZddl	m	Z	ddl
ZddlZddl
ZddlZddlmZddlmZyVddlZddlZddlZddlZddlZddlmZeZWnek
r!eZnXeje�ZdZ d	�Z!ed
�Z"d�Z#d�Z$d
ed�Z%d�Z&d
ed�Z'd
eeed�Z(dd
eeeed�Z*d�Z+d�Z,d�Z-d�Z.d�Z/d�Z0dd�Z1ej2j3j4e1d�Z5d�Z6d�Z7ej2j3j4e7d�Z8d�Z9d�Z:dddeed �Z;ddded!�Z<dddd"eed#�Z=d$�Z>d%�Z?d&�Z@d'�ZAddddddd(�ZBd)�ZCd*�ZDd+�ZEd,�ZFd-�ZGd.�ZHd/�ZId0�ZJd1�ZKd2ZLd3ZMd4�ZNd5�ZOd6�ZPdS(7u�
Module for managing windows systems.

:depends:
    - pywintypes
    - win32api
    - win32con
    - win32net
    - wmi

Support for reboot, shutdown, etc
i(tabsolute_importtunicode_literalstprint_functionN(tdatetime(tCommandExecutionError(tsix(twindllusystemcC@s0tjjj�stdfSts,tdfStS(u:
    Only works on Windows Systems with Win32 Modules
    u#Module win_system: Requires Windowsu(Module win_system: Missing win32 modules(tsalttutilstplatformt
is_windowstFalsetHAS_WIN32NET_MODSt__virtualname__(((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyt__virtual__2s


cC@s|r
|S|dS(u$
    convert timeout to seconds
    i<((ttimeoutt
in_seconds((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyt_convert_minutes_seconds?scC@s2|jd�d}tj|d�}|jd�S(u,
    convert string to date time object
    u.iu%Y%m%d%H%M%Su%Y-%m-%d %H:%M:%S(tsplitRtstrptimetstrftime(t	dt_stringtdt_obj((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyt_convert_date_time_stringFscC@s6|dkst|tj�r"|Stj|d�SdS(u�
    Converts from current users character encoding to unicode.
    When instr has a value of None, the return value of the function
    will also be None.
    uutf8N(tNonet
isinstanceRt	text_type(tinstr((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyt_to_unicodeOsicC@std|d|�S(u�
    Halt a running system.

    Args:

        timeout (int):
            Number of seconds before halting the system. Default is 5 seconds.

        in_seconds (bool):
            Whether to treat timeout as seconds or minutes.

            .. versionadded:: 2015.8.0

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.halt 5 True
    RR(tshutdown(RR((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pythalt[scC@sdS(u�
    Change the system runlevel on sysV compatible systems. Not applicable to
    Windows

    CLI Example:

    .. code-block:: bash

        salt '*' system.init 3
    u(Not implemented on Windows at this time.((trunlevel((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytinituscC@std|d|�S(u�
    Power off a running system.

    Args:

        timeout (int):
            Number of seconds before powering off the system. Default is 5
            seconds.

        in_seconds (bool):
            Whether to treat timeout as seconds or minutes.

            .. versionadded:: 2015.8.0

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.poweroff 5
    RR(R(RR((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytpoweroff�sc	C@sNtd|dtd|d|�}|rJt||�}tj|d�n|S(u�
    Reboot a running system.

    Args:

        timeout (int):
            The number of minutes/seconds before rebooting the system. Use of
            minutes or seconds depends on the value of ``in_seconds``. Default
            is 5 minutes.

        in_seconds (bool):
            ``True`` will cause the ``timeout`` parameter to be in seconds.
             ``False`` will be in minutes. Default is ``False``.

            .. versionadded:: 2015.8.0

        wait_for_reboot (bool)
            ``True`` will sleep for timeout + 30 seconds after reboot has been
            initiated. This is useful for use in a highstate. For example, you
            may have states that you want to apply only after the reboot.
            Default is ``False``.

            .. versionadded:: 2015.8.0

        only_on_pending_reboot (bool):
            If this is set to ``True``, then the reboot will only proceed
            if the system reports a pending reboot. Setting this parameter to
            ``True`` could be useful when calling this function from a final
            housekeeping state intended to be executed at the end of a state run
            (using *order: last*). Default is ``False``.

    Returns:
        bool: ``True`` if successful (a reboot will occur), otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.reboot 5
        salt '*' system.reboot 5 True

    Invoking this function from a final housekeeping state:

    .. code-block:: yaml

        final_housekeeping:
           module.run:
              - name: system.reboot
              - only_on_pending_reboot: True
              - order: last
    RtrebootRtonly_on_pending_rebooti(RtTrueRttimetsleep(RRtwait_for_rebootR#trettseconds((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyR"�s5	c	C@s�tjrt|�}nt||�}|r;t�r;tS|rft|tj�rf|jd�}ny!t	j
d||||�tSWnftj
k
r�}|j\}}}tj
d�tj
d|�tj
d|�tj
d|�tSXdS(u�	
    Shutdown a running system.

    Args:

        message (str):
            The message to display to the user before shutting down.

        timeout (int):
            The length of time (in seconds) that the shutdown dialog box should
            be displayed. While this dialog box is displayed, the shutdown can
            be aborted using the ``system.shutdown_abort`` function.

            If timeout is not zero, InitiateSystemShutdown displays a dialog box
            on the specified computer. The dialog box displays the name of the
            user who called the function, the message specified by the lpMessage
            parameter, and prompts the user to log off. The dialog box beeps
            when it is created and remains on top of other windows (system
            modal). The dialog box can be moved but not closed. A timer counts
            down the remaining time before the shutdown occurs.

            If timeout is zero, the computer shuts down immediately without
            displaying the dialog box and cannot be stopped by
            ``system.shutdown_abort``.

            Default is 5 minutes

        in_seconds (bool):
            ``True`` will cause the ``timeout`` parameter to be in seconds.
             ``False`` will be in minutes. Default is ``False``.

            .. versionadded:: 2015.8.0

        force_close (bool):
            ``True`` will force close all open applications. ``False`` will
            display a dialog box instructing the user to close open
            applications. Default is ``True``.

        reboot (bool):
            ``True`` restarts the computer immediately after shutdown. ``False``
            powers down the system. Default is ``False``.

        only_on_pending_reboot (bool): If this is set to True, then the shutdown
            will only proceed if the system reports a pending reboot. To
            optionally shutdown in a highstate, consider using the shutdown
            state instead of this module.

        only_on_pending_reboot (bool):
            If ``True`` the shutdown will only proceed if there is a reboot
            pending. ``False`` will shutdown the system. Default is ``False``.

    Returns:
        bool:
            ``True`` if successful (a shutdown or reboot will occur), otherwise
            ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.shutdown "System will shutdown in 5 minutes"
    uutf-8u	127.0.0.1uFailed to shutdown the systemunbr: %suctx: %sumsg: %sN(RtPY2RRtget_pending_rebootRRtstring_typestdecodetwin32apitInitiateSystemShutdownR$t
pywintypesterrortargstlog(	tmessageRtforce_closeR"RR#texctnumbertcontext((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyR�s$@	

cC@s
tdd�S(u�
    Shutdown a running system with no timeout or warning.

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.shutdown_hard
    Ri(R(((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyt
shutdown_hard;s
cC@s�ytjd�tSWnftjk
r}}|j\}}}tjd�tjd|�tjd|�tjd|�tSXdS(uB
    Abort a shutdown. Only available while the dialog box is being
    displayed to the user. Once the shutdown has initiated, it cannot be
    aborted.

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.shutdown_abort
    u	127.0.0.1uFailed to abort system shutdownunbr: %suctx: %sumsg: %sN(R.tAbortSystemShutdownR$R0R1R2R3R(R6R7R8R4((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytshutdown_abortKs

cC@s
tjj�S(u�
    Lock the workstation.

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.lock
    (Rtuser32tLockWorkStation(((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytlockfs
cC@s{tjrt|�}ntjjtj|�rwiit�d6d6}t	�}|dtfkrs||dd<n|StS(u�
    Set the Windows computer name

    Args:

        name (str):
            The new name to give the computer. Requires a reboot to take effect.

    Returns:
        dict:
            Returns a dictionary containing the old and new names if successful.
            ``False`` if not.

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.set_computer_name 'DavesComputer'
    uCurrentu
Computer NameuPendingN(RR*RRtkernel32tSetComputerNameExWtwin32contComputerNamePhysicalDnsHostnametget_computer_nametget_pending_computer_nameRR(tnameR(tpending((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytset_computer_namevs			cC@sAt�}tdddd�d}|r=||kr9|SdStS(ub
    Get a pending computer name. If the computer name has been changed, and the
    change is pending a system reboot, this function will return the pending
    computer name. Otherwise, ``None`` will be returned. If there was an error
    retrieving the pending computer name, ``False`` will be returned, and an
    error message will be logged to the minion log.

    Returns:
        str:
            Returns the pending name if pending restart. Returns ``None`` if not
            pending restart.

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.get_pending_computer_name
    ureg.read_valueuHKLMu2SYSTEM\CurrentControlSet\Services\Tcpip\ParametersuNV HostnameuvdataN(RCt__salt__RR(tcurrentRF((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyRD�s	
cC@s tjtj�}|r|StS(u�
    Get the Windows computer name

    Returns:
        str: Returns the computer name if found. Otherwise returns ``False``.

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.get_computer_name
    (R.tGetComputerNameExRARBR(RE((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyRC�s
cC@s�tjrt|�}ntjdd�}|dkr:tS||d<ytjdd|�Wnftjk
r�}|j	\}}}t
jd�t
jd|�t
jd|�t
jd|�tSXit�d6S(	u=
    Set the Windows computer description

    Args:

        desc (str):
            The computer description

    Returns:
        str: Description if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.set_computer_desc 'This computer belongs to Dave!'
    ieucommentuFailed to update systemunbr: %suctx: %sumsg: %suComputer DescriptionN(RR*Rtwin32nettNetServerGetInfoRRtNetServerSetInfoR1R2R3tget_computer_desc(tdesctsystem_infoR6R7R8R4((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytset_computer_desc�s 	

uset_computer_descriptioncC@s|d�}idd6dd6dd6}tjjj��tj�}WdQX|j�d	}it�d
6|jd6|j	d6|j
d
6|jd6|jd6|j
d6|jd6|jd6|jd6||jd6|jd6|jd6|jd6|jd6|jd6}idd	6dd6dd6dd6dd6d d!6}id"d6d#d6d$d6d%d6d&d!6d'd(6}i	d)d	6d*d6d+d6d,d6d-d6d.d!6d/d(6d0d16d2d36}|j�d	}|ji|jd46�|j�d	}tj�dYkr||j}	n(|jid8d36d2d96�||j}	|ji|jd:6|jd;6||jd<6|j d=6|j!d>6||j"d?6|jd@6|j#dA6|j$dB6|j%dC6|	dD6|j&dE6|j'dF6|j(dG6||j)�dH6|j)dI6||j*dJ6|j+dK6�|j,�}
d	|dL<d	|dM<d	|dN<d	|dO<|
d	j|dP<t-j.|
d	j/�dQ|dR<xu|
D]m}|dLcd7<|dMc|j07<|dNc|j17<y|dOc|j27<Wqct3t4fk
r�qcXqcW|dOd	kr�|j5dOt6�n|j7�d	}|ji|j8dS6|jdT6|jdU6|j9dV6|jdW6|jdX6�t:|d�|d<t:|d
�|d
<|S(Zu�
    Get system information.

    .. note::

        Not all system info is available across all versions of Windows. If it
        is not available on an older version, it will be skipped

    Returns:
        dict: Dictionary containing information about the system to include
        name, description, version, etc...

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.get_system_info
    cS@s�t|�}|dkr%dj|�S|dkrBdj|d
�S|dkr_dj|d�S|dkr|d	j|d�Sd
j|d�SdS(Nii
u{0:.3f}Biu	{0:.3f}KBiu	{0:.3f}MBi(u	{0:.3f}GBu	{0:.3f}TBiiii@iIi@I(tfloattformat(tval((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyt	byte_calc	s
uWork StationiuDomain ControlleriuServeriNiunameudescriptionuinstall_dateu	last_bootuos_manufactureruos_nameuusersuorganizationuos_architectureuprimaryuos_typeuregistered_userusystem_directoryusystem_driveu
os_versionuwindows_directoryuStandalone WorkstationuMember WorkstationuStandalone Serveru
Member ServeruBackup Domain ControlleriuPrimary Domain ControlleriuOtheruUnknownuSafeuWarninguCriticaluNon-recoverableiuUnspecifieduDesktopuMobileuWorkstationuEnterprise ServeruSOHO ServeruAppliance PCuPerformance ServeriuMaximumiuchassis_sku_numberuVistau7u8uSlatei	ubootup_stateucaptionuchassis_bootup_stateudns_hostnameudomainudomain_roleuhardware_manufactureruhardware_modelunetwork_server_mode_enabledupart_of_domainupc_system_typeupower_stateustatususystem_typeutotal_physical_memoryutotal_physical_memory_rawu
thermal_stateu	workgroupu
processorsuprocessors_logicaluprocessor_coresuprocessor_cores_enableduprocessor_manufactureruMHzuprocessor_max_clock_speeduhardware_serialubios_manufacturerubios_versionubios_detailsubios_captionubios_description(uVistau7u8(;RRtwinapitComtwmitWMItWin32_OperatingSystemRCtDescriptiontInstallDatetLastBootUpTimetManufacturertCaptiont
NumberOfUserstOrganizationtOSArchitecturetPrimarytProductTypetRegisteredUsertSystemDirectorytSystemDrivetVersiontWindowsDirectorytWin32_ComputerSystemProducttupdatet	SKUNumbertWin32_ComputerSystemR	treleasetPCSystemTypetBootupStatetChassisBootupStatetDNSHostnametDomaint
DomainRoletModeltNetworkServerModeEnabledtPartOfDomaint
PowerStatetStatust
SystemTypetTotalPhysicalMemorytThermalStatet	WorkgrouptWin32_ProcessorRRt
MaxClockSpeedtNumberOfLogicalProcessorst
NumberOfCorestNumberOfEnabledCoretAttributeErrort	TypeErrortpopRt
Win32_BIOStSerialNumbertBIOSVersionR(RUtos_typetconntsystemR(tdomain_roletwarning_statestpc_system_typestproducttpc_system_typet
processors((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytget_system_info�s�	























	




















cC@s!t�d}|dkrtS|S(u�
    Get the Windows computer description

    Returns:
        str: Returns the computer description if found. Otherwise returns
        ``False``.

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.get_computer_desc
    udescriptionN(R�RR(RO((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyRN�s
uget_computer_descriptioncC@sd}tdd|�}|S(u�
    Get the hostname of the windows minion

    .. versionadded:: 2016.3.0

    Returns:
        str: Returns the hostname of the windows minion

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.get_hostname
    uhostnameucmd.runtcmd(RH(R�R(((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytget_hostname�scC@s8t�}dj||�}tdd|�}d|kS(uj
    Set the hostname of the windows minion, requires a restart before this will
    be updated.

    .. versionadded:: 2016.3.0

    Args:
        hostname (str): The hostname to set

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.set_hostname newhostname
    u;wmic computersystem where name='{0}' call rename name='{1}'ucmd.runR�u
successful(R�RSRH(thostnamet
curr_hostnameR�R(((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytset_hostname�s	c	C@sgtjr<t|�}t|�}t|�}t|�}nt�}d|krq|d|krqdj|�Sn|r�d|kr�d|kr�dj||�}n|r�|dkr�dSt|tj�r�|jd�}dj	|�}nt
d|d	|d
|d|d|�}|sHi|d6td
6}|rDt�|d
<n|St
tj|�j���dS(uO
    Join a computer to an Active Directory domain. Requires a reboot.

    Args:

        domain (str):
            The domain to which the computer should be joined, e.g.
            ``example.com``

        username (str):
            Username of an account which is authorized to join computers to the
            specified domain. Needs to be either fully qualified like
            ``user@domain.tld`` or simply ``user``

        password (str):
            Password of the specified user

        account_ou (str):
            The DN of the OU below which the account for this computer should be
            created when joining the domain, e.g.
            ``ou=computers,ou=departm_432,dc=my-company,dc=com``

        account_exists (bool):
            If set to ``True`` the computer will only join the domain if the
            account already exists. If set to ``False`` the computer account
            will be created if it does not exist, otherwise it will use the
            existing account. Default is ``False``

        restart (bool):
            ``True`` will restart the computer after a successful join. Default
            is ``False``

            .. versionadded:: 2015.8.2/2015.5.7

    Returns:
        dict: Returns a dictionary if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.join_domain domain='domain.tld' \
                         username='joinuser' password='joinpassword' \
                         account_ou='ou=clients,ou=org,dc=domain,dc=tld' \
                         account_exists=False, restart=True
    uDomainuAlready joined to {0}u\u@u{0}@{1}u.Must specify a password if you pass a usernameutdomaintusernametpasswordt
account_outaccount_existsuRestartN(RR*Rtget_domain_workgroupRSRRR,Rtjoint_join_domainRR"RR.t
FormatMessagetrstrip(	R�R�R�R�R�trestarttstatusterrR(((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytjoin_domain�s24		

cC@s�d}d}d}d}d}	|	|O}	|	|O}	|	|O}	|sO|	|O}	ntjjj��tj�}
WdQX|
j�d}|jd|d|d	|d
|d|	�dS(uD
    Helper function to join the domain.

    Args:
        domain (str): The domain to which the computer should be joined, e.g.
            ``example.com``

        username (str): Username of an account which is authorized to join
            computers to the specified domain. Need to be either fully qualified
            like ``user@domain.tld`` or simply ``user``

        password (str): Password of the specified user

        account_ou (str): The DN of the OU below which the account for this
            computer should be created when joining the domain, e.g.
            ``ou=computers,ou=departm_432,dc=my-company,dc=com``

        account_exists (bool): If set to ``True`` the computer will only join
            the domain if the account already exists. If set to ``False`` the
            computer account will be created if it does not exist, otherwise it
            will use the existing account. Default is False.

    Returns:
        int:

    :param domain:
    :param username:
    :param password:
    :param account_ou:
    :param account_exists:
    :return:
    iii iiNtNametPasswordtUserNamet	AccountOUtFJoinOptions(RRRVRWRXRYRmtJoinDomainOrWorkgroup(R�R�R�R�R�tNETSETUP_JOIN_DOMAINtNETSETUP_ACCOUNT_CREATEtNETSETUP_DOMAIN_JOIN_IF_JOINEDtNETSETUP_JOIN_WITH_NEW_NAMEtjoin_optionsR�tcomp((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyR�s %



	u	WORKGROUPc
C@s�tjr0t|�}t|�}t|�}nt�}d|kre|d|kredj|�Sn|r�d|kr�d|kr�|r�dj||�}q�dSn|r�|d
kr�dSd}d	}|r�||O}ntjjj	��t
j�}	Wd
QX|	j�d	}
|
j
d|d|d
|�}|d	s�|
jd|�}|d	s�i|d6td6}|r}t�|d<n|Stjtj|d	�j��tjd|�tSn8tjtj|d	�j��tjd|d�tSd
S(u�
    Unjoin a computer from an Active Directory Domain. Requires a restart.

    Args:

        username (str):
            Username of an account which is authorized to manage computer
            accounts on the domain. Needs to be a fully qualified name like
            ``user@domain.tld`` or ``domain.tld\user``. If the domain is not
            specified, the passed domain will be used. If the computer account
            doesn't need to be disabled after the computer is unjoined, this can
            be ``None``.

        password (str):
            The password of the specified user

        domain (str):
            The domain from which to unjoin the computer. Can be ``None``

        workgroup (str):
            The workgroup to join the computer to. Default is ``WORKGROUP``

            .. versionadded:: 2015.8.2/2015.5.7

        disable (bool):
            ``True`` to disable the computer account in Active Directory.
            Default is ``False``

        restart (bool):
            ``True`` will restart the computer after successful unjoin. Default
            is ``False``

            .. versionadded:: 2015.8.2/2015.5.7

    Returns:
        dict: Returns a dictionary if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.unjoin_domain restart=True

        salt 'minion-id' system.unjoin_domain username='unjoinuser' \
                         password='unjoinpassword' disable=True \
                         restart=True
    u	WorkgroupuAlready joined to {0}u\u@u{0}@{1}u/Must specify domain if not supplied in usernameu.Must specify a password if you pass a usernameiiNR�R�tFUnjoinOptionsR�uRestartu!Failed to join the computer to %su!Failed to unjoin computer from %suDomain(RR*RR�RSRRRRVRWRXRYRmtUnjoinDomainOrWorkgroupR�RR"R3R1R.R�R�(
R�R�R�t	workgrouptdisableR�R�tNETSETUP_ACCT_DELETEtunjoin_optionsR�R�R�R(((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyt
unjoin_domain\sL7		
	



  cC@setjjj��tj�}WdQXx9|j�D]+}|jrOi|jd6Si|jd6Sq2WdS(u
    Get the domain or workgroup the computer belongs to.

    .. versionadded:: 2015.5.7
    .. versionadded:: 2015.8.2

    Returns:
        str: The name of the domain or workgroup

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.get_domain_workgroup
    NuDomainu	Workgroup(	RRRVRWRXRYRmRwRs(R�tcomputer((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyR��s	cC@sFd}x9|D]1}ytj||�}PWq
tk
r=q
Xq
W|S(u$
    A helper function that attempts to parse the input time_str as a date.

    Args:

        time_str (str): A string representing the time

        fmts (list): A list of date format strings

    Returns:
        datetime: Returns a datetime object if parsed properly, otherwise None
    N(RRRt
ValueError(ttime_strtfmtstresulttfmt((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyt_try_parse_datetime�s


cC@s�tj�}d}t|d�}|dkr7d}n4|dkrLd}n|dkrk|d}d}ndj||d|d|�S(	u�
    Get the system time.

    Returns:
        str: Returns the system time in HH:MM:SS AM/PM format.

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.get_system_time
    uAMiiuPMiu{0:02d}:{1:02d}:{2:02d} {3}ii(R.tGetLocalTimetintRS(tnowtmeridianthours((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytget_system_time�s
		
	cC@sSddddg}t||�}|dkr1tStd|jd|jd|j�S(	u�
    Set the system time.

    Args:

        newtime (str):
            The time to set. Can be any of the following formats:

            - HH:MM:SS AM/PM
            - HH:MM AM/PM
            - HH:MM:SS (24 hour)
            - HH:MM (24 hour)

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt 'minion-id' system.set_system_time 12:01
    u%I:%M:%S %pu%I:%M %pu%H:%M:%Su%H:%MR�tminutesR)N(R�RRtset_system_date_timethourtminutetsecond(tnewtimeR�R((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytset_system_times	cC@sytj�}Wnftjk
rx}|j\}}	}
tjd�tjd|�tjd|	�tjd|
�tSX|dkr�|d}n|dkr�|d}n|dkr�|d}n|dkr�|d}n|dkr�|d	}n|dkr|d
}ny�dtjfd��Y}|�}t	|�|_
t	|�|_t	|�|_t	|�|_
t	|�|_t	|�|_tj|�}
tjjj|
�}|dk	r�tStjd
�ttj|�j���Wn,tk
r}tjd
�t|��nXdS(u
    Set the system date and time. Each argument is an element of the date, but
    not required. If an element is not passed, the current system value for that
    element will be used. For example, if you don't pass the year, the current
    system year will be used. (Used by set_system_date and set_system_time)

    Args:

        years (int): Years digit, ie: 2015
        months (int): Months digit: 1 - 12
        days (int): Days digit: 1 - 31
        hours (int): Hours digit: 0 - 23
        minutes (int): Minutes digit: 0 - 59
        seconds (int): Seconds digit: 0 - 59

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_system_date_ time 2015 5 12 11 37 53
    uFailed to get local timeunbr: %suctx: %sumsg: %siiiiiit
SYSTEMTIMEc	B@sneZdejfdejfdejfdejfdejfdejfdejfdejfgZRS(uwYearuwMonthu
wDayOfWeekuwDayuwHouruwMinuteuwSecondu
wMilliseconds(t__name__t
__module__tctypestc_int16t_fields_(((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyR�msuFailed to set local timeN(R.R�R1R2R3RRR�t	StructureR�twYeartwMonthtwDaytwHourtwMinutetwSecondtpointerRR?tSetLocalTimeR$RR�R�tOSError(tyearstmonthstdaysR�R�R)t	date_timeR6R7R8R4R�tsystem_timetsystem_time_ptrt	succeededR�((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyR�5sP







	

cC@s+tj�}dj|d|d|d�S(u�
    Get the Windows system date

    Returns:
        str: Returns the system date

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_system_date
    u{0:02d}/{1:02d}/{2:04d}iii(R.R�RS(R�((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytget_system_date�s
cC@sYddddddg}t||�}|d
kr7tStd|jd|jd	|j�S(u�
    Set the Windows system date. Use <mm-dd-yy> format for the date.

    Args:
        newdate (str):
            The date to set. Can be any of the following formats

            - YYYY-MM-DD
            - MM-DD-YYYY
            - MM-DD-YY
            - MM/DD/YYYY
            - MM/DD/YY
            - YYYY/MM/DD

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_system_date '03-28-13'
    u%Y-%m-%du%m-%d-%Yu%m-%d-%yu%m/%d/%Yu%m/%d/%yu%Y/%m/%dR�R�R�N(R�RRR�tyeartmonthtday(tnewdateR�R((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytset_system_date�s		cC@stdd�S(u�
    Start the Windows time service

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.start_time_service
    u
service.startuw32time(RH(((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytstart_time_service�s
cC@stdd�S(u�
    Stop the Windows time service

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.stop_time_service
    uservice.stopuw32time(RH(((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytstop_time_service�s
cC@sAd}tdd|�r-tjd|�tStjd|�tS(ue
    Determine whether there are pending Component Based Servicing tasks that
    require a reboot.

    .. versionadded:: 2016.11.0

    Returns:
        bool: ``True`` if there are pending Component Based Servicing tasks,
        otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_pending_component_servicing
    uQSOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPendingureg.key_existsuHKLMuKey exists: %suKey does not exist: %s(t	__utils__R3tdebugR$R(tkey((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytget_pending_component_servicing�scC@s�d}dj|�}dj|�}tdd|�rKtjd|�tStjd|�tdd|�r�tjd|�tStjd|�tS(uF
    Determine whether there is a pending domain join action that requires a
    reboot.

    .. versionadded:: 2016.11.0

    Returns:
        bool: ``True`` if there is a pending domain join action, otherwise
        ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_pending_domain_join
    u*SYSTEM\CurrentControlSet\Services\Netlogonu{0}\AvoidSpnSetu{0}\JoinDomainureg.key_existsuHKLMuKey exists: %suKey does not exist: %s(RSR�R3R�R$R(tbase_keyt	avoid_keytjoin_key((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytget_pending_domain_join�scC@s�d}d}xo|D]g}tdd||�}|drjtjd|�|drz|dd	krztSqtjd
|�qWtS(uK
    Determine whether there are pending file rename operations that require a
    reboot.

    .. versionadded:: 2016.11.0

    Returns:
        bool: ``True`` if there are pending file rename operations, otherwise
        ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_pending_file_rename
    uPendingFileRenameOperationsuPendingFileRenameOperations2u0SYSTEM\CurrentControlSet\Control\Session Managerureg.read_valueuHKLMusuccessu
Found key: %suvdatau(value not set)uUnable to access key: %s(uPendingFileRenameOperationsuPendingFileRenameOperations2(RHR3R�R$R(tvnamesR�tvnametreg_ret((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytget_pending_file_rename$s

cC@s�d}d}tdd||�}|drqtjd|�yt|d�dkrYtSWq�tk
rmq�Xntjd	|�tS(
uI
    Determine whether there are pending Server Manager tasks that require a
    reboot.

    .. versionadded:: 2016.11.0

    Returns:
        bool: ``True`` if there are pending Server Manager tasks, otherwise
        ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_pending_servermanager
    uCurrentRebootAttemptsu SOFTWARE\Microsoft\ServerManagerureg.read_valueuHKLMusuccessu
Found key: %suvdataiuUnable to access key: %s(RHR3R�R�R$R�R(R�R�R�((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytget_pending_servermanagerHs

cC@sAd}tdd|�r-tjd|�tStjd|�tS(u
    Determine whether there are pending updates that require a reboot.

    .. versionadded:: 2016.11.0

    Returns:
        bool: ``True`` if there are pending updates, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_pending_update
    uRSOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequiredureg.key_existsuHKLMuKey exists: %suKey does not exist: %s(R�R3R�R$R(R�((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytget_pending_updateosu;SYSTEM\CurrentControlSet\Services\salt-minion\Volatile-DatauReboot requiredc
C@s/tddddtdtdtddd	d
�S(ul
    This function is used to remember that an event indicating that a reboot is
    required was witnessed. This function relies on the salt-minion's ability to
    create the following volatile registry key in the *HKLM* hive:

       *SYSTEM\\CurrentControlSet\\Services\\salt-minion\\Volatile-Data*

    Because this registry key is volatile, it will not persist beyond the
    current boot session. Also, in the scope of this key, the name *'Reboot
    required'* will be assigned the value of *1*.

    For the time being, this function is being used whenever an install
    completes with exit code 3010 and can be extended where appropriate in the
    future.

    .. versionadded:: 2016.11.0

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_reboot_required_witnessed
    u
reg.set_valuethiveuHKLMR�tvolatileR�tvdataitvtypeu	REG_DWORD(RHtMINION_VOLATILE_KEYR$tREBOOT_REQUIRED_NAME(((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytset_reboot_required_witnessed�scC@s-tddddtdt�}|ddkS(u@
    Determine if at any time during the current boot session the salt minion
    witnessed an event indicating that a reboot is required.

    This function will return ``True`` if an install completed with exit
    code 3010 during the current boot session and can be extended where
    appropriate in the future.

    .. versionadded:: 2016.11.0

    Returns:
        bool: ``True`` if the ``Requires reboot`` registry flag is set to ``1``,
        otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_reboot_required_witnessed

    ureg.read_valueR�uHKLMR�R�uvdatai(RHR�R�(t
value_dict((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pytget_reboot_required_witnessed�s	cC@s=tttttttf}x|D]}|�r"tSq"WtS(u	
    Determine whether there is a reboot pending.

    .. versionadded:: 2016.11.0

    Returns:
        bool: ``True`` if the system is pending reboot, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_pending_reboot
    (	R�R�R�R�RRDR�R$R(tcheckstcheck((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyR+�s	
	(Qt__doc__t
__future__RRRR�tloggingR%R	Rtsalt.utils.functoolsRtsalt.utils.localestsalt.utils.platformtsalt.utils.winapitsalt.exceptionsRtsalt.extRRXRKR.RAR0RR$RtImportErrorRt	getLoggerR�R3R
RRRRRR R!R"RRR9R;R>RGRDRCRQRt	functoolstalias_functiontset_computer_descriptionR�RNtget_computer_descriptionR�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�RRR+(((s;/usr/lib/python2.7/site-packages/salt/modules/win_system.pyt<module>
s�


	
					>V				"		-	�			S9g				#Q		%				&	$	'		#	

Zerion Mini Shell 1.0