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

�
���^c@@s4dZddlmZmZmZddlZddlZd�Zdddd�Z
dddd�Zdddd�Zdddd	�Z
dddd
�Zdddddddddded
�Zd�Zdddd�Zddddd�Zdddd�Zddddd�Zdddd�ZdS(u�
Module for manageing PagerDuty resource

:configuration: This module can be used by specifying the name of a
    configuration profile in the minion config, minion pillar, or master
    config.  The default configuration profile name is 'pagerduty.'

    For example:

    .. code-block:: yaml

        pagerduty:
            pagerduty.api_key: F3Rbyjbve43rfFWf2214
            pagerduty.subdomain: mysubdomain


For PagerDuty API details, see https://developer.pagerduty.com/documentation/rest

i(tabsolute_importtprint_functiontunicode_literalsNcC@stS(u>
    No dependencies outside of what Salt itself requires
    (tTrue(((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pyt__virtual__su	pagerdutyc	C@stddd|d|d|�S(uk
    List users belonging to this account

    CLI Example:

        salt myminion pagerduty.get_users
    uusersuidtprofilet	subdomaintapi_key(t_list_items(RRR((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pyt	get_users"s	c	C@stddd|d|d|�S(uq
    List services belonging to this account

    CLI Example:

        salt myminion pagerduty.get_services
    uservicesuidRRR(R(RRR((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pytget_services4s	c	C@stddd|d|d|�S(us
    List schedules belonging to this account

    CLI Example:

        salt myminion pagerduty.get_schedules
    u	schedulesuidRRR(R(RRR((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pyt
get_schedulesFs	c	C@stddd|d|d|�S(u�
    List escalation_policies belonging to this account

    CLI Example:

        salt myminion pagerduty.get_escalation_policies
    uescalation_policiesuidRRR(R(RRR((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pytget_escalation_policiesXs	c	C@sNtd|d|d|d|�}i}x ||D]}||||<q2W|S(u]
    List items belonging to an API call.

    This method should be in utils.pagerduty.
    RRRtaction(t_query(R
tkeyRRRtitemstrettitem((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pyRjs	uGETuapi/v1cC@s$|rtd|�}ni|d6|	d6}|dkrUdj|d||�}n|dkrji}n|dkri}nidj|d�d6}|dkr�d|d	<ntj||d
|d|dtjjj|�d
|
�}
|
j	dks	|
j	dkr
dS|
j�}d|kr d|kr d|kr |d}|d}|d}x�|||kr||}d}||d<||d<tj||d
|d|d|d
|
�j�}|d}|d}x@|j
�D]2\}}t|t�r�||c||7<q�q�Wq^Wn|S(uR
    Query the PagerDuty API.

    This method should be in utils.pagerduty.

    u
config.optionupagerduty.api_keyupagerduty.subdomainu!https://{0}.pagerduty.com/{1}/{2}uToken token={0}u
AuthorizationuGETuapplication/jsonuContent-typetheaderstparamstdatatverifyuutotaluoffsetulimitidN(
t__salt__tNonetformattrequeststrequesttsalttutilstjsontdumpsttextRt
isinstancetlist(tmethodRturltpathR
RtserviceRRRt
verify_ssltcredsRtresulttresult_jsontoffsettlimitttotaltnext_page_resultstktv((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pyR|sb

		
	$





	

"cC@s0d|kr|dSd|kr,|ddSdS(uf
    helper method to find the resource id, since PD API doesn't always return it in the same way
    uiduscheduleN(R(tresource((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pyt_get_resource_id�s
c
C@s�dtkritd<n|tdkrx|dkrB|d}n|}td|d|d|d|�|td|<nx|td|D]l}xc|D][}|||kr�|dkr�tdd	j||d
�d|d|d|�}	|	S|Sq�Wq�WdS(um
    Get any single pagerduty resource by key.

    We allow flexible lookup by any of a list of identifier_fields.
    So, for example, you can look up users by email address or name by calling:

            get_resource('users', key, ['name', 'email'], ...)

    This method is mainly used to translate state sls into pagerduty id's for dependent objects.
    For example, a pagerduty escalation policy contains one or more schedules, which must be passed
    by their pagerduty id.  We look up the schedules by name (using this method), and then translate
    the names into id's.

    This method is implemented by getting all objects of the resource type (cached into __context__),
    then brute force searching through the list and trying to match any of the identifier_fields.
    The __context__ cache is purged after any create, update or delete to the resource.
    upagerduty_util.resource_cacheuservicesu?include[]=escalation_policyR
RRRu	schedulesu{0}/{1}uidN(t__context__RRR(
t
resource_nameRtidentifier_fieldsRRRR
R1tfieldtfull_resource_info((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pytget_resource�s*


	c
C@s�d}xL|D]D}||kr
t|||||||�}|dk	rQPqQq
q
W|dkr�tdrodStd|=tddd|d|d|d	|d
|�Si}	|r�|||�}	nixf|j�D]X\}
}|
jd�r�q�n|j|
d�}|dk	r�||kr�||	|
<q�q�Wt|	�dkr�tdrLd
Std|=t	|�}
tddddj
||
�d|	d|d	|d
|�StSdS(u/
    create or update any pagerduty resource
    Helper method for present().

    Determining if two resources are the same is different for different PD resource, so this method accepts a diff function.
    The diff function will be invoked as diff(state_information, object_returned_from_pagerduty), and
    should return a dict of data to pass to the PagerDuty update API method, or None if no update
    is to be performed.  If no diff method is provided, the default behavor is to scan the keys in the state_information,
    comparing the matching values in the object_returned_from_pagerduty, and update any values that differ.

    examples:
        create_or_update_resource("user", ["id","name","email"])
        create_or_update_resource("escalation_policies", ["id","name"], diff=my_diff_function)

    utestuwould createupagerduty_util.resource_cacheR#uPOSTR
RRRRu_iuwould updateuPUTu{0}/{1}N(RR8t__opts__R3RRt
startswithtgettlenR2RR(R4R5RtdiffRRRR1R6tdata_to_updateR/R0tresource_valuetresource_id((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pytcreate_or_update_resource�s8

+
$cC@st||||||�}|rwtdr/dStd|=t|�}tddddj||�d|d	|d
|�StSdS(u�
    delete any pagerduty resource

    Helper method for absent()

    example:
            delete_resource("users", key, ["id","name","email"]) # delete by id or name or email

    utestuwould deleteupagerduty_util.resource_cacheR#uDELETER
u{0}/{1}RRRN(R8R9R3R2RRR(R4RR5RRRR1R@((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pytdelete_resource8s

1c	K@s�i|dd6id6dd6dd6}t|||d|d|d|d	|�}|tkr_ng|dkrxt|d<nNtd
r�||d<n7d|kr�t|d<||d<nt|d<||d<|S(
uI
    Generic resource.present state method.   Pagerduty state modules should be a thin wrapper over this method,
    with a custom diff function.

    This method calls create_or_update_resource() and formats the result as a salt state return value.

    example:
            resource_present("users", ["id","name","email"])
    unameuchangesuresultuucommentR=RRRutestuerrorN(RRARR9tFalse(	R1R5R=RRRtkwargsRR)((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pytresource_presentNs.
	






c
K@s�i|dd6id6dd6dd6}x�|j�D]�\}}||krQq3nt|||d|d|d|�}	|	dkr�t|d<d	j|�|d<|S|	tkr�q3q3td
r�|	|d<|Sd|	kr3t|d<|	|d<|Sq3W|S(
u=
    Generic resource.absent state method.   Pagerduty state modules should be a thin wrapper over this method,
    with a custom diff function.

    This method calls delete_resource() and formats the result as a salt state return value.

    example:
            resource_absent("users", ["id","name","email"])
    unameuchangesuresultuucommentRRRu{0} deletedutestuerrorN(RRRBRRR9RC(
R1R5RRRRDRR/R0R)((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pytresource_absentss6

	




(t__doc__t
__future__RRRRtsalt.utils.jsonRRRR	R
RRRRRR2R8RARBRERF(((s?/usr/lib/python2.7/site-packages/salt/modules/pagerduty_util.pyt<module>s$	I	-9%

Zerion Mini Shell 1.0