Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(813)

Side by Side Diff: boto/ec2/cloudwatch/__init__.py

Issue 8386013: Merging in latest boto. (Closed) Base URL: svn://svn.chromium.org/boto
Patch Set: Redoing vendor drop by deleting and then merging. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « boto/ec2/blockdevicemapping.py ('k') | boto/ec2/cloudwatch/alarm.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/ 1 # Copyright (c) 2006-2011 Mitch Garnaat http://garnaat.org/
2 # 2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a 3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the 4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including 5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis- 6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit 7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol- 8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions: 9 # lowing conditions:
10 # 10 #
11 # The above copyright notice and this permission notice shall be included 11 # The above copyright notice and this permission notice shall be included
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 u'SampleCount': 1.0, 133 u'SampleCount': 1.0,
134 u'Timestamp': u'2009-05-21T19:55:00Z', 134 u'Timestamp': u'2009-05-21T19:55:00Z',
135 u'Unit': u'Percent'} 135 u'Unit': u'Percent'}
136 136
137 My server obviously isn't very busy right now! 137 My server obviously isn't very busy right now!
138 """ 138 """
139 try: 139 try:
140 import simplejson as json 140 import simplejson as json
141 except ImportError: 141 except ImportError:
142 import json 142 import json
143
143 from boto.connection import AWSQueryConnection 144 from boto.connection import AWSQueryConnection
144 from boto.ec2.cloudwatch.metric import Metric 145 from boto.ec2.cloudwatch.metric import Metric
145 from boto.ec2.cloudwatch.alarm import MetricAlarm, AlarmHistoryItem 146 from boto.ec2.cloudwatch.alarm import MetricAlarm, AlarmHistoryItem
146 from boto.ec2.cloudwatch.datapoint import Datapoint 147 from boto.ec2.cloudwatch.datapoint import Datapoint
147 from boto.regioninfo import RegionInfo 148 from boto.regioninfo import RegionInfo
148 import boto 149 import boto
149 150
150 RegionData = { 151 RegionData = {
151 'us-east-1' : 'monitoring.us-east-1.amazonaws.com', 152 'us-east-1' : 'monitoring.us-east-1.amazonaws.com',
152 'us-west-1' : 'monitoring.us-west-1.amazonaws.com', 153 'us-west-1' : 'monitoring.us-west-1.amazonaws.com',
153 'eu-west-1' : 'monitoring.eu-west-1.amazonaws.com', 154 'eu-west-1' : 'monitoring.eu-west-1.amazonaws.com',
155 'ap-northeast-1' : 'monitoring.ap-northeast-1.amazonaws.com',
154 'ap-southeast-1' : 'monitoring.ap-southeast-1.amazonaws.com'} 156 'ap-southeast-1' : 'monitoring.ap-southeast-1.amazonaws.com'}
155 157
156 def regions(): 158 def regions():
157 """ 159 """
158 Get all available regions for the CloudWatch service. 160 Get all available regions for the CloudWatch service.
159 161
160 :rtype: list 162 :rtype: list
161 :return: A list of :class:`boto.RegionInfo` instances 163 :return: A list of :class:`boto.RegionInfo` instances
162 """ 164 """
163 regions = [] 165 regions = []
(...skipping 17 matching lines...) Expand all
181 """ 183 """
182 for region in regions(): 184 for region in regions():
183 if region.name == region_name: 185 if region.name == region_name:
184 return region.connect(**kw_params) 186 return region.connect(**kw_params)
185 return None 187 return None
186 188
187 189
188 class CloudWatchConnection(AWSQueryConnection): 190 class CloudWatchConnection(AWSQueryConnection):
189 191
190 APIVersion = boto.config.get('Boto', 'cloudwatch_version', '2010-08-01') 192 APIVersion = boto.config.get('Boto', 'cloudwatch_version', '2010-08-01')
191 DefaultRegionName = boto.config.get('Boto', 'cloudwatch_region_name', 'us-ea st-1') 193 DefaultRegionName = boto.config.get('Boto', 'cloudwatch_region_name',
192 DefaultRegionEndpoint = boto.config.get('Boto', 'cloudwatch_region_endpoint' , 194 'us-east-1')
195 DefaultRegionEndpoint = boto.config.get('Boto',
196 'cloudwatch_region_endpoint',
193 'monitoring.amazonaws.com') 197 'monitoring.amazonaws.com')
194 198
195 199
196 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, 200 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
197 is_secure=True, port=None, proxy=None, proxy_port=None, 201 is_secure=True, port=None, proxy=None, proxy_port=None,
198 proxy_user=None, proxy_pass=None, debug=0, 202 proxy_user=None, proxy_pass=None, debug=0,
199 https_connection_factory=None, region=None, path='/'): 203 https_connection_factory=None, region=None, path='/'):
200 """ 204 """
201 Init method to create a new connection to EC2 Monitoring Service. 205 Init method to create a new connection to EC2 Monitoring Service.
202 206
203 B{Note:} The host argument is overridden by the host specified in the 207 B{Note:} The host argument is overridden by the host specified in the
204 boto configuration file. 208 boto configuration file.
205 """ 209 """
206 if not region: 210 if not region:
207 region = RegionInfo(self, self.DefaultRegionName, 211 region = RegionInfo(self, self.DefaultRegionName,
208 self.DefaultRegionEndpoint) 212 self.DefaultRegionEndpoint)
209 self.region = region 213 self.region = region
210 214
211 AWSQueryConnection.__init__(self, aws_access_key_id, 215 AWSQueryConnection.__init__(self, aws_access_key_id,
212 aws_secret_access_key, 216 aws_secret_access_key,
213 is_secure, port, proxy, proxy_port, 217 is_secure, port, proxy, proxy_port,
214 proxy_user, proxy_pass, 218 proxy_user, proxy_pass,
215 self.region.endpoint, debug, 219 self.region.endpoint, debug,
216 https_connection_factory, path) 220 https_connection_factory, path)
217 221
218 def _required_auth_capability(self): 222 def _required_auth_capability(self):
219 return ['ec2'] 223 return ['ec2']
220 224
225 def build_dimension_param(self, dimension, params):
226 for dim_name in dimension:
227 dim_value = dimension[dim_name]
228 if isinstance(dim_value, basestring):
229 dim_value = [dim_value]
230 for i, value in enumerate(dim_value):
231 params['Dimensions.member.%d.Name' % (i+1)] = dim_name
232 params['Dimensions.member.%d.Value' % (i+1)] = value
233
221 def build_list_params(self, params, items, label): 234 def build_list_params(self, params, items, label):
222 if isinstance(items, str): 235 if isinstance(items, basestring):
223 items = [items] 236 items = [items]
224 for i in range(1, len(items)+1): 237 for index, item in enumerate(items):
225 params[label % i] = items[i-1] 238 i = index + 1
239 if isinstance(item, dict):
240 for k,v in item.iteritems():
241 params[label % (i, 'Name')] = k
242 if v is not None:
243 params[label % (i, 'Value')] = v
244 else:
245 params[label % i] = item
246
247 def build_put_params(self, params, name, value=None, timestamp=None,
248 unit=None, dimensions=None, statistics=None):
249 args = (name, value, unit, dimensions, statistics)
250 length = max(map(lambda a: len(a) if isinstance(a, list) else 1, args))
251
252 def aslist(a):
253 if isinstance(a, list):
254 if len(a) != length:
255 raise Exception('Must specify equal number of elements; expe cted %d.' % length)
256 return a
257 return [a] * length
258
259 for index, (n, v, u, d, s) in enumerate(zip(*map(aslist, args))):
260 metric_data = {'MetricName': n}
261
262 if timestamp:
263 metric_data['Timestamp'] = timestamp.isoformat()
264
265 if unit:
266 metric_data['Unit'] = u
267
268 if dimensions:
269 self.build_dimension_param(d, metric_data)
270
271 if statistics:
272 metric_data['StatisticValues.Maximum'] = s['maximum']
273 metric_data['StatisticValues.Minimum'] = s['minimum']
274 metric_data['StatisticValues.SampleCount'] = s['samplecount']
275 metric_data['StatisticValues.Sum'] = s['sum']
276 if value != None:
277 msg = 'You supplied a value and statistics for a metric.'
278 msg += 'Posting statistics and not value.'
279 boto.log.warn(msg)
280 elif value != None:
281 metric_data['Value'] = v
282 else:
283 raise Exception('Must specify a value or statistics to put.')
284
285 for key, value in metric_data.iteritems():
286 params['MetricData.member.%d.%s' % (index + 1, key)] = value
226 287
227 def get_metric_statistics(self, period, start_time, end_time, metric_name, 288 def get_metric_statistics(self, period, start_time, end_time, metric_name,
228 namespace, statistics, dimensions=None, unit=None) : 289 namespace, statistics, dimensions=None,
290 unit=None):
229 """ 291 """
230 Get time-series data for one or more statistics of a given metric. 292 Get time-series data for one or more statistics of a given metric.
231 293
294 :type period: integer
295 :param period: The granularity, in seconds, of the returned datapoints.
296 Period must be at least 60 seconds and must be a multiple
297 of 60. The default value is 60.
298
299 :type start_time: datetime
300 :param start_time: The time stamp to use for determining the first
301 datapoint to return. The value specified is
302 inclusive; results include datapoints with the
303 time stamp specified.
304
305 :type end_time: datetime
306 :param end_time: The time stamp to use for determining the last
307 datapoint to return. The value specified is
308 exclusive; results will include datapoints up to
309 the time stamp specified.
310
232 :type metric_name: string 311 :type metric_name: string
233 :param metric_name: CPUUtilization|NetworkIO-in|NetworkIO-out|DiskIO-ALL -read| 312 :param metric_name: The metric name.
234 DiskIO-ALL-write|DiskIO-ALL-read-bytes|DiskIO-ALL-w rite-bytes
235 313
314 :type namespace: string
315 :param namespace: The metric's namespace.
316
317 :type statistics: list
318 :param statistics: A list of statistics names Valid values:
319 Average | Sum | SampleCount | Maximum | Minimum
320
321 :type dimensions: dict
322 :param dimensions: A dictionary of dimension key/values where
323 the key is the dimension name and the value
324 is either a scalar value or an iterator
325 of values to be associated with that
326 dimension.
236 :rtype: list 327 :rtype: list
237 """ 328 """
238 params = {'Period' : period, 329 params = {'Period' : period,
239 'MetricName' : metric_name, 330 'MetricName' : metric_name,
240 'Namespace' : namespace, 331 'Namespace' : namespace,
241 'StartTime' : start_time.isoformat(), 332 'StartTime' : start_time.isoformat(),
242 'EndTime' : end_time.isoformat()} 333 'EndTime' : end_time.isoformat()}
243 self.build_list_params(params, statistics, 'Statistics.member.%d') 334 self.build_list_params(params, statistics, 'Statistics.member.%d')
244 if dimensions: 335 if dimensions:
245 i = 1 336 self.build_dimension_param(dimensions, params)
246 for name in dimensions: 337 return self.get_list('GetMetricStatistics', params,
247 params['Dimensions.member.%d.Name' % i] = name 338 [('member', Datapoint)])
248 params['Dimensions.member.%d.Value' % i] = dimensions[name]
249 i += 1
250 return self.get_list('GetMetricStatistics', params, [('member', Datapoin t)])
251 339
252 def list_metrics(self, next_token=None): 340 def list_metrics(self, next_token=None, dimensions=None,
341 metric_name=None, namespace=None):
253 """ 342 """
254 Returns a list of the valid metrics for which there is recorded data ava ilable. 343 Returns a list of the valid metrics for which there is recorded
344 data available.
255 345
256 :type next_token: string 346 :type next_token: str
257 :param next_token: A maximum of 500 metrics will be returned at one time . 347 :param next_token: A maximum of 500 metrics will be returned at one
258 If more results are available, the ResultSet returned 348 time. If more results are available, the
259 will contain a non-Null next_token attribute. Passin g 349 ResultSet returned will contain a non-Null
260 that token as a parameter to list_metrics will retrie ve 350 next_token attribute. Passing that token as a
261 the next page of metrics. 351 parameter to list_metrics will retrieve the
352 next page of metrics.
353
354 :type dimension: dict
355 :param dimension_filters: A dictionary containing name/value pairs
356 that will be used to filter the results.
357 The key in the dictionary is the name of
358 a Dimension. The value in the dictionary
359 is either a scalar value of that Dimension
360 name that you want to filter on, a list
361 of values to filter on or None if
362 you want all metrics with that Dimension name.
363
364 :type metric_name: str
365 :param metric_name: The name of the Metric to filter against. If None,
366 all Metric names will be returned.
367
368 :type namespace: str
369 :param namespace: A Metric namespace to filter against (e.g. AWS/EC2).
370 If None, Metrics from all namespaces will be returned.
262 """ 371 """
263 params = {} 372 params = {}
264 if next_token: 373 if next_token:
265 params['NextToken'] = next_token 374 params['NextToken'] = next_token
375 if dimensions:
376 self.build_dimension_param(dimensions, params)
377 if metric_name:
378 params['MetricName'] = metric_name
379 if namespace:
380 params['Namespace'] = namespace
381
266 return self.get_list('ListMetrics', params, [('member', Metric)]) 382 return self.get_list('ListMetrics', params, [('member', Metric)])
383
384 def put_metric_data(self, namespace, name, value=None, timestamp=None,
385 unit=None, dimensions=None, statistics=None):
386 """
387 Publishes metric data points to Amazon CloudWatch. Amazon Cloudwatch
388 associates the data points with the specified metric. If the specified
389 metric does not exist, Amazon CloudWatch creates the metric. If a list
390 is specified for some, but not all, of the arguments, the remaining
391 arguments are repeated a corresponding number of times.
267 392
268 def describe_alarms(self, action_prefix=None, alarm_name_prefix=None, alarm_ names=None, 393 :type namespace: str
269 max_records=None, state_value=None, next_token=None): 394 :param namespace: The namespace of the metric.
395
396 :type name: str or list
397 :param name: The name of the metric.
398
399 :type value: float or list
400 :param value: The value for the metric.
401
402 :type timestamp: datetime or list
403 :param timestamp: The time stamp used for the metric. If not specified,
404 the default value is set to the time the metric data was received.
405
406 :type unit: string or list
407 :param unit: The unit of the metric. Valid Values: Seconds |
408 Microseconds | Milliseconds | Bytes | Kilobytes |
409 Megabytes | Gigabytes | Terabytes | Bits | Kilobits |
410 Megabits | Gigabits | Terabits | Percent | Count |
411 Bytes/Second | Kilobytes/Second | Megabytes/Second |
412 Gigabytes/Second | Terabytes/Second | Bits/Second |
413 Kilobits/Second | Megabits/Second | Gigabits/Second |
414 Terabits/Second | Count/Second | None
415
416 :type dimensions: dict
417 :param dimensions: Add extra name value pairs to associate
418 with the metric, i.e.:
419 {'name1': value1, 'name2': (value2, value3)}
420
421 :type statistics: dict or list
422 :param statistics: Use a statistic set instead of a value, for example::
423
424 {'maximum': 30, 'minimum': 1, 'samplecount': 100, 'sum': 10000}
425 """
426 params = {'Namespace': namespace}
427 self.build_put_params(params, name, value=value, timestamp=timestamp,
428 unit=unit, dimensions=dimensions, statistics=statistics)
429
430 return self.get_status('PutMetricData', params)
431
432
433 def describe_alarms(self, action_prefix=None, alarm_name_prefix=None,
434 alarm_names=None, max_records=None, state_value=None,
435 next_token=None):
270 """ 436 """
271 Retrieves alarms with the specified names. If no name is specified, all 437 Retrieves alarms with the specified names. If no name is specified, all
272 alarms for the user are returned. Alarms can be retrieved by using only 438 alarms for the user are returned. Alarms can be retrieved by using only
273 a prefix for the alarm name, the alarm state, or a prefix for any 439 a prefix for the alarm name, the alarm state, or a prefix for any
274 action. 440 action.
275 441
276 :type action_prefix: string 442 :type action_prefix: string
277 :param action_name: The action name prefix. 443 :param action_name: The action name prefix.
278 444
279 :type alarm_name_prefix: string 445 :type alarm_name_prefix: string
280 :param alarm_name_prefix: The alarm name prefix. AlarmNames cannot be sp ecified 446 :param alarm_name_prefix: The alarm name prefix. AlarmNames cannot
281 if this parameter is specified. 447 be specified if this parameter is specified.
282 448
283 :type alarm_names: list 449 :type alarm_names: list
284 :param alarm_names: A list of alarm names to retrieve information for. 450 :param alarm_names: A list of alarm names to retrieve information for.
285 451
286 :type max_records: int 452 :type max_records: int
287 :param max_records: The maximum number of alarm descriptions to retrieve . 453 :param max_records: The maximum number of alarm descriptions
454 to retrieve.
288 455
289 :type state_value: string 456 :type state_value: string
290 :param state_value: The state value to be used in matching alarms. 457 :param state_value: The state value to be used in matching alarms.
291 458
292 :type next_token: string 459 :type next_token: string
293 :param next_token: The token returned by a previous call to indicate tha t there is more data. 460 :param next_token: The token returned by a previous call to
461 indicate that there is more data.
294 462
295 :rtype list 463 :rtype list
296 """ 464 """
297 params = {} 465 params = {}
298 if action_prefix: 466 if action_prefix:
299 params['ActionPrefix'] = action_prefix 467 params['ActionPrefix'] = action_prefix
300 if alarm_name_prefix: 468 if alarm_name_prefix:
301 params['AlarmNamePrefix'] = alarm_name_prefix 469 params['AlarmNamePrefix'] = alarm_name_prefix
302 elif alarm_names: 470 elif alarm_names:
303 self.build_list_params(params, alarm_names, 'AlarmNames.member.%s') 471 self.build_list_params(params, alarm_names, 'AlarmNames.member.%s')
304 if max_records: 472 if max_records:
305 params['MaxRecords'] = max_records 473 params['MaxRecords'] = max_records
306 if next_token: 474 if next_token:
307 params['NextToken'] = next_token 475 params['NextToken'] = next_token
308 if state_value: 476 if state_value:
309 params['StateValue'] = state_value 477 params['StateValue'] = state_value
310 return self.get_list('DescribeAlarms', params, [('member', MetricAlarm)] ) 478 return self.get_list('DescribeAlarms', params,
479 [('member', MetricAlarm)])
311 480
312 def describe_alarm_history(self, alarm_name=None, start_date=None, end_date= None, 481 def describe_alarm_history(self, alarm_name=None,
313 max_records=None, history_item_type=None, next_to ken=None): 482 start_date=None, end_date=None,
483 max_records=None, history_item_type=None,
484 next_token=None):
314 """ 485 """
315 Retrieves history for the specified alarm. Filter alarms by date range 486 Retrieves history for the specified alarm. Filter alarms by date range
316 or item type. If an alarm name is not specified, Amazon CloudWatch 487 or item type. If an alarm name is not specified, Amazon CloudWatch
317 returns histories for all of the owner's alarms. 488 returns histories for all of the owner's alarms.
318 489
319 Amazon CloudWatch retains the history of deleted alarms for a period of 490 Amazon CloudWatch retains the history of deleted alarms for a period of
320 six weeks. If an alarm has been deleted, its history can still be 491 six weeks. If an alarm has been deleted, its history can still be
321 queried. 492 queried.
322 493
323 :type alarm_name: string 494 :type alarm_name: string
324 :param alarm_name: The name of the alarm. 495 :param alarm_name: The name of the alarm.
325 496
326 :type start_date: datetime 497 :type start_date: datetime
327 :param start_date: The starting date to retrieve alarm history. 498 :param start_date: The starting date to retrieve alarm history.
328 499
329 :type end_date: datetime 500 :type end_date: datetime
330 :param end_date: The starting date to retrieve alarm history. 501 :param end_date: The starting date to retrieve alarm history.
331 502
332 :type history_item_type: string 503 :type history_item_type: string
333 :param history_item_type: The type of alarm histories to retreive (Confi gurationUpdate | StateUpdate | Action) 504 :param history_item_type: The type of alarm histories to retreive
505 (ConfigurationUpdate | StateUpdate | Action)
334 506
335 :type max_records: int 507 :type max_records: int
336 :param max_records: The maximum number of alarm descriptions to retrieve . 508 :param max_records: The maximum number of alarm descriptions
509 to retrieve.
337 510
338 :type next_token: string 511 :type next_token: string
339 :param next_token: The token returned by a previous call to indicate tha t there is more data. 512 :param next_token: The token returned by a previous call to indicate
513 that there is more data.
340 514
341 :rtype list 515 :rtype list
342 """ 516 """
343 params = {} 517 params = {}
344 if alarm_name: 518 if alarm_name:
345 params['AlarmName'] = alarm_name 519 params['AlarmName'] = alarm_name
346 if start_date: 520 if start_date:
347 params['StartDate'] = start_date.isoformat() 521 params['StartDate'] = start_date.isoformat()
348 if end_date: 522 if end_date:
349 params['EndDate'] = end_date.isoformat() 523 params['EndDate'] = end_date.isoformat()
350 if history_item_type: 524 if history_item_type:
351 params['HistoryItemType'] = history_item_type 525 params['HistoryItemType'] = history_item_type
352 if max_records: 526 if max_records:
353 params['MaxRecords'] = max_records 527 params['MaxRecords'] = max_records
354 if next_token: 528 if next_token:
355 params['NextToken'] = next_token 529 params['NextToken'] = next_token
356 return self.get_list('DescribeAlarmHistory', params, [('member', AlarmHi storyItem)]) 530 return self.get_list('DescribeAlarmHistory', params,
531 [('member', AlarmHistoryItem)])
357 532
358 def describe_alarms_for_metric(self, metric_name, namespace, period=None, st atistic=None, dimensions=None, unit=None): 533 def describe_alarms_for_metric(self, metric_name, namespace, period=None,
534 statistic=None, dimensions=None, unit=None):
359 """ 535 """
360 Retrieves all alarms for a single metric. Specify a statistic, period, 536 Retrieves all alarms for a single metric. Specify a statistic, period,
361 or unit to filter the set of alarms further. 537 or unit to filter the set of alarms further.
362 538
363 :type metric_name: string 539 :type metric_name: string
364 :param metric_name: The name of the metric 540 :param metric_name: The name of the metric
365 541
366 :type namespace: string 542 :type namespace: string
367 :param namespace: The namespace of the metric. 543 :param namespace: The namespace of the metric.
368 544
369 :type period: int 545 :type period: int
370 :param period: The period in seconds over which the statistic is applied . 546 :param period: The period in seconds over which the statistic
547 is applied.
371 548
372 :type statistic: string 549 :type statistic: string
373 :param statistic: The statistic for the metric. 550 :param statistic: The statistic for the metric.
374 551
375 :type dimensions: list 552 :param dimension_filters: A dictionary containing name/value pairs
553 that will be used to filter the results.
554 The key in the dictionary is the name of
555 a Dimension. The value in the dictionary
556 is either a scalar value of that Dimension
557 name that you want to filter on, a list
558 of values to filter on or None if
559 you want all metrics with that Dimension name.
376 560
377 :type unit: string 561 :type unit: string
378 562
379 :rtype list 563 :rtype list
380 """ 564 """
381 params = { 565 params = {'MetricName' : metric_name,
382 'MetricName' : metric_name, 566 'Namespace' : namespace}
383 'Namespace' : namespace,
384 }
385 if period: 567 if period:
386 params['Period'] = period 568 params['Period'] = period
387 if statistic: 569 if statistic:
388 params['Statistic'] = statistic 570 params['Statistic'] = statistic
389 if dimensions: 571 if dimensions:
390 self.build_list_params(params, dimensions, 'Dimensions.member.%s') 572 self.build_dimension_param(dimensions, params)
391 if unit: 573 if unit:
392 params['Unit'] = unit 574 params['Unit'] = unit
393 return self.get_list('DescribeAlarmsForMetric', params, [('member', Metr icAlarm)]) 575 return self.get_list('DescribeAlarmsForMetric', params,
576 [('member', MetricAlarm)])
394 577
395 def put_metric_alarm(self, alarm): 578 def put_metric_alarm(self, alarm):
396 """ 579 """
397 Creates or updates an alarm and associates it with the specified Amazon 580 Creates or updates an alarm and associates it with the specified Amazon
398 CloudWatch metric. Optionally, this operation can associate one or more 581 CloudWatch metric. Optionally, this operation can associate one or more
399 Amazon Simple Notification Service resources with the alarm. 582 Amazon Simple Notification Service resources with the alarm.
400 583
401 When this operation creates an alarm, the alarm state is immediately 584 When this operation creates an alarm, the alarm state is immediately
402 set to INSUFFICIENT_DATA. The alarm is evaluated and its StateValue is 585 set to INSUFFICIENT_DATA. The alarm is evaluated and its StateValue is
403 set appropriately. Any actions associated with the StateValue is then 586 set appropriately. Any actions associated with the StateValue is then
404 executed. 587 executed.
405 588
406 When updating an existing alarm, its StateValue is left unchanged. 589 When updating an existing alarm, its StateValue is left unchanged.
407 590
408 :type alarm: boto.ec2.cloudwatch.alarm.MetricAlarm 591 :type alarm: boto.ec2.cloudwatch.alarm.MetricAlarm
409 :param alarm: MetricAlarm object. 592 :param alarm: MetricAlarm object.
410 """ 593 """
411 params = { 594 params = {
412 'AlarmName' : alarm.name, 595 'AlarmName' : alarm.name,
413 'MetricName' : alarm.metric, 596 'MetricName' : alarm.metric,
414 'Namespace' : alarm.namespace, 597 'Namespace' : alarm.namespace,
415 'Statistic' : alarm.statistic, 598 'Statistic' : alarm.statistic,
416 'ComparisonOperator' : MetricAlarm._cmp_map[alarm.c omparison], 599 'ComparisonOperator' : alarm.comparison,
417 'Threshold' : alarm.threshold, 600 'Threshold' : alarm.threshold,
418 'EvaluationPeriods' : alarm.evaluation_periods, 601 'EvaluationPeriods' : alarm.evaluation_periods,
419 'Period' : alarm.period, 602 'Period' : alarm.period,
420 } 603 }
421 if alarm.actions_enabled is not None: 604 if alarm.actions_enabled is not None:
422 params['ActionsEnabled'] = alarm.actions_enabled 605 params['ActionsEnabled'] = alarm.actions_enabled
423 if alarm.alarm_actions: 606 if alarm.alarm_actions:
424 self.build_list_params(params, alarm.alarm_actions, 'AlarmActions.me mber.%s') 607 self.build_list_params(params, alarm.alarm_actions,
608 'AlarmActions.member.%s')
425 if alarm.description: 609 if alarm.description:
426 params['AlarmDescription'] = alarm.description 610 params['AlarmDescription'] = alarm.description
427 if alarm.dimensions: 611 if alarm.dimensions:
428 self.build_list_params(params, alarm.dimensions, 'Dimensions.member. %s') 612 self.build_dimension_param(alarm.dimensions, params)
429 if alarm.insufficient_data_actions: 613 if alarm.insufficient_data_actions:
430 self.build_list_params(params, alarm.insufficient_data_actions, 'Ins ufficientDataActions.member.%s') 614 self.build_list_params(params, alarm.insufficient_data_actions,
615 'InsufficientDataActions.member.%s')
431 if alarm.ok_actions: 616 if alarm.ok_actions:
432 self.build_list_params(params, alarm.ok_actions, 'OKActions.member.% s') 617 self.build_list_params(params, alarm.ok_actions,
618 'OKActions.member.%s')
433 if alarm.unit: 619 if alarm.unit:
434 params['Unit'] = alarm.unit 620 params['Unit'] = alarm.unit
435 alarm.connection = self 621 alarm.connection = self
436 return self.get_status('PutMetricAlarm', params) 622 return self.get_status('PutMetricAlarm', params)
437 create_alarm = put_metric_alarm 623 create_alarm = put_metric_alarm
438 update_alarm = put_metric_alarm 624 update_alarm = put_metric_alarm
439 625
440 def delete_alarms(self, alarms): 626 def delete_alarms(self, alarms):
441 """ 627 """
442 Deletes all specified alarms. In the event of an error, no alarms are de leted. 628 Deletes all specified alarms. In the event of an error, no
629 alarms are deleted.
443 630
444 :type alarms: list 631 :type alarms: list
445 :param alarms: List of alarm names. 632 :param alarms: List of alarm names.
446 """ 633 """
447 params = {} 634 params = {}
448 self.build_list_params(params, alarms, 'AlarmNames.member.%s') 635 self.build_list_params(params, alarms, 'AlarmNames.member.%s')
449 return self.get_status('DeleteAlarms', params) 636 return self.get_status('DeleteAlarms', params)
450 637
451 def set_alarm_state(self, alarm_name, state_reason, state_value, state_reaso n_data=None): 638 def set_alarm_state(self, alarm_name, state_reason, state_value,
639 state_reason_data=None):
452 """ 640 """
453 Temporarily sets the state of an alarm. When the updated StateValue 641 Temporarily sets the state of an alarm. When the updated StateValue
454 differs from the previous value, the action configured for the 642 differs from the previous value, the action configured for the
455 appropriate state is invoked. This is not a permanent change. The next 643 appropriate state is invoked. This is not a permanent change. The next
456 periodic alarm check (in about a minute) will set the alarm to its 644 periodic alarm check (in about a minute) will set the alarm to its
457 actual state. 645 actual state.
458 646
459 :type alarm_name: string 647 :type alarm_name: string
460 :param alarm_name: Descriptive name for alarm. 648 :param alarm_name: Descriptive name for alarm.
461 649
462 :type state_reason: string 650 :type state_reason: string
463 :param state_reason: Human readable reason. 651 :param state_reason: Human readable reason.
464 652
465 :type state_value: string 653 :type state_value: string
466 :param state_value: OK | ALARM | INSUFFICIENT_DATA 654 :param state_value: OK | ALARM | INSUFFICIENT_DATA
467 655
468 :type state_reason_data: string 656 :type state_reason_data: string
469 :param state_reason_data: Reason string (will be jsonified). 657 :param state_reason_data: Reason string (will be jsonified).
470 """ 658 """
471 params = { 659 params = {'AlarmName' : alarm_name,
472 'AlarmName' : alarm_name, 660 'StateReason' : state_reason,
473 'StateReason' : state_reason, 661 'StateValue' : state_value}
474 'StateValue' : state_value,
475 }
476 if state_reason_data: 662 if state_reason_data:
477 params['StateReasonData'] = json.dumps(state_reason_data) 663 params['StateReasonData'] = json.dumps(state_reason_data)
478 664
479 return self.get_status('SetAlarmState', params) 665 return self.get_status('SetAlarmState', params)
480 666
481 def enable_alarm_actions(self, alarm_names): 667 def enable_alarm_actions(self, alarm_names):
482 """ 668 """
483 Enables actions for the specified alarms. 669 Enables actions for the specified alarms.
484 670
485 :type alarms: list 671 :type alarms: list
486 :param alarms: List of alarm names. 672 :param alarms: List of alarm names.
487 """ 673 """
488 params = {} 674 params = {}
489 self.build_list_params(params, alarm_names, 'AlarmNames.member.%s') 675 self.build_list_params(params, alarm_names, 'AlarmNames.member.%s')
490 return self.get_status('EnableAlarmActions', params) 676 return self.get_status('EnableAlarmActions', params)
491 677
492 def disable_alarm_actions(self, alarm_names): 678 def disable_alarm_actions(self, alarm_names):
493 """ 679 """
494 Disables actions for the specified alarms. 680 Disables actions for the specified alarms.
495 681
496 :type alarms: list 682 :type alarms: list
497 :param alarms: List of alarm names. 683 :param alarms: List of alarm names.
498 """ 684 """
499 params = {} 685 params = {}
500 self.build_list_params(params, alarm_names, 'AlarmNames.member.%s') 686 self.build_list_params(params, alarm_names, 'AlarmNames.member.%s')
501 return self.get_status('DisableAlarmActions', params) 687 return self.get_status('DisableAlarmActions', params)
502 688
OLDNEW
« no previous file with comments | « boto/ec2/blockdevicemapping.py ('k') | boto/ec2/cloudwatch/alarm.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698