%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/boto_cloudwatch.pyc

�
���^c@@s�dZddlmZmZmZddlZddlZddlmZddl	Z
ddljj
Z
ddlZ
eje�ZySddlZddlZddlZddlZejd�jej�eZWnek
r�eZnXd�Zddddd�Zd�Zdddddd	�Z ddddddddddd
ddddddddd�Z!ddddd�Z"ddddd
�Z#d�Z$dS(u�
Connection module for Amazon CloudWatch

.. versionadded:: 2014.7.0

:configuration: This module accepts explicit credentials but can also utilize
    IAM roles assigned to the instance through Instance Profiles. Dynamic
    credentials are then automatically obtained from AWS API and no further
    configuration is necessary. More Information available at:

    .. code-block:: text

        http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

    If IAM roles are not used you need to specify them either in a pillar or
    in the minion's config file:

    .. code-block:: yaml

        cloudwatch.keyid: GKTADJGHEIQSXMKKRBJ08H
        cloudwatch.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

    A region may also be specified in the configuration:

    .. code-block:: yaml

        cloudwatch.region: us-east-1

    If a region is not specified, the default is us-east-1.

    It's also possible to specify key, keyid and region via a profile, either
    as a passed in dict, or as a string to pull from pillars or minion config:

    .. code-block:: yaml

        myprofile:
            keyid: GKTADJGHEIQSXMKKRBJ08H
            key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
            region: us-east-1

