fog 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) hide show
  1. data/README.rdoc +2 -9
  2. data/Rakefile +3 -2
  3. data/docs/_layouts/default.html +13 -13
  4. data/docs/about/contributing.markdown +1 -1
  5. data/docs/about/getting_started.markdown +28 -3
  6. data/docs/dns/index.markdown +4 -4
  7. data/docs/index.markdown +2 -10
  8. data/docs/public/css/fog.css +14 -1
  9. data/docs/storage/index.markdown +2 -2
  10. data/fog.gemspec +6 -5
  11. data/lib/fog.rb +1 -1
  12. data/lib/fog/aws.rb +26 -1
  13. data/lib/fog/aws/auto_scaling.rb +3 -1
  14. data/lib/fog/aws/cloud_formation.rb +3 -0
  15. data/lib/fog/aws/cloud_watch.rb +17 -1
  16. data/lib/fog/aws/compute.rb +50 -18
  17. data/lib/fog/aws/elb.rb +4 -2
  18. data/lib/fog/aws/emr.rb +133 -0
  19. data/lib/fog/aws/models/cloud_watch/alarm.rb +12 -0
  20. data/lib/fog/aws/models/cloud_watch/alarm_data.rb +39 -0
  21. data/lib/fog/aws/models/cloud_watch/alarm_datum.rb +66 -0
  22. data/lib/fog/aws/models/cloud_watch/alarm_histories.rb +18 -0
  23. data/lib/fog/aws/models/cloud_watch/alarm_history.rb +16 -0
  24. data/lib/fog/aws/models/cloud_watch/alarms.rb +30 -0
  25. data/lib/fog/aws/models/compute/addresses.rb +1 -1
  26. data/lib/fog/aws/models/compute/key_pairs.rb +1 -1
  27. data/lib/fog/aws/models/compute/security_groups.rb +1 -1
  28. data/lib/fog/aws/models/compute/server.rb +4 -2
  29. data/lib/fog/aws/models/compute/servers.rb +1 -1
  30. data/lib/fog/aws/models/compute/snapshots.rb +1 -1
  31. data/lib/fog/aws/models/compute/spot_request.rb +21 -4
  32. data/lib/fog/aws/models/compute/spot_requests.rb +45 -1
  33. data/lib/fog/aws/models/compute/volumes.rb +1 -1
  34. data/lib/fog/aws/models/elb/load_balancer.rb +2 -0
  35. data/lib/fog/aws/models/storage/file.rb +1 -1
  36. data/lib/fog/aws/parsers/cdn/get_invalidation_list.rb +0 -1
  37. data/lib/fog/aws/parsers/cloud_formation/update_stack.rb +19 -0
  38. data/lib/fog/aws/parsers/cloud_watch/delete_alarms.rb +26 -0
  39. data/lib/fog/aws/parsers/cloud_watch/describe_alarm_history.rb +40 -0
  40. data/lib/fog/aws/parsers/cloud_watch/describe_alarms.rb +73 -0
  41. data/lib/fog/aws/parsers/cloud_watch/describe_alarms_for_metric.rb +71 -0
  42. data/lib/fog/aws/parsers/cloud_watch/disable_alarm_actions.rb +26 -0
  43. data/lib/fog/aws/parsers/cloud_watch/enable_alarm_actions.rb +26 -0
  44. data/lib/fog/aws/parsers/cloud_watch/get_metric_statistics.rb +1 -0
  45. data/lib/fog/aws/parsers/cloud_watch/put_metric_alarm.rb +26 -0
  46. data/lib/fog/aws/parsers/cloud_watch/set_alarm_state.rb +26 -0
  47. data/lib/fog/aws/parsers/compute/spot_instance_requests.rb +2 -2
  48. data/lib/fog/aws/parsers/emr/add_instance_groups.rb +28 -0
  49. data/lib/fog/aws/parsers/emr/add_job_flow_steps.rb +17 -0
  50. data/lib/fog/aws/parsers/emr/describe_job_flows.rb +140 -0
  51. data/lib/fog/aws/parsers/emr/modify_instance_groups.rb +17 -0
  52. data/lib/fog/aws/parsers/emr/run_job_flow.rb +19 -0
  53. data/lib/fog/aws/parsers/emr/set_termination_protection.rb +17 -0
  54. data/lib/fog/aws/parsers/emr/terminate_job_flows.rb +17 -0
  55. data/lib/fog/aws/rds.rb +3 -1
  56. data/lib/fog/aws/requests/cloud_formation/create_stack.rb +6 -0
  57. data/lib/fog/aws/requests/cloud_formation/update_stack.rb +62 -0
  58. data/lib/fog/aws/requests/cloud_watch/delete_alarms.rb +30 -0
  59. data/lib/fog/aws/requests/cloud_watch/describe_alarm_history.rb +33 -0
  60. data/lib/fog/aws/requests/cloud_watch/describe_alarms.rb +38 -0
  61. data/lib/fog/aws/requests/cloud_watch/describe_alarms_for_metric.rb +39 -0
  62. data/lib/fog/aws/requests/cloud_watch/disable_alarm_actions.rb +30 -0
  63. data/lib/fog/aws/requests/cloud_watch/enable_alarm_actions.rb +30 -0
  64. data/lib/fog/aws/requests/cloud_watch/put_metric_alarm.rb +84 -0
  65. data/lib/fog/aws/requests/cloud_watch/set_alarm_state.rb +31 -0
  66. data/lib/fog/aws/requests/compute/authorize_security_group_ingress.rb +141 -36
  67. data/lib/fog/aws/requests/compute/create_snapshot.rb +2 -3
  68. data/lib/fog/aws/requests/compute/create_tags.rb +5 -3
  69. data/lib/fog/aws/requests/compute/create_volume.rb +0 -1
  70. data/lib/fog/aws/requests/compute/delete_security_group.rb +25 -0
  71. data/lib/fog/aws/requests/compute/delete_tags.rb +3 -4
  72. data/lib/fog/aws/requests/compute/describe_addresses.rb +2 -2
  73. data/lib/fog/aws/requests/compute/describe_availability_zones.rb +5 -2
  74. data/lib/fog/aws/requests/compute/describe_images.rb +6 -9
  75. data/lib/fog/aws/requests/compute/describe_instances.rb +17 -8
  76. data/lib/fog/aws/requests/compute/describe_key_pairs.rb +2 -2
  77. data/lib/fog/aws/requests/compute/describe_regions.rb +2 -2
  78. data/lib/fog/aws/requests/compute/describe_reserved_instances.rb +1 -1
  79. data/lib/fog/aws/requests/compute/describe_security_groups.rb +2 -2
  80. data/lib/fog/aws/requests/compute/describe_snapshots.rb +7 -5
  81. data/lib/fog/aws/requests/compute/describe_volumes.rb +5 -4
  82. data/lib/fog/aws/requests/compute/modify_image_attribute.rb +32 -0
  83. data/lib/fog/aws/requests/compute/modify_instance_attribute.rb +1 -1
  84. data/lib/fog/aws/requests/compute/purchase_reserved_instances_offering.rb +1 -1
  85. data/lib/fog/aws/requests/compute/register_image.rb +0 -1
  86. data/lib/fog/aws/requests/compute/revoke_security_group_ingress.rb +41 -29
  87. data/lib/fog/aws/requests/compute/run_instances.rb +1 -2
  88. data/lib/fog/aws/requests/elb/create_load_balancer.rb +1 -1
  89. data/lib/fog/aws/requests/elb/create_load_balancer_listeners.rb +1 -1
  90. data/lib/fog/aws/requests/elb/deregister_instances_from_load_balancer.rb +1 -1
  91. data/lib/fog/aws/requests/elb/describe_instance_health.rb +2 -2
  92. data/lib/fog/aws/requests/elb/describe_load_balancers.rb +3 -3
  93. data/lib/fog/aws/requests/elb/register_instances_with_load_balancer.rb +2 -2
  94. data/lib/fog/aws/requests/emr/add_instance_groups.rb +46 -0
  95. data/lib/fog/aws/requests/emr/add_job_flow_steps.rb +49 -0
  96. data/lib/fog/aws/requests/emr/describe_job_flows.rb +108 -0
  97. data/lib/fog/aws/requests/emr/modify_instance_groups.rb +40 -0
  98. data/lib/fog/aws/requests/emr/run_job_flow.rb +106 -0
  99. data/lib/fog/aws/requests/emr/set_termination_protection.rb +39 -0
  100. data/lib/fog/aws/requests/emr/terminate_job_flows.rb +37 -0
  101. data/lib/fog/aws/requests/iam/get_server_certificate.rb +5 -7
  102. data/lib/fog/aws/requests/iam/upload_server_certificate.rb +1 -0
  103. data/lib/fog/aws/requests/simpledb/get_attributes.rb +2 -2
  104. data/lib/fog/aws/requests/simpledb/select.rb +1 -1
  105. data/lib/fog/aws/requests/storage/copy_object.rb +1 -1
  106. data/lib/fog/aws/requests/storage/get_object_url.rb +2 -2
  107. data/lib/fog/aws/requests/storage/hash_to_acl.rb +35 -25
  108. data/lib/fog/aws/ses.rb +1 -1
  109. data/lib/fog/aws/simpledb.rb +2 -0
  110. data/lib/fog/aws/sns.rb +3 -1
  111. data/lib/fog/aws/sqs.rb +4 -2
  112. data/lib/fog/aws/storage.rb +12 -3
  113. data/lib/fog/bin.rb +1 -1
  114. data/lib/fog/bin/aws.rb +8 -4
  115. data/lib/fog/bin/bluebox.rb +2 -2
  116. data/lib/fog/bin/brightbox.rb +1 -1
  117. data/lib/fog/bin/dnsimple.rb +1 -1
  118. data/lib/fog/bin/dnsmadeeasy.rb +1 -1
  119. data/lib/fog/bin/ecloud.rb +1 -1
  120. data/lib/fog/bin/glesys.rb +1 -1
  121. data/lib/fog/bin/go_grid.rb +1 -1
  122. data/lib/fog/bin/google.rb +1 -1
  123. data/lib/fog/bin/libvirt.rb +1 -1
  124. data/lib/fog/bin/linode.rb +2 -2
  125. data/lib/fog/bin/local.rb +1 -1
  126. data/lib/fog/bin/new_servers.rb +1 -1
  127. data/lib/fog/bin/ninefold.rb +2 -2
  128. data/lib/fog/bin/openstack.rb +1 -1
  129. data/lib/fog/bin/rackspace.rb +3 -3
  130. data/lib/fog/bin/slicehost.rb +1 -1
  131. data/lib/fog/bin/stormondemand.rb +1 -1
  132. data/lib/fog/bin/virtual_box.rb +1 -1
  133. data/lib/fog/bin/vmfusion.rb +1 -1
  134. data/lib/fog/bin/voxel.rb +1 -1
  135. data/lib/fog/bin/zerigo.rb +1 -1
  136. data/lib/fog/brightbox/models/compute/account.rb +1 -1
  137. data/lib/fog/compute/models/server.rb +1 -2
  138. data/lib/fog/core/attributes.rb +5 -5
  139. data/lib/fog/core/connection.rb +1 -1
  140. data/lib/fog/core/deprecation.rb +2 -2
  141. data/lib/fog/core/logger.rb +8 -3
  142. data/lib/fog/core/mock.rb +4 -0
  143. data/lib/fog/core/provider.rb +7 -2
  144. data/lib/fog/core/service.rb +8 -2
  145. data/lib/fog/dnsmadeeasy/models/dns/record.rb +3 -2
  146. data/lib/fog/dynect/dns.rb +25 -3
  147. data/lib/fog/ecloud/compute.rb +2 -6
  148. data/lib/fog/go_grid/requests/compute/grid_server_power.rb +1 -1
  149. data/lib/fog/google/models/storage/file.rb +1 -1
  150. data/lib/fog/google/requests/storage/get_object_url.rb +2 -2
  151. data/lib/fog/google/storage.rb +1 -1
  152. data/lib/fog/libvirt/models/compute/uri.rb +7 -3
  153. data/lib/fog/linode/models/compute/server.rb +10 -0
  154. data/lib/fog/ninefold/models/storage/file.rb +8 -6
  155. data/lib/fog/ninefold/models/storage/files.rb +3 -2
  156. data/lib/fog/ninefold/requests/storage/head_namespace.rb +20 -0
  157. data/lib/fog/ninefold/storage.rb +4 -2
  158. data/lib/fog/openstack.rb +4 -3
  159. data/lib/fog/openstack/compute.rb +8 -5
  160. data/lib/fog/openstack/models/compute/server.rb +10 -1
  161. data/lib/fog/openstack/requests/compute/create_server.rb +6 -8
  162. data/lib/fog/rackspace/load_balancers.rb +1 -0
  163. data/lib/fog/rackspace/models/dns/callback.rb +1 -1
  164. data/lib/fog/rackspace/models/dns/record.rb +1 -1
  165. data/lib/fog/rackspace/models/dns/zone.rb +1 -1
  166. data/lib/fog/slicehost/dns.rb +1 -0
  167. data/lib/fog/slicehost/models/dns/record.rb +7 -3
  168. data/lib/fog/slicehost/models/dns/zone.rb +1 -1
  169. data/lib/fog/slicehost/parsers/dns/create_record.rb +8 -2
  170. data/lib/fog/slicehost/parsers/dns/get_record.rb +17 -5
  171. data/lib/fog/slicehost/parsers/dns/get_records.rb +10 -2
  172. data/lib/fog/slicehost/requests/dns/get_record.rb +1 -1
  173. data/lib/fog/slicehost/requests/dns/get_records.rb +7 -8
  174. data/lib/fog/slicehost/requests/dns/update_record.rb +43 -0
  175. data/lib/fog/storm_on_demand/models/compute/balancers.rb +1 -1
  176. data/lib/fog/storm_on_demand/models/compute/configs.rb +1 -1
  177. data/lib/fog/storm_on_demand/models/compute/images.rb +1 -1
  178. data/lib/fog/storm_on_demand/models/compute/servers.rb +1 -1
  179. data/lib/fog/storm_on_demand/models/compute/templates.rb +1 -1
  180. data/lib/fog/terremark/vcloud.rb +1 -1
  181. data/lib/fog/vsphere/compute.rb +40 -23
  182. data/lib/fog/vsphere/models/compute/server.rb +1 -0
  183. data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +36 -4
  184. data/lib/fog/zerigo/dns.rb +14 -3
  185. data/lib/fog/zerigo/models/dns/record.rb +1 -1
  186. data/lib/fog/zerigo/models/dns/records.rb +5 -0
  187. data/lib/fog/zerigo/models/dns/zones.rb +2 -2
  188. data/lib/fog/zerigo/requests/dns/count_hosts.rb +20 -1
  189. data/lib/fog/zerigo/requests/dns/count_zones.rb +12 -1
  190. data/lib/fog/zerigo/requests/dns/create_host.rb +67 -1
  191. data/lib/fog/zerigo/requests/dns/create_zone.rb +44 -1
  192. data/lib/fog/zerigo/requests/dns/delete_host.rb +19 -0
  193. data/lib/fog/zerigo/requests/dns/delete_zone.rb +17 -0
  194. data/lib/fog/zerigo/requests/dns/find_hosts.rb +22 -1
  195. data/lib/fog/zerigo/requests/dns/get_host.rb +18 -1
  196. data/lib/fog/zerigo/requests/dns/get_zone.rb +19 -2
  197. data/lib/fog/zerigo/requests/dns/get_zone_stats.rb +23 -0
  198. data/lib/fog/zerigo/requests/dns/list_hosts.rb +20 -1
  199. data/lib/fog/zerigo/requests/dns/list_zones.rb +15 -0
  200. data/lib/fog/zerigo/requests/dns/update_host.rb +20 -1
  201. data/lib/fog/zerigo/requests/dns/update_zone.rb +20 -1
  202. data/tests/aws/models/cloud_watch/alarm_data_tests.rb +42 -0
  203. data/tests/aws/models/cloud_watch/alarm_history_tests.rb +22 -0
  204. data/tests/aws/models/compute/security_group_tests.rb +15 -10
  205. data/tests/aws/models/elb/model_tests.rb +4 -4
  206. data/tests/aws/requests/cloud_formation/stack_tests.rb +14 -0
  207. data/tests/aws/requests/cloud_watch/list_metrics_test.rb +5 -5
  208. data/tests/aws/requests/compute/image_tests.rb +33 -2
  209. data/tests/aws/requests/compute/instance_tests.rb +16 -1
  210. data/tests/aws/requests/compute/security_group_tests.rb +251 -32
  211. data/tests/aws/requests/compute/tag_tests.rb +42 -2
  212. data/tests/aws/requests/emr/helper.rb +172 -0
  213. data/tests/aws/requests/emr/instance_group_tests.rb +106 -0
  214. data/tests/aws/requests/emr/job_flow_tests.rb +88 -0
  215. data/tests/aws/requests/iam/server_certificate_tests.rb +20 -7
  216. data/tests/aws/requests/storage/bucket_tests.rb +82 -54
  217. data/tests/aws/requests/storage/hash_to_acl_tests.rb +173 -0
  218. data/tests/aws/requests/storage/object_tests.rb +44 -24
  219. data/tests/brightbox/requests/compute/helper.rb +15 -6
  220. data/tests/core/attribute_tests.rb +29 -0
  221. data/tests/core/mocking_tests.rb +60 -0
  222. data/tests/dns/models/record_tests.rb +4 -2
  223. data/tests/dns/models/records_tests.rb +4 -2
  224. data/tests/dns/models/zone_tests.rb +3 -1
  225. data/tests/dns/models/zones_tests.rb +4 -2
  226. data/tests/helper.rb +4 -0
  227. data/tests/rackspace/requests/dns/dns_tests.rb +16 -12
  228. data/tests/rackspace/requests/dns/records_tests.rb +13 -11
  229. data/tests/slicehost/requests/dns/dns_tests.rb +58 -11
  230. data/tests/vsphere/compute_tests.rb +18 -10
  231. data/tests/vsphere/requests/compute/vm_clone_tests.rb +1 -1
  232. metadata +214 -221
