nirvdrum-amazon-ec2 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.gitignore +9 -0
  2. data/.yardopts +1 -0
  3. data/ChangeLog +304 -0
  4. data/LICENSE +66 -0
  5. data/README.rdoc +359 -0
  6. data/README_dev.rdoc +10 -0
  7. data/Rakefile +70 -0
  8. data/VERSION +1 -0
  9. data/amazon-ec2.gemspec +142 -0
  10. data/bin/ec2-gem-example.rb +137 -0
  11. data/bin/ec2-gem-profile.rb +10 -0
  12. data/bin/ec2sh +62 -0
  13. data/bin/setup.rb +29 -0
  14. data/deps.rip +1 -0
  15. data/lib/AWS.rb +321 -0
  16. data/lib/AWS/Autoscaling.rb +70 -0
  17. data/lib/AWS/Autoscaling/autoscaling.rb +273 -0
  18. data/lib/AWS/Cloudwatch.rb +32 -0
  19. data/lib/AWS/Cloudwatch/monitoring.rb +80 -0
  20. data/lib/AWS/EC2.rb +33 -0
  21. data/lib/AWS/EC2/availability_zones.rb +29 -0
  22. data/lib/AWS/EC2/console.rb +25 -0
  23. data/lib/AWS/EC2/devpay.rb +18 -0
  24. data/lib/AWS/EC2/elastic_ips.rb +86 -0
  25. data/lib/AWS/EC2/image_attributes.rb +133 -0
  26. data/lib/AWS/EC2/images.rb +117 -0
  27. data/lib/AWS/EC2/instances.rb +234 -0
  28. data/lib/AWS/EC2/keypairs.rb +47 -0
  29. data/lib/AWS/EC2/products.rb +21 -0
  30. data/lib/AWS/EC2/security_groups.rb +164 -0
  31. data/lib/AWS/EC2/snapshots.rb +102 -0
  32. data/lib/AWS/EC2/spot_instance_requests.rb +105 -0
  33. data/lib/AWS/EC2/volumes.rb +100 -0
  34. data/lib/AWS/ELB.rb +71 -0
  35. data/lib/AWS/ELB/load_balancers.rb +178 -0
  36. data/lib/AWS/RDS.rb +73 -0
  37. data/lib/AWS/RDS/rds.rb +522 -0
  38. data/lib/AWS/exceptions.rb +200 -0
  39. data/lib/AWS/responses.rb +21 -0
  40. data/perftools/ec2prof +0 -0
  41. data/perftools/ec2prof-results.dot +132 -0
  42. data/perftools/ec2prof-results.txt +100 -0
  43. data/perftools/ec2prof.symbols +102 -0
  44. data/test/test_Autoscaling_groups.rb +337 -0
  45. data/test/test_EC2.rb +68 -0
  46. data/test/test_EC2_availability_zones.rb +49 -0
  47. data/test/test_EC2_console.rb +54 -0
  48. data/test/test_EC2_elastic_ips.rb +144 -0
  49. data/test/test_EC2_image_attributes.rb +238 -0
  50. data/test/test_EC2_images.rb +229 -0
  51. data/test/test_EC2_instances.rb +611 -0
  52. data/test/test_EC2_keypairs.rb +123 -0
  53. data/test/test_EC2_products.rb +48 -0
  54. data/test/test_EC2_responses.rb +53 -0
  55. data/test/test_EC2_s3_xmlsimple.rb +80 -0
  56. data/test/test_EC2_security_groups.rb +205 -0
  57. data/test/test_EC2_snapshots.rb +83 -0
  58. data/test/test_EC2_spot_instance_requests.rb +178 -0
  59. data/test/test_EC2_volumes.rb +142 -0
  60. data/test/test_ELB_load_balancers.rb +239 -0
  61. data/test/test_RDS.rb +354 -0
  62. data/test/test_helper.rb +23 -0
  63. data/wsdl/2007-08-29.ec2.wsdl +1269 -0
  64. data/wsdl/2008-02-01.ec2.wsdl +1614 -0
  65. data/wsdl/2008-05-05.ec2.wsdl +2052 -0
  66. data/wsdl/2008-12-01.ec2.wsdl +2354 -0
  67. data/wsdl/2009-10-31.ec2.wsdl +4261 -0
  68. data/wsdl/2009-11-30.ec2.wsdl +4668 -0
  69. metadata +199 -0
