Class: Rivet::Ec2
- Inherits:
-
Object
- Object
- Rivet::Ec2
- Defined in:
- lib/rivet/ec2/ec2.rb
Constant Summary collapse
- OPTIONS =
[ :associate_public_ip_address, :availability_zone, :block_device_mappings, :count, :dedicated_tenancy, :disable_api_termination, :ebs_optimized, :elastic_ips, :iam_instance_profile, :image_id, :instance_initiated_shutdown_behavior, :instance_type, :kernel_id, :key_name, :key_pair, :monitoring_enabled, :network_interfaces, :placement_group, :private_ip_address, :ramdisk_id, :security_group_ids, :security_groups, :subnet, :tags, :user_data ].each { |a| attr_reader a }
- REQUIRED_OPTIONS =
[ :image_id ]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #display(level = 'info') ⇒ Object
-
#initialize(config) ⇒ Ec2
constructor
A new instance of Ec2.
- #options ⇒ Object
- #sync ⇒ Object
Constructor Details
#initialize(config) ⇒ Ec2
Returns a new instance of Ec2.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rivet/ec2/ec2.rb', line 39 def initialize(config) @ec2 = AWS::EC2.new @name = config.name @user_data = Bootstrap.new(config).user_data OPTIONS.each do |o| if config.respond_to?(o) instance_variable_set("@#{o}", config.send(o)) end end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
37 38 39 |
# File 'lib/rivet/ec2/ec2.rb', line 37 def name @name end |
Instance Method Details
#display(level = 'info') ⇒ Object
51 52 53 54 55 |
# File 'lib/rivet/ec2/ec2.rb', line 51 def display(level = 'info') .each_pair do |attr, values| Rivet::Log.write(level, " #{attr}: #{values}") end end |
#options ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rivet/ec2/ec2.rb', line 57 def = {} OPTIONS.each do |field| local_value = self.send(field) [field] = local_value unless local_value.nil? end REQUIRED_OPTIONS.each do |field| unless .has_key? field [field] = self.send(field) end end end |
#sync ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rivet/ec2/ec2.rb', line 73 def sync # The AWS ruby SDK forces you to apply tags AFTER creation # This option must be removed so the create call doesn't blow up. = = .delete :tags eips_to_add = .delete :elastic_ips enis_to_add = .delete :network_interfaces instances = @ec2.instances.create # Since create returns either an instance object or an array let us # just go ahead and make that more sane instances = [instances] unless instances.respond_to? :each (instances,) ready_instances = wait_until_running instances add_eips(ready_instances,eips_to_add) if eips_to_add add_network_interfaces(ready_instances,enis_to_add) if enis_to_add end |