@@ -0,0 +1,38 @@
1
+ module Fog
2
+ module AWS
3
+ class CloudWatch
4
+ class Real
5
+
6
+ require 'fog/aws/parsers/cloud_watch/describe_alarms'
7
+
8
+ # Retrieves alarms with the specified names
9
+ # ==== Options
10
+ # * ActionPrefix<~String>: The action name prefix
11
+ # * AlarmNamePrefix<~String>: The alarm name prefix.
12
+ # AlarmNames cannot be specified if this parameter is specified
13
+ # * AlarmNames<~Array>: A list of alarm names to retrieve information for.
14
+ # * MaxRecords<~Integer>: The maximum number of alarm descriptions to retrieve
15
+ # * NextToken<~String>: The token returned by a previous call to indicate that there is more data available
16
+ # * NextToken<~String> The token returned by a previous call to indicate that there is more data available
17
+ # * StateValue<~String>: The state value to be used in matching alarms
18
+ #
19
+ # ==== Returns
20
+ # * response<~Excon::Response>:
21
+ #
22
+ # ==== See Also
23
+ # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_DescribeAlarms.html
24
+ #
25
+
26
+ def describe_alarms(options={})
27
+ if alarm_names = options.delete('AlarmNames')
28
+ options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names]))
29
+ end
30
+ request({
31
+ 'Action' => 'DescribeAlarms',
32
+ :parser => Fog::Parsers::AWS::CloudWatch::DescribeAlarms.new
33
+ }.merge(options))
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ module Fog
2
+ module AWS
3
+ class CloudWatch
4
+ class Real
5
+
6
+ require 'fog/aws/parsers/cloud_watch/describe_alarms_for_metric'
7
+
8
+ # Retrieves all alarms for a single metric
9
+ # ==== Options
10
+ # * Dimensions<~Array>: a list of dimensions to filter against
11
+ # Name : The name of the dimension
12
+ # Value : The value to filter against
13
+ # * MetricName<~String>: The name of the metric
14
+ # * Namespace<~String>: The namespace of the metric
15
+ # * Period<~Integer>: The period in seconds over which the statistic is applied
16
+ # * Statistics<~String>: The statistic for the metric
17
+ # * Unit<~String> The unit for the metric
18
+ #
19
+ # ==== Returns
20
+ # * response<~Excon::Response>:
21
+ #
22
+ # ==== See Also
23
+ # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_DescribeAlarms.html
24
+ #
25
+
26
+ def describe_alarms_for_metric(options)
27
+ if dimensions = options.delete('Dimensions')
28
+ options.merge!(AWS.indexed_param('Dimensions.member.%d.Name', dimensions.collect {|dimension| dimension['Name']}))
29
+ options.merge!(AWS.indexed_param('Dimensions.member.%d.Value', dimensions.collect {|dimension| dimension['Value']}))
30
+ end
31
+ request({
32
+ 'Action' => 'DescribeAlarmsForMetric',
33
+ :parser => Fog::Parsers::AWS::CloudWatch::DescribeAlarmsForMetric.new
34
+ }.merge(options))
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module AWS
3
+ class CloudWatch
4
+ class Real
5
+
6
+ require 'fog/aws/parsers/cloud_watch/disable_alarm_actions'
7
+
8
+ # Disables actions for the specified alarms
9
+ # ==== Options
10
+ # * AlarmNames<~Array>: The names of the alarms to disable actions for
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ #
15
+ # ==== See Also
16
+ # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_DisableAlarmActions.html
17
+ #
18
+
19
+ def disable_alarm_actions(alarm_names)
20
+ options = {}
21
+ options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names]))
22
+ request({
23
+ 'Action' => 'DisableAlarmActions',
24
+ :parser => Fog::Parsers::AWS::CloudWatch::DisableAlarmActions.new
25
+ }.merge(options))
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module AWS
3
+ class CloudWatch
4
+ class Real
5
+
6
+ require 'fog/aws/parsers/cloud_watch/enable_alarm_actions'
7
+
8
+ # Enables actions for the specified alarms
9
+ # ==== Options
10
+ # * AlarmNames<~Array>: The names of the alarms to enable actions for
11
+ #
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ #
15
+ # ==== See Also
16
+ # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_EnableAlarmActions.html
17
+ #
18
+
19
+ def enable_alarm_actions(alarm_names)
20
+ options = {}
21
+ options.merge!(AWS.indexed_param('AlarmNames.member.%d', [*alarm_names]))
22
+ request({
23
+ 'Action' => 'EnableAlarmActions',
24
+ :parser => Fog::Parsers::AWS::CloudWatch::EnableAlarmActions.new
25
+ }.merge(options))
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,84 @@
1
+ module Fog
2
+ module AWS
3
+ class CloudWatch
4
+ class Real
5
+ require 'fog/aws/parsers/cloud_watch/put_metric_alarm'
6
+
7
+ # Creates or updates an alarm and associates it with the specified Amazon CloudWatch metric
8
+ # ==== Options
9
+ # * ActionsEnabled<~Boolean>: Indicates whether or not actions should be executed during any changes to the alarm's state
10
+ # * AlarmActions<~Array>: A list of actions to execute
11
+ # * AlarmDescription<~String>: The description for the alarm
12
+ # * AlarmName<~String> The unique name for the alarm
13
+ # * ComparisonOperator<~String>: The arithmetic operation to use for comparison
14
+ # * Dimensions<~Array>: a list of dimensions to filter against,
15
+ # Name : The name of the dimension
16
+ # Value : The value to filter against
17
+ # * EvaluationPeriods<~Integer>: The number of periods over which data is compared to the specified threshold
18
+ # * InsufficientDataActions<~Array>: A list of actions to execute
19
+ # * MetricName<~String>: The name for the alarm's associated metric
20
+ # * Namespace<~String>: The namespace for the alarm's associated metric
21
+ # * OKActions<~Array>: A list of actions to execute
22
+ # * Period<~Integer>: The period in seconds over which the specified statistic is applied
23
+ # * Statistic<~String>: The statistic to apply to the alarm's associated metric
24
+ # * Threshold<~Double>: The value against which the specified statistic is compared
25
+ # * Unit<~String>: The unit for the alarm's associated metric
26
+ #
27
+ # ==== Returns
28
+ # * response<~Excon::Response>:
29
+ #
30
+ # ==== See Also
31
+ # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_PutMetricAlarm.html
32
+ #
33
+ def put_metric_alarm(options)
34
+ if dimensions = options.delete('Dimensions')
35
+ options.merge!(AWS.indexed_param('Dimensions.member.%d.Name', dimensions.collect {|dimension| dimension['Name']}))
36
+ options.merge!(AWS.indexed_param('Dimensions.member.%d.Value', dimensions.collect {|dimension| dimension['Value']}))
37
+ end
38
+ if alarm_actions = options.delete('AlarmActions')
39
+ options.merge!(AWS.indexed_param('AlarmActions.member.%d', [*alarm_actions]))
40
+ end
41
+ if insufficient_data_actions = options.delete('InsufficientDataActions')
42
+ options.merge!(AWS.indexed_param('InsufficientDataActions.member.%d', [*insufficient_data_actions]))
43
+ end
44
+ if ok_actions = options.delete('OKActions')
45
+ options.merge!(AWS.indexed_param('OKActions.member.%d', [*ok_actions]))
46
+ end
47
+
48
+ request({
49
+ 'Action' => 'PutMetricAlarm',
50
+ :parser => Fog::Parsers::AWS::CloudWatch::PutMetricAlarm.new
51
+ }.merge(options))
52
+ end
53
+ end
54
+
55
+ class Mock
56
+ require 'fog/aws/parsers/cloud_watch/put_metric_alarm'
57
+
58
+ # See: Fog::AWS::CloudWatch::Real.put_metric_alarm()
59
+ #
60
+ def put_metric_alarm(options)
61
+ supported_actions = [ "InsufficientDataActions", "OKActions", "AlarmActions" ]
62
+ found_actions = options.keys.select {|key| supported_actions.include? key }
63
+ if found_actions.empty?
64
+ raise Fog::Compute::AWS::Error.new("The request must contain at least one of #{supported_actions.join(", ")}'")
65
+ end
66
+
67
+ requirements = [ "AlarmName", "ComparisonOperator", "EvaluationPeriods", "Namespace", "Period", "Statistic", "Threshold" ]
68
+ requirements.each do |req|
69
+ unless options.has_key?(req)
70
+ raise Fog::Compute::AWS::Error.new("The request must contain a the parameter '%s'" % req)
71
+ end
72
+ end
73
+
74
+ response = Excon::Response.new
75
+ response.status = 200
76
+ response.body = {
77
+ 'requestId' => Fog::AWS::Mock.request_id
78
+ }
79
+ response
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,31 @@
1
+ module Fog
2
+ module AWS
3
+ class CloudWatch
4
+ class Real
5
+
6
+ require 'fog/aws/parsers/cloud_watch/set_alarm_state'
7
+
8
+ # Temporarily sets the state of an alarm
9
+ # ==== Options
10
+ # * AlarmName<~String>: The names of the alarm
11
+ # * StateReason<~String>: The reason that this alarm is set to this specific state (in human-readable text format)
12
+ # * StateReasonData<~String>: The reason that this alarm is set to this specific state (in machine-readable JSON format)
13
+ # * StateValue<~String>: The value of the state
14
+ #
15
+ # ==== Returns
16
+ # * response<~Excon::Response>:
17
+ #
18
+ # ==== See Also
19
+ # http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/API_SetAlarmState.html
20
+ #
21
+
22
+ def set_alarm_state(options)
23
+ request({
24
+ 'Action' => 'SetAlarmState',
25
+ :parser => Fog::Parsers::AWS::CloudWatch::SetAlarmState.new
26
+ }.merge(options))
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -13,11 +13,23 @@ module Fog
13
13
  # * 'SourceSecurityGroupName'<~String> - Name of security group to authorize
