amazon-ec2 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,14 @@
1
+ === 0.7.4 2009-12-05
2
+ * Initial support for new EBS AMI's
3
+ * Updated EC2 API version
4
+ * Added US West 1 Data Center to list of valid endpoints. (us-west-1.ec2.amazonaws.com)
5
+ * Updated exceptions.rb to be in sync with latest documented exceptions.
6
+ * Updated #run_instances to support EBS AMI's and sync with latest options.
7
+ * Added new #stop_instances and #start_instances methods.
8
+ * Added new #create_image to allow bundling of a running instance to an EBS backed AMI.
9
+ * Added stub methods for all known missing EC2 methods. (Please help with patches + tests!)
10
+ * Added and updated tests for new/modified methods.
11
+
1
12
  === 0.6.1 2009-10-13
2
13
  * Additional commits for AutoScaling. Thanks to Ari (auser)!
3
14
  * Updated README.rdoc installation instructions. Reflects removal of deprecated GitHub gem building.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.3
1
+ 0.7.4
data/amazon-ec2.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{amazon-ec2}
8
- s.version = "0.7.3"
8
+ s.version = "0.7.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Glenn Rempe"]
12
- s.date = %q{2009-11-16}
12
+ s.date = %q{2009-12-06}
13
13
  s.description = %q{A Ruby library for accessing the Amazon Web Services EC2, ELB, RDS, Cloudwatch, and Autoscaling API's.}
14
14
  s.email = %q{glenn@rempe.us}
15
15
  s.executables = ["ec2-gem-example.rb", "ec2-gem-profile.rb", "ec2sh", "setup.rb"]
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
42
42
  "lib/AWS/EC2.rb",
43
43
  "lib/AWS/EC2/availability_zones.rb",
44
44
  "lib/AWS/EC2/console.rb",
45
+ "lib/AWS/EC2/devpay.rb",
45
46
  "lib/AWS/EC2/elastic_ips.rb",
46
47
  "lib/AWS/EC2/image_attributes.rb",
47
48
  "lib/AWS/EC2/images.rb",
@@ -82,7 +83,8 @@ Gem::Specification.new do |s|
82
83
  "wsdl/2007-08-29.ec2.wsdl",
83
84
  "wsdl/2008-02-01.ec2.wsdl",
84
85
  "wsdl/2008-05-05.ec2.wsdl",
85
- "wsdl/2008-12-01.ec2.wsdl"
86
+ "wsdl/2008-12-01.ec2.wsdl",
87
+ "wsdl/2009-10-31.ec2.wsdl"
86
88
  ]
