From c44c9f9ac531a122bf8b59b6999de69cdd52b88e Mon Sep 17 00:00:00 2001 From: Michael Zeng Date: Fri, 30 Sep 2011 14:49:10 -0400 Subject: [PATCH] cleaned up requesters and parsers --- lib/fog/aws/cloud_watch.rb | 1 - .../aws/parsers/cloud_watch/delete_alarms.rb | 2 ++ .../cloud_watch/describe_alarm_history.rb | 7 +++---- .../parsers/cloud_watch/describe_alarms.rb | 8 ++++---- .../cloud_watch/describe_alarms_for_metric.rb | 8 ++++---- .../cloud_watch/disable_alarm_actions.rb | 2 ++ .../cloud_watch/enable_alarm_actions.rb | 2 ++ .../parsers/cloud_watch/put_metric_alarm.rb | 2 ++ .../aws/requests/cloud_watch/delete_alarms.rb | 19 ++++++++----------- .../cloud_watch/describe_alarm_history.rb | 11 ++++------- .../requests/cloud_watch/describe_alarms.rb | 9 ++++----- .../cloud_watch/describe_alarms_for_metric.rb | 11 ++++------- .../cloud_watch/disable_alarm_actions.rb | 16 +++++++--------- .../cloud_watch/enable_alarm_actions.rb | 16 +++++++--------- .../requests/cloud_watch/put_metric_alarm.rb | 13 +++++-------- 15 files changed, 58 insertions(+), 69 deletions(-) diff --git a/lib/fog/aws/cloud_watch.rb b/lib/fog/aws/cloud_watch.rb index b7d2635f8..c14a98478 100644 --- a/lib/fog/aws/cloud_watch.rb +++ b/lib/fog/aws/cloud_watch.rb @@ -2,7 +2,6 @@ module Fog module AWS class CloudWatch < Fog::Service - requires :aws_access_key_id, :aws_secret_access_key recognizes :region, :host, :path, :port, :scheme, :persistent diff --git a/lib/fog/aws/parsers/cloud_watch/delete_alarms.rb b/lib/fog/aws/parsers/cloud_watch/delete_alarms.rb index e05722411..b45ccfb5e 100644 --- a/lib/fog/aws/parsers/cloud_watch/delete_alarms.rb +++ b/lib/fog/aws/parsers/cloud_watch/delete_alarms.rb @@ -2,7 +2,9 @@ module Fog module Parsers module AWS module CloudWatch + class DeleteAlarms < Fog::Parsers::Base + def reset @response = { 'ResponseMetadata' => {} } end diff --git a/lib/fog/aws/parsers/cloud_watch/describe_alarm_history.rb b/lib/fog/aws/parsers/cloud_watch/describe_alarm_history.rb index 34ab555af..1a6637315 100644 --- a/lib/fog/aws/parsers/cloud_watch/describe_alarm_history.rb +++ b/lib/fog/aws/parsers/cloud_watch/describe_alarm_history.rb @@ -2,9 +2,9 @@ module Fog module Parsers module AWS module CloudWatch - + class DescribeAlarmHistory < Fog::Parsers::Base - + def reset @response = { 'DescribeAlarmHistoryResult' => {'AlarmHistory' => []}, 'ResponseMetadata' => {} } reset_alarm_history @@ -13,13 +13,12 @@ module Fog def reset_alarm_history @alarm_history = {} end - + def start_element(name, attrs = []) super end def end_element(name) - #@alarm_history[name] = value case name when 'AlarmName', 'HistoryItemType', 'HistorySummary' @alarm_history[name] = value diff --git a/lib/fog/aws/parsers/cloud_watch/describe_alarms.rb b/lib/fog/aws/parsers/cloud_watch/describe_alarms.rb index daf8f2db7..62bb18e8b 100644 --- a/lib/fog/aws/parsers/cloud_watch/describe_alarms.rb +++ b/lib/fog/aws/parsers/cloud_watch/describe_alarms.rb @@ -2,9 +2,9 @@ module Fog module Parsers module AWS module CloudWatch - + class DescribeAlarms < Fog::Parsers::Base - + def reset @response = { 'DescribeAlarmsResult' => {'MetricAlarms' => []}, 'ResponseMetadata' => {} } reset_metric_alarms @@ -13,11 +13,11 @@ module Fog def reset_metric_alarms @metric_alarms = {'Dimensions' => []} end - + def reset_dimension @dimension = {} end - + def start_element(name, attrs = []) super case name diff --git a/lib/fog/aws/parsers/cloud_watch/describe_alarms_for_metric.rb b/lib/fog/aws/parsers/cloud_watch/describe_alarms_for_metric.rb index 1dd1b6f41..3c30dd1bd 100644 --- a/lib/fog/aws/parsers/cloud_watch/describe_alarms_for_metric.rb +++ b/lib/fog/aws/parsers/cloud_watch/describe_alarms_for_metric.rb @@ -2,9 +2,9 @@ module Fog module Parsers module AWS module CloudWatch - + class DescribeAlarmsForMetric < Fog::Parsers::Base - + def reset @response = { 'DescribeAlarmsForMetricResult' => {'AlarmsForMetric' => []}, 'ResponseMetadata' => {} } reset_alarms_for_metric @@ -13,11 +13,11 @@ module Fog def reset_alarms_for_metric @alarms_for_metric = {'Dimensions' => []} end - + def reset_dimension @dimension = {} end - + def start_element(name, attrs = []) super case name diff --git a/lib/fog/aws/parsers/cloud_watch/disable_alarm_actions.rb b/lib/fog/aws/parsers/cloud_watch/disable_alarm_actions.rb index ee8884ee9..48db69cc8 100644 --- a/lib/fog/aws/parsers/cloud_watch/disable_alarm_actions.rb +++ b/lib/fog/aws/parsers/cloud_watch/disable_alarm_actions.rb @@ -2,7 +2,9 @@ module Fog module Parsers module AWS module CloudWatch + class DisableAlarmActions < Fog::Parsers::Base + def reset @response = { 'ResponseMetadata' => {} } end diff --git a/lib/fog/aws/parsers/cloud_watch/enable_alarm_actions.rb b/lib/fog/aws/parsers/cloud_watch/enable_alarm_actions.rb index c166ab26b..263a54ebb 100644 --- a/lib/fog/aws/parsers/cloud_watch/enable_alarm_actions.rb +++ b/lib/fog/aws/parsers/cloud_watch/enable_alarm_actions.rb @@ -2,7 +2,9 @@ module Fog module Parsers module AWS module CloudWatch + class EnableAlarmActions < Fog::Parsers::Base + def reset @response = { 'ResponseMetadata' => {} } end diff --git a/lib/fog/aws/parsers/cloud_watch/put_metric_alarm.rb b/lib/fog/aws/parsers/cloud_watch/put_metric_alarm.rb index 57b0bfb63..aa878b28f 100644 --- a/lib/fog/aws/parsers/cloud_watch/put_metric_alarm.rb +++ b/lib/fog/aws/parsers/cloud_watch/put_metric_alarm.rb @@ -2,7 +2,9 @@ module Fog module Parsers module AWS module CloudWatch + class PutMetricAlarm < Fog::Parsers::Base + def reset @response = { 'ResponseMetadata' => {} } end diff --git a/lib/fog/aws/requests/cloud_watch/delete_alarms.rb b/lib/fog/aws/requests/cloud_watch/delete_alarms.rb index 2e07c54b0..7e4a3c0e9 100644 --- a/lib/fog/aws/requests/cloud_watch/delete_alarms.rb +++ b/lib/fog/aws/requests/cloud_watch/delete_alarms.rb @@ -2,12 +2,12 @@ module Fog module AWS class CloudWatch class Real - + require 'fog/aws/parsers/cloud_watch/delete_alarms' - + # Delete a list of alarms # ==== Options - # * AlarmNames<~Array>: An array of alarms to be deleted + # * AlarmNames<~Array>: A list of alarms to be deleted # # ==== Returns # * response<~Excon::Response>: @@ -15,10 +15,10 @@ module Fog # ==== See Also # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/index.html?API_DeleteAlarms.html # - - def delete_alarms(alarms) - options = {} - options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarms])) + + def delete_alarms(alarm_names) + options = {} + options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names])) request({ 'Action' => 'DeleteAlarms', :parser => Fog::Parsers::AWS::CloudWatch::DeleteAlarms.new @@ -27,7 +27,4 @@ module Fog end end end -end - - - +end \ No newline at end of file diff --git a/lib/fog/aws/requests/cloud_watch/describe_alarm_history.rb b/lib/fog/aws/requests/cloud_watch/describe_alarm_history.rb index 31d4de2cb..14035f4b0 100644 --- a/lib/fog/aws/requests/cloud_watch/describe_alarm_history.rb +++ b/lib/fog/aws/requests/cloud_watch/describe_alarm_history.rb @@ -2,9 +2,9 @@ module Fog module AWS class CloudWatch class Real - + require 'fog/aws/parsers/cloud_watch/describe_alarm_history' - + # Retrieves history for the specified alarm # ==== Options # * AlarmName<~String>: The name of the alarm @@ -20,7 +20,7 @@ module Fog # ==== See Also # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/index.html?API_DescribeAlarmHistory.html # - + def describe_alarm_history(options={}) request({ 'Action' => 'DescribeAlarmHistory', @@ -30,7 +30,4 @@ module Fog end end end -end - - - +end \ No newline at end of file diff --git a/lib/fog/aws/requests/cloud_watch/describe_alarms.rb b/lib/fog/aws/requests/cloud_watch/describe_alarms.rb index 6e416fcb6..bbeb70e25 100644 --- a/lib/fog/aws/requests/cloud_watch/describe_alarms.rb +++ b/lib/fog/aws/requests/cloud_watch/describe_alarms.rb @@ -2,15 +2,15 @@ module Fog module AWS class CloudWatch class Real - + require 'fog/aws/parsers/cloud_watch/describe_alarms' - + # Retrieves alarms with the specified names # ==== Options # * ActionPrefix<~String>: The action name prefix # * AlarmNamePrefix<~String>: The alarm name prefix. # AlarmNames cannot be specified if this parameter is specified - # * AlarmNames<~Array>: An array of alarm names to retrieve information for. + # * AlarmNames<~Array>: A list of alarm names to retrieve information for. # * MaxRecords<~Integer>: The maximum number of alarm descriptions to retrieve # * NextToken<~String>: The token returned by a previous call to indicate that there is more data available # * NextToken<~String> The token returned by a previous call to indicate that there is more data available @@ -22,8 +22,7 @@ module Fog # ==== See Also # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_DescribeAlarms.html # - - + def describe_alarms(options={}) if alarm_names = options.delete('AlarmNames') options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names])) diff --git a/lib/fog/aws/requests/cloud_watch/describe_alarms_for_metric.rb b/lib/fog/aws/requests/cloud_watch/describe_alarms_for_metric.rb index 265f8c249..90e288718 100644 --- a/lib/fog/aws/requests/cloud_watch/describe_alarms_for_metric.rb +++ b/lib/fog/aws/requests/cloud_watch/describe_alarms_for_metric.rb @@ -2,9 +2,9 @@ module Fog module AWS class CloudWatch class Real - + require 'fog/aws/parsers/cloud_watch/describe_alarms_for_metric' - + # Retrieves all alarms for a single metric # ==== Options # * Dimensions<~Array>: a list of dimensions to filter against @@ -22,8 +22,7 @@ module Fog # ==== See Also # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_DescribeAlarms.html # - - + def describe_alarms_for_metric(options) if dimensions = options.delete('Dimensions') options.merge!(AWS.indexed_param('Dimensions.member.%d.Name', dimensions.collect {|dimension| dimension['Name']})) @@ -37,6 +36,4 @@ module Fog end end end -end - - +end \ No newline at end of file diff --git a/lib/fog/aws/requests/cloud_watch/disable_alarm_actions.rb b/lib/fog/aws/requests/cloud_watch/disable_alarm_actions.rb index 7b42fee75..3d7436c14 100644 --- a/lib/fog/aws/requests/cloud_watch/disable_alarm_actions.rb +++ b/lib/fog/aws/requests/cloud_watch/disable_alarm_actions.rb @@ -2,9 +2,9 @@ module Fog module AWS class CloudWatch class Real - + require 'fog/aws/parsers/cloud_watch/disable_alarm_actions' - + # Disables actions for the specified alarms # ==== Options # * AlarmNames<~Array>: The names of the alarms to disable actions for @@ -15,11 +15,10 @@ module Fog # ==== See Also # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_DisableAlarmActions.html # - - - def disable_alarm_actions(alarms) - options = {} - options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarms])) + + def disable_alarm_actions(alarm_names) + options = {} + options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names])) request({ 'Action' => 'DisableAlarmActions', :parser => Fog::Parsers::AWS::CloudWatch::DisableAlarmActions.new @@ -28,5 +27,4 @@ module Fog end end end -end - +end \ No newline at end of file diff --git a/lib/fog/aws/requests/cloud_watch/enable_alarm_actions.rb b/lib/fog/aws/requests/cloud_watch/enable_alarm_actions.rb index 77b6b94f1..730edcc4b 100644 --- a/lib/fog/aws/requests/cloud_watch/enable_alarm_actions.rb +++ b/lib/fog/aws/requests/cloud_watch/enable_alarm_actions.rb @@ -2,9 +2,9 @@ module Fog module AWS class CloudWatch class Real - + require 'fog/aws/parsers/cloud_watch/enable_alarm_actions' - + # Enables actions for the specified alarms # ==== Options # * AlarmNames<~Array>: The names of the alarms to enable actions for @@ -15,11 +15,10 @@ module Fog # ==== See Also # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_EnableAlarmActions.html # - - - def enable_alarm_actions(alarms) - options = {} - options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarms])) + + def enable_alarm_actions(alarm_names) + options = {} + options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names])) request({ 'Action' => 'EnableAlarmActions', :parser => Fog::Parsers::AWS::CloudWatch::EnableAlarmActions.new @@ -28,5 +27,4 @@ module Fog end end end -end - +end \ No newline at end of file diff --git a/lib/fog/aws/requests/cloud_watch/put_metric_alarm.rb b/lib/fog/aws/requests/cloud_watch/put_metric_alarm.rb index 080521fb2..989fe369e 100644 --- a/lib/fog/aws/requests/cloud_watch/put_metric_alarm.rb +++ b/lib/fog/aws/requests/cloud_watch/put_metric_alarm.rb @@ -2,11 +2,10 @@ module Fog module AWS class CloudWatch class Real - + require 'fog/aws/parsers/cloud_watch/put_metric_alarm' - - # List availabe metrics - # + + # Creates or updates an alarm and associates it with the specified Amazon CloudWatch metric # ==== Options # * ActionsEnabled<~Boolean>: Indicates whether or not actions should be executed during any changes to the alarm's state # * AlarmActions<~Array>: A list of actions to execute @@ -32,7 +31,7 @@ module Fog # ==== See Also # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html # - + def put_metric_alarm(options) if dimensions = options.delete('Dimensions') options.merge!(AWS.indexed_param('Dimensions.member.%d.Name', dimensions.collect {|dimension| dimension['Name']})) @@ -55,6 +54,4 @@ module Fog end end end -end - - +end \ No newline at end of file