%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/system.pyo

�
���^c@@s�dZddlmZmZmZddlmZmZmZddlZddl	Z
ddlZddl
ZddlZddlmZmZddlmZdZd�Zd	�Zd
�Zd�Zdd�Zdd
�Zd�Zd�Zd�Zd�Zd�Z d�Z!dd�Z"dd�Z#dd�Z$dddddddd�Z%dd�Z&dd�Z'defd��YZ(d�Z)d�Z*d�Z+d�Z,d �Z-d!�Z.d"Z/ed#�d$��Z0ed#�d%��Z1dS(&u�
Support for reboot, shutdown, etc on POSIX-like systems.

.. note::

    If you have configured a wrapper such as ``molly-guard`` to
    intercept *interactive* shutdown commands, be aware that calling
    ``system.halt``, ``system.poweroff``, ``system.reboot``, and
    ``system.shutdown`` with ``salt-call`` will hang indefinitely
    while the wrapper script waits for user input. Calling them with
    ``salt`` will work as expected.

i(tabsolute_importtunicode_literalstprint_function(tdatetimet	timedeltattzinfoN(tCommandExecutionErrortSaltInvocationError(tdependsusystemcC@sXtjjj�rtdfStjjj�r8tdfStjjj�rTtdfStS(uc
    Only supported on POSIX-like systems
    Windows, Solaris, and Mac have their own modules
    u'This module is not available on Windowsu&This module is not available on Mac OSu%This module is not available on SunOS(tsalttutilstplatformt
is_windowstFalset	is_darwintis_sunost__virtualname__(((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyt__virtual__ s


cC@s#dg}td|dt�}|S(ui
    Halt a running system

    CLI Example:

    .. code-block:: bash

        salt '*' system.halt
    uhaltucmd.runtpython_shell(t__salt__R
(tcmdtret((s7/usr/lib/python2.7/site-packages/salt/modules/system.pythalt1s
	cC@s/ddj|�g}td|dt�}|S(u�
    Change the system runlevel on sysV compatible systems

    CLI Example:

    .. code-block:: bash

        salt '*' system.init 3
    uinitu{0}ucmd.runR(tformatRR
(trunlevelRR((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytinit@s
cC@s#dg}td|dt�}|S(uq
    Poweroff a running system

    CLI Example:

    .. code-block:: bash

        salt '*' system.poweroff
    upoweroffucmd.runR(RR
(RR((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytpoweroffOs
	cC@s>dd|rdj|�ndg}td|dt�}|S(u�
    Reboot the system

    at_time
        The wait time in minutes before the system will be rebooted.

    CLI Example:

    .. code-block:: bash

        salt '*' system.reboot
    ushutdownu-ru{0}unowucmd.runR(RRR
(tat_timeRR((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytreboot^s
$cC@s>dd|rdj|�ndg}td|dt�}|S(u�
    Shutdown a running system

    at_time
        The wait time in minutes before the system will be shutdown.

    CLI Example:

    .. code-block:: bash

        salt '*' system.shutdown 5
    ushutdownu-hu{0}unowucmd.runR(RRR
(RRR((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytshutdownps
$c	C@sdg}|j�dk	rS||j�}|jdtd��}|jd�ndj|j��}||g}td|dt�}|ddkrd	j|j��}||g}td|dt�}|ddkrd
j|d�}t	|��qnt
S(
u�
    set the system date/time using the date command

    Note using a strictly posix-compliant date binary we can only set the date
    up to the minute.
    udateRiu-uu%{1:02}{2:02}{3:02}{4:02}{0:04}.{5:02}ucmd.run_allRuretcodeu {1:02}{2:02}{3:02}{4:02}{0:04}udate failed: {0}ustderrN(t	utcoffsettNonetreplacet_FixedOffsettappendRt	timetupleRR
RtTrue(	tnew_dateRt	non_posixt
non_posix_cmdt
ret_non_posixtposixt	posix_cmdt	ret_posixtmsg((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyt_date_bin_set_datetime�s"	

cC@s[tjjjdg�dk	rWtddddgdtdddt�}|d	d
kStS(u�
    Returns True if the system has a hardware clock capable of being
    set from software.

    CLI Example:

    salt '*' system.has_settable_hwclock
    uhwclockucmd.run_allu--testu	--systohcRtoutput_logleveluquiettignore_retcodeuretcodeiN(R	R
tpatht	which_binRRR
R$(tres((s7/usr/lib/python2.7/site-packages/salt/modules/system.pythas_settable_hwclock�s	cC@sRtdddgdt�}|ddkrNdj|d�}t|��ntS(	u8
    Set hardware clock to value of software clock.
    ucmd.run_alluhwclocku	--systohcRuretcodeiu=hwclock failed to set hardware clock from software clock: {0}ustderr(RR
RRR$(R2R,((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyt_swclock_to_hwclock�s
cC@sFd}x9|D]1}ytj||�}PWq
tk
r=q
Xq
W|S(u
    Attempts to parse the input time_str as a date.

    :param str time_str: A string representing the time
    :param list fmts: A list of date format strings.

    :return: Returns a datetime object if parsed properly. Otherwise None
    :rtype datetime:
    N(RRtstrptimet
ValueError(ttime_strtfmtstresulttfmt((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyt_try_parse_datetime�s


cC@s�tjd|�}|s'td��n|jd�dkrBdnd}t|jd��}t|jd��}||d|}|S(	u�
    Helper function that converts the utc offset string into number of minutes
    offset. Input is in form "[+-]?HHMM". Example valid inputs are "+0500"
    "-0300" and "0800". These would return -300, 180, 480 respectively.
    u^([+-])?(\d\d)(\d\d)$uInvalid UTC offsetiu-i����iii<(tretmatchRtgrouptint(t
utc_offsetR=tsignthours_offsettminutes_offsetttotal_offset((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyt_offset_to_min�s!cC@sb|dk	rRt|�}td|�}tj�|}|jdt|��}ntj�}|S(uf
    Will return the current time adjusted using the input timezone offset.

    :rtype datetime:
    tminutesRN(RRERRtutcnowR R!tnow(R@RFtoffsettoffset_time((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyt_get_offset_time�scC@st|�}tj|d�S(u
    Get the system time.

    :param str utc_offset: The utc offset in 4 digit (+0600) format with an
        optional sign (+/-).  Will default to None which will use the local
        timezone. To set the time based off of UTC use "'+0000'". Note: if
        being passed through the command line will need to be quoted twice to
        allow negative offsets.
    :return: Returns the system time in HH:MM:SS AM/PM format.
    :rtype: str

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_system_time
    u%I:%M:%S %p(RKRtstrftime(R@RJ((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytget_system_time�sc	C@sYddddg}t||�}|d	kr1tStd|jd|jd|jd|�S(
u�
    Set the system time.

    :param str newtime:
        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)

        Note that the salt command line parser parses the date/time
        before we obtain the argument (preventing us from doing utc)
        Therefore the argument must be passed in as a string.
        Meaning you may have to quote the text twice from the command line.

    :param str utc_offset: The utc offset in 4 digit (+0600) format with an
        optional sign (+/-).  Will default to None which will use the local
        timezone. To set the time based off of UTC use "'+0000'". Note: if
        being passed through the command line will need to be quoted twice to
        allow negative offsets.
    :return: Returns True if successful. Otherwise False.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_system_time "'11:20'"
    u%I:%M:%S %pu%I:%M %pu%H:%M:%Su%H:%MthoursRFtsecondsR@N(R;RR
tset_system_date_timethourtminutetsecond(tnewtimeR@R8tdt_obj((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytset_system_timescC@st|�}tj|d�S(u-
    Get the system date/time.

    :param str utc_offset: The utc offset in 4 digit (+0600) format with an
        optional sign (+/-).  Will default to None which will use the local
        timezone. To set the time based off of UTC use "'+0000'". Note: if
        being passed through the command line will need to be quoted twice to
        allow negative offsets.
    :return: Returns the system time in YYYY-MM-DD hh:mm:ss format.
    :rtype: str

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_system_date_time "'-0500'"
    u%Y-%m-%d %H:%M:%S(RKRRL(R@RJ((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytget_system_date_time;sc
	C@s
t|�}|dkr$|j}n|dkr<|j}n|dkrT|j}n|dkrl|j}n|dkr�|j}n|dkr�|j}ny(t||||||d|j	�}Wn"t
k
r�}	t|	j��nXt
|�s�tSt�r	t�StS(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)

    Updates hardware clock, if present, in addition to software
    (kernel) clock.

    :param int years: Years digit, ie: 2015
    :param int months: Months digit: 1 - 12
    :param int days: Days digit: 1 - 31
    :param int hours: Hours digit: 0 - 23
    :param int minutes: Minutes digit: 0 - 59
    :param int seconds: Seconds digit: 0 - 59
    :param str utc_offset: The utc offset in 4 digit (+0600) format with an
        optional sign (+/-).  Will default to None which will use the local
        timezone. To set the time based off of UTC use "'+0000'". Note: if
        being passed through the command line will need to be quoted twice to
        allow negative offsets.
    :return: True if successful. Otherwise False.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_system_date_time 2015 5 12 11 37 53 "'-0500'"
    iN(RKRtyeartmonthtdayRQRRRSRRR6RtmessageR-R
R3R4R$(
tyearstmonthstdaysRNRFROR@t	date_timetnew_datetimeterr((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyRPQs.&	cC@st|�}tj|d�S(u�
    Get the system date

    :param str utc_offset: The utc offset in 4 digit (+0600) format with an
        optional sign (+/-).  Will default to None which will use the local
        timezone. To set the time based off of UTC use "'+0000'". Note: if
        being passed through the command line will need to be quoted twice to
        allow negative offsets.
    :return: Returns the system date.
    :rtype: str

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_system_date
    u%a %m/%d/%Y(RKRRL(R@RJ((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytget_system_date�sc	C@sjddddddg}t||�}|dkrBtd��ntd|jd	|jd
|jd|�S(
ut
    Set the system date. Use <mm-dd-yy> format for the date.

    :param str newdate:
        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

    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/%duInvalid date formatR\R]R^R@N(R;RRRPRXRYRZ(tnewdateR@R8RU((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytset_system_date�s	R!cB@s2eZdZd�Zd�Zd�Zd�ZRS(u0
    Fixed offset in minutes east from UTC.
    cC@s,t|j|�j�td|�|_dS(NRF(tsupert	__class__t__init__Rt_FixedOffset__offset(tselfRI((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyRg�scC@s|jS(N(Rh(Ritdt((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyR�scC@sdS(N(R(RiRj((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyttzname�scC@s
td�S(Ni(R(RiRj((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytdst�s(t__name__t
__module__t__doc__RgRRkRl(((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyR!�s
			cC@s2|d|dkr.|jd�r.|dd!S|S(uA
    Helper function to strip off the ' or " off of a string
    ii����u'u"i(u'u"(t
startswith(tstr_q((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyt
_strip_quotes�s#cC@s"tjjjd�}|r=td|ddgdt�}n�d
}tjd�}y�tjj	j
dd��f}x\|j�D]N}tjjj
|�}|j|�}|r}t|jd	�j��}q}q}WWd
QXWntk
r�nX|d
kr�tS|jdd�jd
d�jdd�S(u:
    Get PRETTY_HOSTNAME value stored in /etc/machine-info
    If this file doesn't exist or the variable doesn't exist
    return False.

    :return: Value of PRETTY_HOSTNAME if this does not exist False.
    :rtype: str

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_computer_desc
    uhostnamectlucmd.runustatusu--prettyRu^\s*PRETTY_HOSTNAME=(.*)$u/etc/machine-infouriNu\"u"u\nu
u\tu	(R	R
R0twhichRR
RR<tcompiletfilestfopent	readlineststringutilst
to_unicodeR=RrR>tstriptIOErrorR (thostname_cmdtdesctpatternt	mach_infotlineR=((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytget_computer_desc�s&,
c		C@s�tjjj|�jdd�jdd�jdd�}tjjjd�}|r�td|d	d
|gdt�}|dkr�t	StSt
jjd
�s�tjjj
d
d��WdQXntjd�}tjjjdj|��}y�tjjj
d
d���}|j�}xSt|�D]8\}}|jtjjj|��r"|||<Pq"q"W|j|�|jdd�|j�|j|�t	SWdQXWntk
r�tSXdS(u�
    Set PRETTY_HOSTNAME value stored in /etc/machine-info
    This will create the file if it does not exist. If
    it is unable to create or modify this file returns False.

    :param str desc: The computer description
    :return: False on failure. True if successful.

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_computer_desc "Michael's laptop"
    u"u\"u
u\nu	u\tuhostnamectlucmd.retcodeuset-hostnameu--prettyRiu/etc/machine-infouwNu^\s*PRETTY_HOSTNAME=(.*)$uPRETTY_HOSTNAME="{0}"ur+(R	R
RxRyR R0RsRR
R$tostisfileRuRvR<Rttto_strRRwt	enumerateR=R"tseekttruncatet
writelinesR{(	R}R|R9R~tnew_lineRtlinestiR�((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytset_computer_descs6-		




cC@std|�S(u�
    Modify hostname.

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_computer_name master.saltstack.com
    unetwork.mod_hostname(R(thostname((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytset_computer_nameMs
cC@std�S(uj
    Get hostname.

    CLI Example:

    .. code-block:: bash

        salt '*' network.get_hostname
    unetwork.get_hostname(R(((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytget_computer_nameZs
cC@stjd�dkS(u@
    Determine whether the minion is running on NI Linux RT
    u	os_familyu	NILinuxRT(t
__grains__tget(((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyt_is_nilrt_familygsu'/var/volatile/tmp/salt/reboot_witnessedu_is_nilrt_familycC@s�d}tjjt�}tjj|�s�ytj|�Wn4tk
rq}tdj||j	|j
���nXtddjt��}|d}n|dkS(ud
    This function is used to remember that an event indicating that a reboot is
    required was witnessed. This function writes to a temporary filesystem so
    the event gets cleared upon reboot.

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

    .. code-block:: bash

        salt '*' system.set_reboot_required_witnessed
    i����uError creating {0} (-{1}): {2}ucmd.run_allu	touch {0}uretcodei(R�R0tdirnametNILRT_REBOOT_WITNESS_PATHtexiststmakedirstOSErrorRRterrnotstrerrorR(terrcodetdir_pathtextrdict((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytset_reboot_required_witnessedqs	
cC@stjjt�S(uR
    Determine if at any time during the current boot session the salt minion
    witnessed an event indicating that a reboot is required.

    Returns:
        bool: ``True`` if the a reboot request was witnessed, ``False`` otherwise

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_reboot_required_witnessed
    (R�R0R�R�(((s7/usr/lib/python2.7/site-packages/salt/modules/system.pytget_reboot_required_witnessed�s(2Rot
__future__RRRRRRR<tos.pathR�tsalt.utils.filesR	tsalt.utils.pathtsalt.utils.platformtsalt.exceptionsRRtsalt.utils.decoratorsRRRRRRRRRR-R3R4R;RERKRMRVRWRPRbRdR!RrR�R�R�R�R�R�R�R�(((s7/usr/lib/python2.7/site-packages/salt/modules/system.pyt<module>sX					*					'A&			*	3	
	
	

Zerion Mini Shell 1.0