87
89
  s.homepage = %q{http://github.com/grempe/amazon-ec2}
88
90
  s.rdoc_options = ["--title", "amazon-ec2 documentation", "--line-numbers", "--main", "README.rdoc"]
data/lib/AWS.rb CHANGED
@@ -185,10 +185,14 @@ module AWS
185
185
  # ("People", [{:name=>'jon', :age=>'22'}, {:name=>'chris'}], {:name => 'Name', :age => 'Age'}) you should get
186
186
  # {"People.1.Name"=>"jon", "People.1.Age"=>'22', 'People.2.Name'=>'chris'}
187
187
  def pathhashlist(key, arr_of_hashes, mappings)
188
- params ={}
188
+ raise ArgumentError, "expected a key that is a String" unless key.is_a? String
189
+ raise ArgumentError, "expected a arr_of_hashes that is an Array" unless arr_of_hashes.is_a? Array
190
+ arr_of_hashes.each{|h| raise ArgumentError, "expected each element of arr_of_hashes to be a Hash" unless h.is_a?(Hash)}
191
+ raise ArgumentError, "expected a mappings that is an Hash" unless mappings.is_a? Hash
192
+ params = {}
189
193
  arr_of_hashes.each_with_index do |hash, i|
190
194
  hash.each do |attribute, value|
191
- params["#{key}.#{i+1}.#{mappings[attribute]}"] = value
195
+ params["#{key}.#{i+1}.#{mappings[attribute]}"] = value.to_s
192
196
  end
193
197
  end
194
198
  params
@@ -256,7 +260,7 @@ module AWS
256
260
  end
257
261
 
258
262
  # Raises the appropriate error if the specified Net::HTTPResponse object
259
- # contains an Amazon EC2 error; returns +false+ otherwise.
263
+ # contains an AWS error; returns +false+ otherwise.
260
264
  def aws_error?(response)
261
265
 
262
266
  # return false if we got a HTTP 200 code,
@@ -277,7 +281,7 @@ module AWS
277
281
 
278
282
  # An valid error response looks like this:
279
283
  # <?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>
280
- # AWS EC2 throws some exception codes that look like Error.SubError. Since we can't name classes this way
284
+ # AWS throws some exception codes that look like Error.SubError. Since we can't name classes this way
281
285
  # we need to strip out the '.' in the error 'Code' and we name the error exceptions with this
282
286
  # non '.' name as well.
283
287
  error_code = doc.root.elements['Errors'].elements['Error'].elements['Code'].text.gsub('.', '')
data/lib/AWS/EC2.rb CHANGED
@@ -8,7 +8,7 @@ module AWS
8
8
  # export EC2_URL='https://ec2.amazonaws.com'
9
9
  if ENV['EC2_URL']
10
10
  EC2_URL = ENV['EC2_URL']
11
- VALID_HOSTS = ['https://ec2.amazonaws.com', 'https://us-east-1.ec2.amazonaws.com', 'https://eu-west-1.ec2.amazonaws.com']
11
+ VALID_HOSTS = ['https://ec2.amazonaws.com', 'https://us-east-1.ec2.amazonaws.com', 'https://us-west-1.ec2.amazonaws.com', 'https://eu-west-1.ec2.amazonaws.com']
12
12
  raise ArgumentError, "Invalid EC2_URL environment variable : #{EC2_URL}" unless VALID_HOSTS.include?(EC2_URL)
13
13
  DEFAULT_HOST = URI.parse(EC2_URL).host
14
14
  else
@@ -16,7 +16,7 @@ module AWS
16
16
  DEFAULT_HOST = 'ec2.amazonaws.com'
17
17
  end
18
18
 
19
- API_VERSION = '2009-07-15'
19
+ API_VERSION = '2009-10-31'
20
20
 
21
21
  class Base < AWS::Base
22
22
  def api_version
@@ -15,6 +15,14 @@ module AWS
15
15
  return response_generator(:action => "DescribeAvailabilityZones", :params => params)
16
16
  end
17
17
 
18
+ # Not yet implemented
19
+ #
20
+ # @todo Implement this method
21
+ #
22
+ def describe_regions( options = {} )
23
+ raise "Not yet implemented"
24
+ end
25
+
18
26
  end
19
27
  end
20
28
  end
@@ -2,6 +2,7 @@ module AWS
2
2
  module EC2
3
3
  class Base < AWS::Base
4
4
 
5
+
5
6
  # The GetConsoleOutput operation retrieves console output that has been posted for the specified instance.
6
7
  #
7
8
  # Instance console output is buffered and posted shortly after instance boot, reboot and once the instance
@@ -17,6 +18,7 @@ module AWS
17
18
  return response_generator(:action => "GetConsoleOutput", :params => params)
18
19
  end
19
20
 
21
+
20
22
  end
21
23
  end
22
24
  end
@@ -0,0 +1,18 @@
1
+ module AWS
2
+ module EC2
3
+ class Base < AWS::Base
4
+
5
+
6
+ # Not yet implemented
7
+ #
8
+ # @todo Implement this method
9
+ #
10
+ def confirm_product_instance( options = {} )
11
+ raise "Not yet implemented"
12
+ end
13
+
14
+
15
+ end
16
+ end
17
+ end
18
+
@@ -2,43 +2,13 @@ module AWS
2
2
  module EC2
3
3
  class Base < AWS::Base
4
4
 
5
+
5
6
  # The AllocateAddress operation acquires an elastic IP address for use with your account.
6
7
  #
7
8
  def allocate_address
8
9
  return response_generator(:action => "AllocateAddress")
9
10
  end
10
11
 
11
- # The DescribeAddresses operation lists elastic IP addresses assigned to your account.
12
- #
13
- # @option options [Array] :public_ip ([]) an IP address to be described
14
- #
15
- def describe_addresses( options = {} )
16
- options = { :public_ip => [] }.merge(options)
17
- params = pathlist("PublicIp", options[:public_ip])
18
- return response_generator(:action => "DescribeAddresses", :params => params)
19
- end
20
-
21
- # The ReleaseAddress operation releases an elastic IP address associated with your account.
22
- #
23
- # If you run this operation on an elastic IP address that is already released, the address
24
- # might be assigned to another account which will cause Amazon EC2 to return an error.
25
- #
26
- # Note : Releasing an IP address automatically disassociates it from any instance
27
- # with which it is associated. For more information, see DisassociateAddress.
28
- #
29
- # Important! After releasing an elastic IP address, it is released to the IP
30
- # address pool and might no longer be available to your account. Make sure
31
- # to update your DNS records and any servers or devices that communicate
32
- # with the address.
33
- #
34
- # @option options [String] :public_ip ('') an IP address to be released.
35
- #
36
- def release_address( options = {} )
37
- options = { :public_ip => '' }.merge(options)
38
- raise ArgumentError, "No ':public_ip' provided" if options[:public_ip].nil? || options[:public_ip].empty?
39
- params = { "PublicIp" => options[:public_ip] }
40
- return response_generator(:action => "ReleaseAddress", :params => params)
41
- end
42
12
 
43
13
  # The AssociateAddress operation associates an elastic IP address with an instance.
44
14
  #
@@ -60,6 +30,18 @@ module AWS
60
30
  return response_generator(:action => "AssociateAddress", :params => params)
61
31
  end
62
32
 
33
+
34
+ # The DescribeAddresses operation lists elastic IP addresses assigned to your account.
35
+ #
36
+ # @option options [Array] :public_ip ([]) an IP address to be described
37
+ #
38
+ def describe_addresses( options = {} )
39
+ options = { :public_ip => [] }.merge(options)
40
+ params = pathlist("PublicIp", options[:public_ip])
41
+ return response_generator(:action => "DescribeAddresses", :params => params)
42
+ end
43
+
44
+
63
45
  # The DisassociateAddress operation disassociates the specified elastic IP
64
46
  # address from the instance to which it is assigned. This is an idempotent
65
47
  # operation. If you enter it more than once, Amazon EC2 does not return
@@ -74,8 +56,31 @@ module AWS
74
56
  return response_generator(:action => "DisassociateAddress", :params => params)
75
57
  end
76
58
 
77
- end
78
59
 
60
+ # The ReleaseAddress operation releases an elastic IP address associated with your account.
61
+ #
62
+ # If you run this operation on an elastic IP address that is already released, the address
63
+ # might be assigned to another account which will cause Amazon EC2 to return an error.
64
+ #
65
+ # Note : Releasing an IP address automatically disassociates it from any instance
66
+ # with which it is associated. For more information, see DisassociateAddress.
67
+ #
68
+ # Important! After releasing an elastic IP address, it is released to the IP
69
+ # address pool and might no longer be available to your account. Make sure
70
+ # to update your DNS records and any servers or devices that communicate
71
+ # with the address.
72
+ #
73
+ # @option options [String] :public_ip ('') an IP address to be released.
74
+ #
75
+ def release_address( options = {} )
76
+ options = { :public_ip => '' }.merge(options)
77
+ raise ArgumentError, "No ':public_ip' provided" if options[:public_ip].nil? || options[:public_ip].empty?
78
+ params = { "PublicIp" => options[:public_ip] }
79
+ return response_generator(:action => "ReleaseAddress", :params => params)
80
+ end
81
+
82
+
83
+ end
79
84
  end
80
85
  end
81
86
 
@@ -3,6 +3,46 @@ module AWS
3
3
 
4
4
  class Base < AWS::Base
5
5
 
6
+ # Creates an AMI that uses an Amazon EBS root device from a "running" or "stopped" instance.
7
+ #
8
+ # AMIs that use an Amazon EBS root device boot faster than AMIs that use instance stores.
9
+ # They can be up to 1 TiB in size, use storage that persists on instance failure, and can be
10
+ # stopped and started.
11
+ #
12
+ # @option options [String] :instance_id ("") The ID of the instance.
13
+ # @option options [String] :name ("") The name of the AMI that was provided during image creation. Constraints 3-128 alphanumeric characters, parenthesis (()), commas (,), slashes (/), dashes (-), or underscores(_)
14
+ # @option options [optional,String] :description ("") The description of the AMI that was provided during image creation.
15
+ # @option options [optional,Boolean] :no_reboot (false) By default this property is set to false, which means Amazon EC2 attempts to cleanly shut down the instance before image creation and reboots the instance afterwards. When set to true, Amazon EC2 does not shut down the instance before creating the image. When this option is used, file system integrity on the created image cannot be guaranteed.
16
+ #
17
+ def create_image( options = {} )
18
+ options = { :instance_id => "", :name => "" }.merge(options)
19
+ raise ArgumentError, "No :instance_id provided" if options.does_not_have? :instance_id
20
+ raise ArgumentError, "No :name provided" if options.does_not_have? :name
21
+ raise ArgumentError, "Invalid string length for :name provided" if options[:name] && options[:name].size < 3 || options[:name].size > 128
22
+ raise ArgumentError, "Invalid string length for :description provided (too long)" if options[:description] && options[:description].size > 255
23
+ raise ArgumentError, ":no_reboot option must be a Boolean" unless options[:no_reboot].nil? || [true, false].include?(options[:no_reboot])
24
+ params = {}
25
+ params["InstanceId"] = options[:instance_id].to_s
26
+ params["Name"] = options[:name].to_s
27
+ params["Description"] = options[:description].to_s
28
+ params["NoReboot"] = options[:no_reboot].to_s
29
+ return response_generator(:action => "CreateImage", :params => params)
30
+ end
31
+
32
+
33
+ # The DeregisterImage operation deregisters an AMI. Once deregistered, instances of the AMI may no
34
+ # longer be launched.
35
+ #
36
+ # @option options [String] :image_id ("")
37
+ #
38
+ def deregister_image( options = {} )
39
+ options = { :image_id => "" }.merge(options)
40
+ raise ArgumentError, "No :image_id provided" if options[:image_id].nil? || options[:image_id].empty?
41
+ params = { "ImageId" => options[:image_id] }
42
+ return response_generator(:action => "DeregisterImage", :params => params)
43
+ end
44
+
45
+
6
46
  # The RegisterImage operation registers an AMI with Amazon EC2. Images must be registered before
7
47
  # they can be launched. Each AMI is associated with an unique ID which is provided by the EC2
8
48
  # service via the Registerimage operation. As part of the registration process, Amazon EC2 will
@@ -15,17 +55,13 @@ module AWS
15
55
  # @option options [String] :image_location ("")
16
56
  #
17
57
  def register_image( options = {} )
18
-
19
58
  options = {:image_location => ""}.merge(options)
20
-
21
59
  raise ArgumentError, "No :image_location provided" if options[:image_location].nil? || options[:image_location].empty?
22
-
23
60
  params = { "ImageLocation" => options[:image_location] }
24
-
25
61
  return response_generator(:action => "RegisterImage", :params => params)
26
-
27
62
  end
28
63
 
64
+
29
65
  # The DescribeImages operation returns information about AMIs available for use by the user. This
30
66
  # includes both public AMIs (those available for any user to launch) and private AMIs (those owned by
31
67
  # the user making the request and those owned by other users that the user making the request has explicit
@@ -67,35 +103,15 @@ module AWS
67
103
  # @option options [Array] :executable_by ([])
68
104
  #
69
105
  def describe_images( options = {} )
70
-
71
106
  options = { :image_id => [], :owner_id => [], :executable_by => [] }.merge(options)
72
-
73
107
  params = pathlist( "ImageId", options[:image_id] )
74
108
  params.merge!(pathlist( "Owner", options[:owner_id] ))
75
109
  params.merge!(pathlist( "ExecutableBy", options[:executable_by] ))
76
-
77
110
  return response_generator(:action => "DescribeImages", :params => params)
78
-
79
111
  end
80
112
 
81
- # The DeregisterImage operation deregisters an AMI. Once deregistered, instances of the AMI may no
82
- # longer be launched.
83
- #
84
- # @option options [String] :image_id ("")
85
- #
86
- def deregister_image( options = {} )
87
-
88
- options = { :image_id => "" }.merge(options)
89
-
90
- raise ArgumentError, "No :image_id provided" if options[:image_id].nil? || options[:image_id].empty?
91
-
92
- params = { "ImageId" => options[:image_id] }
93
-
94
- return response_generator(:action => "DeregisterImage", :params => params)
95
-
96
- end
97
113
 
98
114
  end
99
-
100
115
  end
101
- end
116
+ end
117
+
@@ -1,96 +1,72 @@
1
1
  module AWS
2
2
  module EC2
3
-
4
3
  class Base < AWS::Base
5
4
 
6
- # The RunInstances operation launches a specified number of instances.
7
- #
8
- # Note : The Query version of RunInstances only allows instances of a single AMI to be launched in
9
- # one call. This is different from the SOAP API call of the same name but similar to the
10
- # ec2-run-instances command line tool.
11
- #
12
- # If Amazon EC2 cannot launch the minimum number AMIs you request, no instances launch. If there
13
- # is insufficient capacity to launch the maximum number of AMIs you request, Amazon EC2 launches
14
- # as many as possible to satisfy the requested maximum values.
15
- #
16
- # Every instance is launched in a security group. If you do not specify a security group at
17
- # launch, the instances start in the default security group.
18
- #
19
- # An optional instance type can be specified. Currently supported types are 'm1.small', 'm1.large',
20
- # 'm1.xlarge' and the high CPU types 'c1.medium' and 'c1.xlarge'. 'm1.small' is the default
21
- # if no instance_type is specified.
22
- #
23
- # You can provide an optional key pair ID for each image in the launch request. All instances
24
- # that are created from images that use this key pair will have access to the associated public
25
- # key at boot. You can use this key to provide secure access to an instance of an image on a
26
- # per-instance basis. Amazon EC2 public images use this feature to provide secure access
27
- # without passwords.
28
- #
29
- # Important! Launching public images without a key pair ID will leave them inaccessible.
30
- #
31
- # The public key material is made available to the instance at boot time by placing it in a file named
32
- # openssh_id.pub on a logical device that is exposed to the instance as /dev/sda2 (the ephemeral
33
- # store). The format of this file is suitable for use as an entry within ~/.ssh/authorized_keys (the
34
- # OpenSSH format). This can be done at boot time (as part of rclocal, for example) allowing for secure
35
- # password-less access.
36
- #
37
- # Optional user data can be provided in the launch request. All instances comprising the launch
38
- # request have access to this data (see Instance Metadata for details).
39
- #
40
- # If any of the AMIs have product codes attached for which the user has not subscribed,
41
- # the RunInstances call will fail.
42
- #
43
- # @option options [String] :image_id ("")
44
- # @option options [Integer] :min_count (1)
45
- # @option options [Integer] :max_count (1)
46
- # @option options [optional, String] :key_name (nil)
47
- # @option options [optional, Array] :group_id ([])
48
- # @option options [optional, String] :user_data (nil)
49
- # @option options [optional, String] :addressing_type ("public")
50
- # @option options [optional, String] :instance_type ("m1.small")
51
- # @option options [optional, String] :kernel_id (nil)
52
- # @option options [optional, String] :availability_zone (nil)
5
+ # Launches a specified number of instances of an AMI for which you have permissions.
6
+ #
7
+ # Amazon API Docs : HTML[http://docs.amazonwebservices.com/AWSEC2/2009-10-31/APIReference/index.html?ApiReference-query-RunInstances.html]
8
+ #
9
+ # @option options [String] :image_id ("") Unique ID of a machine image.
10
+ # @option options [Integer] :min_count (1) Minimum number of instances to launch. If the value is more than Amazon EC2 can launch, no instances are launched at all.
11
+ # @option options [Integer] :max_count (1) Maximum number of instances to launch. If the value is more than Amazon EC2 can launch, the largest possible number above minCount will be launched instead.
12
+ # @option options [optional, String] :key_name (nil) The name of the key pair.
13
+ # @option options [optional, String] :security_group (nil) Name of the security group.
14
+ # @option options [optional, String] :additional_info (nil) Specifies additional information to make available to the instance(s).
15
+ # @option options [optional, String] :user_data (nil) MIME, Base64-encoded user data.
16
+ # @option options [optional, String] :instance_type (nil) Specifies the instance type.
17
+ # @option options [optional, String] :availability_zone (nil) Specifies the placement constraints (Availability Zones) for launching the instances.
18
+ # @option options [optional, String] :kernel_id (nil) The ID of the kernel with which to launch the instance.
19
+ # @option options [optional, String] :ramdisk_id (nil) The ID of the RAM disk with which to launch the instance. Some kernels require additional drivers at launch. Check the kernel requirements for information on whether you need to specify a RAM disk. To find kernel requirements, go to the Resource Center and search for the kernel ID.
20
+ # @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 => ''},{},...]
21
+ # @option options [optional, Boolean] :monitoring_enabled (false) Enables monitoring for the instance.
22
+ # @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.
23
+ # @option options [optional, Boolean] :disable_api_termination (true) Specifies whether the instance can be terminated using the APIs. You must modify this attribute before you can terminate any "locked" instances from the APIs.
24
+ # @option options [optional, String] :instance_initiated_shutdown_behavior ('stop') Specifies whether the instance's Amazon EBS volumes are stopped or terminated when the instance is shut down. Valid values : 'stop', 'terminate'
53
25
  # @option options [optional, Boolean] :base64_encoded (false)
54
26
  #
55
27
  def run_instances( options = {} )
56
-
57
28
  options = { :image_id => "",
58
29
  :min_count => 1,
59
30
  :max_count => 1,
60
- :key_name => nil,
61
- :group_id => [],
62
- :user_data => nil,
63
- :addressing_type => "public",
64
- :instance_type => "m1.small",
65
- :kernel_id => nil,
66
- :availability_zone => nil,
67
31
  :base64_encoded => false }.merge(options)
68
32
 
69
- # Do some validation on the arguments provided
33
+ raise ArgumentError, ":addressing_type has been deprecated." if options[:addressing_type]
34
+ raise ArgumentError, ":group_id has been deprecated." if options[:group_id]
35
+
70
36
  raise ArgumentError, ":image_id must be provided" if options[:image_id].nil? || options[:image_id].empty?
71
37
  raise ArgumentError, ":min_count is not valid" unless options[:min_count].to_i > 0
72
- raise ArgumentError, ":max_count is not valid" unless options[:max_count].to_i > 0
73
- raise ArgumentError, ":addressing_type must be 'direct' or 'public'" unless ["public", "direct"].include?(options[:addressing_type])
74
- raise ArgumentError, ":instance_type must specify a valid instance size" unless ["m1.small", "m1.large", "m1.xlarge", "c1.medium", "c1.xlarge", "m2.2xlarge", "m2.4xlarge"].include?(options[:instance_type])
38
+ raise ArgumentError, ":max_count is not valid or must be >= :min_count" unless options[:max_count].to_i > 0 && options[:max_count].to_i >= options[:min_count].to_i
39
+ raise ArgumentError, ":instance_type must specify a valid instance size" unless options[:instance_type].nil? || ["m1.small", "m1.large", "m1.xlarge", "c1.medium", "c1.xlarge", "m2.2xlarge", "m2.4xlarge"].include?(options[:instance_type])
40
+ raise ArgumentError, ":monitoring_enabled must be 'true' or 'false'" unless options[:monitoring_enabled].nil? || [true, false].include?(options[:monitoring_enabled])
41
+ raise ArgumentError, ":disable_api_termination must be 'true' or 'false'" unless options[:disable_api_termination].nil? || [true, false].include?(options[:disable_api_termination])
42
+ raise ArgumentError, ":instance_initiated_shutdown_behavior must be 'stop' or 'terminate'" unless options[:instance_initiated_shutdown_behavior].nil? || ["stop", "terminate"].include?(options[:instance_initiated_shutdown_behavior])
75
43
  raise ArgumentError, ":base64_encoded must be 'true' or 'false'" unless [true, false].include?(options[:base64_encoded])
76
44
 
77
45
  user_data = extract_user_data(options)
78
46
 
79
- params = {
80
- "ImageId" => options[:image_id],
81
- "MinCount" => options[:min_count].to_s,
82
- "MaxCount" => options[:max_count].to_s,
83
- }.merge(pathlist("SecurityGroup", options[:group_id]))
47
+ params = {}
84
48
 
85
- params["KeyName"] = options[:key_name] unless options[:key_name].nil?
86
- params["UserData"] = user_data unless user_data.nil?
87
- params["AddressingType"] = options[:addressing_type]
88
- params["InstanceType"] = options[:instance_type]
89
- params["KernelId"] = options[:kernel_id] unless options[:kernel_id].nil?
90
- params["Placement.AvailabilityZone"] = options[:availability_zone] unless options[:availability_zone].nil?
49
+ if options[:block_device_mapping]
50
+ params.merge!(pathhashlist('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' }))
51
+ end
91
52
 
