Class: AmazonInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon-instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment, project, config_dir, verbose = false) ⇒ AmazonInstance

Returns a new instance of AmazonInstance.



13
14
15
16
17
18
19
20
21
# File 'lib/amazon-instance.rb', line 13

def initialize(environment, project, config_dir, verbose=false)
  @config = load_general_config(config_dir)
  
  @config_dir = config_dir
  @environment = environment
  @verbose = verbose
  
  @project = Project::load(project, environment, config_dir)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/amazon-instance.rb', line 7

def config
  @config
end

#config_dirObject

Returns the value of attribute config_dir.



8
9
10
# File 'lib/amazon-instance.rb', line 8

def config_dir
  @config_dir
end

#environmentObject

Returns the value of attribute environment.



9
10
11
# File 'lib/amazon-instance.rb', line 9

def environment
  @environment
end

#projectObject

Returns the value of attribute project.



10
11
12
# File 'lib/amazon-instance.rb', line 10

def project
  @project
end

#verboseObject

Returns the value of attribute verbose.



11
12
13
# File 'lib/amazon-instance.rb', line 11

def verbose
  @verbose
end

Instance Method Details

#launch(ec2 = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/amazon-instance.rb', line 23

def launch(ec2=nil)
  ec2 = AmazonEC2.new(@config['access_key_id'],
                      @config['secret_key_id'],
                      URI.parse(@config['ec2_zone_url']).host,
                      URI.parse(@config['elb_zone_url']).host) if ec2.nil?

  group = @project[:security_group]
  
  raise 'Invalid security group: '+group unless ec2.valid_group?(group)

  print_message('Creating instance') if @verbose
  host = ec2.launch_instance(@environment, @project, @config_dir)
  print_message('Instance created', :ok) if @verbose

  # Wait till ssh port is open
  print_message('Checking SSH port') if @verbose
  ec2.sleep_till_ssh_is_open(host)
  print_message('SSH port open: '+host, :ok) if @verbose
  
  host
end