amazon-ec2 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,44 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:glenn@elasticworkbench.com)
6
+ # Copyright:: Copyright (c) 2007 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://amazon-ec2.rubyforge.org
9
+ #++
10
+
11
+ module EC2
12
+
13
+ class Base
14
+
15
+ #Amazon Developer Guide Docs:
16
+ #
17
+ # The GetConsoleOutput operation retrieves console output that has been posted for the specified instance.
18
+ #
19
+ # Instance console output is buffered and posted shortly after instance boot, reboot and once the instance
20
+ # is terminated. Only the most recent 64 KB of posted output is available. Console output is available for
21
+ # at least 1 hour after the most recent post.
22
+ #
23
+ #Required Arguments:
24
+ #
25
+ # :instance_id => String (default : "")
26
+ #
27
+ #Optional Arguments:
28
+ #
29
+ # none
30
+ #
31
+ def get_console_output( options ={} )
32
+
33
+ options = {:instance_id => ""}.merge(options)
34
+
35
+ raise ArgumentError, "No instance ID provided" if options[:instance_id].nil? || options[:instance_id].empty?
36
+
37
+ params = { "InstanceId" => options[:instance_id] }
38
+
39
+ return response_generator(:action => "GetConsoleOutput", :params => params)
40
+
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,136 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:glenn@elasticworkbench.com)
6
+ # Copyright:: Copyright (c) 2007 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://amazon-ec2.rubyforge.org
9
+ #++
10
+
11
+ module EC2
12
+
13
+ # OUR CUSTOM ERROR CODES
14
+
15
+ # All of our errors are superclassed by Error < RuntimeError
16
+ class Error < RuntimeError #:nodoc:
17
+ end
18
+
19
+ # A client side only argument error
20
+ class ArgumentError < Error #:nodoc:
21
+ end
22
+
23
+
24
+ # AWS EC2 CLIENT ERROR CODES
25
+
26
+ # AWS EC2 can throw error exceptions that contain a '.' in them.
27
+ # since we can't name an exception class with that '.' I compressed
28
+ # each class name into the non-dot version. This allows us to retain
29
+ # the granularity of the exception.
30
+
31
+ # User not authorized.
32
+ class AuthFailure < Error #:nodoc:
33
+ end
34
+
35
+ # Specified AMI has an unparsable manifest.
36
+ class InvalidManifest < Error #:nodoc:
37
+ end
38
+
39
+ # Specified AMI ID is not valid.
40
+ class InvalidAMIIDMalformed < Error #:nodoc:
41
+ end
42
+
43
+ # Specified AMI ID does not exist.
44
+ class InvalidAMIIDNotFound < Error #:nodoc:
45
+ end
46
+
47
+ # Specified AMI ID has been deregistered and is no longer available.
48
+ class InvalidAMIIDUnavailable < Error #:nodoc:
49
+ end
50
+
51
+ # Specified instance ID is not valid.
52
+ class InvalidInstanceIDMalformed < Error #:nodoc:
53
+ end
54
+
55
+ # Specified instance ID does not exist.
56
+ class InvalidInstanceIDNotFound < Error #:nodoc:
57
+ end
58
+
59
+ # Specified keypair name does not exist.
60
+ class InvalidKeyPairNotFound < Error #:nodoc:
61
+ end
62
+
63
+ # Attempt to create a duplicate keypair.
64
+ class InvalidKeyPairDuplicate < Error #:nodoc:
65
+ end
66
+
67
+ # Specified group name does not exist.
68
+ class InvalidGroupNotFound < Error #:nodoc:
69
+ end
70
+
71
+ # Attempt to create a duplicate group.
72
+ class InvalidGroupDuplicate < Error #:nodoc:
73
+ end
74
+
75
+ # Specified group can not be deleted because it is in use.
76
+ class InvalidGroupInUse < Error #:nodoc:
77
+ end
78
+
79
+ # Specified group name is a reserved name.
80
+ class InvalidGroupReserved < Error #:nodoc:
81
+ end
82
+
83
+ # Attempt to authorize a permission that has already been authorized.
84
+ class InvalidPermissionDuplicate < Error #:nodoc:
85
+ end
86
+
87
+ # Specified permission is invalid.
88
+ class InvalidPermissionMalformed < Error #:nodoc:
89
+ end
90
+
91
+ # Specified reservation ID is invalid.
92
+ class InvalidReservationIDMalformed < Error #:nodoc:
93
+ end
94
+
95
+ # Specified reservation ID does not exist.
96
+ class InvalidReservationIDNotFound < Error #:nodoc:
97
+ end
98
+
99
+ # User has reached max allowed concurrent running instances.
100
+ class InstanceLimitExceeded < Error #:nodoc:
101
+ end
102
+
103
+ # An invalid set of parameters were passed as arguments
104
+ # e.g. RunInstances was called with minCount and maxCount set to 0 or minCount > maxCount.
105
+ class InvalidParameterCombination < Error #:nodoc:
106
+ end
107
+
108
+ # An unknown parameter was passed as an argument
109
+ class UnknownParameter < Error #:nodoc:
110
+ end
111
+
112
+ # The user ID is neither in the form of an AWS account ID or one
113
+ # of the special values accepted by the owner or executableBy flags
114
+ # in the DescribeImages call.
115
+ class InvalidUserIDMalformed < Error #:nodoc:
116
+ end
117
+
118
+ # The value of an item added to, or removed from, an image attribute is invalid.
119
+ class InvalidAMIAttributeItemValue < Error #:nodoc:
120
+ end
121
+
122
+ # AWS EC2 SERVER ERROR CODES
123
+
124
+ # Internal AWS EC2 Error.
125
+ class InternalError < Error #:nodoc:
126
+ end
127
+
128
+ # There are not enough available instances to satify your minimum request.
129
+ class InsufficientInstanceCapacity < Error #:nodoc:
130
+ end
131
+
132
+ # The server is overloaded and cannot handle request.
133
+ class Unavailable < Error #:nodoc:
134
+ end
135
+
136
+ end
@@ -1,45 +1,153 @@
1
- # Amazon Web Services EC2 Query API Ruby Library
2
- # This library has been packaged as a Ruby Gem
3
- # by Glenn Rempe ( grempe @nospam@ rubyforge.org ).
4
- #
5
- # Source code and gem hosted on RubyForge
6
- # under the Ruby License as of 12/14/2006:
7
- # http://amazon-ec2.rubyforge.org
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:glenn@elasticworkbench.com)
6
+ # Copyright:: Copyright (c) 2007 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://amazon-ec2.rubyforge.org
9
+ #++
8
10
 