92
- return response_generator(:action => "RunInstances", :params => params)
53
+ params["ImageId"] = options[:image_id]
54
+ params["MinCount"] = options[:min_count].to_s
55
+ params["MaxCount"] = options[:max_count].to_s
56
+ params["KeyName"] = options[:key_name] unless options[:key_name].nil?
57
+ params["SecurityGroup"] = options[:security_group] unless options[:security_group].nil?
58
+ params["AdditionalInfo"] = options[:additional_info] unless options[:additional_info].nil?
59
+ params["UserData"] = user_data unless user_data.nil?
60
+ params["InstanceType"] = options[:instance_type] unless options[:instance_type].nil?
61
+ params["Placement.AvailabilityZone"] = options[:availability_zone] unless options[:availability_zone].nil?
62
+ params["KernelId"] = options[:kernel_id] unless options[:kernel_id].nil?
63
+ params["RamdiskId"] = options[:ramdisk_id] unless options[:ramdisk_id].nil?
64
+ params["Monitoring.Enabled"] = options[:monitoring_enabled].to_s unless options[:monitoring_enabled].nil?
65
+ params["SubnetId"] = options[:subnet_id] unless options[:subnet_id].nil?
66
+ params["DisableApiTermination"] = options[:disable_api_termination].to_s unless options[:disable_api_termination].nil?
67
+ params["InstanceInitiatedShutdownBehavior"] = options[:instance_initiated_shutdown_behavior] unless options[:instance_initiated_shutdown_behavior].nil?
93
68
 
