Current File : //lib/python2.7/site-packages/euca2ools/commands/monitoring/putmetricdata.pyc
�
��Xc@s�ddlZddlZddlZddlmZddlZddlmZddlm	Z	ddl
mZdZi	dd6d	d
6dd6d
d6dd6dd6dd6dd6dd6Z
de	fd��YZdS(i����N(tArg(tdelimited_list(tCloudWatchRequest(tcloudwatch_dimensionit
Dimensionstdimt
MetricNametmetrictMaximumtmaxtMinimumtmintSampleCounttcounttSumtsumt	TimestampttstUnittunittValuetvalt
PutMetricDatacBsjeZdZedddddedd�edd	dd
dd/dd
dedddd�edddddd/dddddd�edddddddd/dej�edddd/dddd�edddddd/de	dd e
�dd!�ed"d#dd/dd$dd%�ed&d'dd/dd(dd)�gZd*�Zd+�Z
d,�Zd-�Zd.�ZRS(0sJ

    Add data values or statistics to a CloudWatch metric

    A metric datum consists of a metric name, any of several attributes,
    and either a simple, numeric value (-v) or a set of statistical
    values (-s).

    All metric data in a given invocation of %(prog)s must belong to one
    namespace.  %(prog)s supports the following attributes (and
    equivalent aliases, in parentheses) for all data.  Each of
    these attributes has a corresponding command line option that
    specifies that attribute for all metric data.

      * MetricName (metric)
      * Dimensions (dim)
      * Timestamp (ts)
      * Unit (unit)

    Simple metric data have one additional attribute for their values:

      * Value (val)

    Statistical metric data have four additional attributes:

      * Maximum (max)
      * Minimum (min)
      * SampleCount (count)
      * Sum (sum)

    The -v/--value option allows you to specify the value of a simple
    metric datum.  To specify other attributes for data given using
    this option, use the options that correspond to them, such as
    -d/--dimensions.  In particular, the -m/--metric-name option is
    required when -v/--value is used.

    The -s/--metric-datum option allows for full control of each data
    point's attributes.  This is necessary for statistical data
    points.  To specify a metric datum using this option, join each
    attribute's name or alias from the lists above with its value
    using an '=' character, and join each of those pairs with ','
    characters.  If a value contains a ',' character, surround the
    entire attribute with '"' characters.

    For example, each of the following is a valid string
    to pass to -s/--metric-datum:

        MetricName=MyMetric,Value=1.5

        MetricName=MyMetric,Maximum=5,Minimum=1,SampleCount=5,Sum=10

        metric=MyMetric,val=9,"dim=InstanceId:i-12345678,Volume:/dev/sda"

    Attributes specified via -s/--metric-datum take precedence over those
    specified with attribute-specific command line options, such as
    -d/--dimensions.

    Timestamps must use a format specified in ISO 8601, such as
    "1989-11-09T19:17:45.000+01:00".  Note that the CloudWatch
    service does not accept data with timestamps more than two weeks
    in the past.

    Dimensions' attributes are specified as a comma-separated list
    of dimension names and values that are themselves separated by
    ':' characters.  This means that when more than one dimension is
    necessary, the entire Dimensions attribute must be enclosed in '"'
    characters.  Most shell environments require this to be escaped.
    s-ns--namespacetdestt	Namespacetrequiredthelps,namespace for the new metric data (required)s-vs--valuet
simple_valuestroute_totmetavartFLOATttypetactiontappendsZa simple value for a metric datum.  Each use
                specifies a new metric datum.s-ss--metric-datumtattr_valuessKEY1=VALUE1,KEY2=VALUE2,...s�names and values of the attributes for a metric
                datum.  When values include ',' characters, enclose the
                entire name/value pair in '"' characters.s--statistic-valuess--statisticValuess-ms
--metric-nametMETRICs(name of the metric to add metric data tos-ds--dimensionst,t	item_typesLone or more dimensions to associate with the new
                metric datas-ts--timestampsYYYY-MM-DDThh:mm:ssZs!timestamp for the new metric datas-us--unittUNITsOunit in which to report the new metric data
                points (e.g. Bytes)cCs�tj|�g}x6|jjd�p+dD]}|j|j|��q,Wx6|jjd�pddD]}|j|j|��qeW||jd<dS(NRR"tdata(((Rt	configuretargstgetR!t&_PutMetricData__build_datum_from_valuet&_PutMetricData__build_datum_from_pairs(tselfR'R((sO/usr/lib/python2.7/site-packages/euca2ools/commands/monitoring/putmetricdata.pyR(�s
cCs�|jjd�pg}x^tdt|�t�D]D}t|tt|��}i|||!d6|jd<|j�q1W|jdS(NR'itmembert
MetricData(R)R*trangetlentPOINTS_PER_REQUESTRtparamstsend(R-R'tslice_startt	slice_end((sO/usr/lib/python2.7/site-packages/euca2ools/commands/monitoring/putmetricdata.pytmain�scCs{i}yt|�|d<Wn)tk
rEtjdj|���nX|j|�|jd�swtjj	d��n|S(NRs0argument -v/--value: value '{0}' must be numericRs-argument -v/--value requires -m/--metric-name(
tfloatt
ValueErrortargparsetArgumentTypeErrortformatt_PutMetricData__complete_datumR*trequestbuildert
exceptionst
ArgumentError(R-tvaluetdatum((sO/usr/lib/python2.7/site-packages/euca2ools/commands/monitoring/putmetricdata.pyt__build_datum_from_value�s

	c
Cskddddg}i}|j�s6tjd��nxHttjtj|���D](}y|jd�\}}Wnet	k
r�|j
d�s�|j
d�r�tjd	j|���ntjd
j||���nXtj
||�}||krLy t|�|jdi�|<Wq}t	k
rHtjdj||���q}XqU|d
kr�yt|�||<Wq}t	k
r�tjdj||���q}XqU|dkrI|j|igd6�x�|jd�D]q}y|jd�\}}	Wn,t	k
rtjdj||���nX||dji|d6|	d
6�q�WqU|dkrb|||<qUtjdj||���qUW|j|�|j
d�s�tjdj|���nd|kr@d
|kr�tjdj|t|dj�����nxf|D]4}||dkrtjdj||���qqWn'd
|krgtjdj|���n|S(NRR
RRs3argument -s/--metric-datum: value must not be emptyt=sdim=sDimensions=siargument -s/--metric-datum: dimension names and values in datum '{0}' must be separated with ':', not '='sOargument -s/--metric-datum: '{0}' in datum '{1}' must have format KEY=VALUE,...tStatisticValuessEargument -s/--metric-datum: {0} value for datum '{1}' must be numericRRR.R$t:sZargument -s/--metric-datum: dimension '{0}' for datum '{1}' must have format KEY:VALUE,...tNameRRRsMargument -s/--metric-datum: datum '{0}' contains unrecognized attribute '{1}'s�argument -s/--metric-datum: datum '{0}' must have a metric name; supply one individually with 'MetricName=NAME' or set a default for this request with -m/--metric-namesVargument -s/--metric-datum: datum '{0}' must not contain both Value and {1} attributessGargument -s/--metric-datum: a {0} is required for statistic datum '{1}'soargument -s/--metric-datum: datum '{0}' must contain either a Value or a Maximum, Minimum, SampleCount, and Sum(s
MetricNameRR(tstripR:R;tnexttcsvtreadertiotBytesIOtsplitR9t
startswithR<t
DATUM_KEYSR*R8t
setdefaultR!R=tvalues(
R-tpairs_as_strtstatistic_set_keysRBtpairtkeyRtdim_pairtdim_nametdim_val((sO/usr/lib/python2.7/site-packages/euca2ools/commands/monitoring/putmetricdata.pyt__build_datum_from_pairs�s�%
 




"
cCs�idd6dd6dd6}xK|j�D]=\}}|jj|�r(|j||jj|��q(q(W|jjd�r�|jdi|jjd�d	6�ndS(
Ntmetric_nameRt	timestampRRRt
dimensionsRR.(titemsR)R*RQ(R-RBtattr_mapRVR((sO/usr/lib/python2.7/site-packages/euca2ools/commands/monitoring/putmetricdata.pyt__complete_datum
s
#	N(t__name__t
__module__t__doc__RtTruetNoneR8R:tSUPPRESSRRtARGSR(R7R+R,R=(((sO/usr/lib/python2.7/site-packages/euca2ools/commands/monitoring/putmetricdata.pyR2s6C				O(R:RJRLR>Rtrequestbuilder.exceptionsteuca2ools.commands.argtypesRteuca2ools.commands.monitoringRt&euca2ools.commands.monitoring.argtypesRR2RPR(((sO/usr/lib/python2.7/site-packages/euca2ools/commands/monitoring/putmetricdata.pyt<module>s$