9
11
  module EC2
10
12
 
11
- class AWSAuthConnection
13
+ class Base
12
14
 
13
- # The ModifyImageAttribute operation modifies an attribute of an AMI.
14
- #
15
- # Currently the only attribute supported is launchPermission. By
16
- # modifying this attribute it is possible to make an AMI public or
17
- # to grant specific users launch permissions for the AMI. To make the
18
- # AMI public add the group=all attribute item. To grant launch permissions
19
- # for a specific user add a userId=<userid> attribute item.
20
- def modify_image_attribute(imageId, attribute, operationType, attributeValueHash)
15
+ #Amazon Developer Guide Docs:
16
+ #
17
+ # The ModifyImageAttribute operation modifies an attribute of an AMI.
18
+ # Currently the only attribute supported is launchPermission. By modifying this attribute it is possible to
19
+ # make an AMI public or to grant specific users launch permissions for the AMI. To make the AMI public
20
+ # add the group=all attribute item. To grant launch permissions for a specific user add a
21
+ # userId=<userid> attribute item.
22
+ #
23
+ #Required Arguments:
24
+ #
25
+ # :image_id => String (default : "")
26
+ # :attribute => String (default : "launchPermission")
27
+ # :operation_type => String (default : "add")
28
+ #
29
+ #Optional Arguments:
30
+ #
31
+ # :user_id => Array (default : [])
32
+ # :group => Array (default : [])
33
+ #
34
+ def modify_image_attribute( options = {} )
35
+
36
+ # defaults
37
+ options = { :image_id => "",
38
+ :attribute => "launchPermission",
39
+ :operation_type => "add",
40
+ :user_id => [],
41
+ :group => [] }.merge(options)
42
+
43
+ raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
44
+ raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
45
+ raise ArgumentError, "No ':operation_type' provided" if options[:operation_type].nil? || options[:operation_type].empty?
46
+
21
47
  params = {
22
- "ImageId" => imageId,
23
- "Attribute" => attribute,
24
- "OperationType" => operationType
48
+ "ImageId" => options[:image_id],
49
+ "Attribute" => options[:attribute],
50
+ "OperationType" => options[:operation_type]
25
51
  }