69
+ return response_generator(:action => "RunInstances", :params => params)
94
70
  end
95
71
 
96
72
  # If :user_data is passed in then URL escape and Base64 encode it
@@ -122,13 +98,65 @@ module AWS
122
98
  # @option options [Array] :instance_id ([])
123
99
  #
124
100
  def describe_instances( options = {} )
125
-
126
101
  options = { :instance_id => [] }.merge(options)
127
-
128
102
  params = pathlist("InstanceId", options[:instance_id])
129
-
130
103
  return response_generator(:action => "DescribeInstances", :params => params)
104
+ end
131
105
 
106
+
107
+ # Not yet implemented
108
+ #
109
+ # @todo Implement this method
110
+ #
111
+ def describe_instance_attribute( options = {} )
112
+ raise "Not yet implemented"
113
+ end
114
+
115
+
116
+ # Not yet implemented
117
+ #
118
+ # @todo Implement this method
119
+ #
120
+ def modify_instance_attribute( options = {} )
121
+ raise "Not yet implemented"
122
+ end
123
+
124
+
125
+ # Not yet implemented
126
+ #
127
+ # @todo Implement this method
128
+ #
129
+ def reset_instance_attribute( options = {} )
130
+ raise "Not yet implemented"
131
+ end
132
+
133
+
134
+ # Starts an instance that uses an Amazon EBS volume as its root device.
135
+ #
136
+ # @option options [Array] :instance_id ([]) Array of unique instance ID's of stopped instances.
137
+ #
138
+ def start_instances( options = {} )
139
+ options = { :instance_id => [] }.merge(options)
140
+ raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
141
+ params = {}
142
+ params.merge!(pathlist("InstanceId", options[:instance_id]))
143
+ return response_generator(:action => "StartInstances", :params => params)
144
+ end
145
+
146
+
147
+ # Stops an instance that uses an Amazon EBS volume as its root device.
148
+ #
149
+ # @option options [Array] :instance_id ([]) Unique instance ID of a running instance.
150
+ # @option options [optional, Boolean] :force (false) Forces the instance to stop. The instance will not have an opportunity to flush file system caches nor file system meta data. If you use this option, you must perform file system check and repair procedures. This option is not recommended for Windows instances.
151
+ #
152
+ def stop_instances( options = {} )
153
+ options = { :instance_id => [] }.merge(options)
154
+ raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
155
+ raise ArgumentError, ":force must be 'true' or 'false'" unless options[:force].nil? || [true, false].include?(options[:force])
156
+ params = {}
157
+ params.merge!(pathlist("InstanceId", options[:instance_id]))
158
+ params["Force"] = options[:force].to_s unless options[:force].nil?
159
+ return response_generator(:action => "StopInstances", :params => params)
132
160
  end