14
14
  # * 'SourceSecurityGroupOwnerId'<~String> - Name of owner to authorize
15
15
  # or
16
- # * 'CidrIp' - CIDR range
17
- # * 'FromPort' - Start of port range (or -1 for ICMP wildcard)
18
- # * 'GroupName' - Name of group to modify
19
- # * 'IpProtocol' - Ip protocol, must be in ['tcp', 'udp', 'icmp']
20
- # * 'ToPort' - End of port range (or -1 for ICMP wildcard)
16
+ # * 'CidrIp'<~String> - CIDR range
17
+ # * 'FromPort'<~Integer> - Start of port range (or -1 for ICMP wildcard)
18
+ # * 'IpProtocol'<~String> - Ip protocol, must be in ['tcp', 'udp', 'icmp']
19
+ # * 'ToPort'<~Integer> - End of port range (or -1 for ICMP wildcard)
20
+ # or
21
+ # * 'IpPermissions'<~Array>:
22
+ # * permission<~Hash>:
23
+ # * 'FromPort'<~Integer> - Start of port range (or -1 for ICMP wildcard)
24
+ # * 'Groups'<~Array>:
25
+ # * group<~Hash>:
26
+ # * 'GroupName'<~String> - Name of security group to authorize
27
+ # * 'UserId'<~String> - Name of owner to authorize
28
+ # * 'IpProtocol'<~String> - Ip protocol, must be in ['tcp', 'udp', 'icmp']
29
+ # * 'IpRanges'<~Array>:
30
+ # * ip_range<~Hash>:
31
+ # * 'CidrIp'<~String> - CIDR range
32
+ # * 'ToPort'<~Integer> - End of port range (or -1 for ICMP wildcard)
21
33
  #
