Sha256: 21f1836ec492e3ccba1179a87ea88075c5863e423940ae3ca43033bf3ab84f4a

Contents?: true

Size: 1.76 KB

Versions: 50

Compression:

Stored size: 1.76 KB

Contents

Standup.script :node do
  def run
    ensure_security_group
      
    open_port 22
      
    ensure_instance
      
    configure_elastic_ip
  end
  
  def open_ports *ports
    ports.map(&:to_s).each do |port|
      rule = Standup::EC2::SecurityGroup::IPRule.new('0.0.0.0/0', 'tcp', port, port)
      group = Standup::EC2::SecurityGroup.list[node.id_group]
      unless group.rules.include? rule
        bright_p "opening port #{port}"
        group.add_rule rule
      end
    end
  end
  alias :open_port :open_ports
  
  protected
  
  def ensure_security_group
    return if Standup::EC2::SecurityGroup.list[node.id_group]
    
    bright_p "creating security group #{node.id_group}"
    Standup::EC2::SecurityGroup.create node.id_group
  end
  
  def ensure_instance
    return if instance
    
    bright_p "launching #{params.instance_type} instance with image #{params.image_id}"
    inst = Standup::EC2::Instance.create params.image_id,
                                         params.instance_type,
                                         [Standup::EC2::SecurityGroup.list[node.id_group]]
    puts "waiting until it's up"
    inst.wait_until {inst.state != :running}
    puts "and a bit more to let it really up"
    sleep 20
  end
  
  def configure_elastic_ip
    if params.elastic_ip
      unless params.elastic_ip == instance.external_ip
        bright_p "attaching elastic ip #{params.elastic_ip}"
        Standup::EC2::ElasticIP.list[params.elastic_ip].attach_to instance
        
        puts "waiting until it's attached"
        instance.wait_until {instance.external_ip != params.elastic_ip}
      end
    else
      if ip = Standup::EC2::ElasticIP.list[instance.external_ip]
        bright_p "detaching elastic ip #{params.elastic_ip}"
        ip.detach
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
standup-0.6.9 scripts/ec2.rb
standup-0.6.8 scripts/ec2.rb
standup-0.6.7 scripts/ec2.rb
standup-0.6.6 scripts/ec2.rb
standup-0.6.5 scripts/ec2.rb
standup-0.6.4 scripts/ec2.rb
standup-0.6.3 scripts/ec2.rb
standup-0.6.2 scripts/ec2.rb
standup-0.6.1 scripts/ec2.rb
standup-0.6.0 scripts/ec2.rb
standup-0.5.14 scripts/ec2.rb
standup-0.5.13 scripts/ec2.rb
standup-0.5.11 scripts/ec2.rb
standup-0.5.10 scripts/ec2.rb
standup-0.5.9 scripts/ec2.rb
standup-0.5.8 scripts/ec2.rb
standup-0.5.7 scripts/ec2.rb
standup-0.5.6 scripts/ec2.rb
standup-0.5.5 scripts/ec2.rb
standup-0.5.4 scripts/ec2.rb