133
161
 
134
162
 
@@ -139,16 +167,10 @@ module AWS
139
167
  # @option options [Array] :instance_id ([])
140
168
  #
141
169
  def reboot_instances( options = {} )
142
-
143
- # defaults
144
170
  options = { :instance_id => [] }.merge(options)
145
-
146
171
  raise ArgumentError, "No instance IDs provided" if options[:instance_id].nil? || options[:instance_id].empty?
147
-
148
172
  params = pathlist("InstanceId", options[:instance_id])
149
-
150
173
  return response_generator(:action => "RebootInstances", :params => params)
151
-
152
174
  end
153
175
 
154
176
 
@@ -160,15 +182,10 @@ module AWS
160
182
  # @option options [Array] :instance_id ([])
161
183
  #
162
184
  def terminate_instances( options = {} )
163
-
164
185
  options = { :instance_id => [] }.merge(options)
165
-
166
186
  raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
167
-
168
187
  params = pathlist("InstanceId", options[:instance_id])
169
-
170
188
  return response_generator(:action => "TerminateInstances", :params => params)
171
-
172
189
  end
173
190
 
174
191
 
@@ -177,37 +194,53 @@ module AWS
177
194
  # @option options [Array] :instance_id ([])
178
195
  #
179
196
  def monitor_instances( options = {} )