26
- if attribute == "launchPermission"
27
- params.merge!(pathlist("UserGroup", attributeValueHash[:userGroups])) if attributeValueHash.has_key? :userGroups
28
- params.merge!(pathlist("UserId", attributeValueHash[:userIds])) if attributeValueHash.has_key? :userIds
52
+
53
+ # test options provided and make sure they are valid
54
+ case options[:attribute]
55
+ when "launchPermission"
56
+ if (options[:user_id].nil? || options[:user_id].empty?) && (options[:group].nil? || options[:group].empty?)
57
+ raise ArgumentError, "Option :attribute=>'launchPermission' requires ':user_id' or ':group' options to also be specified"
58
+ end
59
+
60
+ params.merge!(pathlist("UserId", options[:user_id])) unless options[:user_id].nil?
61
+ params.merge!(pathlist("Group", options[:group])) unless options[:group].nil?
62
+ else
63
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known option."
64
+ end
65
+
66
+ # test options provided and make sure they are valid
67
+ case options[:operation_type]
68
+ when "add", "remove"
69
+ # these args are ok
70
+ else
71
+ raise ArgumentError, ":operation_type was #{options[:operation_type].to_s} but must be 'add' or 'remove'"
29
72
  end
30
- ModifyImageAttributeResponse.new(make_request("ModifyImageAttribute", params))
73
+
74
+ return response_generator(:action => "ModifyImageAttribute", :params => params)
75
+
31
76
  end
32
77
 
78
+ #Amazon Developer Guide Docs:
79
+ #
33
80
  # The DescribeImageAttribute operation returns information about an attribute of an AMI.
34
- def describe_image_attribute(imageId, attribute)
35
- params = { "ImageId" => imageId, "Attribute" => attribute }
36
- DescribeImageAttributeResponse.new(make_request("DescribeImageAttribute", params))
81
+ #
82
+ #Required Arguments:
83
+ #
84
+ # :image_id => String (default : "")
85
+ # :attribute => String (default : "launchPermission")
86
+ #
87
+ #Optional Arguments:
88
+ #
89
+ # none
90
+ #
91
+ def describe_image_attribute( options = {} )
92
+
93
+ # defaults
94
+ options = {:image_id => "",
95
+ :attribute => "launchPermission"
96
+ }.merge(options)
97
+
98
+ raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
99
+ raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
100
+
101
+ params = { "ImageId" => options[:image_id], "Attribute" => options[:attribute] }
102
+
103
+ # test options provided and make sure they are valid
104
+ case options[:attribute]
105
+ when "launchPermission"
106
+ # these args are ok
107
+ else
108
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known option."
109
+ end
110
+
111
+ return response_generator(:action => "DescribeImageAttribute", :params => params)
112
+
37
113
  end
38
114
 
115
+
116
+ #Amazon Developer Guide Docs:
117
+ #
39
118
  # The ResetImageAttribute operation resets an attribute of an AMI to its default value.
40
- def reset_image_attribute(imageId, attribute)
41
- params = { "ImageId" => imageId, "Attribute" => attribute }
42
- ResetImageAttributeResponse.new(make_request("ResetImageAttribute", params))
119
+ #
120
+ #Required Arguments:
121
+ #
122
+ # :image_id => String (default : "")
123
+ # :attribute => String (default : "launchPermission")
124
+ #
125
+ #Optional Arguments:
126
+ #
127
+ # none
128
+ #
129
+ def reset_image_attribute( options = {} )
130
+
131
+ # defaults
132
+ options = {:image_id => "",
133
+ :attribute => "launchPermission"}.merge(options)
134
+
135
+ raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
136
+ raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
137
+
138
+ params = {"ImageId" => options[:image_id],
139
+ "Attribute" => options[:attribute] }
140
+
141
+ # test options provided and make sure they are valid
142
+ case options[:attribute]
143
+ when "launchPermission"
144
+ # these args are ok
145
+ else
146
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known option."
147
+ end
148
+
149
+ return response_generator(:action => "ResetImageAttribute", :params => params)
150
+
43
151
  end
44
152
 
45
153
  end
data/lib/EC2/images.rb CHANGED
@@ -1,85 +1,132 @@
1
- # Amazon Web Services EC2 Query API Ruby Library
2
- # This library has been packaged as a Ruby Gem
3
- # by Glenn Rempe ( grempe @nospam@ rubyforge.org ).
4
- #
5
- # Source code and gem hosted on RubyForge
6
- # under the Ruby License as of 12/14/2006:
7
- # http://amazon-ec2.rubyforge.org
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:glenn@elasticworkbench.com)
6
+ # Copyright:: Copyright (c) 2007 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://amazon-ec2.rubyforge.org
9
+ #++
8
10
 