22
34
  # === Returns
23
35
  # * response<~Excon::Response>:
@@ -28,10 +40,15 @@ module Fog
28
40
  # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-AuthorizeSecurityGroupIngress.html]
29
41
  def authorize_security_group_ingress(group_name, options = {})
30
42
  if group_name.is_a?(Hash)
31
- Fog::Logger.warning("Fog::AWS::Compute#authorize_security_group_ingress now requires the 'group_name' parameter. Only specifying an options hash is now deprecated [light_black](#{caller.first})[/]")
43
+ Fog::Logger.deprecation("Fog::AWS::Compute#authorize_security_group_ingress now requires the 'group_name' parameter. Only specifying an options hash is now deprecated [light_black](#{caller.first})[/]")
32
44
  options = group_name
33
- group_name = options['GroupName']
45
+ group_name = options.delete('GroupName')
46
+ end
47
+
48
+ if ip_permissions = options.delete('IpPermissions')
49
+ options.merge!(indexed_ip_permissions_params(ip_permissions))
34
50
  end
51
+
35
52
  request({
36
53
  'Action' => 'AuthorizeSecurityGroupIngress',
37
54
  'GroupName' => group_name,
@@ -40,51 +57,69 @@ module Fog
40
57
  }.merge!(options))
41
58
  end
