Cloudwatch support multiple regions

This commit is contained in:
beeva-antonioirizar 2016-02-18 18:35:32 +01:00
parent a9d161e58e
commit 4bbd2a11a7
3 changed files with 21 additions and 4 deletions

View File

@ -1,2 +1,11 @@
from .models import cloudwatch_backend
mock_cloudwatch = cloudwatch_backend.decorator
from .models import cloudwatch_backends
from ..core.models import MockAWS
cloudwatch_backend = cloudwatch_backends['us-east-1']
def mock_cloudwatch(func=None):
if func:
return MockAWS(cloudwatch_backends)(func)
else:
return MockAWS(cloudwatch_backends)

View File

@ -1,4 +1,5 @@
from moto.core import BaseBackend
import boto.ec2.cloudwatch
class Dimension(object):
@ -99,4 +100,6 @@ class CloudWatchBackend(BaseBackend):
return self.metric_data
cloudwatch_backend = CloudWatchBackend()
cloudwatch_backends = {}
for region in boto.ec2.cloudwatch.regions():
cloudwatch_backends[region.name] = CloudWatchBackend()

View File

@ -1,5 +1,5 @@
from moto.core.responses import BaseResponse
from .models import cloudwatch_backend
from .models import cloudwatch_backends
import logging
@ -18,6 +18,7 @@ class CloudWatchResponse(BaseResponse):
ok_actions = self._get_multi_param('OKActions.member')
insufficient_data_actions = self._get_multi_param("InsufficientDataActions.member")
unit = self._get_param('Unit')
cloudwatch_backend = cloudwatch_backends[self.region]
alarm = cloudwatch_backend.put_metric_alarm(name, comparison_operator,
evaluation_periods, period,
threshold, statistic,
@ -33,6 +34,7 @@ class CloudWatchResponse(BaseResponse):
alarm_name_prefix = self._get_param('AlarmNamePrefix')
alarm_names = self._get_multi_param('AlarmNames.member')
state_value = self._get_param('StateValue')
cloudwatch_backend = cloudwatch_backends[self.region]
if action_prefix:
alarms = cloudwatch_backend.get_alarms_by_action_prefix(action_prefix)
@ -50,6 +52,7 @@ class CloudWatchResponse(BaseResponse):
def delete_alarms(self):
alarm_names = self._get_multi_param('AlarmNames.member')
cloudwatch_backend = cloudwatch_backends[self.region]
cloudwatch_backend.delete_alarms(alarm_names)
template = self.response_template(DELETE_METRIC_ALARMS_TEMPLATE)
return template.render()
@ -76,11 +79,13 @@ class CloudWatchResponse(BaseResponse):
dimension_index += 1
metric_data.append([metric_name, value, dimensions])
metric_index += 1
cloudwatch_backend = cloudwatch_backends[self.region]
cloudwatch_backend.put_metric_data(namespace, metric_data)
template = self.response_template(PUT_METRIC_DATA_TEMPLATE)
return template.render()
def list_metrics(self):
cloudwatch_backend = cloudwatch_backends[self.region]
metrics = cloudwatch_backend.get_all_metrics()
template = self.response_template(LIST_METRICS_TEMPLATE)
return template.render(metrics=metrics)