9
11
  module EC2
10
12
 
11
- class AWSAuthConnection
13
+ class Base
12
14
 
13
- # The RegisterImage operation registers an AMI with Amazon EC2.
14
- # Images must be registered before they can be launched. Each
15
- # AMI is associated with an unique ID which is provided by the
16
- # EC2 service via the Registerimage operation. As part of the
17
- # registration process, Amazon EC2 will retrieve the specified
18
- # image manifest from Amazon S3 and verify that the image is
19
- # owned by the user requesting image registration. The image
20
- # manifest is retrieved once and stored within the Amazon EC2
21
- # network. Any modifications to an image in Amazon S3 invalidate
22
- # this registration. If you do have to make changes and upload
23
- # a new image deregister the previous image and register the new image.
24
- def register_image(imageLocation)
25
- params = { "ImageLocation" => imageLocation }
26
- RegisterImageResponse.new(make_request("RegisterImage", params))
15
+ #Amazon Developer Guide Docs:
16
+ #
17
+ # The RegisterImage operation registers an AMI with Amazon EC2. Images must be registered before
18
+ # they can be launched. Each AMI is associated with an unique ID which is provided by the EC2
19
+ # service via the Registerimage operation. As part of the registration process, Amazon EC2 will
20
+ # retrieve the specified image manifest from Amazon S3 and verify that the image is owned by the
21
+ # user requesting image registration. The image manifest is retrieved once and stored within the
22
+ # Amazon EC2 network. Any modifications to an image in Amazon S3 invalidate this registration.
23
+ # If you do have to make changes and upload a new image deregister the previous image and register
24
+ # the new image.
25
+ #
26
+ #Required Arguments:
27
+ #
28
+ # :image_location => String (default : "")
29
+ #
30
+ #Optional Arguments:
31
+ #
32
+ # none
33
+ #
34
+ def register_image( options = {} )
35
+
36
+ options = {:image_location => ""}.merge(options)
37
+
38
+ raise ArgumentError, "No :image_location provided" if options[:image_location].nil? || options[:image_location].empty?
39
+
40
+ params = { "ImageLocation" => options[:image_location] }
41
+
42
+ return response_generator(:action => "RegisterImage", :params => params)
43
+
27
44
  end
28
45
 
29
- # The DescribeImages operation returns information about AMIs available
30
- # for use by the user. This includes both public AMIs (those available
31
- # for any user to launch) and private AMIs (those owned by the user
32
- # making the request and those owned by other users that the user
33
- # making the request has explicit launch permissions for).
34
- #
35
- # The list of AMIs returned can be modified via optional lists of AMI IDs,
36
- # owners or users with launch permissions. If all three optional lists
37
- # are empty all AMIs the user has launch permissions for are returned.
38
- # Launch permissions fall into three categories:
39
- #
40
- # Launch Permission Description
41
- # * public The all group has launch permissions for the AMI. All users have
42
- # launch permissions for these AMIs.
43
- # * explicit The owner of the AMIs has granted a specific user launch permissions for the AMI.
44
- # * implicit A user has implicit launch permissions for all AMIs he or she owns.
45
- #
46
- # If one or more of the lists are specified the result set is the intersection
47
- # of AMIs matching the criteria of the individual lists.
48
- #
49
- # Providing the list of AMI IDs requests information for those AMIs only.
50
- # If no AMI IDs are provided, information of all relevant AMIs will be
51
- # returned. If an AMI is specified that does not exist a fault is returned.
52
- # If an AMI is specified that exists but the user making the request does
53
- # not have launch permissions for, then that AMI will not be included in
54
- # the returned results.
55
- #
56
- # Providing the list of owners requests information for AMIs owned
57
- # by the specified owners only. Only AMIs the user has launch permissions
58
- # for are returned. The items of the list may be account ids for AMIs
59
- # owned by users with those account ids, amazon for AMIs owned by Amazon
60
- # or self for AMIs owned by the user making the request.
46
+ #Amazon Developer Guide Docs:
47
+ #
48
+ # The DescribeImages operation returns information about AMIs available for use by the user. This
49
+ # includes both public AMIs (those available for any user to launch) and private AMIs (those owned by
50
+ # the user making the request and those owned by other users that the user making the request has explicit
51
+ # launch permissions for).
52
+ #
53
+ # The list of AMIs returned can be modified via optional lists of AMI IDs, owners or users with launch
54
+ # permissions. If all three optional lists are empty all AMIs the user has launch permissions for are
55
+ # returned. Launch permissions fall into three categories:
56
+ #
57
+ # Launch Permission Description
58
+ #
59
+ # public - The all group has launch permissions for the AMI. All users have launch permissions for these AMIs.
60
+ # explicit - The owner of the AMIs has granted a specific user launch permissions for the AMI.
61
+ # implicit - A user has implicit launch permissions for all AMIs he or she owns.
62
+ #
63
+ # If one or more of the lists are specified the result set is the intersection of AMIs matching the criteria of
64
+ # the individual lists.
65
+ #
66
+ # Providing the list of AMI IDs requests information for those AMIs only. If no AMI IDs are provided,
67
+ # information of all relevant AMIs will be returned. If an AMI is specified that does not exist a fault is
68
+ # returned. If an AMI is specified that exists but the user making the request does not have launch
69
+ # permissions for, then that AMI will not be included in the returned results.
70
+ #
71
+ # Providing the list of owners requests information for AMIs owned by the specified owners only. Only
72
+ # AMIs the user has launch permissions for are returned. The items of the list may be account ids for
73
+ # AMIs owned by users with those account ids, amazon for AMIs owned by Amazon or self for AMIs
74
+ # owned by the user making the request.
61
75
  #