:depends: boto
i(tabsolute_importtprint_functiontunicode_literalsN(tsixubotocC@sHtjjjdt�}|tkrDtdtddddt�n|S(u,
    Only load if boto libraries exist.
    tcheck_boto3uboto.assign_funcsu
cloudwatchtmoduleuec2.cloudwatchtpack(	tsalttutilstversionstcheck_boto_reqstFalsetTruet	__utils__t__name__t__salt__(t
has_boto_reqs((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudwatch.pyt__virtual__Is
c	C@std|d|d|d|�}|jd|g�}t|�dkrLd	St|�dkrqtjd|�nt|d�S(
u�
    Get alarm details. Also can be used to check to see if an alarm exists.

    CLI example::

        salt myminion boto_cloudwatch.get_alarm myalarm region=us-east-1
    tregiontkeytkeyidtprofiletalarm_namesiiu!multiple alarms matched name '%s'N(t	_get_conntdescribe_alarmstlentNonetlogterrort_metric_alarm_to_dict(tnameRRRRtconntalarms((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudwatch.pyt	get_alarmUs!cC@sztdd�}d�}tjtjjjj|d|�d�}tjtjjjj	|d|�td|d|�S(uv
    this presenter magic makes yaml.safe_dump
    work with the objects returned from
    boto.describe_alarms()
    uyaml.get_dumperuSafeOrderedDumpercS@s|jt|��S(N(trepresent_listtlist(tdumpertdata((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudwatch.pytboto_listelement_presenterostDumpercS@s|jt|��S(N(trepresent_dicttdict(R$R%((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudwatch.pytdimension_presentervsu	yaml.dump(
R
tyamltadd_representertbototec2t
cloudwatchtlistelementtListElementt	dimensiont	Dimension(R%t
custom_dumperR&R*((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudwatch.pyt
_safe_dumpgs		
c	C@s�td|d|d|d|�}|j�}tj�}x�|D]~}t|�}|d}	|r�|	j|�rwq@n||d}	n|d=i|	d6i|d6g}
i|
d6|d|	<q@Wt|�S(	u7
    Get all alarm details.  Produces results that can be used to create an sls
    file.

    If prefix parameter is given, alarm names in the output will be prepended
    with the prefix; alarms that have the prefix will be skipped.  This can be
    used to convert existing alarms to be managed by salt, as follows:

        1. Make a "backup" of all existing alarms
            $ salt-call boto_cloudwatch.get_all_alarms --out=txt | sed "s/local: //" > legacy_alarms.sls

        2. Get all alarms with new prefixed names
            $ salt-call boto_cloudwatch.get_all_alarms "prefix=**MANAGED BY SALT** " --out=txt | sed "s/local: //" > managed_alarms.sls

        3. Insert the managed alarms into cloudwatch
            $ salt-call state.template managed_alarms.sls

        4.  Manually verify that the new alarms look right

        5.  Delete the original alarms
            $ sed s/present/absent/ legacy_alarms.sls > remove_legacy_alarms.sls
            $ salt-call state.template remove_legacy_alarms.sls

        6.  Get all alarms again, verify no changes
            $ salt-call boto_cloudwatch.get_all_alarms --out=txt | sed "s/local: //" > final_alarms.sls
            $ diff final_alarms.sls managed_alarms.sls

    CLI example::

        salt myminion boto_cloudwatch.get_all_alarms region=us-east-1 --out=txt
    RRRRunameu
attributesuboto_cloudwatch_alarm.presentu
manage alarm (RRtodicttOrderedDictRt
startswithR5(RtprefixRRRRR tresultstalarmRt	alarm_sls((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudwatch.pytget_all_alarmss!!

ucC@s0|rt|�}n|r*t|�}n|r?t|�}nt|tj�r�tjjj|�}t|t	�s�t
jd|�tSnt|tj�r�|j
d�}nt|
tj�r�|
j
d�}
nt|tj�r�|j
d�}n|r%t|d|d|d|d|�}n|
rRt|
d|d|d|d|�}
n|rt|d|d|d|d|�}ntd|d|d|d|�}tjjjjd|d|d	|d
|d|d|d
|d|d|d|	d|
d|d|d|
d|�}|j|�t
jd|�tS(u=
    Create or update a cloudwatch alarm.

    Params are the same as:
        https://boto.readthedocs.io/en/latest/ref/cloudwatch.html#boto.ec2.cloudwatch.alarm.MetricAlarm.

    Dimensions must be a dict. If the value of Dimensions is a string, it will
    be json decoded to produce a dict. alarm_actions, insufficient_data_actions,
    and ok_actions must be lists of string.  If the passed-in value is a string,
    it will be split on "," to produce a list. The strings themselves for
    alarm_actions, insufficient_data_actions, and ok_actions must be Amazon
    resource names (ARN's); however, this method also supports an arn lookup
    notation, as follows:

        arn:aws:....                                    ARN as per http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
        scaling_policy:<as_name>:<scaling_policy_name>  The named autoscale group scaling policy, for the named group (e.g.  scaling_policy:my-asg:ScaleDown)

    This is convenient for setting up autoscaling as follows.  First specify a
    boto_asg.present state for an ASG with scaling_policies, and then set up
    boto_cloudwatch_alarm.present states which have alarm_actions that
    reference the scaling_policy.

    CLI example:

        salt myminion boto_cloudwatch.create_alarm name=myalarm ... region=us-east-1
    uJcould not parse dimensions argument: must be json encoding of a dict: '%s'u,RRRRt
connectionRtmetrict	namespacet	statistict
comparisont	thresholdtperiodtevaluation_periodstunittdescriptiont
dimensionst
alarm_actionstinsufficient_data_actionst
ok_actionsuCreated/updated alarm %s(tfloattintt
isinstanceRtstring_typesRRtjsontloadsR)RRRtsplittconvert_to_arnRR-R.R/R;tMetricAlarmtcreate_alarmtinfoR(R>RR?R@RARBRCRDRERFRGRHRIRJRKRRRRRR;((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudwatch.pytcreate_or_update_alarm�sn"			!	
cC@s�g}x�|D]�}|jd�r�|jd�\}}}	td||	||||�}
|
ro|j|
�q�tjd|�q
|j|�q
W|S(u�
    Convert a list of strings into actual arns. Converts convenience names such
    as 'scaling_policy:...'

    CLI Example::

        salt '*' convert_to_arn 'scaling_policy:'
    uscaling_policy:u:uboto_asg.get_scaling_policy_arnuCould not convert: %s(R8RRRtappendRR(tarnsRRRRR:tarnt_tas_grouptscaling_policy_namet
policy_arn((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudwatch.pyRSs	
c	C@sEtd|d|d|d|�}|j|g�tjd|�tS(u�
    Delete a cloudwatch alarm

    CLI example to delete a queue::

        salt myminion boto_cloudwatch.delete_alarm myalarm region=us-east-1
    RRRRuDeleted alarm %s(Rt
delete_alarmsRRVR(RRRRRR((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudwatch.pytdelete_alarm+s!cC@svtj�}ddddddddd	d
ddd
dg}x3|D]+}t||�rCt||�||<qCqCW|S(uk
    Convert a boto.ec2.cloudwatch.alarm.MetricAlarm into a dict. Convenience
    for pretty printing.
    unameumetricu	namespaceu	statisticu
comparisonu	thresholduperioduevaluation_periodsuunitudescriptionu
dimensionsu
alarm_actionsuinsufficient_data_actionsu
ok_actions(R6R7thasattrtgetattr(R;tdtfieldstf((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudwatch.pyR:s	
(%t__doc__t
__future__RRRtloggingR+tsalt.extRtsalt.utils.jsonRtsalt.utils.odictRR6tsalt.utils.versionst	getLoggerRRR-tboto.ec2.cloudwatchtboto.ec2.cloudwatch.listelementtboto.ec2.cloudwatch.dimensiontsetLeveltCRITICALRtHAS_BOTOtImportErrorRRRR!R5R=RWRSR`R(((s@/usr/lib/python2.7/site-packages/salt/modules/boto_cloudwatch.pyt<module>+s>


		3	Z

Zerion Mini Shell 1.0