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.5.3 scripts/ec2.rb
standup-0.5.1 scripts/ec2.rb
standup-0.5.0 scripts/ec2.rb
standup-0.4.0 scripts/ec2.rb
standup-0.3.37 scripts/ec2.rb
standup-0.3.36 scripts/ec2.rb
standup-0.3.35 scripts/ec2.rb
standup-0.3.34 scripts/ec2.rb
standup-0.3.33 scripts/ec2.rb
standup-0.3.32 scripts/ec2.rb
standup-0.3.31 scripts/ec2.rb
standup-0.3.30 scripts/ec2.rb
standup-0.3.29 scripts/ec2.rb
standup-0.3.28 scripts/ec2.rb
standup-0.3.27 scripts/ec2.rb
standup-0.3.26 scripts/ec2.rb
standup-0.3.25 scripts/ec2.rb
standup-0.3.24 scripts/ec2.rb
standup-0.3.23 scripts/ec2.rb
standup-0.3.22 scripts/ec2.rb