62
- # The executable list may be provided to request information for AMIs
63
- # that only the specified users have launch permissions for. The items of
64
- # the list may be account ids for AMIs owned by the user making the request
65
- # that the users with the specified account ids have explicit launch permissions
66
- # for, self for AMIs the user making the request has explicit launch permissions
67
- # for or all for public AMIs.
68
- #
69
- # Deregistered images will be included in the returned results for an
70
- # unspecified interval subsequent to deregistration.
71
- def describe_images(imageIds=[], owners=[], executableBy=[])
72
- params = pathlist("ImageId", imageIds)
73
- params.merge!(pathlist("Owner", owners))
74
- params.merge!(pathlist("ExecutableBy", executableBy))
75
- DescribeImagesResponse.new(make_request("DescribeImages", params))
76
+ # The executable list may be provided to request information for AMIs that only the specified users have
77
+ # launch permissions for. The items of the list may be account ids for AMIs owned by the user making the
78
+ # request that the users with the specified account ids have explicit launch permissions for, self for AMIs
79
+ # the user making the request has explicit launch permissions for or all for public AMIs.
80
+ #
81
+ # Deregistered images will be included in the returned results for an unspecified interval subsequent to
82
+ # deregistration.
83
+ #
84
+ #Required Arguments:
85
+ #
86
+ # none
87
+ #
88
+ #Optional Arguments:
89
+ #
90
+ # :image_id => Array (default : [])
91
+ # :owner_id => Array (default : [])
92
+ # :executable_by => Array (default : [])
93
+ #
94
+ def describe_images( options = {} )
95
+
96
+ options = { :image_id => [], :owner_id => [], :executable_by => [] }.merge(options)
97
+
98
+ params = pathlist( "ImageId", options[:image_id] )
99
+ params.merge!(pathlist( "Owner", options[:owner_id] ))
100
+ params.merge!(pathlist( "ExecutableBy", options[:executable_by] ))
101
+
102
+ return response_generator(:action => "DescribeImages", :params => params)
103
+
76
104
  end
77
105
 
78
- # The DeregisterImage operation deregisters an AMI. Once deregistered,
79
- # instances of the AMI may no longer be launched.
80
- def deregister_image(imageId)
81
- params = { "ImageId" => imageId }
82
- DeregisterImageResponse.new(make_request("DeregisterImage", params))
106
+ #Amazon Developer Guide Docs:
107
+ #
108
+ # The DeregisterImage operation deregisters an AMI. Once deregistered, instances of the AMI may no
109
+ # longer be launched.
110
+ #
111
+ #Required Arguments:
112
+ #
113
+ # :image_id => String (default : "")
114
+ #
115
+ #Optional Arguments:
116
+ #
117
+ # none
118
+ #
119
+ def deregister_image( options = {} )
120
+
121
+ # defaults
122
+ options = { :image_id => "" }.merge(options)
123
+
124
+ raise ArgumentError, "No :image_id provided" if options[:image_id].nil? || options[:image_id].empty?
125
+
126
+ params = { "ImageId" => options[:image_id] }
127
+
128
+ return response_generator(:action => "DeregisterImage", :params => params)
129
+
83
130
  end
84
131
 
85
132
  end