awsum 0.5
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.
- data/.autotest +1 -0
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +44 -0
- data/LICENSE +19 -0
- data/README.rdoc +42 -0
- data/Rakefile +75 -0
- data/awsum.gemspec +199 -0
- data/lib/awsum.rb +20 -0
- data/lib/awsum/ec2.rb +741 -0
- data/lib/awsum/ec2/address.rb +67 -0
- data/lib/awsum/ec2/availability_zone.rb +16 -0
- data/lib/awsum/ec2/image.rb +62 -0
- data/lib/awsum/ec2/instance.rb +57 -0
- data/lib/awsum/ec2/keypair.rb +16 -0
- data/lib/awsum/ec2/parsers/address_parser.rb +61 -0
- data/lib/awsum/ec2/parsers/availability_zone_parser.rb +57 -0
- data/lib/awsum/ec2/parsers/image_parser.rb +74 -0
- data/lib/awsum/ec2/parsers/instance_parser.rb +90 -0
- data/lib/awsum/ec2/parsers/keypair_parser.rb +64 -0
- data/lib/awsum/ec2/parsers/purchase_reserved_instances_offering_parser.rb +34 -0
- data/lib/awsum/ec2/parsers/region_parser.rb +56 -0
- data/lib/awsum/ec2/parsers/register_image_parser.rb +34 -0
- data/lib/awsum/ec2/parsers/reserved_instance_parser.rb +64 -0
- data/lib/awsum/ec2/parsers/reserved_instances_offering_parser.rb +63 -0
- data/lib/awsum/ec2/parsers/security_group_parser.rb +106 -0
- data/lib/awsum/ec2/parsers/snapshot_parser.rb +64 -0
- data/lib/awsum/ec2/parsers/volume_parser.rb +77 -0
- data/lib/awsum/ec2/region.rb +54 -0
- data/lib/awsum/ec2/reserved_instance.rb +24 -0
- data/lib/awsum/ec2/reserved_instances_offering.rb +20 -0
- data/lib/awsum/ec2/security_group.rb +74 -0
- data/lib/awsum/ec2/snapshot.rb +23 -0
- data/lib/awsum/ec2/volume.rb +65 -0
- data/lib/awsum/error.rb +53 -0
- data/lib/awsum/net_fix.rb +100 -0
- data/lib/awsum/parser.rb +18 -0
- data/lib/awsum/requestable.rb +216 -0
- data/lib/awsum/s3.rb +220 -0
- data/lib/awsum/s3/bucket.rb +28 -0
- data/lib/awsum/s3/headers.rb +24 -0
- data/lib/awsum/s3/object.rb +138 -0
- data/lib/awsum/s3/parsers/bucket_parser.rb +43 -0
- data/lib/awsum/support.rb +94 -0
- data/spec/fixtures/ec2/addresses.xml +10 -0
- data/spec/fixtures/ec2/allocate_address.xml +5 -0
- data/spec/fixtures/ec2/associate_address.xml +5 -0
- data/spec/fixtures/ec2/attach_volume.xml +9 -0
- data/spec/fixtures/ec2/authorize_ip_access.xml +5 -0
- data/spec/fixtures/ec2/authorize_owner_group_access.xml +5 -0
- data/spec/fixtures/ec2/authorize_owner_group_access_error.xml +2 -0
- data/spec/fixtures/ec2/availability_zones.xml +16 -0
- data/spec/fixtures/ec2/available_volume.xml +14 -0
- data/spec/fixtures/ec2/create_key_pair.xml +29 -0
- data/spec/fixtures/ec2/create_security_group.xml +5 -0
- data/spec/fixtures/ec2/create_snapshot.xml +9 -0
- data/spec/fixtures/ec2/create_volume.xml +10 -0
- data/spec/fixtures/ec2/delete_key_pair.xml +5 -0
- data/spec/fixtures/ec2/delete_security_group.xml +5 -0
- data/spec/fixtures/ec2/delete_snapshot.xml +5 -0
- data/spec/fixtures/ec2/delete_volume.xml +5 -0
- data/spec/fixtures/ec2/deregister_image.xml +5 -0
- data/spec/fixtures/ec2/detach_volume.xml +9 -0
- data/spec/fixtures/ec2/disassociate_address.xml +5 -0
- data/spec/fixtures/ec2/image.xml +15 -0
- data/spec/fixtures/ec2/images.xml +77 -0
- data/spec/fixtures/ec2/instance.xml +36 -0
- data/spec/fixtures/ec2/instances.xml +88 -0
- data/spec/fixtures/ec2/internal_error.xml +2 -0
- data/spec/fixtures/ec2/invalid_amiid_error.xml +2 -0
- data/spec/fixtures/ec2/invalid_request_error.xml +2 -0
- data/spec/fixtures/ec2/key_pairs.xml +10 -0
- data/spec/fixtures/ec2/purchase_reserved_instances_offering.xml +5 -0
- data/spec/fixtures/ec2/purchase_reserved_instances_offerings.xml +6 -0
- data/spec/fixtures/ec2/regions.xml +14 -0
- data/spec/fixtures/ec2/register_image.xml +5 -0
- data/spec/fixtures/ec2/release_address.xml +5 -0
- data/spec/fixtures/ec2/reserved_instances.xml +18 -0
- data/spec/fixtures/ec2/reserved_instances_offering.xml +15 -0
- data/spec/fixtures/ec2/reserved_instances_offerings.xml +276 -0
- data/spec/fixtures/ec2/revoke_ip_access.xml +5 -0
- data/spec/fixtures/ec2/revoke_owner_group_access.xml +5 -0
- data/spec/fixtures/ec2/run_instances.xml +30 -0
- data/spec/fixtures/ec2/security_groups.xml +159 -0
- data/spec/fixtures/ec2/snapshots.xml +13 -0
- data/spec/fixtures/ec2/terminate_instances.xml +17 -0
- data/spec/fixtures/ec2/unassociated_address.xml +10 -0
- data/spec/fixtures/ec2/volumes.xml +23 -0
- data/spec/fixtures/errors/invalid_parameter_value.xml +2 -0
- data/spec/fixtures/s3/buckets.xml +2 -0
- data/spec/fixtures/s3/copy_failure.xml +23 -0
- data/spec/fixtures/s3/invalid_request_signature.xml +5 -0
- data/spec/fixtures/s3/keys.xml +2 -0
- data/spec/lib/awsum/ec2/address_spec.rb +149 -0
- data/spec/lib/awsum/ec2/availability_zones_spec.rb +21 -0
- data/spec/lib/awsum/ec2/image_spec.rb +92 -0
- data/spec/lib/awsum/ec2/instance_spec.rb +125 -0
- data/spec/lib/awsum/ec2/keypair_spec.rb +55 -0
- data/spec/lib/awsum/ec2/parsers/address_parser_spec.rb +51 -0
- data/spec/lib/awsum/ec2/parsers/availability_zone_parser_spec.rb +28 -0
- data/spec/lib/awsum/ec2/parsers/image_parser_spec.rb +66 -0
- data/spec/lib/awsum/ec2/parsers/instance_parser_spec.rb +75 -0
- data/spec/lib/awsum/ec2/parsers/keypair_parser_spec.rb +74 -0
- data/spec/lib/awsum/ec2/parsers/purchase_reserved_instances_offering_parser_spec.rb +14 -0
- data/spec/lib/awsum/ec2/parsers/region_parser_spec.rb +27 -0
- data/spec/lib/awsum/ec2/parsers/register_image_parser_spec.rb +15 -0
- data/spec/lib/awsum/ec2/parsers/reserved_instance_parser_spec.rb +35 -0
- data/spec/lib/awsum/ec2/parsers/reserved_instances_offering_parser_spec.rb +32 -0
- data/spec/lib/awsum/ec2/parsers/security_group_parser_spec.rb +78 -0
- data/spec/lib/awsum/ec2/parsers/snapshot_parser_spec.rb +30 -0
- data/spec/lib/awsum/ec2/parsers/volume_parser_spec.rb +35 -0
- data/spec/lib/awsum/ec2/region_spec.rb +73 -0
- data/spec/lib/awsum/ec2/reserved_instance_spec.rb +61 -0
- data/spec/lib/awsum/ec2/reserved_instances_offering_spec.rb +33 -0
- data/spec/lib/awsum/ec2/security_group_spec.rb +179 -0
- data/spec/lib/awsum/ec2/snapshots_spec.rb +69 -0
- data/spec/lib/awsum/ec2/volume_spec.rb +107 -0
- data/spec/lib/awsum/ec2_spec.rb +6 -0
- data/spec/lib/awsum/error_spec.rb +31 -0
- data/spec/lib/awsum/requestable_spec.rb +126 -0
- data/spec/lib/awsum/s3/bucket_spec.rb +95 -0
- data/spec/lib/awsum/s3/object_spec.rb +128 -0
- data/spec/lib/awsum/s3/parsers/bucket_parser_spec.rb +41 -0
- data/spec/lib/awsum/s3/parsers/object_parser_spec.rb +41 -0
- data/spec/spec_helper.rb +16 -0
- metadata +240 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'awsum/ec2/parsers/address_parser'
|
|
2
|
+
|
|
3
|
+
module Awsum
|
|
4
|
+
class Ec2
|
|
5
|
+
class Address
|
|
6
|
+
attr_reader :public_ip, :instance_id
|
|
7
|
+
|
|
8
|
+
def initialize(ec2, public_ip, instance_id) #:nodoc:
|
|
9
|
+
@ec2 = ec2
|
|
10
|
+
@public_ip = public_ip
|
|
11
|
+
@instance_id = instance_id
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Get the Instance associated with this address.
|
|
15
|
+
#
|
|
16
|
+
# Returns nil if no instance is associated.
|
|
17
|
+
def instance
|
|
18
|
+
@ec2.instance(@instance_id) if @instance_id
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Will associate this address with an instance
|
|
22
|
+
#
|
|
23
|
+
# Raises an error if the address is already associated with an instance
|
|
24
|
+
def associate(instance_id)
|
|
25
|
+
if @instance_id.nil?
|
|
26
|
+
@ec2.associate_address instance_id, @public_ip
|
|
27
|
+
else
|
|
28
|
+
raise 'Cannot associate with an already associated instance' #FIXME: Write a better Awsum error here'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Will associate this address with an instance (even if it is already associated with another instance)
|
|
33
|
+
def associate!(instance_id)
|
|
34
|
+
@ec2.associate_address instance_id, @public_ip
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Will disassociate this address from it's instance
|
|
38
|
+
#
|
|
39
|
+
# Raises an error if the address is not associated with an instance
|
|
40
|
+
def disassociate
|
|
41
|
+
if @instance_id.nil?
|
|
42
|
+
raise 'Not associated' #FIXME: Write a better Awsum error here'
|
|
43
|
+
else
|
|
44
|
+
result = @ec2.disassociate_address @public_ip
|
|
45
|
+
@instance_id = nil
|
|
46
|
+
result
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Will release this address
|
|
51
|
+
#
|
|
52
|
+
# Raises an error if the address is associated with an instance
|
|
53
|
+
def release
|
|
54
|
+
if @instance_id.nil?
|
|
55
|
+
@ec2.release_address @public_ip
|
|
56
|
+
else
|
|
57
|
+
raise 'Associated with an instance' #FIXME: Write a better Awsum error here'
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Will release this address regardless of whether it is associated with an instance or not.
|
|
62
|
+
def release!
|
|
63
|
+
@ec2.release_address! @public_ip
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'awsum/ec2/parsers/availability_zone_parser'
|
|
2
|
+
|
|
3
|
+
module Awsum
|
|
4
|
+
class Ec2
|
|
5
|
+
class AvailabilityZone
|
|
6
|
+
attr_reader :name, :state, :region_name
|
|
7
|
+
|
|
8
|
+
def initialize(ec2, name, state, region_name) #:nodoc:
|
|
9
|
+
@ec2 = ec2
|
|
10
|
+
@name = name
|
|
11
|
+
@state = state
|
|
12
|
+
@region_name = region_name
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'awsum/ec2/parsers/image_parser.rb'
|
|
2
|
+
require 'awsum/ec2/parsers/register_image_parser.rb'
|
|
3
|
+
|
|
4
|
+
module Awsum
|
|
5
|
+
class Ec2
|
|
6
|
+
class Image
|
|
7
|
+
attr_reader :id, :location, :state, :owner, :public, :architecture, :type, :kernel_id, :ramdisk_id, :platform, :product_codes
|
|
8
|
+
|
|
9
|
+
def initialize(ec2, id, location, state, owner, public, architecture, type, kernel_id, ram_disk_id, platform, product_codes) #:nodoc:
|
|
10
|
+
@ec2 = ec2
|
|
11
|
+
@id = id
|
|
12
|
+
@location = location
|
|
13
|
+
@state = state
|
|
14
|
+
@owner = owner
|
|
15
|
+
@public = public
|
|
16
|
+
@architecture = architecture
|
|
17
|
+
@type = type
|
|
18
|
+
@kernel_id = kernel_id
|
|
19
|
+
@ramdisk_id = ram_disk_id
|
|
20
|
+
@platform = platform
|
|
21
|
+
@product_codes = product_codes
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def public?
|
|
25
|
+
@public
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Deregister this Image
|
|
29
|
+
def deregister
|
|
30
|
+
@ec2.deregister_image @id
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Reregister this image
|
|
34
|
+
#
|
|
35
|
+
# Will both deregister and then register the Image again
|
|
36
|
+
def reregister
|
|
37
|
+
@ec2.deregister_image @id
|
|
38
|
+
new_id = @ec2.register_image @location
|
|
39
|
+
@id = new_id
|
|
40
|
+
self
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# launches instances of this image
|
|
44
|
+
#
|
|
45
|
+
# ===Options:
|
|
46
|
+
# * <tt>:min</tt> - The minimum number of instances to launch. Default: 1
|
|
47
|
+
# * <tt>:max</tt> - The maximum number of instances to launch. Default: 1
|
|
48
|
+
# * <tt>:key_name</tt> - The name of the key pair with which to launch instances
|
|
49
|
+
# * <tt>:security_groups</tt> - The names of security groups to associate launched instances with
|
|
50
|
+
# * <tt>:user_data</tt> - User data made available to instances (Note: Must be 16K or less, will be base64 encoded by Awsum)
|
|
51
|
+
# * <tt>:instance_type</tt> - The size of the instances to launch, can be one of [m1.small, m1.large, m1.xlarge, c1.medium, c1.xlarge], default is m1.small
|
|
52
|
+
# * <tt>:availability_zone</tt> - The name of the availability zone to launch this instance in
|
|
53
|
+
# * <tt>:kernel_id</tt> - The ID of the kernel with which to launch instances
|
|
54
|
+
# * <tt>:ramdisk_id</tt> - The ID of the RAM disk with which to launch instances
|
|
55
|
+
# * <tt>:block_device_map</tt> - A 'hash' of mappings. E.g. {'instancestore0' => 'sdb'}
|
|
56
|
+
def run(options = {})
|
|
57
|
+
@ec2.run_instances(id, options)
|
|
58
|
+
end
|
|
59
|
+
alias_method :launch, :run
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'awsum/ec2/parsers/instance_parser.rb'
|
|
2
|
+
|
|
3
|
+
module Awsum
|
|
4
|
+
class Ec2
|
|
5
|
+
class Instance
|
|
6
|
+
attr_reader :id, :image_id, :type, :state, :dns_name, :private_dns_name, :key_name, :kernel_id, :launch_time, :availability_zone, :product_codes, :ramdisk_id, :reason, :launch_index
|
|
7
|
+
|
|
8
|
+
def initialize(ec2, id, image_id, type, state, dns_name, private_dns_name, key_name, kernel_id, launch_time, availability_zone, product_codes, ramdisk_id, reason, launch_index) #:nodoc:
|
|
9
|
+
@ec2 = ec2
|
|
10
|
+
@id = id
|
|
11
|
+
@image_id = image_id
|
|
12
|
+
@type = type
|
|
13
|
+
@state = state
|
|
14
|
+
@dns_name = dns_name
|
|
15
|
+
@private_dns_name = private_dns_name
|
|
16
|
+
@key_name = key_name
|
|
17
|
+
@kernel_id = kernel_id
|
|
18
|
+
@launch_time = launch_time
|
|
19
|
+
@availability_zone = availability_zone
|
|
20
|
+
@product_codes = product_codes
|
|
21
|
+
@ramdisk_id = ramdisk_id
|
|
22
|
+
@reason = reason
|
|
23
|
+
@launch_index = launch_index
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Terminates this instance
|
|
27
|
+
def terminate
|
|
28
|
+
@ec2.terminate_instances(id)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Lists all the Volume(s) attached to this Instance
|
|
32
|
+
def volumes
|
|
33
|
+
volumes = @ec2.volumes
|
|
34
|
+
volumes.delete_if {|v| v.instance_id != id}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Will create and attach a Volume to this Instance
|
|
38
|
+
# You must specify a size or a snapshot_id
|
|
39
|
+
def create_volume(size = nil, snapshot_id = nil, device = '/dev/sdh')
|
|
40
|
+
raise ArgumentError.new('You must specify a size if not creating a volume from a snapshot') if size.blank? && snapshot_id.blank?
|
|
41
|
+
raise ArgumentError.new('You must specify a device to attach the volume to') unless device
|
|
42
|
+
|
|
43
|
+
volume = @ec2.create_volume availability_zone, :size => size, :snapshot_id => snapshot_id
|
|
44
|
+
while volume.status != 'available'
|
|
45
|
+
volume.reload
|
|
46
|
+
end
|
|
47
|
+
attach volume, device
|
|
48
|
+
volume
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Will attach a Volume to this Instance
|
|
52
|
+
def attach(volume, device = '/dev/sdh')
|
|
53
|
+
@ec2.attach_volume volume.id, id, device
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'awsum/ec2/parsers/keypair_parser'
|
|
2
|
+
|
|
3
|
+
module Awsum
|
|
4
|
+
class Ec2
|
|
5
|
+
class KeyPair
|
|
6
|
+
attr_reader :name, :fingerprint, :material
|
|
7
|
+
|
|
8
|
+
def initialize(ec2, name, fingerprint, material)
|
|
9
|
+
@ec2 = ec2
|
|
10
|
+
@name = name
|
|
11
|
+
@fingerprint = fingerprint
|
|
12
|
+
@material = material
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module Awsum
|
|
2
|
+
class Ec2
|
|
3
|
+
class AddressParser < Awsum::Parser #:nodoc:
|
|
4
|
+
def initialize(ec2)
|
|
5
|
+
@ec2 = ec2
|
|
6
|
+
@addresses = []
|
|
7
|
+
@text = nil
|
|
8
|
+
@stack = []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def tag_start(tag, attributes)
|
|
12
|
+
#Quick hack so we can use the same parser for AllocateAddress which doesn't use the item tag to wrap the address information
|
|
13
|
+
if tag == 'AllocateAddressResponse'
|
|
14
|
+
@stack << 'addressesSet'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
case tag
|
|
18
|
+
when 'addressesSet'
|
|
19
|
+
@stack << 'addressesSet'
|
|
20
|
+
when 'item', 'AllocateAddressResponse'
|
|
21
|
+
case @stack[-1]
|
|
22
|
+
when 'addressesSet'
|
|
23
|
+
@current = {}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
@text = ''
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def text(text)
|
|
30
|
+
@text << text unless @text.nil?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def tag_end(tag)
|
|
34
|
+
case tag
|
|
35
|
+
when 'DescribeAddressesResponse'
|
|
36
|
+
#no-op
|
|
37
|
+
when 'addressesSet'
|
|
38
|
+
@stack.pop
|
|
39
|
+
when 'item', 'AllocateAddressResponse'
|
|
40
|
+
case @stack[-1]
|
|
41
|
+
when 'addressesSet'
|
|
42
|
+
@addresses << Address.new(
|
|
43
|
+
@ec2,
|
|
44
|
+
@current['publicIp'],
|
|
45
|
+
@current['instanceId']
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
else
|
|
49
|
+
unless @text.nil? || @current.nil?
|
|
50
|
+
text = @text.strip
|
|
51
|
+
@current[tag] = (text == '' ? nil : text)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def result
|
|
57
|
+
@addresses
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module Awsum
|
|
2
|
+
class Ec2
|
|
3
|
+
class AvailabilityZoneParser < Awsum::Parser #:nodoc:
|
|
4
|
+
def initialize(ec2)
|
|
5
|
+
@ec2 = ec2
|
|
6
|
+
@availability_zones = []
|
|
7
|
+
@text = nil
|
|
8
|
+
@stack = []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def tag_start(tag, attributes)
|
|
12
|
+
case tag
|
|
13
|
+
when 'availabilityZoneInfo'
|
|
14
|
+
@stack << 'availabilityZoneInfo'
|
|
15
|
+
when 'item'
|
|
16
|
+
case @stack[-1]
|
|
17
|
+
when 'availabilityZoneInfo'
|
|
18
|
+
@current = {}
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
@text = ''
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def text(text)
|
|
25
|
+
@text << text unless @text.nil?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def tag_end(tag)
|
|
29
|
+
case tag
|
|
30
|
+
when 'DescribeAvailabilityZonesResponse', 'requestId'
|
|
31
|
+
#no-op
|
|
32
|
+
when 'availabilityZoneInfo'
|
|
33
|
+
@stack.pop
|
|
34
|
+
when 'item'
|
|
35
|
+
case @stack[-1]
|
|
36
|
+
when 'availabilityZoneInfo'
|
|
37
|
+
@availability_zones << AvailabilityZone.new(
|
|
38
|
+
@ec2,
|
|
39
|
+
@current['zoneName'],
|
|
40
|
+
@current['zoneState'],
|
|
41
|
+
@current['regionName']
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
else
|
|
45
|
+
unless @text.nil? || @current.nil?
|
|
46
|
+
text = @text.strip
|
|
47
|
+
@current[tag] = (text == '' ? nil : text)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def result
|
|
53
|
+
@availability_zones
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Awsum
|
|
2
|
+
class Ec2
|
|
3
|
+
class ImageParser < Awsum::Parser #:nodoc:
|
|
4
|
+
def initialize(ec2)
|
|
5
|
+
@ec2 = ec2
|
|
6
|
+
@images = []
|
|
7
|
+
@text = nil
|
|
8
|
+
@stack = []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def tag_start(tag, attributes)
|
|
12
|
+
case tag
|
|
13
|
+
when 'imagesSet'
|
|
14
|
+
@stack << 'imagesSet'
|
|
15
|
+
when 'item'
|
|
16
|
+
case @stack[-1]
|
|
17
|
+
when 'imagesSet'
|
|
18
|
+
@current = {}
|
|
19
|
+
@text = ''
|
|
20
|
+
when 'productCodes'
|
|
21
|
+
@product_codes = []
|
|
22
|
+
@text = ''
|
|
23
|
+
end
|
|
24
|
+
when 'productCodes'
|
|
25
|
+
@stack << 'productCodes'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def text(text)
|
|
30
|
+
@text << text unless @text.nil?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def tag_end(tag)
|
|
34
|
+
case tag
|
|
35
|
+
when 'DescribeImagesResponse', 'requestId'
|
|
36
|
+
#no-op
|
|
37
|
+
when 'imagesSet', 'productCodes'
|
|
38
|
+
@stack.pop
|
|
39
|
+
when 'item'
|
|
40
|
+
case @stack[-1]
|
|
41
|
+
when 'imagesSet'
|
|
42
|
+
@images << Image.new(
|
|
43
|
+
@ec2,
|
|
44
|
+
@current['imageId'],
|
|
45
|
+
@current['imageLocation'],
|
|
46
|
+
@current['imageState'],
|
|
47
|
+
@current['imageOwnerId'],
|
|
48
|
+
@current['isPublic'] == 'true',
|
|
49
|
+
@current['architecture'],
|
|
50
|
+
@current['imageType'],
|
|
51
|
+
@current['kernelId'],
|
|
52
|
+
@current['ramdiskId'],
|
|
53
|
+
@current['platform'],
|
|
54
|
+
@product_codes || []
|
|
55
|
+
)
|
|
56
|
+
@text = ''
|
|
57
|
+
end
|
|
58
|
+
when 'productCode'
|
|
59
|
+
@product_codes << @text.strip
|
|
60
|
+
else
|
|
61
|
+
unless @text.nil?
|
|
62
|
+
text = @text.strip
|
|
63
|
+
@current[tag] = (text == '' ? nil : text)
|
|
64
|
+
@text = ''
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def result
|
|
70
|
+
@images
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
module Awsum
|
|
2
|
+
class Ec2
|
|
3
|
+
class InstanceParser < Awsum::Parser #:nodoc:
|
|
4
|
+
def initialize(ec2)
|
|
5
|
+
@ec2 = ec2
|
|
6
|
+
@instances = []
|
|
7
|
+
@text = nil
|
|
8
|
+
@stack = []
|
|
9
|
+
@placement = nil
|
|
10
|
+
@state = nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def tag_start(tag, attributes)
|
|
14
|
+
case tag
|
|
15
|
+
when 'reservationSet'
|
|
16
|
+
@stack << 'reservationSet'
|
|
17
|
+
when 'instancesSet'
|
|
18
|
+
@stack << 'instancesSet'
|
|
19
|
+
when 'productCodes'
|
|
20
|
+
@stack << 'productCodes'
|
|
21
|
+
when 'instanceState'
|
|
22
|
+
@stack << 'instanceState'
|
|
23
|
+
when 'placement'
|
|
24
|
+
@stack << 'placement'
|
|
25
|
+
when 'item'
|
|
26
|
+
case @stack[-1]
|
|
27
|
+
when 'reservationSet'
|
|
28
|
+
when 'instancesSet'
|
|
29
|
+
@current = {}
|
|
30
|
+
@state = {}
|
|
31
|
+
when 'productCodes'
|
|
32
|
+
@product_codes = []
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
@text = ''
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def text(text)
|
|
39
|
+
@text << text unless @text.nil?
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def tag_end(tag)
|
|
43
|
+
case tag
|
|
44
|
+
when 'DescribeInstancesResponse', 'requestId', 'reservationId'
|
|
45
|
+
#no-op
|
|
46
|
+
when 'reservationSet', 'instancesSet', 'productCodes', 'instanceState', 'placement'
|
|
47
|
+
@stack.pop
|
|
48
|
+
when 'item'
|
|
49
|
+
case @stack[-1]
|
|
50
|
+
when 'instancesSet'
|
|
51
|
+
@instances << Instance.new(
|
|
52
|
+
@ec2,
|
|
53
|
+
@current['instanceId'],
|
|
54
|
+
@current['imageId'],
|
|
55
|
+
@current['instanceType'],
|
|
56
|
+
@state,
|
|
57
|
+
@current['dnsName'],
|
|
58
|
+
@current['privateDnsName'],
|
|
59
|
+
@current['keyName'],
|
|
60
|
+
@current['kernalId'],
|
|
61
|
+
Time.parse(@current['launchTime']),
|
|
62
|
+
@placement,
|
|
63
|
+
@product_codes || [],
|
|
64
|
+
@current['ramdisk_id'],
|
|
65
|
+
@current['reason'],
|
|
66
|
+
@current['amiLaunchIndex'].to_i
|
|
67
|
+
)
|
|
68
|
+
end
|
|
69
|
+
when 'productCode'
|
|
70
|
+
@product_codes << @text.strip
|
|
71
|
+
when 'availabilityZone'
|
|
72
|
+
@placement = @text.strip
|
|
73
|
+
when 'code'
|
|
74
|
+
@state[:code] = @text.strip.to_i if @stack[-1] == 'instanceState'
|
|
75
|
+
when 'name'
|
|
76
|
+
@state[:name] = @text.strip if @stack[-1] == 'instanceState'
|
|
77
|
+
else
|
|
78
|
+
unless @text.nil? || @current.nil?
|
|
79
|
+
text = @text.strip
|
|
80
|
+
@current[tag] = (text == '' ? nil : text)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def result
|
|
86
|
+
@instances
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|