180
-
181
197
  options = { :instance_id => [] }.merge(options)
182
-
183
198
  raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
184
-
185
199
  params = pathlist("InstanceId", options[:instance_id])
186
-
187
200
  return response_generator(:action => "MonitorInstances", :params => params)
188
-
189
201
  end
190
202
 
191
203
 
192
-
193
204
  # The UnmonitorInstances operation tells Cloudwatch to stop logging metrics from one or more EC2 instances
194
205
  #
195
206
  # @option options [Array] :instance_id ([])
196
207
  #
197
208
  def unmonitor_instances( options = {} )
198
-
199
209
  options = { :instance_id => [] }.merge(options)
200
-
201
210
  raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
202
-
203
211
  params = pathlist("InstanceId", options[:instance_id])
204
-
205
212
  return response_generator(:action => "UnmonitorInstances", :params => params)
213
+ end
206
214
 
215
+
216
+ # Not yet implemented
217
+ #
218
+ # @todo Implement this method
219
+ #
220
+ def describe_reserved_instances( options = {} )
221
+ raise "Not yet implemented"
222
+ end
223
+
224
+
225
+ # Not yet implemented
226
+ #
227
+ # @todo Implement this method
228
+ #
229
+ def describe_reserved_instances_offerings( options = {} )
230
+ raise "Not yet implemented"
207
231
  end
208
232
 
209
- end
210
233
 
234
+ # Not yet implemented
235
+ #
236
+ # @todo Implement this method
237
+ #
238
+ def purchase_reserved_instances_offering( options = {} )
239
+ raise "Not yet implemented"
240
+ end
241
+
242
+
243
+ end
211
244
  end
212
245
  end
213
246