@@ -0,0 +1,102 @@
1
+ module AWS
2
+ module EC2
3
+
4
+ class Base < AWS::Base
5
+
6
+
7
+ # The DescribeSnapshots operation describes the status of Amazon EBS snapshots.
8
+ #
9
+ # @option options [optional,Array] :snapshot_id ([]) The ID of the Amazon EBS snapshot.
10
+ # @option options [optional,String] :owner ('') Returns snapshots owned by the specified owner. Multiple owners can be specified. Valid values self | amazon | AWS Account ID
11
+ # @option options [optional,String] :restorable_by ('') Account ID of a user that can create volumes from the snapshot.
12
+ #
13
+ def describe_snapshots( options = {} )
14
+ params = {}
15
+ params.merge!(pathlist("SnapshotId", options[:snapshot_id] )) unless options[:snapshot_id].nil? || options[:snapshot_id] == []
16
+ params["RestorableBy"] = options[:restorable_by] unless options[:restorable_by].nil?
17
+ params["Owner"] = options[:owner] unless options[:owner].nil?
18
+ return response_generator(:action => "DescribeSnapshots", :params => params)
19
+ end
20
+
21
+
22
+ # The CreateSnapshot operation creates a snapshot of an Amazon EBS volume and stores it in Amazon S3. You can use snapshots for backups, to launch instances from identical snapshots, and to save data before shutting down an instance.
23
+ #
24
+ # @option options [String] :volume_id ('')
25
+ #
26
+ def create_snapshot( options = {} )
27
+ options = { :volume_id => '' }.merge(options)
28
+ raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
29
+ params = {
30
+ "VolumeId" => options[:volume_id]
31
+ }
32
+ return response_generator(:action => "CreateSnapshot", :params => params)
33
+ end
34
+
35
+
36
+ # The DeleteSnapshot operation deletes a snapshot of an Amazon EBS volume that is stored in Amazon S3.
37
+ #
38
+ # @option options [String] :snapshot_id ('')
39
+ #
40
+ def delete_snapshot( options = {} )
41
+ options = { :snapshot_id => '' }.merge(options)
42
+ raise ArgumentError, "No :snapshot_id provided" if options[:snapshot_id].nil? || options[:snapshot_id].empty?
43
+ params = {
44
+ "SnapshotId" => options[:snapshot_id]
45
+ }
46
+ return response_generator(:action => "DeleteSnapshot", :params => params)
47
+ end
48
+
49
+
50
+ # The DescribeSnapshotAttribute operation returns information about an attribute of a snapshot. Only one attribute can be specified per call.
51
+ #
52
+ # @option options [String] :attribute ('createVolumePermission') Attribute to modify.
53
+ # @option options [optional,Array] :snapshot_id ([]) The ID of the Amazon EBS snapshot.
54
+ #
55
+ def describe_snapshot_attribute( options = {} )
56
+ params = { "Attribute" => options[:attribute] || 'createVolumePermission' }
57
+ params.merge!(pathlist("SnapshotId", options[:snapshot_id] )) unless options[:snapshot_id].nil? || options[:snapshot_id] == []
58
+ return response_generator(:action => "DescribeSnapshotAttribute", :params => params)
59
+ end
60
+
61
+
62
+ # The ModifySnapshotAttribute operation adds or remove permission settings for the specified snapshot.
63
+ #
64
+ # @option options [String] :snapshot_id ('') The ID of the Amazon EBS snapshot.
65
+ # @option options [String] :attribute ('createVolumePermission') Attribute to modify.
66
+ # @option options [String] :operation_type ('') Operation to perform on the attribute.
67
+ # @option options [optional,String] :user_id ('') Account ID of a user that can create volumes from the snapshot.
68
+ # @option options [optional,String] :user_group ('') Group that is allowed to create volumes from the snapshot.
69
+ #
70
+ def modify_snapshot_attribute( options = {} )
71
+ options = { :snapshot_id => '' }.merge(options)
72
+ raise ArgumentError, "No :snapshot_id provided" if options[:snapshot_id].nil? || options[:snapshot_id].empty?
73
+ options = { :operation_type => '' }.merge(options)
74
+ raise ArgumentError, "No :operation_type provided" if options[:snapshot_id].nil? || options[:snapshot_id].empty?
75
+ params = {
76
+ "Attribute" => options[:attribute] || 'createVolumePermission',
77
+ "SnapshotId" => options[:snapshot_id],
78
+ "OperationType" => options[:operation_type]
79
+ }
80
+ params["UserId"] = options[:user_id] unless options[:user_id].nil?
81
+ params["UserGroup"] = options[:user_group] unless options[:user_group].nil?
82
+ return response_generator(:action => "ModifySnapshotAttribute", :params => params)
83
+ end
84
+
85
+
86
+ # The ResetSnapshotAttribute operation resets permission settings for the specified snapshot.
87
+ #
88
+ # @option options [optional,Array] :snapshot_id ([]) The ID of the Amazon EBS snapshot.
89
+ # @option options [String] :attribute ('createVolumePermission') Attribute to reset.
90
+ #
91
+ def reset_snapshot_attribute( options = {} )
92
+ options = { :snapshot_id => '' }.merge(options)
93
+ raise ArgumentError, "No :snapshot_id provided" if options[:snapshot_id].nil? || options[:snapshot_id].empty?
94
+ params = { "Attribute" => options[:attribute] || 'createVolumePermission' }
95
+ params["SnapshotId"] = options[:snapshot_id] unless options[:snapshot_id].nil? || options[:snapshot_id].empty?
96
+ return response_generator(:action => "ResetSnapshotAttribute", :params => params)
97
+ end
98
+
99
+ end
100
+ end
101
+ end
102
+
@@ -0,0 +1,105 @@
1
+ module AWS
2
+ module EC2
3
+
4
+ class Base < AWS::Base
5
+
6
+ # Creates a Spot Instance request. Spot Instances are instances that Amazon EC2 starts on your behalf
7
+ # when the maximum price that you specify exceeds the current Spot Price. Amazon EC2 periodically sets
8
+ # the Spot Price based on available Spot Instance capacity and current spot instance requests. For conceptual
9
+ # information about Spot Instances, refer to the Amazon Elastic Compute Cloud Developer Guide or Amazon Elastic
10
+ # Compute Cloud User Guide.
11
+ #
12
+ # @option options [String] :spot_price (nil) Specifies the maximum hourly price for any Spot Instance launched to fulfill the request.
13
+ # @option options [optional,Integer] :instance_count (1) The maximum number of Spot Instances to launch.
14
+ # @option options [optional,String] :type (nil) Specifies the Spot Instance type.
15
+ # @option options [optional,Date] :valid_from (nil) Start date of the request. If this is a one-time request, the request becomes active at this date and time and remains active until all instances launch, the request expires, or the request is canceled. If the request is persistent, the request becomes active at this date and time and remains active until it expires or is canceled.
16
+ # @option options [optional,Date] :valid_until (nil) End date of the request. If this is a one-time request, the request remains active until all instances launch, the request is canceled, or this date is reached. If the request is persistent, it remains active until it is canceled or this date and time is reached.
17
+ # @option options [optional,String] :launch_group (nil) Specifies the instance launch group. Launch groups are Spot Instances that launch together and terminate together.
18
+ # @option options [optional,String] :availability_zone_group ("") Specifies the Availability Zone group. If you specify the same Availability Zone group for all Spot Instance requests, all Spot Instances are launched in the same Availability Zone.
19
+ # @option options [optional,String] :image_id (nil) The AMI ID.
20
+ # @option options [optional,String] :key_name (nil) The name of the key pair.
21
+ # @option options [optional,Array of Strings or String] :security_group (nil) Name of the security group(s).
22
+ # @option options [optional,String] :user_data (nil) MIME, Base64-encoded user data.
23
+ # @option options [optional,String] :instance_type ("m1.small") Specifies the instance type.
24
+ # @option options [optional,String] :kernel_id (nil) The ID of the kernel to select.
25
+ # @option options [optional,String] :ramdisk_id (nil) The ID of the RAM disk to select. Some kernels require additional drivers at launch. Check the kernel requirements for information on whether you need to specify a RAM disk and search for the kernel ID.
26
+ # @option options [optional,String] :subnet_id (nil) Specifies the Amazon VPC subnet ID within which to launch the instance(s) for Amazon Virtual Private Cloud.
27
+ # @option options [optional,String] :availability_zone (nil) Specifies the placement constraints (Availability Zones) for launching the instances.
28
+ # @option options [optional, Array] :block_device_mapping ([]) An array of Hashes representing the elements of the block device mapping. e.g. [{:device_name => '/dev/sdh', :virtual_name => '', :ebs_snapshot_id => '', :ebs_volume_size => '', :ebs_delete_on_termination => ''},{},...]
29
+ # @option options [optional, Boolean] :monitoring_enabled (false) Enables monitoring for the instance.
30
+ #
31
+ def create_spot_instances_request( options = {} )
32
+ options = { :instance_count => 1,
33
+ :instance_type => 'm1.small',
34
+ :base64_encoded => false }.merge(options)
35
+
36
+ raise ArgumentError, ":addressing_type has been deprecated." if options[:addressing_type]
37
+ raise ArgumentError, ":spot_price must be provided" if options[:spot_price].nil? || options[:spot_price].empty?
38
+
39
+ user_data = extract_user_data(options)
40
+
41
+ params = {}
42
+
43
+ if options[:security_group]
44
+ params.merge!(pathlist("LaunchSpecification.SecurityGroup", options[:security_group]))
45
+ end
46
+
47
+ if options[:block_device_mapping]
48
+ params.merge!(pathhashlist('LaunchSpecification.BlockDeviceMapping', options[:block_device_mapping].flatten, {:device_name => 'DeviceName', :virtual_name => 'VirtualName', :ebs_snapshot_id => 'Ebs.SnapshotId', :ebs_volume_size => 'Ebs.VolumeSize', :ebs_delete_on_termination => 'Ebs.DeleteOnTermination' }))
49
+ end
50
+
51
+ params["SpotPrice"] = options[:spot_price]
52
+ params["InstanceCount"] = options[:instance_count].to_s
53
+ params["Type"] = options[:type] unless options[:type].nil?
54
+ params["ValidFrom"] = options[:valid_from].to_s unless options[:valid_from].nil?
55
+ params["ValidUntil"] = options[:valid_until].to_s unless options[:valid_until].nil?
56
+ params["LaunchGroup"] = options[:launch_group] unless options[:launch_group].nil?
57
+ params["AvailabilityZoneGroup"] = options[:availability_zone_group] unless options[:availability_zone_group].nil?
58
+ params["LaunchSpecification.ImageId"] = options[:image_id] unless options[:image_id].nil?
59
+ params["LaunchSpecification.KeyName"] = options[:key_name] unless options[:key_name].nil?
60
+ params["LaunchSpecification.UserData"] = user_data unless user_data.nil?
61
+ params["LaunchSpecification.InstanceType"] = options[:instance_type] unless options[:instance_type].nil?
62
+ params["LaunchSpecification.KernelId"] = options[:kernel_id] unless options[:kernel_id].nil?
63
+ params["LaunchSpecification.RamdiskId"] = options[:ramdisk_id] unless options[:ramdisk_id].nil?
64
+ params["LaunchSpecification.SubnetId"] = options[:subnet_id] unless options[:subnet_id].nil?
65
+ params["LaunchSpecification.Placement.AvailabilityZone"] = options[:availability_zone] unless options[:availability_zone].nil?
66
+ params["LaunchSpecification.Monitoring.Enabled"] = options[:monitoring_enabled].to_s unless options[:monitoring_enabled].nil?
67
+
68
+ return response_generator(:action => "RequestSpotInstances", :params => params)
69
+ end
70
+
71
+ # Describes Spot Instance requests. Spot Instances are instances that Amazon EC2 starts on your behalf when the
72
+ # maximum price that you specify exceeds the current Spot Price. Amazon EC2 periodically sets the Spot Price
73
+ # based on available Spot Instance capacity and current spot instance requests. For conceptual information about
74
+ # Spot Instances, refer to the Amazon Elastic Compute Cloud Developer Guide or Amazon Elastic Compute Cloud User Guide.
75
+ #
76
+ # @option options [Array] :spot_instance_request_id ([])
77
+ #
78
+ def describe_spot_instance_requests( options = {} )
79
+ options = { :spot_instance_request_id => []}.merge(options)
80
+ params = pathlist( "SpotInstanceRequestId", options[:spot_instance_request_id] )
81
+
82
+ return response_generator(:action => "DescribeSpotInstanceRequests", :params => params)
83
+ end
84
+
85
+ # Cancels one or more Spot Instance requests. Spot Instances are instances that Amazon EC2 starts on your behalf
86
+ # when the maximum price that you specify exceeds the current Spot Price. Amazon EC2 periodically sets the Spot
87
+ # Price based on available Spot Instance capacity and current spot instance requests. For conceptual information
88
+ # about Spot Instances, refer to the Amazon Elastic Compute Cloud Developer Guide or Amazon Elastic Compute Cloud
89
+ # User Guide.
90
+ #
91
+ # NB: Canceling a Spot Instance request does not terminiate running Spot Instances associated with the request.
92
+ #
93
+ # @option options [Array] :spot_instance_request_id ([])
94
+ #
95
+ def destroy_spot_instance_requests( options = {} )
96
+ options = { :spot_instance_request_id => []}.merge(options)
97
+ params = pathlist( "SpotInstanceRequestId", options[:spot_instance_request_id] )
98
+
99
+ return response_generator(:action => "CancelSpotInstanceRequests", :params => params)
100
+ end
101
+
102
+ end
103
+ end
104
+ end
105
+
@@ -0,0 +1,100 @@
1
+ module AWS
2
+ module EC2
3
+ class Base < AWS::Base
4
+
5
+
6
+ # The DescribeVolumes operation lists one or more Amazon EBS volumes that you own, If you do not specify any volumes, Amazon EBS returns all volumes that you own.
7
+ #
8
+ # @option options [optional, String] :volume_id ([])
9
+ #
10
+ def describe_volumes( options = {} )
11
+ options = { :volume_id => [] }.merge(options)
12
+ params = pathlist("VolumeId", options[:volume_id] )
13
+ return response_generator(:action => "DescribeVolumes", :params => params)
14
+ end
15
+
16
+
17
+ # The CreateVolume operation creates a new Amazon EBS volume that you can mount from any Amazon EC2 instance.
18
+ #
19
+ # @option options [String] :availability_zone ('')
20
+ # @option options [optional, String] :size ('')
21
+ # @option options [optional, String] :snapshot_id ('')
22
+ #
23
+ def create_volume( options = {} )
24
+ options = { :availability_zone => '' }.merge(options)
25
+ raise ArgumentError, "No :availability_zone provided" if options[:availability_zone].nil? || options[:availability_zone].empty?
26
+ options = { :size => '' }.merge(options)
27
+ options = { :snapshot_id => '' }.merge(options)
28
+ params = {
29
+ "AvailabilityZone" => options[:availability_zone],
30
+ "Size" => options[:size],
31
+ "SnapshotId" => options[:snapshot_id]
32
+ }
33
+ return response_generator(:action => "CreateVolume", :params => params)
34
+ end
35
+
36
+
37
+ # The DeleteVolume operation deletes an Amazon EBS volume.
38
+ #
39
+ # @option options [String] :volume_id ('')
40
+ #
41
+ def delete_volume( options = {} )
42
+ options = { :volume_id => '' }.merge(options)
43
+ raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
44
+ params = {
45
+ "VolumeId" => options[:volume_id]
46
+ }
47
+ return response_generator(:action => "DeleteVolume", :params => params)
48
+ end
49
+
50
+
51
+ # The AttachVolume operation attaches an Amazon EBS volume to an instance.
52
+ #
53
+ # @option options [String] :volume_id ('')
54
+ # @option options [String] :instance_id ('')
55
+ # @option options [String] :device ('')
56
+ #
57
+ def attach_volume( options = {} )
58
+ options = { :volume_id => '' }.merge(options)
59
+ options = { :instance_id => '' }.merge(options)
60
+ options = { :device => '' }.merge(options)
61
+ raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
62
+ raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
63
+ raise ArgumentError, "No :device provided" if options[:device].nil? || options[:device].empty?
64
+
65
+ params = {
66
+ "VolumeId" => options[:volume_id],
67
+ "InstanceId" => options[:instance_id],
68
+ "Device" => options[:device]
69
+ }
70
+ return response_generator(:action => "AttachVolume", :params => params)
71
+ end
72
+
73
+
74
+ # The DetachVolume operation detaches an Amazon EBS volume from an instance.
75
+ #
76
+ # @option options [String] :volume_id ('')
77
+ # @option options [optional, String] :instance_id ('')
78
+ # @option options [optional, String] :device ('')
79
+ # @option options [optional, Boolean] :force ('')
80
+ #
81
+ def detach_volume( options = {} )
82
+ options = { :volume_id => '' }.merge(options)
83
+ raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
84
+ options = { :instance_id => '' }.merge(options)
85
+ options = { :device => '' }.merge(options)
86
+ options = { :force => '' }.merge(options)
87
+ params = {
88
+ "VolumeId" => options[:volume_id],
89
+ "InstanceId" => options[:instance_id],
90
+ "Device" => options[:device],
91
+ "Force" => options[:force]
92
+ }
93
+ return response_generator(:action => "DetachVolume", :params => params)
94
+ end
95
+
96
+
97
+ end
98
+ end
99
+ end
100
+
@@ -0,0 +1,71 @@
1
+ module AWS
2
+ module ELB
3
+
4
+ # Which host FQDN will we connect to for all API calls to AWS?
5
+ # If ELB_URL is defined in the users ENV we can override the default with that.
6
+ #
7
+ # @example
8
+ # export ELB_URL='https://elasticloadbalancing.amazonaws.com'
9
+ if ENV['ELB_URL']
10
+ ELB_URL = ENV['ELB_URL']
11
+ VALID_HOSTS = ['elasticloadbalancing.amazonaws.com']
12
+ raise ArgumentError, "Invalid ELB_URL environment variable : #{ELB_URL}" unless VALID_HOSTS.include?(ELB_URL)
13
+ DEFAULT_HOST = URI.parse(ELB_URL).host
14
+ else
15
+ # Default US API endpoint
16
+ DEFAULT_HOST = 'elasticloadbalancing.amazonaws.com'
17
+ end
18
+
19
+ API_VERSION = '2009-05-15'
20
+
21
+ class Base < AWS::Base
22
+ def api_version
23
+ API_VERSION
24
+ end
25
+
26
+ def default_host
27
+ DEFAULT_HOST
28
+ end
29
+
30
+ # Raises the appropriate error if the specified Net::HTTPResponse object
31
+ # contains an Amazon EC2 error; returns +false+ otherwise.
32
+ def aws_error?(response)
33
+
34
+ # return false if we got a HTTP 200 code,
35
+ # otherwise there is some type of error (40x,50x) and
36
+ # we should try to raise an appropriate exception
37
+ # from one of our exception classes defined in
38
+ # exceptions.rb
39
+ return false if response.is_a?(Net::HTTPSuccess)
40
+
41
+ # parse the XML document so we can walk through it
42
+ doc = REXML::Document.new(response.body)
43
+
44
+ # Check that the Error element is in the place we would expect.
45
+ # and if not raise a generic error exception
46
+ unless doc.root.elements[1].name == "Error"
47
+ raise Error, "Unexpected error format. response.body is: #{response.body}"
48
+ end
49
+
50
+ # An valid error response looks like this:
51
+ # <?xml version="1.0"?><Response><Errors><Error><Code>InvalidParameterCombination</Code><Message>Unknown parameter: foo</Message></Error></Errors><RequestID>291cef62-3e86-414b-900e-17246eccfae8</RequestID></Response>
52
+ # AWS EC2 throws some exception codes that look like Error.SubError. Since we can't name classes this way
53
+ # we need to strip out the '.' in the error 'Code' and we name the error exceptions with this
54
+ # non '.' name as well.
55
+ error_code = doc.root.elements['//ErrorResponse/Error/Code'].text.gsub('.', '')
56
+ error_message = doc.root.elements['//ErrorResponse/Error/Message'].text
57
+
58
+ # Raise one of our specific error classes if it exists.
59
+ # otherwise, throw a generic EC2 Error with a few details.
60
+ if AWS.const_defined?(error_code)
61
+ raise AWS.const_get(error_code), error_message
62
+ else
63
+ raise AWS::Error, error_message
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,178 @@
1
+ module AWS
2
+ module ELB
3
+ class Base < AWS::Base
4
+
5
+ # This API creates a new LoadBalancer. Once the call has completed
6
+ # successfully, a new LoadBalancer will be created, but it will not be
7
+ # usable until at least one instance has been registered. When the
8
+ # LoadBalancer creation is completed, you can check whether it is usable
9
+ # by using the DescribeInstanceHealth API. The LoadBalancer is usable as
10
+ # soon as any registered instance is InService.
11
+ #
12
+ # @option options [String] :load_balancer_name (nil) the name of the load balancer
13
+ # @option options [Array] :availability_zones (nil)
14
+ # @option options [Array] :listeners (nil) An Array of Hashes (:protocol, :load_balancer_port, :instance_port)
15
+ # @option options [Array] :availability_zones (nil) An Array of Strings
16
+ #
17
+ def create_load_balancer( options = {} )
18
+ raise ArgumentError, "No :availability_zones provided" if options[:availability_zones].nil? || options[:availability_zones].empty?
19
+ raise ArgumentError, "No :listeners provided" if options[:listeners].nil? || options[:listeners].empty?
20
+ raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?
21
+
22
+ params = {}
23
+
24
+ params.merge!(pathlist('AvailabilityZones.member', [options[:availability_zones]].flatten))
25
+ params.merge!(pathhashlist('Listeners.member', [options[:listeners]].flatten, {
26
+ :protocol => 'Protocol',
27
+ :load_balancer_port => 'LoadBalancerPort',
28
+ :instance_port => 'InstancePort'
29
+ }))
30
+ params['LoadBalancerName'] = options[:load_balancer_name]
31
+
32
+ return response_generator(:action => "CreateLoadBalancer", :params => params)
33
+ end
34
+
35
+ # This API deletes the specified LoadBalancer. On deletion, all of the
36
+ # configured properties of the LoadBalancer will be deleted. If you
37
+ # attempt to recreate the LoadBalancer, you need to reconfigure all the
38
+ # settings. The DNS name associated with a deleted LoadBalancer is no
39
+ # longer be usable. Once deleted, the name and associated DNS record of
40
+ # the LoadBalancer no longer exist and traffic sent to any of its IP
41
+ # addresses will no longer be delivered to your instances. You will not
42
+ # get the same DNS name even if you create a new LoadBalancer with same
43
+ # LoadBalancerName.
44
+ #
45
+ # @option options [String] :load_balancer_name the name of the load balancer
46
+ #
47
+ def delete_load_balancer( options = {} )
48
+ raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?
49
+ params = { 'LoadBalancerName' => options[:load_balancer_name] }
50
+ return response_generator(:action => "DeleteLoadBalancer", :params => params)
51
+ end
52
+
53
+ # This API returns detailed configuration information for the specified
54
+ # LoadBalancers, or if no LoadBalancers are specified, then the API
55
+ # returns configuration information for all LoadBalancers created by the
56
+ # caller. For more information, please see LoadBalancer.
57
+ #
58
+ # You must have created the specified input LoadBalancers in order to
59
+ # retrieve this information. In other words, in order to successfully call
60
+ # this API, you must provide the same account credentials as those that
61
+ # were used to create the LoadBalancer.
62
+ #
63
+ # @option options [Array<String>] :load_balancer_names ([]) An Array of names of load balancers to describe.
64
+ #
65
+ def describe_load_balancers( options = {} )
66
+ options = { :load_balancer_names => [] }.merge(options)
67
+ params = pathlist("LoadBalancerName.member", options[:load_balancer_names])
68
+ return response_generator(:action => "DescribeLoadBalancers", :params => params)
69
+ end
70
+
71
+ # This API adds new instances to the LoadBalancer.
72
+ #
73
+ # Once the instance is registered, it starts receiving traffic and
74
+ # requests from the LoadBalancer. Any instance that is not in any of the
75
+ # Availability Zones registered for the LoadBalancer will be moved to
76
+ # the OutOfService state. It will move to the InService state when the
77
+ # Availability Zone is added to the LoadBalancer.
78
+ #
79
+ # You must have been the one who created the LoadBalancer. In other
80
+ # words, in order to successfully call this API, you must provide the
81
+ # same account credentials as those that were used to create the
82
+ # LoadBalancer.
83
+ #
84
+ # NOTE: Completion of this API does not guarantee that operation has
85
+ # completed. Rather, it means that the request has been registered and
86
+ # the changes will happen shortly.
87
+ #
88
+ # @option options [Array<String>] :instances An Array of instance names to add to the load balancer.
89
+ # @option options [String] :load_balancer_name The name of the load balancer.
90
+ #
91
+ def register_instances_with_load_balancer( options = {} )
92
+ raise ArgumentError, "No :instances provided" if options[:instances].nil? || options[:instances].empty?
93
+ raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?
94
+ params = {}
95
+ params.merge!(pathhashlist('Instances.member', options[:instances].flatten.collect{|e| {:instance_id => e}}, {:instance_id => 'InstanceId'}))
96
+ params['LoadBalancerName'] = options[:load_balancer_name]
97
+ return response_generator(:action => "RegisterInstancesWithLoadBalancer", :params => params)
98
+ end
99
+
100
+ # This API deregisters instances from the LoadBalancer. Trying to
101
+ # deregister an instance that is not registered with the LoadBalancer
102
+ # does nothing.
103
+ #
104
+ # In order to successfully call this API, you must provide the same
105
+ # account credentials as those that were used to create the
106
+ # LoadBalancer.
107
+ #
108
+ # Once the instance is deregistered, it will stop receiving traffic from
109
+ # the LoadBalancer.
110
+ #
111
+ # @option options [Array<String>] :instances An Array of instance names to remove from the load balancer.
112
+ # @option options [String] :load_balancer_name The name of the load balancer.
113
+ #
114
+ def deregister_instances_from_load_balancer( options = {} )
115
+ raise ArgumentError, "No :instances provided" if options[:instances].nil? || options[:instances].empty?
116
+ raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?
117
+ params = {}
118
+ params.merge!(pathlist('Instances.member', [options[:instances]].flatten))
119
+ params['LoadBalancerName'] = options[:load_balancer_name]
120
+ return response_generator(:action => "DeregisterInstancesFromLoadBalancer", :params => params)
121
+ end
122
+
123
+ # This API enables you to define an application healthcheck for the
124
+ # instances.
125
+ #
126
+ # Note: Completion of this API does not guarantee that operation has completed. Rather, it means that the request has been registered and the changes will happen shortly.
127
+ #
128
+ # @option options [Hash] :health_check A Hash with the keys (:timeout, :interval, :unhealthy_threshold, :healthy_threshold)
129
+ # @option options [String] :load_balancer_name The name of the load balancer.
130
+ #
131
+ def configure_health_check( options = {} )
132
+ raise ArgumentError, "No :health_check provided" if options[:health_check].nil? || options[:health_check].empty?
133
+ raise ArgumentError, "No :health_check => :target provided" if options[:health_check][:target].nil? || options[:health_check][:target].empty?
134
+ raise ArgumentError, "No :health_check => :timeout provided" if options[:health_check][:timeout].nil? || options[:health_check][:timeout].empty?
135
+ raise ArgumentError, "No :health_check => :interval provided" if options[:health_check][:interval].nil? || options[:health_check][:interval].empty?
136
+ raise ArgumentError, "No :health_check => :unhealthy_threshold provided" if options[:health_check][:unhealthy_threshold].nil? || options[:health_check][:unhealthy_threshold].empty?
137
+ raise ArgumentError, "No :health_check => :healthy_threshold provided" if options[:health_check][:healthy_threshold].nil? || options[:health_check][:healthy_threshold].empty?
138
+ raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?
139
+
140
+ params = {}
141
+
142
+ params['LoadBalancerName'] = options[:load_balancer_name]
143
+ params['HealthCheck.Target'] = options[:health_check][:target]
144
+ params['HealthCheck.Timeout'] = options[:health_check][:timeout]
145
+ params['HealthCheck.Interval'] = options[:health_check][:interval]
146
+ params['HealthCheck.UnhealthyThreshold'] = options[:health_check][:unhealthy_threshold]
147
+ params['HealthCheck.HealthyThreshold'] = options[:health_check][:healthy_threshold]
148
+
149
+ return response_generator(:action => "ConfigureHealthCheck", :params => params)
150
+ end
151
+
152
+ # Not yet implemented
153
+ #
154
+ # @todo Implement this method
155
+ #
156
+ def describe_instance_health( options = {} )
157
+ raise "Not yet implemented"
158
+ end
159
+
160
+ # Not yet implemented
161
+ #
162
+ # @todo Implement this method
163
+ #
164
+ def disable_availability_zones_for_load_balancer( options = {} )
165
+ raise "Not yet implemented"
166
+ end
167
+
168
+ # Not yet implemented
169
+ #
170
+ # @todo Implement this method
171
+ #
172
+ def enable_availability_zones_for_load_balancer( options = {} )
173
+ raise "Not yet implemented"
174
+ end
175
+
176
+ end
177
+ end
178
+ end