42
59
 
60
+ private
61
+
62
+ def indexed_ip_permissions_params(ip_permissions)
63
+ params = {}
64
+ ip_permissions.each_with_index do |permission, key_index|
65
+ key_index += 1
66
+ params[format('IpPermissions.%d.IpProtocol', key_index)] = permission['IpProtocol']
67
+ params[format('IpPermissions.%d.FromPort', key_index)] = permission['FromPort']
68
+ params[format('IpPermissions.%d.ToPort', key_index)] = permission['ToPort']
69
+ (permission['Groups'] || []).each_with_index do |group, group_index|
70
+ group_index += 1
71
+ params[format('IpPermissions.%d.Groups.%d.UserId', key_index, group_index)] = group['UserId']
72
+ params[format('IpPermissions.%d.Groups.%d.GroupName', key_index, group_index)] = group['GroupName']
73
+ params[format('IpPermissions.%d.Groups.%d.GroupId', key_index, group_index)] = group['GroupId']
74
+ end
75
+ (permission['IpRanges'] || []).each_with_index do |ip_range, range_index|
76
+ range_index += 1
77
+ params[format('IpPermissions.%d.IpRanges.%d.CidrIp', key_index, range_index)] = ip_range['CidrIp']
78
+ end
79
+ end
80
+ params.reject {|k, v| v.nil? }
81
+ end
82
+
43
83
  end
44
84
 
45
85
  class Mock
46
86
 
47
87
  def authorize_security_group_ingress(group_name, options = {})
48
88
  if group_name.is_a?(Hash)
49
- Fog::Logger.warning("Fog::AWS::Compute#authorize_security_group_ingress now requires the 'group_name' parameter. Only specifying an options hash is now deprecated [light_black](#{caller.first})[/]")
89
+ Fog::Logger.deprecation("Fog::AWS::Compute#authorize_security_group_ingress now requires the 'group_name' parameter. Only specifying an options hash is now deprecated [light_black](#{caller.first})[/]")
50
90
  options = group_name
51
- group_name = options['GroupName']
91
+ group_name = options.delete('GroupName')
52
92
  end
53
93
 
94
+ verify_permission_options(options)
95
+
54
96
  response = Excon::Response.new
55
97
  group = self.data[:security_groups][group_name]
56
98
 
57
99
  if group
58
- group['ipPermissions'] ||= []
59
- if group_name && source_group_name = options['SourceSecurityGroupName']
60
- ['tcp', 'udp'].each do |protocol|
61
- group['ipPermissions'] << {
62
- 'groups' => [{'groupName' => source_group_name, 'userId' => (options['SourceSecurityGroupOwnerId'] || self.data[:owner_id]) }],
63
- 'fromPort' => 1,
64
- 'ipRanges' => [],
65
- 'ipProtocol' => protocol,
66
- 'toPort' => 65535
67
- }
100
+ normalized_permissions = normalize_permissions(options)
101
+
102
+ normalized_permissions.each do |permission|
103
+ if matching_group_permission = find_matching_permission(group, permission)
104
+ if permission['groups'].any? {|pg| matching_group_permission['groups'].include?(pg) }
105
+ raise Fog::Compute::AWS::Error, "InvalidPermission.Duplicate => The permission '123' has already been authorized in the specified group"
106
+ end
107
+
108
+ if permission['ipRanges'].any? {|pr| matching_group_permission['ipRanges'].include?(pr) }
109
+ raise Fog::Compute::AWS::Error, "InvalidPermission.Duplicate => The permission '123' has already been authorized in the specified group"
110
+ end
68
111
  end
69
- group['ipPermissions'] << {
70
- 'groups' => [{'groupName' => source_group_name, 'userId' => (options['SourceSecurityGroupOwnerId'] || self.data[:owner_id]) }],
71
- 'fromPort' => -1,
72
- 'ipRanges' => [],
73
- 'ipProtocol' => 'icmp',
74
- 'toPort' => -1
75
- }
76
- else
77
- group['ipPermissions'] << {
78
- 'groups' => [],
79
- 'fromPort' => options['FromPort'],
80
- 'ipRanges' => [],
81
- 'ipProtocol' => options['IpProtocol'],
82
- 'toPort' => options['ToPort']
83
- }
84
- if options['CidrIp']
85
- group['ipPermissions'].last['ipRanges'] << { 'cidrIp' => options['CidrIp'] }
112
+ end
113
+
114
+ normalized_permissions.each do |permission|
115
+ if matching_group_permission = find_matching_permission(group, permission)
116
+ matching_group_permission['groups'] += permission['groups']
117
+ matching_group_permission['ipRanges'] += permission['ipRanges']
118
+ else
119
+ group['ipPermissions'] << permission
86
120
  end
87
121
  end
122
+
88
123
  response.status = 200
89
124
  response.body = {
90
125
  'requestId' => Fog::AWS::Mock.request_id,
@@ -96,6 +131,76 @@ module Fog
96
131
  end
97
132
  end
98
133
 
134
+ private
135
+
136
+ def verify_permission_options(options)
137
+ if options.empty?
138
+ raise Fog::Compute::AWS::Error.new("InvalidRequest => The request received was invalid.")
139
+ end
140
+ if options['IpProtocol'] && !['tcp', 'udp', 'icmp'].include?(options['IpProtocol'])
141
+ raise Fog::Compute::AWS::Error.new("InvalidPermission.Malformed => Unsupported IP protocol \"#{options['IpProtocol']}\" - supported: [tcp, udp, icmp]")
142
+ end
143
+ if options['IpProtocol'] && (!options['FromPort'] || !options['ToPort'])
144
+ raise Fog::Compute::AWS::Error.new("InvalidPermission.Malformed => TCP/UDP port (-1) out of range")
145
+ end
146
+ if options.has_key?('IpPermissions')
147
+ if !options['IpPermissions'].is_a?(Array) || options['IpPermissions'].empty?
148
+ raise Fog::Compute::AWS::Error.new("InvalidRequest => The request received was invalid.")
149
+ end
150
+ options['IpPermissions'].each {|p| verify_permission_options(p) }
151
+ end
152
+ end
153
+
154
+ def normalize_permissions(options)
155
+ normalized_permissions = []
156
+
157
+ if options['SourceSecurityGroupName']
158
+ ['tcp', 'udp'].each do |protocol|
159
+ normalized_permissions << {
160
+ 'ipProtocol' => protocol,
161
+ 'fromPort' => 1,
162
+ 'toPort' => 65535,
163
+ 'groups' => [{'groupName' => options['SourceSecurityGroupName'], 'userId' => options['SourceSecurityGroupOwnerId'] || self.data[:owner_id]}],
164
+ 'ipRanges' => []
165
+ }
166
+ end
167
+ normalized_permissions << {
168
+ 'ipProtocol' => 'icmp',
169
+ 'fromPort' => -1,
170
+ 'toPort' => -1,
171
+ 'groups' => [{'groupName' => options['SourceSecurityGroupName'], 'userId' => options['SourceSecurityGroupOwnerId'] || self.data[:owner_id]}],
172
+ 'ipRanges' => []
173
+ }
174
+ elsif options['CidrIp']
175
+ normalized_permissions << {
176
+ 'ipProtocol' => options['IpProtocol'],
177
+ 'fromPort' => Integer(options['FromPort']),
178
+ 'toPort' => Integer(options['ToPort']),
179
+ 'groups' => [],
180
+ 'ipRanges' => [{'cidrIp' => options['CidrIp']}]
181
+ }
182
+ elsif options['IpPermissions']
183
+ options['IpPermissions'].each do |permission|
184
+ normalized_permissions << {
185
+ 'ipProtocol' => permission['IpProtocol'],
186
+ 'fromPort' => Integer(permission['FromPort']),
187
+ 'toPort' => Integer(permission['ToPort']),
188
+ 'groups' => (permission['Groups'] || []).map {|g| {'groupName' => g['GroupName'], 'userId' => g['UserId'] || self.data[:owner_id]} },
189
+ 'ipRanges' => (permission['IpRanges'] || []).map {|r| { 'cidrIp' => r['CidrIp'] } }
190
+ }
191
+ end
192
+ end
193
+
194
+ normalized_permissions
195
+ end
196
+
197
+ def find_matching_permission(group, permission)
198
+ group['ipPermissions'].detect {|group_permission|
199
+ permission['ipProtocol'] == group_permission['ipProtocol'] &&
200
+ permission['fromPort'] == group_permission['fromPort'] &&
201
+ permission['toPort'] == group_permission['toPort'] }
202
+ end
203
+
99
204
  end
100
205
  end
101
206
  end